def setUp(self): self.database_file = 'assets/password_keyfile.kdbx' self.password = '******' self.key_file = 'assets/password_keyfile.key' self.database = Database(self.database_file, password=self.password, key_file=self.key_file)
def setUp(self): self.database_file_1 = 'assets/keyfile.kdbx' self.key_file_1 = 'assets/keyfile.key' self.database_1 = Database(self.database_file_1, key_file=self.key_file_1) self.database_file_2 = 'assets/keyfile_2.kdbx' self.key_file_2 = 'assets/keyfile_2.key' self.database_2 = Database(self.database_file_2, key_file=self.key_file_2)
class UnicodePasswordDatabaseTest(AbstractDatabaseTest): def setUp(self): self.database_file = 'assets/password_unicode.kdbx' self.password = '******' self.database = Database(self.database_file, password=self.password) def test_get_info(self): self.assertSetEqual(set(self.database.get_info().keys()), {"uuid", "name", "description", "cipher", "kdf"}) self.assertEqual(self.database.get_info().get('name'), "Passwörter") def test_export_xml(self): self.assertIn('<DatabaseName>Passwörter</DatabaseName>', self.database.export(format='xml'))
class PasswordDatabaseTest(AbstractDatabaseTest): def setUp(self): self.database_file = 'assets/password.kdbx' self.password = '******' self.database = Database(self.database_file, password=self.password) def test_has_password(self): self.assertTrue(self.database.has_password()) def test_get_password(self): self.assertEqual(self.database.get_password(), self.password) def test_has_key_file(self): self.assertFalse(self.database.has_key_file()) def test_get_key_file(self): self.assertIsNone(self.database.get_key_file())
def create_database(path: str, password: str = None, key_file: str = None, decryption_time: int = None) -> IDatabase: """ A wrapper around :py:meth:`~entity.Database.create`. :return: The newly created database :raise IOError: If the database file already exists and `decryption_time` has been specified. """ database = Database(path, password, key_file) if not database.exists(): database.create(decryption_time) elif decryption_time is not None: raise IOError( 'Decryption time cannot be assured for existing database at "{}"'. format(path)) return database
class KeyFileDatabaseTest(AbstractDatabaseTest): def setUp(self): self.database_file = 'assets/keyfile.kdbx' self.key_file = 'assets/keyfile.key' self.database = Database(self.database_file, key_file=self.key_file) def test_has_password(self): self.assertFalse(self.database.has_password()) def test_get_password(self): self.assertIsNone(self.database.get_password()) def test_has_key_file(self): self.assertTrue(self.database.has_key_file()) def test_get_key_file(self): self.assertEqual(self.database.get_key_file(), os.path.join(os.getcwd(), self.key_file))
class CompareIdenticalDatabaseTest(CompareDatabaseTest): def setUp(self): self.database_1 = Database('assets/merge.kdbx', password='******') self.database_2 = Database('assets/merge.kdbx', password='******') def test_compare(self): changes = self.database_1.compare(self.database_2) self.assertSetEqual( changes, {'Merge Test entry/Test entry with local on top/under Root'})
class PasswordAndKeyFileDatabaseTest(AbstractDatabaseTest): def setUp(self): self.database_file = 'assets/password_keyfile.kdbx' self.password = '******' self.key_file = 'assets/password_keyfile.key' self.database = Database(self.database_file, password=self.password, key_file=self.key_file) def test_has_password(self): self.assertTrue(self.database.has_password()) def test_get_password(self): self.assertEqual(self.database.get_password(), self.password) def test_has_key_file(self): self.assertTrue(self.database.has_key_file()) def test_get_key_file(self): self.assertEqual(self.database.get_key_file(), os.path.join(os.getcwd(), self.key_file))
class CompareDatabaseTest(unittest.TestCase): def setUp(self): self.database_1 = Database('assets/new.kdbx', password='******') self.database_2 = Database('assets/merge.kdbx', password='******') def test_compare(self): changes = self.database_1.compare(self.database_2) self.assertSetEqual( changes, { 'Creating missing Test entry [898c7067a74e4aada0d2a3cf590f8c2a]', 'Adding custom data KPXC_DECRYPTION_TIME_PREFERENCE [1000]', 'Adding custom data FDO_SECRETS_EXPOSED_GROUP [{00000000-0000-0000-0000-000000000000}]' })
class CompareKeyfileDatabaseTest(CompareDatabaseTest): def setUp(self): self.database_file_1 = 'assets/keyfile.kdbx' self.key_file_1 = 'assets/keyfile.key' self.database_1 = Database(self.database_file_1, key_file=self.key_file_1) self.database_file_2 = 'assets/keyfile_2.kdbx' self.key_file_2 = 'assets/keyfile_2.key' self.database_2 = Database(self.database_file_2, key_file=self.key_file_2) def test_compare(self): changes = self.database_1.compare(self.database_2) self.assertSetEqual( changes, { 'Merge Entry/Entry 2 with alien on top under Root', 'Synchronizing from newer source Entry [a81dc75e22344e92b27e78b2af04f251]' })
def setUp(self): self.database_file = 'assets/keyfile.kdbx' self.key_file = 'assets/keyfile.key' self.database = Database(self.database_file, key_file=self.key_file)
def setUp(self): self.database_file = 'assets/password.kdbx' self.password = '******' self.database = Database(self.database_file, password=self.password)
def setUp(self): self.database_1 = Database('assets/merge.kdbx', password='******') self.database_2 = Database('assets/merge.kdbx', password='******')
def setUp(self): self.database_file = 'assets/password_unicode.kdbx' self.password = '******' self.database = Database(self.database_file, password=self.password)