Skip to content

Refactor API parsers #7002

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

Merged
merged 77 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d99baa4
Rename "..._api" parsers to "api_..."
kiblik Oct 17, 2022
c2a9faa
Reorder + categorise parsers in documentation
kiblik Oct 17, 2022
8c00b2e
Group same step to one definition
kiblik Oct 17, 2022
a5297f0
Fix some imports
kiblik Oct 17, 2022
d7988ec
Add Edgescan and fix some imports
kiblik Oct 17, 2022
809736c
Fix mocks
kiblik Oct 17, 2022
b9e097b
Fix next unittests
kiblik Oct 18, 2022
6cd56f0
Bump packageurl-python from 0.10.3 to 0.10.4 (#6997)
dependabot[bot] Oct 18, 2022
7bf9f69
Bump sqlalchemy from 1.4.41 to 1.4.42 (#6996)
dependabot[bot] Oct 18, 2022
ea481e8
Update rabbitmq:3.11.1-alpine Docker digest from 3.11.1 to 3.11.1-alp…
renovate[bot] Oct 18, 2022
868ac25
Update release-drafter/release-drafter action from v5.21.0 to v5.21.1…
renovate[bot] Oct 18, 2022
0abbd1f
Parse Veracode library_id for SCA to get the maven component name (#6…
coheigea Oct 20, 2022
5b65e65
Enable filtering Findings on steps_to_reproduce (#6970)
CharlieSears Oct 20, 2022
27107ff
Bump python from 3.8.14-slim-bullseye to 3.8.15-slim-bullseye (#6998)
dependabot[bot] Oct 20, 2022
2ef1ed0
Update asset and findings retrieval for Cobalt API parser (#7005)
Oct 20, 2022
43f1465
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Oct 21, 2022
122d313
Update tj-actions/changed-files action from v32 to v33 (.github/workf…
renovate[bot] Oct 22, 2022
64db9a2
Update rabbitmq Docker tag from 3.11.1 to v3.11.2 (docker-compose.yml…
renovate[bot] Oct 22, 2022
3bcf9c0
[FIX] Issues on disconnection and connection using Social Auth (#6066)
X0x1RG9f Oct 25, 2022
1b3feed
Fix out of SLA time (#7017)
coheigea Oct 26, 2022
1e0cbee
Add a HTML link in the references back to the Bugcrowd finding (#7018)
coheigea Oct 26, 2022
8f71136
Bump boto3 from 1.24.55 to 1.25.0 (#7022)
dependabot[bot] Oct 26, 2022
f0c3bbb
Update tj-actions/changed-files action from v33 to v34 (.github/workf…
renovate[bot] Oct 26, 2022
75a0a91
Update gcr.io/cloudsql-docker/gce-proxy Docker tag from 1.32.0 to v1.…
renovate[bot] Oct 26, 2022
0eef812
Bump uwsgi from 2.0.20 to 2.0.21 (#7023)
dependabot[bot] Oct 26, 2022
ab61689
Update postgres:14.5-alpine Docker digest from 14.5 to v (docker-comp…
renovate[bot] Oct 26, 2022
0a59059
Bump google-auth-oauthlib from 0.5.3 to 0.6.0 (#7021)
dependabot[bot] Oct 26, 2022
3b11349
Update rabbitmq:3.11.2-alpine Docker digest from 3.11.2 to 3.11.2-alp…
renovate[bot] Oct 26, 2022
49d1c15
Bump nginx from 1.23.1-alpine to 1.23.2-alpine (#7019)
dependabot[bot] Oct 26, 2022
e8262d2
Update stefanzweifel/git-auto-commit-action action from v4.15.1 to v4…
renovate[bot] Oct 26, 2022
a1dee6c
Add support for ZAP "XML with requests and responses" format (#7013)
malexmave Oct 26, 2022
ebab2ba
Bump pyjwt from 2.5.0 to 2.6.0 (#7010)
dependabot[bot] Oct 26, 2022
c801764
Update mysql:5.7.40 Docker digest from 5.7.40 to v (docker-compose.ym…
renovate[bot] Oct 26, 2022
90672ac
Bump pytz from 2022.4 to 2022.5 (#7003)
dependabot[bot] Oct 26, 2022
0fca78a
Don't save vulnerability Ids on a re-import if they're already define…
coheigea Oct 26, 2022
ba1ff77
Bump gitpython from 3.1.28 to 3.1.29 (#6966)
dependabot[bot] Oct 26, 2022
f798e3f
Add the ability to only create finding groups when you have more than…
coheigea Oct 26, 2022
5965ca8
Bump google-auth from 2.12.0 to 2.13.0 (#7004)
dependabot[bot] Oct 26, 2022
6e77256
Update postgres Docker tag from 14.5 to v15 (docker-compose.yml) (#6994)
renovate[bot] Oct 26, 2022
91e8962
Bump google-api-python-client from 2.64.0 to 2.65.0 (#7006)
dependabot[bot] Oct 26, 2022
e245cb1
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Nov 14, 2022
b66d1e4
Forms: allow to prefill values
kiblik Nov 14, 2022
a0d6603
Fix class names - to be able to load them
kiblik Nov 14, 2022
166168f
Better logging in tools.factory
kiblik Nov 14, 2022
55bf1f2
add 'get_api_scan_configuration_hints' + render hints
kiblik Nov 14, 2022
2bc0b89
Flake8
kiblik Nov 14, 2022
8812942
Cleanup of parsers
kiblik Nov 14, 2022
ff7eff1
Fix unittests
kiblik Nov 15, 2022
e0b3e18
Fix hint rendering
kiblik Nov 15, 2022
a459d3a
Add tool config unittests
kiblik Nov 15, 2022
3c77da2
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Nov 15, 2022
800ca4c
PoC: ToolConfig tests
kiblik Nov 18, 2022
1d0cab5
Add int test to all tests
kiblik Nov 18, 2022
9dfaf80
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Nov 21, 2022
dddefdd
Tests: Fix IDs
kiblik Nov 21, 2022
dbed0a9
Move scans in tests
kiblik Nov 21, 2022
e75374e
Revert "Tests: Fix IDs"
kiblik Nov 21, 2022
f1e617c
Fix intTest login, flake8
kiblik Nov 21, 2022
e856dce
Add BlackDuck to SCAN_APIS
kiblik Nov 21, 2022
439186e
Fix intTest path
kiblik Nov 21, 2022
0855d72
Fix test
kiblik Nov 21, 2022
0dca84a
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Nov 29, 2022
7e8e564
Fix edit page
kiblik Nov 30, 2022
3c23f25
Avoid 2 useless tests
kiblik Nov 30, 2022
b4bc745
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Dec 5, 2022
a0e57c3
Rebase Vulners
kiblik Dec 5, 2022
4827683
Fix double docs
kiblik Dec 5, 2022
68a984b
add VulnersAPI to factory
kiblik Dec 5, 2022
bc33b15
Small typos
kiblik Jan 5, 2023
fb1f7ec
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Jan 5, 2023
dcb272d
Fix VulnersAPI in factory
kiblik Jan 10, 2023
73e5c23
Fix unittests
kiblik Jan 10, 2023
6cd86d8
add tests
kiblik Jan 10, 2023
426df4e
Documentation - how to write API parsers
kiblik Jan 11, 2023
ecf98d7
Fix integration test
kiblik Jan 11, 2023
7780112
Docs: Add test_connection and test_product_connection [skip action]
kiblik Jan 11, 2023
8e31e35
Merge remote-tracking branch 'upstream/dev' into refactor_api_parsers
kiblik Jan 12, 2023
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 .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
"tests/dedupe_test.py",
"tests/check_various_pages.py",
"tests/notifications_test.py",
"tests/tool_config.py",
]
profile: ["mysql-rabbitmq", "postgres-redis"]
fail-fast: false
Expand Down
9 changes: 9 additions & 0 deletions docker/entrypoint-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,14 @@ else
# else
# echo "Error: Zap integration test failed"; exit 1
# fi

test="Tool Config integration tests"
echo "Running: $test"
if python3 tests/tool_config.py ; then
success $test
else
fail $test
fi

exec echo "Done Running all configured integration tests."
fi
36 changes: 36 additions & 0 deletions docs/content/en/contributing/how-to-write-a-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $ docker-compose build --build-arg uid=1000
|`unittests/scans/<parser_dir>/{many_vulns,no_vuln,one_vuln}.json` | Sample files containing meaningful data for unit tests. The minimal set.
|`unittests/tools/test_<parser_name>_parser.py` | Unit tests of the parser.
|`dojo/settings/settings.dist.py` | If you want to use a modern hashcode based deduplication algorithm
|`doc/content/en/integrations/parsers` | Documentation, what kind of file format is required and how it should be obtained

## Factory contract

Expand Down Expand Up @@ -91,6 +92,35 @@ class MyToolParser(object):

```

## API Parsers

Some reports are not reachable as a file that the user or pipeline can upload but the results of the scans have to be downloaded via API (or we just want to add support for multiple methods).
In that case, an "API parser" is needed. Core code is the same as a regular parser but there are some additional requirements.

### Which files do you need to modify? (API Parsers only)

| File | Purpose
|------- |--------
|`dojo/tools/api_<parser_dir>/api_client.py` | API client should perform all HTTP API calls and JSON with data from the API
|`dojo/tools/api_<parser_dir>/importer.py` | Importer should prepare the API client and process its results
|`dojo/tools/api_<parser_dir>/parser.py` | Parser should fetch processed data from the importer
|`unittests/tools/test_api_<parser_name>_parser.py` | Unit tests of the parser.
|`unittests/tools/test_api_<parser_name>_importer.py` | Unit tests of the importer.
|`dojo/tool_config/factory.py` | Parser must be listed in `SCAN_APIS`
|`unittests/test_tool_config.py` | Unit tests for content of hints and other metadata

### Factory contract (API Parsers only)

1. Parser directory *MUST* starts with `api_`
- ex: `dojo/tools/api_mytool`
2. class-name of parser *MUST* starts with `Api`
- ex: `ApiMytoolParser`
3. Parser *MUST* implements function `def api_scan_configuration_hint(self)` which returns a string with a hint, on how to configure service keys in Product ...TODO. Using of HTML tag `<b>` is required. Help will be rendered on the website.
- ex: `return 'the field <b>Service key 1</b> has to be set to ID of the project. <b>Service key 2</b> has to be set to the version of the project'`
4. Parser *MUST* implemets function `def requires_tool_type(self, scan_type)` which returns name of the required `Tool_Type`.
5. Parser *MUST NOT* create related `Tool_Type`. It will be created automatically based on the function `requires_tool_type`.
6. API client *SHOULD* implemets `def test_connection(self):` and `def test_product_connection(self, api_scan_configuration):` to be able to test connectivity and test permissions. It should return string with a sucessfull status (like _you have access to 125 projects_) or raise an exception.

## Template Generator

Use the [template](https://github.com/DefectDojo/cookiecutter-scanner-parser) parser to quickly generate the files required. To get started you will need to install [cookiecutter](https://github.com/cookiecutter/cookiecutter).
Expand Down Expand Up @@ -284,6 +314,12 @@ for finding in findings:
endpoint.clean()
```

### Tests API Parsers

Not only parser but also importer should be tested.
`patch` method from `unittest.mock` is usualy usefull for simulating API responses.
It is highly recommeded to use it.

## Other files that could be involved

### Change to the model
Expand Down
Loading