github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/50_simulation.bats (about) 1 #!/usr/bin/env bats 2 # vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si: 3 4 set -u 5 6 fake_log() { 7 for _ in $(seq 1 10); do 8 echo "$(LC_ALL=C date '+%b %d %H:%M:%S ')"'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.174 port 35424' 9 done 10 } 11 12 setup_file() { 13 load "../lib/setup_file.sh" 14 ./instance-data load 15 16 cscli collections install crowdsecurity/sshd --error 17 cscli parsers install crowdsecurity/syslog-logs --error 18 cscli parsers install crowdsecurity/dateparse-enrich --error 19 20 ./instance-crowdsec start 21 } 22 23 teardown_file() { 24 load "../lib/teardown_file.sh" 25 } 26 27 setup() { 28 load "../lib/setup.sh" 29 cscli decisions delete --all 30 } 31 32 #---------- 33 34 @test "we have one decision" { 35 rune -0 cscli simulation disable --global 36 fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 37 rune -0 cscli decisions list -o json 38 rune -0 jq '. | length' <(output) 39 assert_output 1 40 } 41 42 @test "1.1.1.174 has been banned (exact)" { 43 rune -0 cscli simulation disable --global 44 fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 45 rune -0 cscli decisions list -o json 46 rune -0 jq -r '.[].decisions[0].value' <(output) 47 assert_output '1.1.1.174' 48 } 49 50 @test "decision has simulated == false (exact)" { 51 rune -0 cscli simulation disable --global 52 fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 53 rune -0 cscli decisions list -o json 54 rune -0 jq '.[].decisions[0].simulated' <(output) 55 assert_output 'false' 56 } 57 58 @test "simulated scenario, listing non-simulated: expect no decision" { 59 rune -0 cscli simulation enable crowdsecurity/ssh-bf 60 fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 61 rune -0 cscli decisions list --no-simu -o json 62 assert_json '[]' 63 } 64 65 @test "global simulation, listing non-simulated: expect no decision" { 66 rune -0 cscli simulation disable crowdsecurity/ssh-bf 67 rune -0 cscli simulation enable --global 68 fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 69 rune -0 cscli decisions list --no-simu -o json 70 assert_json '[]' 71 }