Skip to content

Commit

Permalink
add ssl test and fix SASL Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Jan 26, 2024
1 parent 1eacf43 commit 254d58d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion micropg.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def _process_messages(self, obj):
data = self._read(ln)
assert _bytes_to_bint(data[:4]) == 0
elif auth_method == 10: # SASL
assert data[4:-2].decode('utf-8') == 'SCRAM-SHA-256'
assert b'SCRAM-SHA-256\x00\x00' in data
printable = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'
# len(printable) == 2**6
client_nonce = ''.join(printable[random.getrandbits(6)] for i in range(24))
Expand Down
17 changes: 8 additions & 9 deletions test_micropg.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@


# test ssl connection
#
# conn = micropg.connect(
# host='127.0.0.1', user='postgres', password='password', database='test_micropg', use_ssl=True
# )
# cur = conn.cursor()
# cur.execute("SELECT id, name FROM test_micropg")
# assert cur.fetchall() == [(1, "test"), (2, "test2")]
#
# conn.close()
conn = micropg.connect(
host='127.0.0.1', user='postgres', password='password', database='test_micropg', use_ssl=True
)
cur = conn.cursor()
cur.execute("SELECT id, name FROM test_micropg")
assert cur.fetchall() == [(1, "test"), (2, "test2")]

conn.close()

0 comments on commit 254d58d

Please sign in to comment.