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

Report cleanup #297

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions framework/python/src/common/testreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ def generate_module_reports(self, json_data):

#Add styling to the markdown
content = content.replace('<table>', '<table class=markdown-table>')
content = content.replace('<h1>', '<h1 class=markdown-header>')
content = content.replace('<h2>', '<h2 class=markdown-header>')
content = content.replace('<h1>', '<h1 class=markdown-header-h1>')
content = content.replace('<h2>', '<h2 class=markdown-header-h2>')

content = self.generate_module_pages(json_data=json_data,
module_reports=content)
Expand Down Expand Up @@ -804,10 +804,24 @@ def generate_css(self):
padding: 8px;
}

.markdown-header{
.markdown-header-h1{
margin-left:20px;
margin-top:20px;
margin-bottom:20px;
margin-right:0px;

font-size: 2em;
font-weight: bold;
}

.markdown-header-h2{
margin-left:20px;
margin-top:20px;
margin-bottom:20px;
margin-right:0px;

font-size: 1.5em;
font-weight: bold;
}

.module-page-content{
Expand Down
42 changes: 26 additions & 16 deletions modules/test/dns/python/src/dns_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,40 @@ def generate_module_report(self):

total_responses = sum(1 for row in dns_table_data
if row['Type'] == 'Response')
#total_requests = len(dns_table_data)

# Find the maximum length of 'Destination' values
max_data_length = max(len(row['Data']) for row in dns_table_data) if len(dns_table_data)>0 else 8

table_content = ''
for row in dns_table_data:
table_content += f'''| {row['Source']: ^12} | {row['Destination']: ^13} | {row['Type']: ^9} | {row['Data']: ^{max_data_length}} |\r'''

# Dynamically adjust the header width based on the longest 'Destination' content
header = f'''| {'Source': ^12} | {'Destination': ^{13}} | {'Type': ^9} | {'Data': ^{max_data_length}} |'''
header_line = f'''|{'-' * 14}|{'-' * 15}|{'-' * 11}|{'-' * (max_data_length + 2)}|'''

summary = '## Summary'
summary += f'''\n- Requests to local DNS server: {local_requests}'''
summary += f'''\n- Requests to external DNS servers: {external_requests}'''
summary += f'''\n- Total DNS requests: {total_requests}'''
summary += f'''\n- Total DNS responses: {total_responses}'''

markdown_template = f'''# DNS Module
\r{header}\r{header_line}\r{table_content}\r{summary}
'''
if (total_requests + total_responses) > 0:

# Find the maximum length of 'Destination' values
max_data_length = max(len(row['Data']) for row in dns_table_data) if len(dns_table_data)>0 else 8

LOGGER.debug("Markdown Report:\n" + markdown_template)
table_content = ''
for row in dns_table_data:
table_content += (f'''| {row['Source']: ^12} '''
f'''| {row['Destination']: ^13} '''
f'''| {row['Type']: ^9} '''
f'''| {row['Data']: ^{max_data_length}} |\n''')

header = (f'''| {'Source': ^12} '''
f'''| {'Destination': ^{13}} '''
f'''| {'Type': ^{9}} '''
f'''| {'Data': ^{max_data_length}} |''')
header_line = (f'''|{'-' * 14}|{'-' * 15}|{'-' * 11}|'''
f'''{'-' * (max_data_length + 2)}''')

markdown_template = (f'''# DNS Module\n'''
f'''\n{header}\n{header_line}\n{table_content}\n{summary}''')

else:
markdown_template = (f'''# DNS Module\n'''
f'''\n- No DNS traffic detected\n'''
f'''\n{summary}''')
LOGGER.debug('Markdown Report:\n' + markdown_template)

# Use os.path.join to create the complete file path
report_path = os.path.join(self._results_dir, MODULE_REPORT_FILE_NAME)
Expand Down
1 change: 0 additions & 1 deletion modules/test/nmap/python/src/nmap_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def generate_module_report(self):
# Use os.path.join to create the complete file path
nmap_scan_results_file = os.path.join(self._nmap_scan_results_path,
NMAP_SCAN_RESULTS_SCAN_FILE)
LOGGER.info('Scan Results File:\n' + str(nmap_scan_results_file))

# Read the nmap scan results
with open(nmap_scan_results_file, 'r', encoding='utf-8') as file:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 11 additions & 9 deletions testing/unit/dns/dns_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@

MODULE = 'dns'

# Define the file paths
# Define the directories
TEST_FILES_DIR = 'testing/unit/' + MODULE
OUTPUT_DIR = TEST_FILES_DIR + '/output/'
# TEMP_DIR = TEST_FILES_DIR + '/temp/'
LOCAL_REPORT = TEST_FILES_DIR + '/dns_report_local.md'
LOCAL_REPORT_NO_DNS = TEST_FILES_DIR + '/dns_report_local_no_dns.md'
OUTPUT_DIR = os.path.join(TEST_FILES_DIR,'output/')
REPORTS_DIR = os.path.join(TEST_FILES_DIR,'reports/')
CAPTURES_DIR = os.path.join(TEST_FILES_DIR,'captures/')

LOCAL_REPORT = os.path.join(REPORTS_DIR,'dns_report_local.md')
LOCAL_REPORT_NO_DNS = os.path.join(REPORTS_DIR,'dns_report_local_no_dns.md')
CONF_FILE = 'modules/test/' + MODULE + '/conf/module_config.json'
# Define the capture files to be used for the test
DNS_SERVER_CAPTURE_FILE = TEST_FILES_DIR + '/dns.pcap'
STARTUP_CAPTURE_FILE = TEST_FILES_DIR + '/startup.pcap'
MONITOR_CAPTURE_FILE = TEST_FILES_DIR + '/monitor.pcap'

# Define the capture files to be used for the test
DNS_SERVER_CAPTURE_FILE = os.path.join(CAPTURES_DIR,'dns.pcap')
STARTUP_CAPTURE_FILE = os.path.join(CAPTURES_DIR,'startup.pcap')
MONITOR_CAPTURE_FILE = os.path.join(CAPTURES_DIR,'monitor.pcap')

class TLSModuleTest(unittest.TestCase):
"""Contains and runs all the unit tests concerning DNS behaviors"""
Expand Down
1 change: 0 additions & 1 deletion testing/unit/dns/dns_report_local.md

This file was deleted.

11 changes: 0 additions & 11 deletions testing/unit/dns/dns_report_local_no_dns.md

This file was deleted.

Loading
Loading