Пример #1
0
 def test_execute_valid_get(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     actual = storage.execute(self._search_path_valid.search,
                              check_mode=False,
                              fail_silently=True)
     self.assertFalse(actual["changed"])
     self.assertFalse(actual["failed"])
     self.assertDictEqual(self._search_path_valid.search.__dict__,
                          actual["result"]["search"])
     self.assertDictEqual(self._database_entry, actual["result"]["outcome"])
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vvv('Keepass: execute - %s' %
                  [{
                      'search': to_native(self._search_path_valid.search)
                  }, {
                      'check_mode': 'False'
                  }, {
                      'fail_silently': 'True'
                  }]),
         call.vv("KeePass: entry found - %s" %
                 self._search_path_valid.search)
     ])
Пример #2
0
 def test_execute_valid_delete_entry(self):
     database_details_delete = self._copy_database("temp_" + "".join(
         random.choices(string.ascii_uppercase + string.digits, k=16)))
     storage = KeepassDatabase(self._display, database_details_delete)
     actual = storage.execute(self._delete_entry.search,
                              check_mode=False,
                              fail_silently=False)
     self.assertTrue(actual["changed"])
     self.assertFalse(actual["failed"])
     self.assertDictEqual(self._delete_entry.search.__dict__,
                          actual["result"]["search"])
     self.assertEqual(None, actual["result"]["outcome"])
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                database_details_delete["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  database_details_delete["keyfile"]),
         call.v("Keepass: database opened - %s" %
                database_details_delete["location"]),
         call.vvv('Keepass: execute - %s' %
                  [{
                      'search': to_native(self._delete_entry.search)
                  }, {
                      'check_mode': 'False'
                  }, {
                      'fail_silently': 'False'
                  }]),
         call.vv("KeePass: entry found - %s" % self._delete_entry.search),
         call.v("Keepass: database saved - %s" %
                database_details_delete["location"])
     ])
Пример #3
0
 def test__open_valid_details(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     self.assertIsNotNone(storage._database)
     self.assertTrue(isinstance(storage._database, PyKeePass))
     self._display.assert_has_calls([
         call.v('Keepass: database found - %s' %
                self._database_details_valid["location"]),
         call.vvv('Keepass: keyfile found - %s' %
                  self._database_details_valid["keyfile"]),
         call.v('Keepass: database opened - %s' %
                self._database_details_valid["location"])
     ])
Пример #4
0
 def test_get_invalid(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     self.assertRaises(AttributeError, storage.get,
                       self._query_invalid.search, False)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry found - %s" % self._query_invalid.search)
     ])
Пример #5
0
 def test__entry_find_invalid_path_raise_error(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     self.assertRaises(AnsibleError, storage._entry_find,
                       self._search_path_invalid.search, None, True)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry NOT found - %s" %
                 self._search_path_invalid.search)
     ])
Пример #6
0
 def test_delete_valid_no_property_exists(self):
     database_details_delete = self._copy_database("temp_" + "".join(
         random.choices(string.ascii_uppercase + string.digits, k=16)))
     storage = KeepassDatabase(self._display, database_details_delete)
     self.assertRaises(AttributeError, storage.delete,
                       self._delete_invalid_property.search, False)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                database_details_delete["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  database_details_delete["keyfile"]),
         call.v("Keepass: database opened - %s" %
                database_details_delete["location"]),
         call.vv("KeePass: entry found - %s" %
                 self._delete_invalid_property.search)
     ])
Пример #7
0
 def test_get_valid_property(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     has_changed, actual_entry = storage.get(self._query_password.search,
                                             check_mode=False)
     self.assertFalse(has_changed)
     self.assertEqual(self._database_entry["password"],
                      actual_entry["password"])
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry found - %s" % self._query_password.search)
     ])
Пример #8
0
 def test__entry_find_invalid_by_path_no_error(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     actual_entry = storage._entry_find(self._search_path_invalid.search,
                                        ref_uuid=None,
                                        not_found_throw=False)
     self.assertEqual(None, actual_entry)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry NOT found - %s" %
                 self._search_path_invalid.search),
     ])
Пример #9
0
 def test__save_valid(self):
     database_details_save = self._copy_database("temp_" + "".join(
         random.choices(string.ascii_uppercase + string.digits, k=16)))
     storage = KeepassDatabase(self._display, database_details_save)
     self.assertTrue(isinstance(storage._database, PyKeePass))
     storage._save()
     self._display.assert_has_calls([
         call.v(u"Keepass: database found - %s" %
                database_details_save["location"]),
         call.vvv(u"Keepass: keyfile found - %s" %
                  database_details_save["keyfile"]),
         call.v(u"Keepass: database opened - %s" %
                database_details_save["location"]),
         call.v(u"Keepass: database saved - %s" %
                database_details_save["location"])
     ])
Пример #10
0
 def test__open_invalid_missing_keyfile(self):
     self.assertRaises(AnsibleParserError, KeepassDatabase, self._display,
                       self._database_details_invalid_keyfile_missing)
     self._display.assert_has_calls([
         call.v(u"Keepass: database found - %s" %
                self._database_details_invalid_keyfile_missing["location"])
     ])
Пример #11
0
 def test__entry_upsert_valid_noop(self):
     database_details_upsert = self._copy_database("temp_" + "".join(
         random.choices(string.ascii_uppercase + string.digits, k=16)))
     storage = KeepassDatabase(self._display, database_details_upsert)
     has_changed, updated_entry = storage._entry_upsert(
         self._noop_path_valid.search, check_mode=False)
     self.assertFalse(has_changed)
     self.assertDictEqual(self._clone_entry, updated_entry)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                database_details_upsert["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  database_details_upsert["keyfile"]),
         call.v("Keepass: database opened - %s" %
                database_details_upsert["location"]),
         call.vv("KeePass: entry found - %s" % self._noop_path_valid.search)
     ])
Пример #12
0
 def test__entry_find_valid_by_path(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     actual_entry = storage._entry_find(self._search_path_valid.search,
                                        ref_uuid=None,
                                        not_found_throw=True)
     self.assertDictEqual(self._database_entry,
                          EntryDump(actual_entry).__dict__)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry found - %s" %
                 self._search_path_valid.search),
     ])
Пример #13
0
 def test_delete_valid_entry(self):
     database_details_delete = self._copy_database("temp_" + "".join(
         random.choices(string.ascii_uppercase + string.digits, k=16)))
     storage = KeepassDatabase(self._display, database_details_delete)
     has_changed, deleted_entry = storage.delete(self._delete_entry.search,
                                                 check_mode=False)
     self.assertTrue(has_changed)
     self.assertEqual(None, deleted_entry)
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                database_details_delete["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  database_details_delete["keyfile"]),
         call.v("Keepass: database opened - %s" %
                database_details_delete["location"]),
         call.vv("KeePass: entry found - %s" % self._delete_entry.search),
         call.v("Keepass: database saved - %s" %
                database_details_delete["location"])
     ])
Пример #14
0
 def test_get_valid_file(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     has_changed, actual_entry = storage.get(self._query_file.search,
                                             check_mode=False)
     with open(self._database_details_valid["keyfile"], mode="rb") as file:
         self.assertFalse(has_changed)
         self.assertEqual(
             base64.b64encode(file.read()), actual_entry[os.path.basename(
                 self._database_details_valid["keyfile"])])
     self._display.assert_has_calls([
         call.v("Keepass: database found - %s" %
                self._database_details_valid["location"]),
         call.vvv("Keepass: keyfile found - %s" %
                  self._database_details_valid["keyfile"]),
         call.v("Keepass: database opened - %s" %
                self._database_details_valid["location"]),
         call.vv("KeePass: entry found - %s" % self._query_file.search),
         call.vv("KeePass: found property/file on entry - %s" %
                 self._query_file.search)
     ])
Пример #15
0
 def test__open_invalid_missing_password(self):
     self.assertRaises(CredentialsError, KeepassDatabase, self._display,
                       self._database_details_invalid_password_missing)
     self._display.assert_has_calls([
         call.v(
             u"Keepass: database found - %s" %
             self._database_details_invalid_password_missing["location"]),
         call.vvv(
             u"Keepass: keyfile found - %s" %
             self._database_details_invalid_password_missing["keyfile"])
     ])