def test_get_decrypted_password_specific_entry(self): store = PasswordStore(self.dir) password = '******' store.insert_password('hello.com', password) # When there is no 'password:'******'ELLO', store.get_decrypted_password('hello.com', entry=EntryType.password)) store.insert_password('hello.com', 'sdfsdf\npassword: pwd') self.assertEqual( 'pwd', store.get_decrypted_password('hello.com', entry=EntryType.password)) store.insert_password( 'hello', 'sdf\npassword: pwd\nusername: bob\nhost: salut.fr') self.assertEqual( 'bob', store.get_decrypted_password('hello', entry=EntryType.username)) self.assertEqual( 'salut.fr', store.get_decrypted_password('hello', entry=EntryType.hostname))
def test_get_decrypted_password_deeply_nested(self): store = PasswordStore(self.dir) self.assertFalse(os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C'))) store.insert_password('A/B/C/D/hello.com', 'Alice') store.insert_password('A/B/C/hello.com', 'Bob') self.assertEqual('Alice', store.get_decrypted_password('A/B/C/D/hello.com')) self.assertEqual('Bob', store.get_decrypted_password('A/B/C/hello.com')) self.assertTrue( os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C', 'D')))
def test_generate_password(self): store = PasswordStore(self.dir) store.generate_password('letters.net', digits=False, symbols=False) only_letters = store.get_decrypted_password('letters.net') self.assertTrue(only_letters.isalpha()) store.generate_password('alphanum.co.uk', digits=True, symbols=False) alphanum = store.get_decrypted_password('alphanum.co.uk') self.assertTrue(alphanum.isalnum()) for char in alphanum: self.assertTrue(char not in string.punctuation) store.generate_password('hundred.org', length=100) length_100 = store.get_decrypted_password('hundred.org') self.assertEqual(len(length_100), 100)
def test_get_decrypted_password_only_password(self): store = PasswordStore(self.dir) password = '******' store.insert_password('hello.com', password) self.assertEqual( 'ELLO', store.get_decrypted_password('hello.com') )
def test_get_decrypted_password_deeply_nested(self): store = PasswordStore(self.dir) self.assertFalse( os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C')) ) store.insert_password('A/B/C/D/hello.com', 'Alice') store.insert_password('A/B/C/hello.com', 'Bob') self.assertEqual( 'Alice', store.get_decrypted_password('A/B/C/D/hello.com') ) self.assertEqual( 'Bob', store.get_decrypted_password('A/B/C/hello.com') ) self.assertTrue( os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C', 'D')) )
def test_encrypt_decrypt(self): self.assertFalse( os.path.isfile(os.path.join(self.dir, 'hello.com.gpg'))) store = PasswordStore(self.dir) password = '******' store.insert_password('hello.com', password) self.assertTrue(os.path.isfile(os.path.join(self.dir, 'hello.com.gpg'))) self.assertEqual(password, store.get_decrypted_password('hello.com'))
def test_get_decrypted_password_specific_entry(self): store = PasswordStore(self.dir) password = '******' store.insert_password('hello.com', password) # When there is no 'password:'******'ELLO', store.get_decrypted_password('hello.com', entry=EntryType.password) ) store.insert_password('hello.com', 'sdfsdf\npassword: pwd') self.assertEqual( 'pwd', store.get_decrypted_password('hello.com', entry=EntryType.password) ) store.insert_password('hello.com', 'sdf\npassword: pwd\nusername: bob') self.assertEqual( 'bob', store.get_decrypted_password('hello.com', entry=EntryType.username) )
def test_generate_in_place(self): store = PasswordStore(self.dir) self.assertRaises(Exception, store.generate_password, 'nope.org', first_line_only=True) store.insert_password('nope.org', 'pw\nremains intact') store.generate_password('nope.org', length=3, first_line_only=True) new_content = store.get_decrypted_password('nope.org') new_password, _, remainder = new_content.partition('\n') self.assertNotEqual(new_password, 'pw') self.assertEqual(remainder, 'remains intact')
def test_encrypt_decrypt(self): self.assertFalse( os.path.isfile(os.path.join(self.dir, 'hello.com.gpg')) ) store = PasswordStore(self.dir) password = '******' store.insert_password('hello.com', password) self.assertTrue( os.path.isfile(os.path.join(self.dir, 'hello.com.gpg')) ) self.assertEqual( password, store.get_decrypted_password('hello.com') )