2022-03-09 13:45:36 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
# vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si:
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
fake_log() {
|
|
|
|
for _ in $(seq 1 10); do
|
|
|
|
echo "$(LC_ALL=C date '+%b %d %H:%M:%S ')"'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.174 port 35424'
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/setup_file.sh"
|
2022-03-09 13:45:36 +00:00
|
|
|
./instance-data load
|
2023-11-24 14:57:32 +00:00
|
|
|
|
|
|
|
cscli collections install crowdsecurity/sshd --error
|
|
|
|
cscli parsers install crowdsecurity/syslog-logs --error
|
|
|
|
cscli parsers install crowdsecurity/dateparse-enrich --error
|
|
|
|
|
2022-03-09 13:45:36 +00:00
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/teardown_file.sh"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load "../lib/setup.sh"
|
|
|
|
cscli decisions delete --all
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "we have one decision" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli simulation disable --global
|
2022-03-09 13:45:36 +00:00
|
|
|
fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -o json
|
|
|
|
rune -0 jq '. | length' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 1
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "1.1.1.174 has been banned (exact)" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli simulation disable --global
|
2022-03-09 13:45:36 +00:00
|
|
|
fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -o json
|
|
|
|
rune -0 jq -r '.[].decisions[0].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1.1.1.174'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "decision has simulated == false (exact)" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli simulation disable --global
|
2022-03-09 13:45:36 +00:00
|
|
|
fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -o json
|
|
|
|
rune -0 jq '.[].decisions[0].simulated' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'false'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "simulated scenario, listing non-simulated: expect no decision" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli simulation enable crowdsecurity/ssh-bf
|
2022-03-09 13:45:36 +00:00
|
|
|
fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list --no-simu -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "global simulation, listing non-simulated: expect no decision" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli simulation disable crowdsecurity/ssh-bf
|
|
|
|
rune -0 cscli simulation enable --global
|
2022-03-09 13:45:36 +00:00
|
|
|
fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list --no-simu -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|