|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +set -u |
| 4 | + |
| 5 | +fake_log() { |
| 6 | + for _ in $(seq 1 6); do |
| 7 | + echo "$(LC_ALL=C date '+%b %d %H:%M:%S ')"'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.172 port 35424' |
| 8 | + done |
| 9 | +} |
| 10 | + |
| 11 | +setup_file() { |
| 12 | + load "../lib/setup_file.sh" |
| 13 | + # we reset config and data, and only run the daemon once for all the tests in this file |
| 14 | + ./instance-data load |
| 15 | + |
| 16 | + cscli collections install crowdsecurity/sshd --error >/dev/null |
| 17 | + cscli parsers install crowdsecurity/syslog-logs --error >/dev/null |
| 18 | + cscli parsers install crowdsecurity/dateparse-enrich --error >/dev/null |
| 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 | +} |
| 30 | + |
| 31 | +#---------- |
| 32 | + |
| 33 | +@test "apply postoverflow" { |
| 34 | + CONFIG_DIR=$(dirname "$CONFIG_YAML") |
| 35 | + mkdir -p "$CONFIG_DIR"/postoverflows/s01-whitelist |
| 36 | + cat > "$CONFIG_DIR"/postoverflows/s01-whitelist/po-test.yaml <<-EOT |
| 37 | + name: crowdsecurity/po-test |
| 38 | + description: "foo" |
| 39 | + whitelist: |
| 40 | + reason: "foo" |
| 41 | + expression: |
| 42 | + - "evt.Overflow.Alert.Source.IP == '1.1.1.172'" |
| 43 | + EOT |
| 44 | + |
| 45 | + rune -0 "$CROWDSEC" -dsn file://<(fake_log) -type syslog -no-api |
| 46 | + refute_output |
| 47 | + assert_stderr --regexp "Adding file .* to filelist" |
| 48 | + assert_stderr --regexp "reading .* at once" |
| 49 | + assert_stderr --partial "Ban for 1.1.1.172 whitelisted" |
| 50 | + assert_stderr --regexp "Acquisition is finished, shutting down" |
| 51 | + assert_stderr --regexp "Killing parser routines" |
| 52 | + assert_stderr --regexp "Bucket routine exiting" |
| 53 | + assert_stderr --regexp "crowdsec shutdown" |
| 54 | +} |
| 55 | + |
| 56 | +@test "we have no decision" { |
| 57 | + rune -0 cscli decisions list -o json |
| 58 | + rune -0 jq '. | length' <(output) |
| 59 | + assert_output 0 |
| 60 | +} |
0 commit comments