forked from p0pr0ck5/lua-resty-waf
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
my $pwd = cwd(); | ||
|
||
our $HttpConfig = qq{ | ||
lua_package_path "$pwd/lib/?.lua;$pwd/t/?.lua;;"; | ||
lua_package_cpath "$pwd/lib/?.lua;;"; | ||
}; | ||
|
||
repeat_each(3); | ||
plan tests => repeat_each() * 4 * blocks(); | ||
|
||
no_shuffle(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: Ignore a rule at runtime | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /t { | ||
access_by_lua_block { | ||
local lua_resty_waf = require "resty.waf" | ||
local waf = lua_resty_waf:new() | ||
waf:set_option("debug", true) | ||
waf:set_option("mode", "ACTIVE") | ||
waf:set_option("add_ruleset", "10000_ctl") | ||
waf:exec() | ||
} | ||
content_by_lua_block { ngx.exit(ngx.HTTP_OK) } | ||
} | ||
--- request | ||
GET /t | ||
--- error_code: 200 | ||
--- error_log | ||
Runtime ignoring rule 12346 | ||
Ignoring rule 12346 | ||
--- no_error_log | ||
[error] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"access":[{"actions":{"disrupt":"IGNORE","nondisrupt":[{"action":"rule_remove_id","data":"12346"}]},"id":"12345","opts":{"nolog":1},"vars":[{"unconditional":1}]},{"actions":{"disrupt":"DENY"},"id":"12346","operator":"REFIND","pattern":"foo","vars":[{"parse":["values","1"],"type":"REQUEST_ARGS"}]}],"body_filter":[],"header_filter":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
my $pwd = cwd(); | ||
|
||
our $HttpConfig = qq{ | ||
lua_package_path "$pwd/lib/?.lua;;"; | ||
lua_package_cpath "$pwd/lib/?.lua;;"; | ||
}; | ||
|
||
repeat_each(3); | ||
plan tests => repeat_each() * 4 * blocks(); | ||
|
||
no_shuffle(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: rule_remove_id adds to waf._ignore_rule | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local actions = require "resty.waf.actions" | ||
|
||
local waf = { _debug = true, _debug_log_level = ngx.INFO, _ignore_rule = {} } | ||
|
||
actions.nondisruptive_lookup["rule_remove_id"]( | ||
waf, | ||
12345 | ||
) | ||
|
||
for k, v in pairs(waf._ignore_rule) do | ||
ngx.say(k) | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- error_code: 200 | ||
--- response_body | ||
12345 | ||
--- error_log | ||
Runtime ignoring rule 12345 | ||
--- no_error_log | ||
[error] | ||
|
||
=== TEST 2: rule_remove_id adds to waf._ignore_rule with config-time ignore | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local actions = require "resty.waf.actions" | ||
|
||
local waf = { _debug = true, _debug_log_level = ngx.INFO, _ignore_rule = { [12344] = true } } | ||
|
||
actions.nondisruptive_lookup["rule_remove_id"]( | ||
waf, | ||
12345 | ||
) | ||
|
||
for k, v in pairs(waf._ignore_rule) do | ||
ngx.say(k) | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- error_code: 200 | ||
--- response_body | ||
12345 | ||
12344 | ||
--- error_log | ||
Runtime ignoring rule 12345 | ||
--- no_error_log | ||
[error] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters