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
Copy file name to clipboardExpand all lines: docs/IntelOwl/contribute.md
+47-3Lines changed: 47 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,40 @@ You may want to look at a few existing examples to start to build a new one, suc
211
211
After having written the new python module, you have to remember to:
212
212
213
213
1. Put the module in the `file_analyzers` or `observable_analyzers` directory based on what it can analyze
214
-
2. Remember to use `_monkeypatch()` in its class to create automated tests for the new analyzer. This is a trick to have tests in the same class of its analyzer.
214
+
2.**Write Unit Tests for the Analyzer**
215
+
- Monkeypatch-based tests are no longer used.
216
+
- All analyzers are now tested using pure unit tests that focus only on the business logic. This ensures that our tests are fast, deterministic, and independent of external services.
217
+
- To make writing tests easier, base test classes are available for both observable analyzers and file analyzers. These base classes handle all common setup and mocking, so you only need to define analyzer-specific behavior.
- Place your test file under the appropriate directory (`observable_analyzers` or `file_analyzers`).
223
+
- Example structure:
224
+
```
225
+
tests/
226
+
└── api_app/
227
+
└── analyzers_manager/
228
+
└── unit_tests/
229
+
├── observable_analyzers/
230
+
│ ├── test_mynewanalyzer.py
231
+
│ └── base_test_class.py
232
+
└── file_analyzers/
233
+
├── ...
234
+
```
235
+
236
+
- Your test case should:
237
+
- Each analyzer test class should inherit from the base test class provided in the same directory.
238
+
- Define which analyzer is under test by assigning it to analyzer_class - Set `analyzer_class = YourAnalyzerClass`
239
+
- Override `get_mocked_response()` to simulate the data your analyzer would normally produce. All external dependencies (e.g., API calls, file I/O, subprocesses) must be mocked — no real external calls should happen.
240
+
This method should return a list of all applied patches, ensuring that every external call used by the analyzer is properly mocked.
241
+
- Optionally override `get_extra_config()` to provide additional runtime config that are not already defined inside the base test class.
242
+
243
+
- **For reference**, you can find numerous analyzer test examples already implemented under `tests/api_app/analyzers_manager/unit_tests/observable_analyzers/` and `file_analyzers/`.
244
+
245
+
246
+
> Note: If your analyzer is Docker-based, you can refer to tests/api_app/analyzers_manager/unit_tests/file_analyzers/test_suricate.py for an example of how such analyzers are tested.
247
+
215
248
3. Create the configuration inside django admin in `Analyzers_manager/AnalyzerConfigs` (\* = mandatory, ~ = mandatory on conditions)
216
249
1. \*Name: specific name of the configuration
217
250
2. \*Python module: <module_name>.<class_name>
@@ -628,11 +661,11 @@ Follow these guides to understand how to start to contribute to them while devel
628
661
629
662
## How to test the application
630
663
631
-
IntelOwl makes use of the django testing framework and the `unittest` library for unit testing of the API endpoints and End-to-End testing of the analyzers and connectors.
664
+
IntelOwl makes use of the django testing framework and the `unittest` library for unit testing of the API endpoints and End-to-End testing of the analyzers and connectors.
632
665
633
666
### Configuration
634
667
635
-
- In the encrypted folder `tests/test_files.zip` (password: "intelowl") there are some files that you can use for testing purposes.
668
+
- In the encrypted folder `tests/test_files.zip` (password: "intelowl") there are some files that you can use for testing purposes. The async_tests/ dir has mainly transactional test cases as they are run separately from other unit tests.
636
669
637
670
- With the following environment variables you can customize your tests:
638
671
@@ -678,6 +711,17 @@ To test a plugin in real environment, i.e. without mocked data, we suggest that
678
711
Meaning that you have your plugin configured, you have selected a correct observable/file to analyze,
679
712
and the final report shown in the GUI of IntelOwl is exactly what you wanted.
680
713
714
+
##### Running Tests for a Specific Analyzer
715
+
716
+
To test a particular analyzer, locate its corresponding unittest file inside: tests/api_app/analyzers_manager/unit_tests/[observable_analyzers / file_analyzers]
717
+
718
+
719
+
Once you’ve identified the test file, you can run it individually with:
720
+
721
+
```bash
722
+
docker exec -ti intelowl_uwsgi python manage.py test tests.api_app.analyzers_manager.unit_tests.observable_analyzers.<test_file>
0 commit comments