support/testing: add nmap runtime test

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
This commit is contained in:
Julien Olivain
2024-07-21 22:57:31 +02:00
committed by Arnout Vandecappelle
parent 8bb67c230b
commit 5510d2890f
2 changed files with 43 additions and 0 deletions

View File

@@ -1918,6 +1918,7 @@ F: support/testing/tests/package/test_netsnmp/
F: support/testing/tests/package/test_nftables.py
F: support/testing/tests/package/test_nftables/
F: support/testing/tests/package/test_ngrep.py
F: support/testing/tests/package/test_nmap.py
F: support/testing/tests/package/test_ntp.py
F: support/testing/tests/package/test_ntp/
F: support/testing/tests/package/test_numactl.py

View File

@@ -0,0 +1,42 @@
import os
import time
import infra.basetest
class TestNmap(infra.basetest.BRTest):
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_NMAP=y
BR2_PACKAGE_NMAP_NCAT=y
BR2_PACKAGE_NMAP_NMAP=y
BR2_TARGET_ROOTFS_CPIO=y
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
self.emulator.boot(arch="armv5",
kernel="builtin",
options=["-initrd", cpio_file])
self.emulator.login()
# Check the program can execute.
self.assertRunOk("nmap --version")
# We open few ports, using the nmap netcat "nc" commands.
ports = [21, 23, 25, 80]
for port in ports:
cmd = f"nc -l -p {port} </dev/null &>/dev/null &"
self.assertRunOk(cmd)
time.sleep(1 * self.timeout_multiplier)
# We run a local port scan. We should see in the output the
# ports we previously opened.
out, ret = self.emulator.run("nmap -n -sS 127.0.0.1", timeout=20)
self.assertEqual(ret, 0)
nmap_out = "\n".join(out)
for port in ports:
self.assertRegex(nmap_out, f"{port}/tcp *open")