Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging functionality to Nmap parsing tests #1330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions web/tests/test_nmap.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
logging.info("Testing nmap_vulscan_multiple")
# Implement test logic here

if __name__ == '__main__':
unittest.main()