Skip to content

Commit 09f6381

Browse files
defanatorFelipe Zimmerle
authored and
Felipe Zimmerle
committed
modsecurity_transaction_id: tests extended with audit/debug logs
1 parent 67cf063 commit 09f6381

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

tests/modsecurity-transaction-id.t

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use Test::Nginx;
2121
select STDERR; $| = 1;
2222
select STDOUT; $| = 1;
2323

24-
my $t = Test::Nginx->new()->plan(3)->write_file_expand('nginx.conf', <<'EOF');
24+
my $t = Test::Nginx->new()->plan(5)->write_file_expand('nginx.conf', <<'EOF');
2525
2626
%%TEST_GLOBALS%%
2727
@@ -76,6 +76,33 @@ http {
7676
SecRule ARGS "@streq block403" "id:4,phase:1,status:403,block"
7777
';
7878
}
79+
80+
location /debuglog {
81+
modsecurity on;
82+
modsecurity_transaction_id "tid-DEBUG-$request_id";
83+
modsecurity_rules '
84+
SecRuleEngine On
85+
SecDebugLog %%TESTDIR%%/modsec_debug.log
86+
SecDebugLogLevel 4
87+
SecDefaultAction "phase:1,log,deny,status:403"
88+
SecRule ARGS "@streq block403" "id:4,phase:1,status:403,block"
89+
';
90+
}
91+
92+
location /auditlog {
93+
modsecurity on;
94+
modsecurity_transaction_id "tid-AUDIT-$request_id";
95+
modsecurity_rules '
96+
SecRuleEngine On
97+
SecDefaultAction "phase:1,log,deny,status:403"
98+
SecAuditEngine On
99+
SecAuditLogParts A
100+
SecAuditLog %%TESTDIR%%/modsec_audit.log
101+
SecAuditLogType Serial
102+
SecAuditLogStorageDir %%TESTDIR%%/
103+
SecRule ARGS "@streq block403" "id:4,phase:1,status:403,block"
104+
';
105+
}
79106
}
80107
}
81108
EOF
@@ -92,23 +119,39 @@ Host: server1
92119
93120
EOF
94121

95-
is(lines($t, 'e_s1l1.log', 'unique_id "tid-HTTP-DEFAULT-'), 2, 'http default');
122+
isnt(lines($t, 'e_s1l1.log', 'unique_id "tid-HTTP-DEFAULT-'), 0, 'http default');
96123

97124
http(<<EOF);
98125
GET /?what=block403 HTTP/1.0
99126
Host: server2
100127
101128
EOF
102129

103-
is(lines($t, 'e_s2l1.log', 'unique_id "tid-SERVER-DEFAULT-'), 2, 'server default');
130+
isnt(lines($t, 'e_s2l1.log', 'unique_id "tid-SERVER-DEFAULT-'), 0, 'server default');
104131

105132
http(<<EOF);
106133
GET /specific/?what=block403 HTTP/1.0
107134
Host: server2
108135
109136
EOF
110137

111-
is(lines($t, 'e_s2l2.log', 'unique_id "tid-LOCATION-SPECIFIC-'), 2, 'location specific');
138+
isnt(lines($t, 'e_s2l2.log', 'unique_id "tid-LOCATION-SPECIFIC-'), 0, 'location specific');
139+
140+
http(<<EOF);
141+
GET /debuglog/?what=block403 HTTP/1.0
142+
Host: server2
143+
144+
EOF
145+
146+
isnt(lines($t, 'modsec_debug.log', 'tid-DEBUG-'), 0, 'libmodsecurity debug log');
147+
148+
http(<<EOF);
149+
GET /auditlog/?what=block403 HTTP/1.0
150+
Host: server2
151+
152+
EOF
153+
154+
isnt(lines($t, 'modsec_audit.log', 'tid-AUDIT-'), 0, 'libmodsecurity audit log');
112155

113156
###############################################################################
114157

0 commit comments

Comments
 (0)