Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Aug 21, 2024
1 parent 08826d4 commit d37459d
Show file tree
Hide file tree
Showing 21 changed files with 279 additions and 3 deletions.
12 changes: 9 additions & 3 deletions validator/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ void test_runner::validate_matches(const YAML::Node &expected, const YAML::Node
expect(expected.size(), obtained.size());

static std::set<std::string_view, std::less<>> scalar_operators{"match_regex", "phrase_match",
"exact_match", "ip_match", "equals", "is_sqli", "is_xss", "greater_than", "lower_than"};
"exact_match", "ip_match", "equals", "is_sqli", "is_xss", "exists", "greater_than",
"lower_than", "!match_regex", "!phrase_match", "!exact_match", "!ip_match", "!equals",
"!is_sqli", "!is_xss", "!exists"};

// Iterate through matches, assume they are in the same order as rule
// conditions for now.
Expand All @@ -240,7 +242,9 @@ void test_runner::validate_matches(const YAML::Node &expected, const YAML::Node
if (expected_match["key_path"].IsDefined()) {
expect(expected_match["key_path"], obtained_match["key_path"]);
}
expect(expected_match["value"], obtained_match["value"]);
if (expected_match["value"].IsDefined()) {
expect(expected_match["value"], obtained_match["value"]);
}
} else {
for (YAML::const_iterator it = expected_match.begin(); it != expected_match.end();
++it) {
Expand All @@ -255,7 +259,9 @@ void test_runner::validate_matches(const YAML::Node &expected, const YAML::Node
if (expected_param["key_path"].IsDefined()) {
expect(expected_param["key_path"], obtained_param["key_path"]);
}
expect(expected_param["value"], obtained_param["value"]);
if (expected_param["value"].IsDefined()) {
expect(expected_param["value"], obtained_param["value"]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with equals operator",
runs: [
{
persistent-input: {
rule1-input: "arachn"
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with equals operator",
runs: [
{
persistent-input: {
rule2-input: true
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with equals operator",
runs: [
{
persistent-input: {
rule3-input: 42
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with equals operator",
runs: [
{
persistent-input: {
rule4-input: 43
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with equals operator",
runs: [
{
persistent-input: {
rule5-input: 4.3
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
name: "Basic run with not equals operator",
runs: [
{
persistent-input: {
rule6-input: "arachn"
},
rules: [
{
6: [
{
address: rule6-input,
value: "arachn"
}
]
}
],
code: match
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with not equals operator and no match",
runs: [
{
persistent-input: {
rule6-input: "arachni"
},
code: ok
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
name: "Basic run with not equals operator",
runs: [
{
persistent-input: {
rule7-input: true
},
rules: [
{
7: [
{
address: rule7-input,
value: "true"
}
]
}
],
code: match
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with not equals operator and no match",
runs: [
{
persistent-input: {
rule7-input: false
},
code: ok
}
]
}
60 changes: 60 additions & 0 deletions validator/tests/rules/operators/equals/ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,63 @@ rules:
- address: rule5-input
type: float
value: 4.2
- id: "6"
name: rule6-string-not-equals
tags:
type: flow1
category: category
conditions:
- operator: "!equals"
parameters:
inputs:
- address: rule6-input
type: string
value: arachni
- id: "7"
name: rule7-bool-not-equals
tags:
type: flow1
category: category
conditions:
- operator: "!equals"
parameters:
inputs:
- address: rule7-input
type: boolean
value: false
- id: "8"
name: rule8-signed-not-equals
tags:
type: flow1
category: category
conditions:
- operator: "!equals"
parameters:
inputs:
- address: rule8-input
type: signed
value: -42
- id: "9"
name: rule9-unsigned-not-equals
tags:
type: flow1
category: category
conditions:
- operator: "!equals"
parameters:
inputs:
- address: rule9-input
type: unsigned
value: 42
- id: "10"
name: rule10-float-not-equals
tags:
type: flow1
category: category
conditions:
- operator: "!equals"
parameters:
inputs:
- address: rule10-input
type: float
value: 4.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
name: "Basic run with negated exact_match operator",
runs: [
{
persistent-input: {
rule2-input: "something else or other"
},
rules: [
{
2: [
{
address: rule2-input,
value: "something else or other"
}
]
}
],
code: match
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with negated exact_match operator and no match",
runs: [
{
persistent-input: {
rule2-input: "something else"
},
code: ok
}
]
}
14 changes: 14 additions & 0 deletions validator/tests/rules/operators/exact_match/ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ rules:
- "string"
- "other"
- "something else"
- id: "2"
name: rule2-ip-match
tags:
type: flow2
category: category
conditions:
- operator: "!exact_match"
parameters:
inputs:
- address: rule2-input
list:
- "string"
- "other"
- "something else"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
name: "Basic run with negated phrase_match",
runs: [
{
persistent-input: {
rule3-input: "asjkdansdasdkjasndk"
},
rules: [
{
3: [
{
address: rule3-input,
value: "asjkdansdasdkjasndk",
}
]
}
],
code: match
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name: "Basic run with negated phrase_match, no match",
runs: [
{
persistent-input: {
rule3-input: "asjkdansdstring00asdkjasndk"
},
code: ok
}
]
}
13 changes: 13 additions & 0 deletions validator/tests/rules/operators/phrase_match/ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ rules:
- string01
options:
enforce_word_boundary: true
- id: "3"
name: rule3-phrase-match
tags:
type: flow
category: category
conditions:
- operator: "!phrase_match"
parameters:
inputs:
- address: rule3-input
list:
- string00
- string01

0 comments on commit d37459d

Please sign in to comment.