mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Added tests to verify the password is obscured
The url test fails: see issue #528
This commit is contained in:
parent
7187d6408a
commit
cc047a445a
|
@ -1479,6 +1479,46 @@ class AutocommitTests(ConnectingTestCase):
|
|||
self.assertEqual(cur.fetchone()[0], 'on')
|
||||
|
||||
|
||||
class PasswordLeakTestCase(ConnectingTestCase):
|
||||
def setUp(self):
|
||||
super(PasswordLeakTestCase, self).setUp()
|
||||
PasswordLeakTestCase.dsn = None
|
||||
|
||||
class GrassingConnection(ext.connection):
|
||||
"""A connection snitching the dsn away.
|
||||
|
||||
This connection passes the dsn to the test case class even if init
|
||||
fails (e.g. connection error). Test that we mangle the dsn ok anyway.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
try:
|
||||
super(PasswordLeakTestCase.GrassingConnection, self).__init__(
|
||||
*args, **kwargs)
|
||||
finally:
|
||||
# The connection is not initialized entirely, however the C
|
||||
# code should have set the dsn, and it should have scrubbed
|
||||
# the password away
|
||||
PasswordLeakTestCase.dsn = self.dsn
|
||||
|
||||
def test_leak(self):
|
||||
self.assertRaises(psycopg2.DatabaseError,
|
||||
self.GrassingConnection, "dbname=nosuch password=whateva")
|
||||
|
||||
self.assert_('nosuch' in self.dsn)
|
||||
self.assert_('password' in self.dsn)
|
||||
self.assert_('whateva' not in self.dsn)
|
||||
|
||||
def test_url_leak(self):
|
||||
self.assertRaises(psycopg2.DatabaseError,
|
||||
self.GrassingConnection,
|
||||
"postgres://someone:whateva@localhost/nosuch")
|
||||
|
||||
self.assert_('nosuch' in self.dsn)
|
||||
self.assert_('someone' in self.dsn)
|
||||
self.assert_('whateva' not in self.dsn)
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user