Exemple #1
0
 def test_execute_valid_put_changed(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)
     actual = storage.execute(self._update_path_valid.search,
                              check_mode=False,
                              fail_silently=True)
     self.assertTrue(actual["changed"])
     self.assertFalse(actual["failed"])
     self.assertDictEqual(self._update_path_valid.search.__dict__,
                          actual["result"]["search"])
     self.assertDictEqual(self._update_entry_value,
                          actual["result"]["outcome"])
     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.vvv('Keepass: execute - %s' %
                  [{
                      'search': to_native(self._update_path_valid.search)
                  }, {
                      'check_mode': 'False'
                  }, {
                      'fail_silently': 'True'
                  }]),
         call.vv("KeePass: entry found - %s" %
                 self._update_path_valid.search),
         call.v("Keepass: database saved - %s" %
                database_details_upsert["location"]),
         call.vv("KeePass: entry found - %s" %
                 self._update_path_valid.search)
     ])
Exemple #2
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)
     ])
Exemple #3
0
 def test_get_valid_custom(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     has_changed, actual_entry = storage.get(self._query_custom.search,
                                             check_mode=False)
     self.assertFalse(has_changed)
     self.assertEqual(
         self._database_entry["custom_properties"]["test_custom_key"],
         actual_entry["test_custom_key"])
     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_custom.search),
         call.vv("KeePass: found property/file on entry - %s" %
                 self._query_custom.search)
     ])
Exemple #4
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)
     ])
Exemple #5
0
 def test_delete_valid_clone(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_clone.search,
                                                 check_mode=False)
     self.assertTrue(has_changed)
     self.assertDictEqual(dict(self._clone_entry, password=""),
                          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_clone.search),
         call.v("Keepass: database saved - %s" %
                database_details_delete["location"]),
         call.vv("KeePass: entry found - %s" % self._delete_clone.search)
     ])
Exemple #6
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)
     ])
Exemple #7
0
 def test__entry_insert_valid(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._insert_path_valid.search, check_mode=False)
     self.assertTrue(has_changed)
     self.assertDictEqual(self._insert_entry_value, 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 NOT found - %s" %
                 self._insert_path_valid.search),
         call.v("Keepass: database saved - %s" %
                database_details_upsert["location"]),
         call.vv("KeePass: entry found - %s" %
                 self._insert_path_valid.search)
     ])
Exemple #8
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)
     ])
Exemple #9
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)
     ])
Exemple #10
0
 def test_get_valid_entry(self):
     storage = KeepassDatabase(self._display, self._database_details_valid)
     has_changed, actual_entry = storage.get(self._search_path_valid.search,
                                             check_mode=False)
     self.assertFalse(has_changed)
     self.assertDictEqual(self._database_entry, 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 found - %s" %
                 self._search_path_valid.search)
     ])
Exemple #11
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),
     ])
Exemple #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),
     ])