From 71745ae09b01a8aa3114e7991fb73c9664a2f436 Mon Sep 17 00:00:00 2001 From: Tejas Amol Hande <59686002+tejhande@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:29:08 +0530 Subject: [PATCH] Add logging functionality to Nmap parsing tests This commit introduces logging functionality to the Nmap parsing test suite. Changes include: - Import the logging module - Configure basic logging settings - Add log messages to each test method for better visibility - Fix a minor bug in the test_nmap_parse method Contributed by: @tejhande --- web/tests/test_nmap.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/web/tests/test_nmap.py b/web/tests/test_nmap.py index 337cf1f89..6c258a2fb 100644 --- a/web/tests/test_nmap.py +++ b/web/tests/test_nmap.py @@ -1,23 +1,24 @@ import logging import os import unittest - -os.environ['RENGINE_SECRET_KEY'] = 'secret' -os.environ['CELERY_ALWAYS_EAGER'] = 'True' - +import pathlib from celery.utils.log import get_task_logger from reNgine.settings import DEBUG from reNgine.tasks import parse_nmap_results, parse_nmap_vuln_output, parse_nmap_vulscan_output -import pathlib + +os.environ['RENGINE_SECRET_KEY'] = 'secret' +os.environ['CELERY_ALWAYS_EAGER'] = 'True' logger = get_task_logger(__name__) DOMAIN_NAME = os.environ['DOMAIN_NAME'] FIXTURES_DIR = pathlib.Path().absolute() / 'fixtures' / 'nmap_xml' +# Configure logging +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') + if not DEBUG: logging.disable(logging.CRITICAL) - class TestNmapParsing(unittest.TestCase): def setUp(self): self.nmap_vuln_single_xml = FIXTURES_DIR / 'nmap_vuln_single.xml' @@ -33,17 +34,25 @@ def setUp(self): def test_nmap_parse(self): for xml_file in self.all_xml: - vulns = parse_nmap_results(self.nmap_vuln_single_xml) - self.assertGreater(self.vulns, 0) + vulns = parse_nmap_results(xml_file) + self.assertGreater(len(vulns), 0) + logging.info(f"Parsed {len(vulns)} vulnerabilities from {xml_file}") def test_nmap_vuln_single(self): - pass + logging.info("Testing nmap_vuln_single") + # Implement test logic here def test_nmap_vuln_multiple(self): - pass + logging.info("Testing nmap_vuln_multiple") + # Implement test logic here def test_nmap_vulscan_single(self): - pass + logging.info("Testing nmap_vulscan_single") + # Implement test logic here def test_nmap_vulscan_multiple(self): - pass \ No newline at end of file + logging.info("Testing nmap_vulscan_multiple") + # Implement test logic here + +if __name__ == '__main__': + unittest.main()