Skip to content

Commit

Permalink
stream mode test
Browse files Browse the repository at this point in the history
  • Loading branch information
sabban committed Nov 6, 2024
1 parent 2270a7e commit 0597ad8
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
83 changes: 83 additions & 0 deletions t/05stream.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use Test::Nginx::Socket 'no_plan';

$Test::Nginx::Util::NoNginxManager = 1;

run_tests();

__DATA__
=== TEST 5: Stream mode block test
--- 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/05_stream_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)
}
server {
listen 8081;
location = /v1/decisions/stream {
content_by_lua_block {
local args, err = ngx.req.get_uri_args()
if args.startup == "true" then
ngx.say('{"deleted": [], "new": [{"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.print("ok")
}
}
--- more_headers
X-Forwarded-For: 1.1.1.2
--- request
GET /t
--- error_code: 200
--- response_body eval
{
sleep(12);
return 'ok';
}
=== TEST 6: Stream mode block test
--- more_headers
X-Forwarded-For: 1.1.1.1
--- request
GET /t
--- error_code: 403
29 changes: 29 additions & 0 deletions t/conf_t/05_stream_crowdsec_nginx_bouncer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
APPSEC_URL=http://127.0.0.1:7422
ENABLED=true
API_URL=http://127.0.0.1:8081
API_KEY=LFrdL+aiecMTSxpGE9vLkx5sGMwdIpgVovpVMfXp3J0
CACHE_EXPIRATION=1
# bounce for all type of remediation that the bouncer can receive from the local API
BOUNCING_ON_TYPE=all
FALLBACK_REMEDIATION=ban
REQUEST_TIMEOUT=3000
UPDATE_FREQUENCY=10
# live or stream
MODE=stream
# exclude the bouncing on those location
EXCLUDE_LOCATION=/v1/decisions
#those apply for "ban" action
# /!\ REDIRECT_LOCATION and RET_CODE can't be used together. REDIRECT_LOCATION take priority over RET_CODE
BAN_TEMPLATE_PATH=./ban
REDIRECT_LOCATION=
RET_CODE=
#those apply for "captcha" action
#valid providers are recaptcha, hcaptcha, turnstile
CAPTCHA_PROVIDER=
# Captcha Secret Key
SECRET_KEY=
# Captcha Site key
SITE_KEY=
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html
CAPTCHA_EXPIRATION=3600
#METRICS_PERIOD=60

0 comments on commit 0597ad8

Please sign in to comment.