Skip to content

Commit

Permalink
Merge branch 'main' into feature/boefje-normalizer-models
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie0x00 authored Jun 12, 2024
2 parents b53fcee + 02621ee commit 424e05c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
8 changes: 4 additions & 4 deletions boefjes/boefjes/plugins/kat_external_db/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ For example:
```json
{
"ip_addresses": [
{ "ip_address": "198.51.100.2" },
{ "ip_address": "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff" },
{ "ip_address": "192.0.2.0/24" }
{ "address": "198.51.100.2" },
{ "address": "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff" },
{ "address": "192.0.2.0/24" }
],
"domains": [{ "domain": "example.com" }]
"domains": [{ "name": "example.com" }]
}
```

Expand Down
4 changes: 2 additions & 2 deletions boefjes/boefjes/plugins/kat_external_db/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# are defined below.
# T O D O add these variables as normalizer settings in UI.
IP_ADDRESS_LIST_PATH = ["ip_addresses"]
IP_ADDRESS_ITEM_PATH = ["ip_address"]
IP_ADDRESS_ITEM_PATH = ["address"]
DOMAIN_LIST_PATH = ["domains"]
DOMAIN_ITEM_PATH = ["domain"]
DOMAIN_ITEM_PATH = ["name"]


def follow_path_in_dict(path, path_dict):
Expand Down
19 changes: 6 additions & 13 deletions boefjes/tests/test_scan_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@
from octopoes.models import DeclaredScanProfile
from tests.loading import get_dummy_data

RAW_DATA = json.dumps(
{"ip_addresses": [{"address": "127.0.0.1"}, {"address": "10.0.0.0"}], "domains": [{"name": "example.com"}]}
)


class ScanProfileTest(TestCase):
def test_normalizer_can_yield_scan_profiles(self):
local_repository = LocalPluginRepository(Path(__file__).parent.parent / "boefjes" / "plugins")
runner = LocalNormalizerJobRunner(local_repository)
meta = NormalizerMeta.model_validate_json(get_dummy_data("external_db.json"))

raw = json.dumps(
{
"ip_addresses": [{"ip_address": "127.0.0.1"}, {"ip_address": "10.0.0.0"}],
"domains": [{"domain": "example.com"}],
}
)
output = runner.run(meta, bytes(raw, "UTF-8"))
output = runner.run(meta, bytes(RAW_DATA, "UTF-8"))

self.assertEqual(1, len(output.observations))
self.assertEqual(3, len(output.observations[0].results))
Expand All @@ -49,12 +46,8 @@ def test_normalizer_can_yield_scan_profiles(self):
self.assertEqual(3, profile.level)

def test_job_handler_respects_whitelist(self):
raw = {
"ip_addresses": [{"ip_address": "127.0.0.1"}, {"ip_address": "10.0.0.0"}],
"domains": [{"domain": "example.com"}],
}
bytes_mock = mock.Mock()
bytes_mock.get_raw.return_value = json.dumps(raw)
bytes_mock.get_raw.return_value = RAW_DATA
octopoes = mock.Mock()

local_repository = LocalPluginRepository(Path(__file__).parent.parent / "boefjes" / "plugins")
Expand Down

0 comments on commit 424e05c

Please sign in to comment.