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/about.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ This guide was authored and is maintained by:
9
9
10
10
This guide is meant to enable the implementation of detections as code in a generic manner, through the application of its use on Elastic detection rules (SIEM). We will continue to maintain and improve this guide, especially in the early stages of the new code and adoption, with intent of this eventually stabilizing.
11
11
12
+
If you have any feedback or questions along the way, the best place to reach us is in the public slack channel for [security-rules-dac](https://elasticstack.slack.com/archives/C06TE19EP09).
13
+
12
14
## Licensing and Use
13
15
14
16
See the LICENSE file for licensing information. This guide is provided as-is and is not officially supported by Elastic. It is intended to be a community-driven project, and we welcome contributions and feedback.
Copy file name to clipboardExpand all lines: docs/core_component_managing_detection_rules_in_a_vcs.md
+45-3Lines changed: 45 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -56,11 +56,53 @@ Reference the [Unit Tests](./internals_of_the_detection_rules_repo.md#unit-tests
56
56
57
57
### Custom Unit Tests
58
58
59
-
WIP
59
+
Custom unit tests enable teams to create and execute their own test suites tailored to their specific detection rules and operational requirements. By developing custom tests, teams can extend the validation beyond the pre-configured tests provided in the detection-rules repository. This approach is crucial for organizations that have unique rule logic or complex detection scenarios not covered by the standard test suite.
60
+
61
+
##### Sub-Component: Custom Test Development
62
+
63
+
Developing custom unit tests typically involves leveraging Python’s `pytest` framework, which is already installed as a python dependency into the Elastic detection-rules repo. Teams can create a separate directory for custom tests to ensure they are isolated from the general test suite, which allows for more controlled execution and easier maintenance.
64
+
65
+
###### Option 1: Isolated Test Environment
66
+
67
+
| Pros | Cons |
68
+
|------|------|
69
+
| - Ensures that custom tests do not interfere with general repository tests.</br> - Allows for targeted testing of specific rule logic or configurations unique to the team’s environment. | - Requires additional setup to integrate with existing CI/CD pipelines.</br> - May require duplication of some setup code or fixtures used in the main test suite.|
70
+
71
+
**Steps:**
72
+
73
+
1. Create a new directory within the forked detection-rules repository specifically for custom tests (e.g., `custom_tests/`).
74
+
2. Develop custom test scripts using `pytest`, focusing on the specific aspects of detection rules that are critical to your operational context.
75
+
3. Configure your CI/CD pipeline to include running these custom tests as part of the rule validation process.
76
+
4. Ensure that test results are reviewed and acted upon as part of the pull request review process.
77
+
78
+
###### Option 2: Integrated Test Suite
79
+
80
+
Integrate custom unit tests directly into the existing `pytest` configuration, using tags or markers to distinguish them from standard tests. This method leverages the full power of the existing testing infrastructure without needing significant modifications to the CI/CD setup.
60
81
61
82
| Pros | Cons |
62
-
| - | - |
63
-
|||
83
+
|------|------|
84
+
| - Leverages existing testing tools and configurations.</br> - Simplifies the CI/CD pipeline by using a single test command. | - Requires careful management of test markers to avoid executing unwanted tests.</br> - Potential for confusion or conflicts with upstream test cases if not managed properly.|
85
+
86
+
**Steps:**
87
+
88
+
1. Use `pytest` markers to tag custom tests, e.g., `@pytest.mark.custom`.
89
+
2. Modify the CI/CD test execution command to selectively run tests based on tags, e.g., `pytest -m custom`.
90
+
3. Maintain a clear documentation and naming convention for custom tests to ensure they are easily identifiable.
91
+
4. Regularly review and update the custom tests to align with any changes in detection rule structures or the underlying platform.
92
+
93
+
### Integration with CI/CD
94
+
95
+
Ensure that the integration of custom unit tests into the CI/CD pipeline is seamless and provides real-time feedback on the rule validation status. This integration is vital for maintaining the agility and responsiveness of the security operations team, enabling rapid deployment of validated and tested detection rules.
96
+
97
+
|Pros|Cons|
98
+
|-|-|
99
+
| - Immediate feedback on rule validation enhances the agility of rule deployment.</br> - Ensures that only thoroughly tested and validated rules are deployed, reducing the risk of false positives or ineffective detections. | - Requires continuous maintenance to align the test suite with evolving detection rules and threat landscapes.</br> - Initial setup and integration can be complex, requiring expertise in both security and CI/CD technologies.|
100
+
101
+
**Steps:**
102
+
103
+
1. Configure the CI/CD pipeline to automatically run custom unit tests on every commit to a designated branch or on pull request creation.
104
+
2. Set up notifications or integration with development tools to alert developers to test failures or issues detected during CI/CD.
105
+
3. Regularly review the test coverage and effectiveness, adjusting the test suite as necessary to cover new threat scenarios or rule changes.
0 commit comments