Skip to content

Commit 08d0afc

Browse files
fzipiclaude
andcommitted
Use JSON regression test with a build-gated resource instead of a standalone test binary
Per @airween's review feedback: the regression test framework already supports skipping a JSON test case at runtime via a "resource" key (test/regression/regression.cc), matching it against a list of compile-time-enabled features (WITH_CURL, WITH_LUA, WITH_LIBXML2, etc.). Register "regex-dollar-endonly" the same way under MODSEC_REGEX_DOLLAR_ENDONLY, and add test/test-cases/regression/operator-rx-dollar-endonly.json gated on it, covering both a single-line match (still blocks) and a multi-line ARGS value (anchors no longer span line breaks). Builds without the flag skip these two cases; builds with it pass. This replaces the standalone regex_multiline_test.cc binary and its Makefile.am/test-suite.in/test-suite.sh wiring from the previous commit, which needlessly diverged from how every other test in this project is structured. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent d595832 commit 08d0afc

7 files changed

Lines changed: 99 additions & 119 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ src/headers.mk
3636
/test/rules_optimization
3737
/test/regression_tests
3838
/test/unit_tests
39-
/test/regex_multiline_test
4039
/test-driver
4140
/test/massif.out.*
4241
/test/benchmark/benchmark

test/Makefile.am

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,6 @@ unit_tests_LDFLAGS = \
7070
$(YAJL_LDFLAGS)
7171

7272

73-
# regex_multiline_test
74-
#
75-
# Direct coverage for the Regex(pattern, ignoreCase, multiLine) parameter
76-
# behind --enable-regex-dollar-endonly, independent of the rest of the
77-
# SecRules pipeline exercised by unit_tests/regression_tests.
78-
79-
noinst_PROGRAMS += regex_multiline_test
80-
regex_multiline_test_SOURCES = \
81-
unit/regex_multiline_test.cc
82-
83-
regex_multiline_test_LDFLAGS = \
84-
-L$(top_builddir)/src/.libs/ \
85-
-lmodsecurity \
86-
-lpthread \
87-
-lm \
88-
-lstdc++
89-
90-
regex_multiline_test_CPPFLAGS = \
91-
-I$(top_srcdir)/ \
92-
-g \
93-
-I$(top_builddir)/headers \
94-
$(GLOBAL_CPPFLAGS) \
95-
$(PCRE_CFLAGS) \
96-
$(PCRE2_CFLAGS)
97-
98-
9973
unit_tests_CPPFLAGS = \
10074
-Icommon \
10175
-I$(top_srcdir)/ \

test/regression/regression.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ int main(int argc, char **argv)
430430
#ifdef WITH_LIBXML2
431431
resources.push_back("libxml2");
432432
#endif
433+
#ifdef MODSEC_REGEX_DOLLAR_ENDONLY
434+
resources.push_back("regex-dollar-endonly");
435+
#endif
433436

434437
#ifdef NO_LOGS
435438
std::cout << "Test utility cannot work without logging support." \
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[
2+
{
3+
"enabled": 1,
4+
"version_min": 300000,
5+
"resource": "regex-dollar-endonly",
6+
"title": "Testing Operator :: @rx --enable-regex-dollar-endonly (single-line match still blocks)",
7+
"client": {
8+
"ip": "200.249.12.31",
9+
"port": 123
10+
},
11+
"server": {
12+
"ip": "200.249.12.31",
13+
"port": 80
14+
},
15+
"request": {
16+
"headers": {
17+
"Host": "localhost",
18+
"User-Agent": "curl/7.38.0",
19+
"Accept": "*/*",
20+
"Content-Length": "0"
21+
},
22+
"uri": "/?param1=hello%20world",
23+
"method": "GET",
24+
"body": [
25+
""
26+
]
27+
},
28+
"response": {
29+
"headers": {
30+
"Date": "Mon, 13 Jul 2015 20:02:41 GMT",
31+
"Last-Modified": "Sun, 26 Oct 2014 22:33:37 GMT",
32+
"Content-Type": "text/html",
33+
"Content-Length": "8"
34+
},
35+
"body": [
36+
"no need."
37+
]
38+
},
39+
"expected": {
40+
"debug_log": "Executing operator \"Rx\"",
41+
"http_code": 403
42+
},
43+
"rules": [
44+
"SecRuleEngine On",
45+
"SecRule ARGS:param1 \"^hello.*world$\" \"id:1,phase:2,deny,log,msg:'multiline-anchor-test'\""
46+
]
47+
},
48+
{
49+
"enabled": 1,
50+
"version_min": 300000,
51+
"resource": "regex-dollar-endonly",
52+
"title": "Testing Operator :: @rx --enable-regex-dollar-endonly (anchors do not span internal line breaks)",
53+
"client": {
54+
"ip": "200.249.12.31",
55+
"port": 123
56+
},
57+
"server": {
58+
"ip": "200.249.12.31",
59+
"port": 80
60+
},
61+
"request": {
62+
"headers": {
63+
"Host": "localhost",
64+
"User-Agent": "curl/7.38.0",
65+
"Accept": "*/*",
66+
"Content-Length": "0"
67+
},
68+
"uri": "/?param1=test%0Ahello%20world%0Amore",
69+
"method": "GET",
70+
"body": [
71+
""
72+
]
73+
},
74+
"response": {
75+
"headers": {
76+
"Date": "Mon, 13 Jul 2015 20:02:41 GMT",
77+
"Last-Modified": "Sun, 26 Oct 2014 22:33:37 GMT",
78+
"Content-Type": "text/html",
79+
"Content-Length": "8"
80+
},
81+
"body": [
82+
"no need."
83+
]
84+
},
85+
"expected": {
86+
"debug_log": "Executing operator \"Rx\"",
87+
"http_code": 200
88+
},
89+
"rules": [
90+
"SecRuleEngine On",
91+
"SecRule ARGS:param1 \"^hello.*world$\" \"id:1,phase:2,deny,log,msg:'multiline-anchor-test'\""
92+
]
93+
}
94+
]

test/test-suite.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# for i in `find test/test-cases -iname *.json`; do echo TESTS+=$i; done
2-
TESTS+=test/unit/regex_multiline_test
32
TESTS+=test/test-cases/regression/action-allow.json
43
TESTS+=test/test-cases/regression/action-block.json
54
TESTS+=test/test-cases/regression/action-ctl_request_body_access.json
@@ -89,6 +88,7 @@ TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
8988
TESTS+=test/test-cases/regression/operator-pm.json
9089
TESTS+=test/test-cases/regression/operator-pmfromfile.json
9190
TESTS+=test/test-cases/regression/operator-rx.json
91+
TESTS+=test/test-cases/regression/operator-rx-dollar-endonly.json
9292
TESTS+=test/test-cases/regression/operator-rxGlobal.json
9393
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
9494
TESTS+=test/test-cases/regression/operator-validate-byte-range.json

test/test-suite.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ array=${@:1:$length}
88
PARAM=$array
99
FILE=${@: -1}
1010

11-
if [[ $FILE != *.json ]]
12-
then
13-
# Self-contained test binary (not a JSON test-case file) - run it directly.
14-
$VALGRIND $PARAM ./$(basename $FILE)
15-
RET=$?
16-
if [ $RET -ne 0 ]; then
17-
echo ":test-result: FAIL: ../$FILE"
18-
fi
19-
elif [[ $FILE == *"test-cases/regression/"* ]]
11+
if [[ $FILE == *"test-cases/regression/"* ]]
2012
then
2113
AMOUNT=$(./regression_tests countall ../$FILE)
2214
RET=$?

test/unit/regex_multiline_test.cc

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)