From fe6e65db11030cfad1379f08c5a699081ee87787 Mon Sep 17 00:00:00 2001 From: ostorlab Date: Wed, 6 Dec 2023 14:53:40 +0100 Subject: [PATCH] - More specific asserts - Fix fast mode flag --- tests/conftest.py | 12 ++++++-- tests/nmap_wrapper_test.py | 61 +++++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d8e9c988..365ac01b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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", ) @@ -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", @@ -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, diff --git a/tests/nmap_wrapper_test.py b/tests/nmap_wrapper_test.py index 7161ce0b..850643b0 100644 --- a/tests/nmap_wrapper_test.py +++ b/tests/nmap_wrapper_test.py @@ -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( @@ -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( @@ -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", + ]