Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #60 from minvws/fix/integer-settings
Browse files Browse the repository at this point in the history
Fix nmap schema and add test showing integers are not yet supported
  • Loading branch information
underdarknl authored Jan 16, 2023
2 parents fae750e + 5753ddf commit 43fd461
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions boefjes/katalogus/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
20 changes: 20 additions & 0 deletions boefjes/katalogus/tests/test_plugin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 3 additions & 5 deletions boefjes/plugins/kat_nmap/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -14,7 +14,5 @@
"description": "Scan 'udp' or 'tcp'. Defaults to 'tcp'."
}
},
"required": [

]
}
"required": []
}

0 comments on commit 43fd461

Please sign in to comment.