Skip to content

Commit

Permalink
Merge pull request #36 from Ostorlab/feature/start_parsing_contact_names
Browse files Browse the repository at this point in the history
feature/emitting contact_names instead of contact_name
  • Loading branch information
3asm authored Nov 3, 2023
2 parents fd0c26d + cb958f6 commit c51d7a5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
8 changes: 2 additions & 6 deletions agent/result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ def parse_results(results: whois.parser.WhoisCom) -> Iterator[Dict[str, Any]]:
if name is not None:
names.add(name.lower())

contact_name = scan_output_dict.pop("name", "")
for name in names:
if name != "":
output = {
output: dict[str, str | list[str] | None] = {
"updated_date": get_isoformat(scan_output_dict.get("updated_date", [])),
"creation_date": get_isoformat(
scan_output_dict.get("creation_date", [])
Expand All @@ -52,10 +51,7 @@ def parse_results(results: whois.parser.WhoisCom) -> Iterator[Dict[str, Any]]:
"name_servers": get_list_from_string(
scan_output_dict.get("name_servers", "")
),
# TODO(ticket: os-3017): change the proto of v3.asset.domain_name.whois to send contact names.
"contact_name": contact_name[0]
if isinstance(contact_name, list)
else contact_name,
"contact_names": get_list_from_string(scan_output_dict.get("name", "")),
"dnssec": get_list_from_string(scan_output_dict.get("dnssec", "")),
}
for field in OPTIONAL_FIELDS:
Expand Down
51 changes: 50 additions & 1 deletion tests/whois_domain_agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@
"email": ["[email protected]", "[email protected]"],
}

SCAN_OUTPUT_NO_CONTACT_NAMES = {
"domain_name": "marksandspencer.at",
"registrar": "Key-Systems GmbH ( https://nic.at/registrar/404 )",
"name": [],
"org": ["Marks And Spencer P.l.c.", "IP TWINS S.A.S."],
"address": ["Waterside House", "35 North Wharf Road", "78 rue de Turbigo"],
"registrant_postal_code": ["W2 1NW", "75003"],
"city": ["London", "PARIS"],
"country": ["United Kingdom of Great Britain and Northern Ireland (the)", "France"],
"phone": ["+442087186494", "+33142789312"],
"fax": "+440207487267",
"updated_date": [
datetime.datetime(2021, 6, 23, 10, 10, 57),
datetime.datetime(2021, 6, 23, 10, 7, 2),
datetime.datetime(2023, 1, 4, 19, 30, 24),
],
"email": ["[email protected]", "[email protected]"],
}


def testAgentWhois_whenDomainNameAsset_emitsMessages(
scan_message: message.Message,
Expand Down Expand Up @@ -163,7 +182,37 @@ def testAgentWhois_whenMultipleContactNames_emitsMessages(
"[email protected]",
"[email protected]",
]
assert agent_mock[0].data["contact_name"] == "Catherine Shapiro"
assert agent_mock[0].data["contact_names"] == ["Catherine Shapiro", "Ivan SLY"]


def testAgentWhois_whenNoContactNames_emitsMessages(
scan_message: message.Message,
test_agent: whois_domain_agent.AgentWhoisDomain,
agent_persist_mock: Any,
mocker: plugin.MockerFixture,
agent_mock: List[message.Message],
) -> None:
"""Tests running the agent and emitting vulnerabilities."""
del agent_persist_mock

mock_whois = mocker.patch("whois.whois", return_value=SCAN_OUTPUT_NO_CONTACT_NAMES)
test_agent.start()
test_agent.process(scan_message)
mock_whois.assert_called_once()

assert len(agent_mock) > 0
assert agent_mock[0].selector == "v3.asset.domain_name.whois"
assert agent_mock[0].data["name"] == "marksandspencer.at"
assert agent_mock[0].data["updated_date"] == [
"2021-06-23T10:10:57",
"2021-06-23T10:07:02",
"2023-01-04T19:30:24",
]
assert agent_mock[0].data["emails"] == [
"[email protected]",
"[email protected]",
]
assert "contact_names" not in agent_mock[0].data


def testAgentWhois_whenDomainNameInputIsEmpty_NotEmitsMessages(
Expand Down

0 comments on commit c51d7a5

Please sign in to comment.