Skip to content

Commit

Permalink
- More specific asserts
Browse files Browse the repository at this point in the history
- Fix fast mode flag
  • Loading branch information
ostorlab committed Dec 6, 2023
1 parent 1e8424b commit fe6e65d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ def nmap_agent_fast_mode(
key="agent/ostorlab/nmap_agent",
bus_url="NA",
bus_exchange_topic="NA",
args=[],
args=[
utils_definitions.Arg(
name="fast_mode",
type="boolean",
value=json.dumps(True).encode(),
)
],
healthcheck_port=5301,
redis_url="redis://guest:guest@localhost:6379",
)
Expand All @@ -322,7 +328,7 @@ def nmap_agent_top_ports(
utils_definitions.Arg(
name="fast_mode",
type="boolean",
value=json.dumps("false").encode(),
value=json.dumps(False).encode(),
),
utils_definitions.Arg(
name="top_ports",
Expand Down Expand Up @@ -356,7 +362,7 @@ def nmap_agent_all_ports(
utils_definitions.Arg(
name="fast_mode",
type="boolean",
value=json.dumps("false").encode(),
value=json.dumps(False).encode(),
)
],
healthcheck_port=5301,
Expand Down
61 changes: 50 additions & 11 deletions tests/nmap_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ def testNmapWrapper_whenFastMode_returnCommand(

command = client.construct_command_host("127.0.0.1", 24)

assert "-F" in command
assert "--top-ports" not in command
assert "-p" not in command
assert command == [
"nmap",
"-sV",
"-n",
"-F",
"-T3",
"-sT",
"--script",
"banner",
"-sC",
"-oX",
"/tmp/xmloutput",
"-oN",
"/tmp/normal",
"127.0.0.1/24",
]


def testNmapWrapper_whenTopPortsUsed_returnCommand(
Expand All @@ -48,10 +61,23 @@ def testNmapWrapper_whenTopPortsUsed_returnCommand(

command = client.construct_command_host("127.0.0.1", 24)

assert "--top-ports" in command
assert "420" in command
assert "-F" not in command
assert "-p" not in command
assert command == [
"nmap",
"-sV",
"-n",
"--top-ports",
"420",
"-T3",
"-sT",
"--script",
"banner",
"-sC",
"-oX",
"/tmp/xmloutput",
"-oN",
"/tmp/normal",
"127.0.0.1/24",
]


def testNmapWrapper_whenAllTopPortsUsed_returnCommand(
Expand All @@ -73,7 +99,20 @@ def testNmapWrapper_whenAllTopPortsUsed_returnCommand(

command = client.construct_command_host("127.0.0.1", 24)

assert "-p" in command
assert "0-65535" in command
assert "-F" not in command
assert "--top-ports" not in command
assert command == [
"nmap",
"-sV",
"-n",
"-p",
"0-65535",
"-T3",
"-sT",
"--script",
"banner",
"-sC",
"-oX",
"/tmp/xmloutput",
"-oN",
"/tmp/normal",
"127.0.0.1/24",
]

0 comments on commit fe6e65d

Please sign in to comment.