You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`unittests/scans/<parser_dir>/{many_vulns,no_vuln,one_vuln}.json` | Sample files containing meaningful data for unit tests. The minimal set.
40
40
|`unittests/tools/test_<parser_name>_parser.py` | Unit tests of the parser.
41
41
|`dojo/settings/settings.dist.py` | If you want to use a modern hashcode based deduplication algorithm
42
+
|`doc/content/en/integrations/parsers` | Documentation, what kind of file format is required and how it should be obtained
42
43
43
44
## Factory contract
44
45
@@ -91,6 +92,35 @@ class MyToolParser(object):
91
92
92
93
```
93
94
95
+
## API Parsers
96
+
97
+
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).
98
+
In that case, an "API parser" is needed. Core code is the same as a regular parser but there are some additional requirements.
99
+
100
+
### Which files do you need to modify? (API Parsers only)
101
+
102
+
| File | Purpose
103
+
|------- |--------
104
+
|`dojo/tools/api_<parser_dir>/api_client.py` | API client should perform all HTTP API calls and JSON with data from the API
105
+
|`dojo/tools/api_<parser_dir>/importer.py` | Importer should prepare the API client and process its results
106
+
|`dojo/tools/api_<parser_dir>/parser.py` | Parser should fetch processed data from the importer
107
+
|`unittests/tools/test_api_<parser_name>_parser.py` | Unit tests of the parser.
108
+
|`unittests/tools/test_api_<parser_name>_importer.py` | Unit tests of the importer.
109
+
|`dojo/tool_config/factory.py` | Parser must be listed in `SCAN_APIS`
110
+
|`unittests/test_tool_config.py` | Unit tests for content of hints and other metadata
111
+
112
+
### Factory contract (API Parsers only)
113
+
114
+
1. Parser directory *MUST* starts with `api_`
115
+
- ex: `dojo/tools/api_mytool`
116
+
2. class-name of parser *MUST* starts with `Api`
117
+
- ex: `ApiMytoolParser`
118
+
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.
119
+
- 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'`
120
+
4. Parser *MUST* implemets function `def requires_tool_type(self, scan_type)` which returns name of the required `Tool_Type`.
121
+
5. Parser *MUST NOT* create related `Tool_Type`. It will be created automatically based on the function `requires_tool_type`.
122
+
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.
123
+
94
124
## Template Generator
95
125
96
126
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).
@@ -284,6 +314,12 @@ for finding in findings:
284
314
endpoint.clean()
285
315
```
286
316
317
+
### Tests API Parsers
318
+
319
+
Not only parser but also importer should be tested.
320
+
`patch` method from `unittest.mock` is usualy usefull for simulating API responses.
0 commit comments