Skip to content
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

tests: add keyword check to requires test #2133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions tests/requires-fail/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Similar to `../requires-ok` but does include one rule that will fail
to load. This is to test that a bad rule after "skipped" rule fails
out and is not recorded as skipped.

Ticket: https://redmine.openinfosecfoundation.org/issues/6710
2 changes: 1 addition & 1 deletion tests/requires-fail/test.rules
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ alert udp any any -> any any (vxlan_vni:10; requires: version >= 10; sid:2;)
alert http any any => any any (requires: version >= 10; sid:3;)
alert tcp any any -> any any (frame:smtp.not_supported; requires: version >= 10; sid:4;)

alert asdf any any -> any any (requires: version >= 6, foo bar; sid:102; rev:1;)
alert asdf any any -> any any (requires: version >= 6; foo: bar; sid:102; rev:1;)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we change this existing test ?

Copy link
Member Author

@jasonish jasonish Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the test to fail parsing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More details. In master, requires: version >= 6, foo bar is considered as all requirements met. So this rule fails out as asdf is unknown. With the PR, this rule is considered without requirements met, so the asdf is never parsed. This is to test somewhat of an edge case documented in ticket https://redmine.openinfosecfoundation.org/issues/6710, which I've added to the README now as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in the new version foo: bar; is totally unused then, right ?

And it would still be good to test requires: version >= 6, foo bar; somehow, right ?

7 changes: 5 additions & 2 deletions tests/requires-ok/test.rules
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ alert http any any -> any any (msg:"TEST Suricata >= 7 and < 8"; content:"uid=0"
# Rule for Suricata >= 7.0.3 but less than 8... Or >= 8.0.1
alert http any any -> any any (content:"uid=0"; requires: version >= 7.0.3 < 8 | >= 8.0.1; sid:9; rev:1;)

# Rule for Suricata >= 8.
alert http any any -> any any (msg:"TEST Suricata >= 8"; content:"uid=0"; requires: version >= 8.0.0; sid:8; rev:1;)
# Rule for Suricata >= 8, with pretty useless check for sid keyword.
alert http any any -> any any (msg:"TEST Suricata >= 8"; content:"uid=0"; requires: version >= 8.0.0, keyword sid; sid:8; rev:1;)

# Requires unknown keyword, should be marked as skipped.
alert http any any -> any any (msg:"TEST Requires unknown keyword"; requires: version >= 8, keyword foobar; sid:100; rev:1;)

# These rules have something invalid about them, but do follow the general rule
# structure, so should be eliminated by the requires statement.
Expand Down
4 changes: 2 additions & 2 deletions tests/requires-ok/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ checks:
count: 1
match:
event_type: stats
stats.detect.engines[0].rules_skipped: 5
stats.detect.engines[0].rules_skipped: 6
stats.detect.engines[0].rules_loaded: 2
stats.detect.engines[0].rules_failed: 0

Expand All @@ -60,6 +60,6 @@ checks:
count: 1
match:
event_type: stats
stats.detect.engines[0].rules_skipped: 6
stats.detect.engines[0].rules_skipped: 7
stats.detect.engines[0].rules_loaded: 1
stats.detect.engines[0].rules_failed: 0
Loading