Skip to content

Commit

Permalink
Improve unit tests coverage in findings models
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosnt committed Dec 9, 2023
1 parent 76dcebb commit b34ac96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/backend/findings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ class OSINT(Finding):
def parse(
self, target: Target = None, accumulated: Dict[str, Any] = {}
) -> Dict[str, Any]:
if self.data_type in [OSINTDataType.IP, OSINTDataType.DOMAIN]:
return {
InputKeyword.TARGET.name.lower(): self.data,
InputKeyword.HOST.name.lower(): self.data,
InputKeyword.URL.name.lower(): self._get_url(self.data),
}
return {}
return {
InputKeyword.TARGET.name.lower(): self.data,
InputKeyword.HOST.name.lower(): self.data,
InputKeyword.URL.name.lower(): self._get_url(self.data),
} if self.data_type in [OSINTDataType.IP, OSINTDataType.DOMAIN] else {}

def defect_dojo(self) -> Dict[str, Any]:
return {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/tests/executors/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def test_get_arguments_only_findings(self) -> None:
@mock.patch("framework.models.BaseInput._get_url", get_url)
def test_get_arguments_only_required_findings(self) -> None:
self._success_get_arguments(
"-p http://10.10.10.10:80/ -p 80 -p WordPress -p CVE-2023-1111",
"-p 10.10.10.10 -p http://10.10.10.10:80/ -p 80 -p WordPress -p CVE-2023-1111",
[self.host, self.port, self.technology, self.vulnerability],
)

@mock.patch("framework.models.BaseInput._get_url", get_url)
def test_get_arguments_multiple_ports(self) -> None:
self._success_get_arguments(
"-p http://10.10.10.10:80/ -p 80,443 -p WordPress -p CVE-2023-1111",
"-p 10.10.10.10 -p http://10.10.10.10:80/ -p 80,443 -p WordPress -p CVE-2023-1111",
[
self.host,
self.port,
Expand All @@ -90,7 +90,7 @@ def _test_get_arguments_no_findings(self) -> None:
self.target.target = "10.10.10.12"
self.target.save(update_fields=["target"])
self._success_get_arguments(
f"-p http://10.10.10.12:80/login.php -p 80 -p /login.php -p Joomla -p CVE-2023-2222 -p {base64.b64encode('root:root'.encode()).decode() if self.authentication.type == AuthenticationType.BASIC else 'root'} -p {self.wordlist.path}",
f"-p 10.10.10.10 -p http://10.10.10.12:80/login.php -p 80 -p /login.php -p Joomla -p CVE-2023-2222 -p {base64.b64encode('root:root'.encode()).decode() if self.authentication.type == AuthenticationType.BASIC else 'root'} -p {self.wordlist.path}",
[],
[self.target_port],
[self.input_vulnerability],
Expand Down
2 changes: 1 addition & 1 deletion src/backend/tests/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _setup_fake_tool(self) -> None:
default=True,
)
for value, required, multiple, input_type_names in [
("host", False, False, [InputTypeName.OSINT]),
("host", False, False, [InputTypeName.OSINT, InputTypeName.HOST]),
(
"url",
True,
Expand Down

0 comments on commit b34ac96

Please sign in to comment.