github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/40_live-ban.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 6); do 8 echo "$(LC_ALL=C date '+%b %d %H:%M:%S ')"'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.172 port 35424' 9 done 10 } 11 12 setup_file() { 13 load "../lib/setup_file.sh" 14 # we reset config and data, but run the daemon only in the tests that need it 15 ./instance-data load 16 17 cscli collections install crowdsecurity/sshd --error 18 cscli parsers install crowdsecurity/syslog-logs --error 19 cscli parsers install crowdsecurity/dateparse-enrich --error 20 21 } 22 23 teardown_file() { 24 load "../lib/teardown_file.sh" 25 } 26 27 setup() { 28 load "../lib/setup.sh" 29 } 30 31 teardown() { 32 ./instance-crowdsec stop 33 } 34 35 #---------- 36 37 @test "1.1.1.172 has been banned" { 38 tmpfile=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp) 39 touch "${tmpfile}" 40 ACQUIS_YAML=$(config_get '.crowdsec_service.acquisition_path') 41 echo -e "---\nfilename: ${tmpfile}\nlabels:\n type: syslog\n" >>"${ACQUIS_YAML}" 42 43 ./instance-crowdsec start 44 45 sleep 0.2 46 47 fake_log >>"${tmpfile}" 48 49 sleep 0.2 50 51 rm -f -- "${tmpfile}" 52 53 found=0 54 # this may take some time in CI 55 for _ in $(seq 1 10); do 56 if cscli decisions list -o json | jq -r '.[].decisions[0].value' | grep -q '1.1.1.172'; then 57 found=1 58 break 59 fi 60 sleep 0.2 61 done 62 assert_equal 1 "${found}" 63 }