/usr/lib/python3/dist-packages/postgresql/test/test_pgpassfile.py is in python3-postgresql 1.1.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | ##
# .test.test_pgpassfile
##
import unittest
from .. import pgpassfile as client_pgpass
from io import StringIO
passfile_sample = """
# host:1111:dbname:user:password1
host:1111:dbname:user:password1
*:1111:dbname:user:password2
*:*:dbname:user:password3
# Comment
*:*:*:user:password4
*:*:*:usern:password4.5
*:*:*:*:password5
"""
passfile_sample_map = {
('user', 'host', '1111', 'dbname') : 'password1',
('user', 'host', '1111', 'dbname') : 'password1',
('user', 'foo', '1111', 'dbname') : 'password2',
('user', 'foo', '4321', 'dbname') : 'password3',
('user', 'foo', '4321', 'db,name') : 'password4',
('uuser', 'foo', '4321', 'db,name') : 'password5',
('usern', 'foo', '4321', 'db,name') : 'password4.5',
('foo', 'bar', '19231', 'somedbn') : 'password5',
}
difficult_passfile_sample = r"""
host\\:1111:db\:name:u\\ser:word1
*:1111:\:dbname\::\\user\\:pass\:word2
foohost:1111:\:dbname\::\\user\\:pass\:word3
"""
difficult_passfile_sample_map = {
('u\\ser','host\\','1111','db:name') : 'word1',
('\\user\\','somehost','1111',':dbname:') : 'pass:word2',
('\\user\\','someotherhost','1111',':dbname:') : 'pass:word2',
# More specific, but comes after '*'
('\\user\\','foohost','1111',':dbname:') : 'pass:word2',
('','','','') : None,
}
class test_pgpass(unittest.TestCase):
def runTest(self):
sample1 = client_pgpass.parse(StringIO(passfile_sample))
sample2 = client_pgpass.parse(StringIO(difficult_passfile_sample))
for k, pw in passfile_sample_map.items():
lpw = client_pgpass.lookup_password(sample1, k)
self.assertEqual(lpw, pw,
"password lookup incongruity, expecting %r got %r with %r"
" in \n%s" %(
pw, lpw, k, passfile_sample
)
)
for k, pw in difficult_passfile_sample_map.items():
lpw = client_pgpass.lookup_password(sample2, k)
self.assertEqual(lpw, pw,
"password lookup incongruity, expecting %r got %r with %r"
" in \n%s" %(
pw, lpw, k, difficult_passfile_sample
)
)
if __name__ == '__main__':
unittest.main()
|