Skip to content

Commit

Permalink
add a test of not blocked request
Browse files Browse the repository at this point in the history
  • Loading branch information
sabban committed Oct 2, 2024
1 parent a17510d commit b7b91c1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion t/03live_and_ban.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run_tests();

__DATA__

=== TEST 2: Test body response on block
=== TEST 3: Test body response on block

--- main_config
load_module /usr/share/nginx/modules/ndk_http_module.so;
Expand Down
77 changes: 77 additions & 0 deletions t/04live_and_not_ban.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use Test::Nginx::Socket 'no_plan';

run_tests();

__DATA__

=== TEST 4: Test body response on a not blocked request

--- main_config
load_module /usr/share/nginx/modules/ndk_http_module.so;
load_module /usr/share/nginx/modules/ngx_http_lua_module.so;

--- http_config

lua_package_path './lib/?.lua;;';
lua_shared_dict crowdsec_cache 50m;
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;


init_by_lua_block
{
cs = require "crowdsec"
local ok, err = cs.init("./t/conf_t/03_live_and_ban_crowdsec_nginx_bouncer.conf", "crowdsec-nginx-bouncer/v1.0.8")
if ok == nil then
ngx.log(ngx.ERR, "[Crowdsec] " .. err)
error()
end
ngx.log(ngx.ALERT, "[Crowdsec] Initialisation done")
}

access_by_lua_block {
local cs = require "crowdsec"
cs.Allow(ngx.var.remote_addr)
if ngx.var.unix == "1" then
ngx.log(ngx.DEBUG, "[Crowdsec] Unix socket request ignoring...")
else
cs.Allow(ngx.var.remote_addr)
end
}

server {
listen 8081;

location = /v1/decisions {
content_by_lua_block {
local args, err = ngx.req.get_uri_args()
if args.ip == "1.1.1.1" then
ngx.say('[{"duration":"1h00m00s","id":4091593,"origin":"CAPI","scenario":"crowdsecurity/vpatch-CVE-2024-4577","scope":"Ip","type":"ban","value":"1.1.1.1"}]')
else
ngx.say('[{}]')
end
}
}
}


--- config


location = /t {
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
content_by_lua_block {
ngx.say("Hello, world")
}
}
--- more_headers
X-Forwarded-For: 1.1.1.2
--- request
GET /t
--- response_body

Hello, world

--- error_code: 200

0 comments on commit b7b91c1

Please sign in to comment.