Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Extend results with optional URI parameter #282

Merged
merged 1 commit into from
Jun 11, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[#278](https://github.com/greenbone/ospd/pull/278)
[#279](https://github.com/greenbone/ospd/pull/279)
[#281](https://github.com/greenbone/ospd/pull/281)
- Extend results with optional argument URI [#282](https://github.com/greenbone/ospd/pull/282)

### Changes
- Modify __init__() method and use new syntax for super(). [#186](https://github.com/greenbone/ospd/pull/186)
Expand Down
9 changes: 8 additions & 1 deletion ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ def add_scan_log(
port: str = '',
test_id: str = '',
qod: str = '',
uri: str = '',
) -> None:
""" Adds a log result to scan_id scan. """

Expand All @@ -1454,6 +1455,7 @@ def add_scan_log(
test_id,
'0.0',
qod,
uri,
)

def add_scan_error(
Expand All @@ -1465,6 +1467,7 @@ def add_scan_error(
value: str = '',
port: str = '',
test_id='',
uri: str = '',
) -> None:
""" Adds an error result to scan_id scan. """
self.scan_collection.add_result(
Expand All @@ -1476,6 +1479,7 @@ def add_scan_error(
value,
port,
test_id,
uri,
)

def add_scan_host_detail(
Expand All @@ -1485,10 +1489,11 @@ def add_scan_host_detail(
hostname: str = '',
name: str = '',
value: str = '',
uri: str = '',
) -> None:
""" Adds a host detail result to scan_id scan. """
self.scan_collection.add_result(
scan_id, ResultType.HOST_DETAIL, host, hostname, name, value
scan_id, ResultType.HOST_DETAIL, host, hostname, name, value, uri
)

def add_scan_alarm(
Expand All @@ -1502,6 +1507,7 @@ def add_scan_alarm(
test_id: str = '',
severity: str = '',
qod: str = '',
uri: str = '',
) -> None:
""" Adds an alarm result to scan_id scan. """
self.scan_collection.add_result(
Expand All @@ -1515,4 +1521,5 @@ def add_scan_alarm(
test_id,
severity,
qod,
uri,
)
13 changes: 10 additions & 3 deletions ospd/resultlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def add_scan_host_detail_to_list(
hostname: str = '',
name: str = '',
value: str = '',
uri: str = '',
) -> None:
""" Adds a host detail result to result list. """
self.add_result_to_list(
ResultType.HOST_DETAIL, host, hostname, name, value,
ResultType.HOST_DETAIL, host, hostname, name, value, uri,
)

def add_scan_error_to_list(
Expand All @@ -54,10 +55,11 @@ def add_scan_error_to_list(
value: str = '',
port: str = '',
test_id='',
uri: str = '',
) -> None:
""" Adds an error result to result list. """
self.add_result_to_list(
ResultType.ERROR, host, hostname, name, value, port, test_id,
ResultType.ERROR, host, hostname, name, value, port, test_id, uri,
)

def add_scan_log_to_list(
Expand All @@ -69,6 +71,7 @@ def add_scan_log_to_list(
port: str = '',
test_id: str = '',
qod: str = '',
uri: str = '',
) -> None:
""" Adds log result to a list of results. """
self.add_result_to_list(
Expand All @@ -81,6 +84,7 @@ def add_scan_log_to_list(
test_id,
'0.0',
qod,
uri,
)

def add_scan_alarm_to_list(
Expand All @@ -93,6 +97,7 @@ def add_scan_alarm_to_list(
test_id: str = '',
severity: str = '',
qod: str = '',
uri: str = '',
) -> None:
""" Adds an alarm result to a result list. """
self.add_result_to_list(
Expand All @@ -105,6 +110,7 @@ def add_scan_alarm_to_list(
test_id,
severity,
qod,
uri,
)

def add_result_to_list(
Expand All @@ -118,6 +124,7 @@ def add_result_to_list(
test_id: str = '',
severity: str = '',
qod: str = '',
uri: str = '',
) -> None:

result = OrderedDict() # type: Dict
Expand All @@ -130,7 +137,7 @@ def add_result_to_list(
result['hostname'] = hostname
result['port'] = port
result['qod'] = qod

result['uri'] = uri
self._result_list.append(result)

def __iter__(self):
Expand Down
2 changes: 2 additions & 0 deletions ospd/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def add_result(
test_id: str = '',
severity: str = '',
qod: str = '',
uri: str = '',
) -> None:
""" Add a result to a scan in the table. """

Expand All @@ -98,6 +99,7 @@ def add_result(
result['hostname'] = hostname
result['port'] = port
result['qod'] = qod
result['uri'] = uri
results = self.scans_table[scan_id]['results']
results.append(result)

Expand Down
1 change: 1 addition & 0 deletions ospd/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def get_result_xml(result):
('test_id', result['test_id']),
('port', result['port']),
('qod', result['qod']),
('uri', result['uri']),
]:
result_xml.set(name, escape(str(value)))
if result['value'] is not None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self, type_, **kwargs):
self.test_id = ''
self.severity = ''
self.qod = ''
self.uri = ''
for name, value in kwargs.items():
setattr(self, name, value)

Expand Down