diff --git a/t/03live_and_ban.t b/t/03live_and_ban.t index 04c8195..607a026 100644 --- a/t/03live_and_ban.t +++ b/t/03live_and_ban.t @@ -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; diff --git a/t/04live_and_not_ban.t b/t/04live_and_not_ban.t new file mode 100644 index 0000000..767895b --- /dev/null +++ b/t/04live_and_not_ban.t @@ -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