diff --git a/boefjes/katalogus/storage/memory.py b/boefjes/katalogus/storage/memory.py index e5cae86..910ef21 100644 --- a/boefjes/katalogus/storage/memory.py +++ b/boefjes/katalogus/storage/memory.py @@ -74,10 +74,10 @@ def get_all(self, organisation_id: str, plugin_id: str) -> Dict[str, str]: return {k.split(".", maxsplit=1)[1]: v for k, v in self._data[organisation_id].items() if plugin_id in k} def create(self, key: str, value: str, organisation_id: str, plugin_id: str) -> None: - self._data[organisation_id][f"{plugin_id}.{key}"] = value + self._data[organisation_id][f"{plugin_id}.{key}"] = str(value) def update_by_key(self, key: str, value: str, organisation_id: str, plugin_id: str) -> None: - self._data[organisation_id][f"{plugin_id}.{key}"] = value + self._data[organisation_id][f"{plugin_id}.{key}"] = str(value) def delete_by_key(self, key: str, organisation_id: str, plugin_id: str) -> None: del self._data[organisation_id][f"{plugin_id}.{key}"] diff --git a/boefjes/katalogus/tests/boefjes_test_dir/kat_test/kat_test_2/schema.json b/boefjes/katalogus/tests/boefjes_test_dir/kat_test/kat_test_2/schema.json index 236004f..7f1e42c 100644 --- a/boefjes/katalogus/tests/boefjes_test_dir/kat_test/kat_test_2/schema.json +++ b/boefjes/katalogus/tests/boefjes_test_dir/kat_test/kat_test_2/schema.json @@ -5,10 +5,15 @@ "api_key": { "title": "Api Key", "maxLength": 128, + "type": "integer" + }, + "optional_key": { + "title": "Optional Key", + "maxLength": 128, "type": "string" } }, "required": [ "api_key" ] -} \ No newline at end of file +} diff --git a/boefjes/katalogus/tests/test_plugin_service.py b/boefjes/katalogus/tests/test_plugin_service.py index a008186..9ebbbcb 100644 --- a/boefjes/katalogus/tests/test_plugin_service.py +++ b/boefjes/katalogus/tests/test_plugin_service.py @@ -206,3 +206,23 @@ def test_removing_mandatory_setting_disables_plugin(self): plugin = self.service.by_plugin_id(plugin_id, self.organisation) self.assertFalse(plugin.enabled) + + def test_adding_integer_settings_with_faulty_value_given_constraints(self): + plugin_id = "kat_test_2" + + self.service.settings_storage.update_by_key("api_key", "24", self.organisation, plugin_id) + + with self.assertRaises(SettingsNotConformingToSchema) as ctx: + self.service.update_by_id("test-repo-2", plugin_id, self.organisation, True) + + self.assertIn("'24' is not of type 'integer'", ctx.exception.message) + + self.service.settings_storage.update_by_key("api_key", 24, self.organisation, plugin_id) # Will become a string + + with self.assertRaises(SettingsNotConformingToSchema) as ctx: + self.service.update_by_id("test-repo-2", plugin_id, self.organisation, True) + + self.assertIn("'24' is not of type 'integer'", ctx.exception.message) + + plugin = self.service.by_plugin_id(plugin_id, self.organisation) + self.assertFalse(plugin.enabled) diff --git a/boefjes/plugins/kat_nmap/schema.json b/boefjes/plugins/kat_nmap/schema.json index 2900904..5d3854f 100644 --- a/boefjes/plugins/kat_nmap/schema.json +++ b/boefjes/plugins/kat_nmap/schema.json @@ -4,7 +4,7 @@ "properties": { "TOP_PORTS": { "title": "TOP_PORTS", - "type": "integer", + "type": "string", "description": "Scan TOP_PORTS most common ports. Defaults to 250." }, "PROTOCOL": { @@ -14,7 +14,5 @@ "description": "Scan 'udp' or 'tcp'. Defaults to 'tcp'." } }, - "required": [ - - ] -} \ No newline at end of file + "required": [] +}