mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-17 01:20:32 +03:00
Fixed keywords support for encrypt_password and tests completed
This commit is contained in:
parent
9e4f89a2a1
commit
abca14d601
|
@ -957,7 +957,7 @@ static PyMethodDef psycopgMethods[] = {
|
||||||
{"get_wait_callback", (PyCFunction)psyco_get_wait_callback,
|
{"get_wait_callback", (PyCFunction)psyco_get_wait_callback,
|
||||||
METH_NOARGS, psyco_get_wait_callback_doc},
|
METH_NOARGS, psyco_get_wait_callback_doc},
|
||||||
{"encrypt_password", (PyCFunction)psyco_encrypt_password,
|
{"encrypt_password", (PyCFunction)psyco_encrypt_password,
|
||||||
METH_VARARGS, psyco_encrypt_password_doc},
|
METH_VARARGS|METH_KEYWORDS, psyco_encrypt_password_doc},
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
|
@ -1421,6 +1421,13 @@ class TestEncryptPassword(ConnectingTestCase):
|
||||||
'md594839d658c28a357126f105b9cb14cfc'
|
'md594839d658c28a357126f105b9cb14cfc'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# keywords
|
||||||
|
self.assertEqual(
|
||||||
|
ext.encrypt_password(
|
||||||
|
password='psycopg2', user='ashesh',
|
||||||
|
scope=self.conn, algorithm='md5'),
|
||||||
|
'md594839d658c28a357126f105b9cb14cfc'
|
||||||
|
)
|
||||||
if libpq_version() < 100000:
|
if libpq_version() < 100000:
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
psycopg2.NotSupportedError,
|
psycopg2.NotSupportedError,
|
||||||
|
@ -1444,6 +1451,9 @@ class TestEncryptPassword(ConnectingTestCase):
|
||||||
)[:14], 'SCRAM-SHA-256$'
|
)[:14], 'SCRAM-SHA-256$'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertRaises(psycopg2.ProgrammingError,
|
||||||
|
ext.encrypt_password, 'psycopg2', 'ashesh', self.conn, 'abc')
|
||||||
|
|
||||||
@skip_after_postgres(10)
|
@skip_after_postgres(10)
|
||||||
def test_encrypt_password_pre_10(self):
|
def test_encrypt_password_pre_10(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -1451,11 +1461,27 @@ class TestEncryptPassword(ConnectingTestCase):
|
||||||
'md594839d658c28a357126f105b9cb14cfc'
|
'md594839d658c28a357126f105b9cb14cfc'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Encryption algorithm will be ignored for postgres version < 10, it
|
|
||||||
# will always use MD5.
|
|
||||||
self.assertRaises(psycopg2.ProgrammingError,
|
self.assertRaises(psycopg2.ProgrammingError,
|
||||||
ext.encrypt_password, 'psycopg2', 'ashesh', self.conn, 'abc')
|
ext.encrypt_password, 'psycopg2', 'ashesh', self.conn, 'abc')
|
||||||
|
|
||||||
|
def test_encrypt_md5(self):
|
||||||
|
self.assertEqual(
|
||||||
|
ext.encrypt_password('psycopg2', 'ashesh', algorithm='md5'),
|
||||||
|
'md594839d658c28a357126f105b9cb14cfc'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_encrypt_scram(self):
|
||||||
|
if libpq_version() >= 100000:
|
||||||
|
self.assert_(
|
||||||
|
ext.encrypt_password(
|
||||||
|
'psycopg2', 'ashesh', self.conn, 'scram-sha-256')
|
||||||
|
.startswith('SCRAM-SHA-256$'))
|
||||||
|
else:
|
||||||
|
self.assertRaises(psycopg2.NotSupportedError,
|
||||||
|
ext.encrypt_password,
|
||||||
|
password='psycopg2', user='ashesh',
|
||||||
|
scope=self.conn, algorithm='scram-sha-256')
|
||||||
|
|
||||||
|
|
||||||
class AutocommitTests(ConnectingTestCase):
|
class AutocommitTests(ConnectingTestCase):
|
||||||
def test_closed(self):
|
def test_closed(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user