Skip to content

Commit 6be5915

Browse files
authored
Handle missing password authentication cleanly (MagicStack#1351)
1 parent 00319a9 commit 6be5915

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎asyncpg/protocol/coreproto.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ cdef class CoreProtocol:
675675
WriteBuffer msg
676676

677677
msg = WriteBuffer.new_message(b'p')
678-
msg.write_bytestring(self.password.encode(self.encoding))
678+
msg.write_bytestring((self.password or '').encode(self.encoding))
679679
msg.end_message()
680680

681681
return msg

‎tests/test_connect.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ async def test_auth_password_cleartext(self):
270270
user='password_user',
271271
password='wrongpassword')
272272

273+
async def test_auth_password_cleartext_without_password(self):
274+
with self.assertRaises(asyncpg.InvalidPasswordError):
275+
await self._try_connect(
276+
user='password_user', password=lambda: None)
277+
273278
async def test_auth_password_cleartext_callable(self):
274279
def get_correctpassword():
275280
return CORRECT_PASSWORD

0 commit comments

Comments
 (0)