Skip to content

Commit e96529b

Browse files
author
pr-relay
committed
fix: handle missing cleartext password cleanly
1 parent db8ecc2 commit e96529b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

asyncpg/protocol/coreproto.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,14 @@ cdef class CoreProtocol:
573573

574574
elif status == AUTH_REQUIRED_PASSWORD:
575575
# AuthenticationCleartextPassword
576-
self.result_type = RESULT_OK
577-
self.auth_msg = self._auth_password_message_cleartext()
576+
if self.password is None:
577+
self.result_type = RESULT_FAILED
578+
self.result = apg_exc.InterfaceError(
579+
'password authentication requested by server, '
580+
'but no password was supplied')
581+
else:
582+
self.result_type = RESULT_OK
583+
self.auth_msg = self._auth_password_message_cleartext()
578584

579585
elif status == AUTH_REQUIRED_PASSWORDMD5:
580586
# AuthenticationMD5Password

tests/test_connect.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ async def test_auth_password_cleartext(self):
266266
user='password_user',
267267
password='wrongpassword')
268268

269+
async def test_auth_password_cleartext_without_password(self):
270+
with self.assertRaisesRegex(
271+
asyncpg.InterfaceError, 'no password was supplied'):
272+
await self._try_connect(
273+
user='password_user', password=None)
274+
269275
async def test_auth_password_cleartext_callable(self):
270276
def get_correctpassword():
271277
return CORRECT_PASSWORD

0 commit comments

Comments
 (0)