Skip to content

Commit

Permalink
update unittest form more converge
Browse files Browse the repository at this point in the history
  • Loading branch information
ybadaoui-ostorlab committed Aug 19, 2024
1 parent f37c7b6 commit 3f374af
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agent/nmap_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def _emit_fingerprints(

if type(os_class) is list and len(os_class) > 0:
os_class = os_class[0]
else:
elif os_class == []:
continue

fingerprint_data = {
Expand Down
56 changes: 56 additions & 0 deletions tests/nmap_agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,59 @@ def testAgent_whenOsMatchIsEmptyList_fingerprintMessageShouldHaveOs(
nmap_test_agent.process(ipv4_msg)

assert len(agent_mock) == 2


def testAgent_whenOsClassIsEmptyList_fingerprintMessageShouldHaveOs(
nmap_test_agent: nmap_agent.NmapAgent,
agent_mock: List[message.Message],
ipv4_msg: message.Message,
agent_persist_mock: Dict[Union[str, bytes], Union[str, bytes]],
mocker: plugin.MockerFixture,
) -> None:
"""Ensure the agents emits the detected library name with its version."""
del agent_persist_mock
product_fake_output = {
"nmaprun": {
"host": {
"address": {"@addr": "127.0.0.1", "@addrtype": "ipv4"},
"ports": {
"port": {
"@portid": "22",
"@protocol": "tcp",
"state": {
"@state": "open",
"@reason": "syn-ack",
"@reason_ttl": "0",
},
"service": {
"@name": "ssh",
"@product": "OpenSSH",
"@version": "7.4",
"cpe": "cpe:/a:openbsd:openssh:7.4",
},
}
},
"os": {
"osmatch": [
[
{
"@name": "Microsoft Windows 10 1511",
"@accuracy": "88",
"@line": "69505",
"osclass": [],
}
]
]
},
}
}
}

mocker.patch(
"agent.nmap_wrapper.NmapWrapper.scan_hosts",
return_value=(product_fake_output, ""),
)

nmap_test_agent.process(ipv4_msg)

assert len(agent_mock) == 2

0 comments on commit 3f374af

Please sign in to comment.