-
Notifications
You must be signed in to change notification settings - Fork 527
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
Modify Unit Test to Support Alert Suppression for EQL Sequences #4457
Conversation
Enhancement - GuidelinesThese guidelines serve as a reminder set of considerations when addressing adding a feature to the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
For testing theres more we can do.
|
Additional TestingSuccessful Rule Import to Repo❯ python -m detection_rules import-rules-to-repo /Users/shashankks/Downloads/rules_export_eql_supression.ndjson --required-only
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
[+] Building rule for /Users/shashankks/elastic_workspace/detection-rules/custom_rules/rules/eql_sequence_alert_supression.toml
1 results exported
1 rules converted
0 exceptions exported
0 actions connectors exported
(.venv)
detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected]
❯ Successful Rule Export from Kibana❯ python -m detection_rules kibana export-rules -r "4a06ba5b-09f1-4522-a91a-a40d014e2a37" -d /Users/shashankks/elastic_workspace/detection-rules/custom_rules
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
1 results exported
1 rules converted
0 exceptions exported
0 action connectors exported
1 rules saved to /Users/shashankks/elastic_workspace/detection-rules/custom_rules
0 exception lists saved to /Users/shashankks/elastic_workspace/detection-rules/custom_rules/exceptions
0 action connectors saved to /Users/shashankks/elastic_workspace/detection-rules/custom_rules/action_connectors
(.venv)
detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected] took 2s Successful Rule Import from KibanaExpected to Fail as rule exists ❯ python -m detection_rules kibana import-rules -id "4a06ba5b-09f1-4522-a91a-a40d014e2a37"
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
1 rule(s) failed to import!
- 4a06ba5b-09f1-4522-a91a-a40d014e2a37: (409) rule_id: "4a06ba5b-09f1-4522-a91a-a40d014e2a37" already exists
(.venv)
detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected] took 3s
❯ Changed rule id and name just to test ❯ python -m detection_rules kibana import-rules -id "4a06ba5b-09f1-4522-a91a-a40d014e2a38"
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
WARNING: Rule path does not match required path: eql_sequence_alert_supression.toml != eql_sequence_alert_supression_1.toml
1 rule(s) successfully imported
- 4a06ba5b-09f1-4522-a91a-a40d014e2a38
(.venv)
detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected] took 5s
rules_export_eql_supression.ndjson.txt make test-cliExporting rule by ID: 0a97b20f-4144-49ea-be32-b540ecc445de
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
Importing rule by ID: 0a97b20f-4144-49ea-be32-b540ecc445de
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
make test-remote-cliRunning detection-rules remote CLI tests...
Performing a quick rule alerts search...
Requires .detection-rules-cfg.json credentials file set.
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
No alerts detected
Performing a rule export...
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
- skipping Potential Abuse of Resources by High Token Count and Large Response Sizes - ValidationError
6 results exported
5 rules converted
0 exceptions exported
0 action connectors exported
5 rules saved to tmp-export
0 exception lists saved to /Users/shashankks/elastic_workspace/detection-rules/custom_rules/exceptions
0 action connectors saved to /Users/shashankks/elastic_workspace/detection-rules/custom_rules/action_connectors
1 errors saved to tmp-export/_errors.txt Custom Rule has an error local to my branch, It does not have the latest KEEP command for ES|QL |
For your additional testing, can you also run the unit tests between import and export? Remember the import and export only puts the rules through schema validation and not through the unit testing (which the two test scripts also do not check). Also as a note for the |
On main/pvt branch after importing the rule. The test is skipped detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected]
❯ python -m detection_rules import-rules-to-repo /Users/shashankks/Downloads/rules_export_eql_supression.ndjson --required-only
Loaded config file: /Users/shashankks/elastic_workspace/detection-rules/.detection-rules-cfg.json
█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
█ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
█▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
[+] Building rule for /Users/shashankks/elastic_workspace/detection-rules/rules/eql_sequence_alert_supression.toml
1 results exported
1 rules converted
0 exceptions exported
0 actions connectors exported
(.venv)
detection-rules on issue-4326 [$?] is 📦 v0.4.11 via 🐍 v3.12.8 (.venv) on ☁️ [email protected]
❯ pytest -v tests/test_all_rules.py::TestAlertSuppression::test_eql_non_sequence_support_only
========================================================== test session starts ===========================================================
platform darwin -- Python 3.12.8, pytest-8.1.1, pluggy-1.4.0 -- /Users/shashankks/elastic_workspace/detection-rules/.venv/bin/python3.12
cachedir: .pytest_cache
rootdir: /Users/shashankks/elastic_workspace/detection-rules
configfile: pyproject.toml
plugins: typeguard-3.0.2
collected 1 item
tests/test_all_rules.py::TestAlertSuppression::test_eql_non_sequence_support_only SKIPPED (Test is applicable to 8.14 --> 8.17...) [100%]
===================================================== 1 skipped in 62.47s (0:01:02) ====================================================== On say a older protected branch 8.17. The test runs and errors as expected ❯ pytest -v tests/test_all_rules.py::TestAlertSuppression::test_eql_non_sequence_support_only
========================================================== test session starts ===========================================================
platform darwin -- Python 3.12.8, pytest-8.1.1, pluggy-1.4.0 -- /Users/shashankks/elastic_workspace/detection-rules/.venv/bin/python3.12
cachedir: .pytest_cache
rootdir: /Users/shashankks/elastic_workspace/detection-rules
configfile: pyproject.toml
plugins: typeguard-3.0.2
collected 1 item
tests/test_all_rules.py::TestAlertSuppression::test_eql_non_sequence_support_only FAILED [100%]
================================================================ FAILURES ================================================================
________________________________________ TestAlertSuppression.test_eql_non_sequence_support_only _________________________________________
self = <tests.test_all_rules.TestAlertSuppression testMethod=test_eql_non_sequence_support_only>
@unittest.skipIf(PACKAGE_STACK_VERSION < Version.parse("8.14.0"),
"Test only applicable to 8.14+ stacks for eql non-sequence rule alert suppression feature.")
def test_eql_non_sequence_support_only(self):
for rule in self.all_rules:
if (
isinstance(rule.contents.data, EQLRuleData) and rule.contents.data.get("alert_suppression")
and rule.contents.data.is_sequence # noqa: W503
):
# is_sequence method not yet available during schema validation
# so we have to check in a unit test
> self.fail(
f"{self.rule_str(rule)} Sequence rules cannot have alert suppression"
)
E AssertionError: 4a06ba5b-09f1-4522-a91a-a40d014e2a37 - EQL Sequence Alert Supression -> Sequence rules cannot have alert suppression
tests/test_all_rules.py:1462: AssertionError
======================================================== short test summary info =========================================================
FAILED tests/test_all_rules.py::TestAlertSuppression::test_eql_non_sequence_support_only - AssertionError: 4a06ba5b-09f1-4522-a91a-a40d014e2a37 - EQL Sequence Alert Supression -> Sequence rules cannot have alert suppression
=========================================================== 1 failed in 53.61s ===========================================================
(.venv)
detection-rules on 8.17 [$!+?⇣] is 📦 v0.4.8 via 🐍 v3.12.8 (.venv) on ☁️ [email protected] took 54s
❯ |
Pull Request
Issue link(s): #4326
Summary - What I changed
test_eql_non_sequence_support_only
can be safely ignored.How To Test
8.18 Testing
8.17 Testing
Checklist
bug
,enhancement
,schema
,maintenance
,Rule: New
,Rule: Deprecation
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hoursContributor checklist