Skip to content

Commit

Permalink
Fix errors in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosnt committed Apr 12, 2022
1 parent a628659 commit 407178e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
sudo apt install redis-server -y
sudo systemctl start redis-server
- name: Install Nmap to check its installation
run: sudo apt install nmap -y
- name: Install Nikto to check its installation
run: sudo apt install nikto -y

- name: Install Dirsearch to check its installation
run: |
Expand Down
6 changes: 3 additions & 3 deletions rekono/findings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ def defect_dojo(self) -> Dict[str, Any]:
Dict[str, Any]: Useful information for Defect-Dojo imports
'''
return {
'protocol': self.port.service,
'host': self.port.host.address,
'port': self.port.port,
'protocol': self.port.service if self.port else None,
'host': self.port.host.address if self.port else None,
'port': self.port.port if self.port else None,
'path': self.path
}

Expand Down
16 changes: 7 additions & 9 deletions rekono/testing/executions/test_base_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tasks.models import Task
from testing.mocks.defectdojo import (defect_dojo_error, defect_dojo_success,
defect_dojo_success_multiple)
from tools.enums import IntensityRank, Stage
from tools.enums import Stage
from tools.exceptions import ToolExecutionException
from tools.models import Argument, Configuration, Input, Intensity, Tool
from tools.tools.base_tool import BaseTool
Expand Down Expand Up @@ -135,7 +135,7 @@ def create_targets(self) -> None:
target=target,
tool=self.nikto,
configuration=self.configuration,
intensity=IntensityRank.NORMAL,
intensity=self.intensity.value,
status=Status.COMPLETED,
start=timezone.now(),
end=timezone.now(),
Expand Down Expand Up @@ -507,9 +507,8 @@ def test_tool_execution(self) -> None:
self.tool_instance.tool_execution(['/directory-not-found'], [], []) # Directory not found
except ToolExecutionException as ex:
self.tool_instance.on_error(stderr=str(ex)) # Test on_error feature
execution = Execution.objects.get(pk=self.new_execution.id) # Check execution data
self.assertEqual(Status.ERROR, execution.status)
self.assertEqual(str(ex).strip(), execution.output_error)
self.assertEqual(Status.ERROR, self.new_execution.status)
self.assertEqual(str(ex).strip(), self.new_execution.output_error)
errors_count += 1
self.tool_instance.tool_execution(['/'], [], []) # Valid ls execution
self.assertEqual(1, errors_count)
Expand All @@ -526,10 +525,9 @@ def process_findings(self, imported_in_defectdojo: bool) -> None:
self.tool_instance.run(self.targets, self.all_findings) # Run tool
worker = SimpleWorker([queue], connection=queue.connection) # Create RQ worker for findings queue
worker.work(burst=True) # Launch RQ worker
execution = Execution.objects.get(pk=self.new_execution.id) # Check execution status
self.assertEqual(Status.COMPLETED, execution.status)
self.assertEqual(self.nikto_report, execution.output_file)
self.assertEqual(imported_in_defectdojo, execution.imported_in_defectdojo)
self.assertEqual(Status.COMPLETED, self.new_execution.status)
self.assertEqual(self.nikto_report, self.new_execution.output_file)
self.assertEqual(imported_in_defectdojo, self.new_execution.imported_in_defectdojo)

@mock.patch('defectdojo.api.DefectDojo.request', defect_dojo_success) # Mocks Defect-Dojo response
def test_process_findings_with_defectdojo_target_engagement(self) -> None:
Expand Down
6 changes: 5 additions & 1 deletion rekono/tools/tools/base_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.db.models import Model
from django.db.models.fields.related_descriptors import \
ReverseManyToOneDescriptor
from django.db.models.query_utils import DeferredAttribute
from django.utils import timezone
from executions.models import Execution
from findings.models import Finding, Vulnerability
Expand Down Expand Up @@ -342,7 +343,10 @@ def process_findings(self) -> None:
continue
if (
hasattr(finding, key) and
not isinstance(getattr(finding.__class__, key), ReverseManyToOneDescriptor)
# Discard relations between findings
not isinstance(getattr(finding.__class__, key), ReverseManyToOneDescriptor) and
# Discard standard fields: Text, Number, etc.
not isinstance(getattr(finding.__class__, key), DeferredAttribute)
):
# Finding has a field that matches the current relation
setattr(finding, key, value) # Set relation between findings
Expand Down

0 comments on commit 407178e

Please sign in to comment.