Skip to content

fix anchore reimport, sync reimport logic API<->UI, add unit tests - #3629

Merged
valentijnscholten merged 15 commits into
DefectDojo:devfrom
valentijnscholten:test-import-reimport-ui
Jan 15, 2021
Merged

valentijnscholten merged 15 commits into
DefectDojo:devfrom
valentijnscholten:test-import-reimport-ui

Conversation

@valentijnscholten

@valentijnscholten valentijnscholten commented Jan 14, 2021 •

Copy link
Copy Markdown
Member
some parsers generate 1 finding for each vulnerable file for each vulnerability
i.e
#: title                     : sev : file_path
1: CVE-2020-1234 jquery      : 1   : /file1.jar
2: CVE-2020-1234 jquery      : 1   : /file2.jar

if we don't filter on file_path, we would find 2 existing findings
and the logic below will get confused and map all incoming findings
from the reimport on the first finding

for Anchore we fix this here, we may need a broader fix (and testcases)
or we may need to change the matching logic here to use the same logic
as the deduplication logic (hashcode fields)

     if scan_type == 'Anchore Engine Scan':
           if item.file_path:
                findings = findings.filter(file_path=item.file_path)

I have refactored the existing 9 testscases to be run against the APIv2 and UI.

And added an extra testcase for anchore. In the first unit test run I did not yet include the fix described above and you can see the test failing. This test is using a real world anchore report: https://github.com/DefectDojo/django-DefectDojo/pull/3629/checks?check_run_id=1707458436#step:9:40351

I fixed some other things a long the way:

  • There was a diffrence in logic between the API reimport and UI import when the matching found multiple existing findins for a finding in the reimported report. This is now made in sync, UI now follows API logic
  • don't run dedupe on findings that we are closing
  • remove some push_to_jira=False as that is the default
  • use the same way to calculate differences between new items / reactivated items / closed items in API and UI
  • add some DEBUG logging to help future troubles

Question for a future PR:

  • Should we add this fix for all scanners?
  • Should we use the deduplication config in reimport instead of hardcoded field matching?
  • Should we raise an error if we detect scenario's where the reimport can't handle it correctly?
  • Should we add instructions for people to recalculate their hashes if they change dedupe config?

@valentijnscholten valentijnscholten changed the title unit tests: test import/reimport also on UI fix anchore reimport, sync reimport logic API<->UI, add unit tests Jan 15, 2021
@madchap
madchap self-requested a review January 15, 2021 08:56
@madchap

madchap commented Jan 15, 2021

Copy link
Copy Markdown
Contributor

fyi @yilmi

Comment thread dojo/test/views.py
status.mitigated = False
status.last_modified = timezone.now()
status.save(push_to_jira=push_to_jira)
status.save()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always false anyways, so good to remove 👍

@madchap madchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed live with @valentijnscholten, looks good to me. Thanks.

@madchap
madchap requested review from a team January 15, 2021 11:24
@valentijnscholten
valentijnscholten merged commit aa7be20 into DefectDojo:dev Jan 15, 2021
@madchap madchap mentioned this pull request Jan 19, 2021
9alexx3 pushed a commit to 9alexx3/django-DefectDojo that referenced this pull request Aug 12, 2026
…efectDojo#3629)

* unit tests: test import/reimport also on UI
* import/reimport: fix anchore matching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants