2022-03-16 08:30:04 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
# vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si:
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
setup_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/setup_file.sh"
|
2022-03-29 15:06:49 +00:00
|
|
|
[ -n "${PACKAGE_TESTING}" ] && return
|
|
|
|
|
2022-03-16 08:30:04 +00:00
|
|
|
./instance-data load
|
|
|
|
|
|
|
|
tempfile=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
|
|
|
|
export tempfile
|
|
|
|
|
2022-04-20 13:05:34 +00:00
|
|
|
yq e '
|
2022-03-29 15:06:49 +00:00
|
|
|
.group_wait="5s" |
|
|
|
|
.group_threshold=2 |
|
|
|
|
.output_file=strenv(tempfile)
|
|
|
|
' -i "$(config_yq '.config_paths.notification_dir')/dummy.yaml"
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2022-04-20 13:05:34 +00:00
|
|
|
yq e '
|
2022-03-29 15:06:49 +00:00
|
|
|
.notifications=["dummy_default"] |
|
|
|
|
.filters=["Alert.GetScope() == \"Ip\""]
|
|
|
|
' -i "$(config_yq '.api.server.profiles_path')"
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2022-04-20 13:05:34 +00:00
|
|
|
yq e '
|
2022-03-29 15:06:49 +00:00
|
|
|
.plugin_config.user="" |
|
|
|
|
.plugin_config.group=""
|
|
|
|
' -i "${CONFIG_YAML}"
|
2022-03-16 08:30:04 +00:00
|
|
|
|
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/teardown_file.sh"
|
2022-03-16 08:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
2022-03-29 15:06:49 +00:00
|
|
|
[ -n "${PACKAGE_TESTING}" ] && skip
|
2022-03-16 08:30:04 +00:00
|
|
|
load "../lib/setup.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
|
|
|
@test "$FILE add two bans" {
|
|
|
|
run -0 cscli decisions add --ip 1.2.3.4 --duration 30s
|
|
|
|
assert_output --partial 'Decision successfully added'
|
|
|
|
|
|
|
|
run -0 cscli decisions add --ip 1.2.3.5 --duration 30s
|
|
|
|
assert_output --partial 'Decision successfully added'
|
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "$FILE expected 1 notification" {
|
|
|
|
run -0 cat "${tempfile}"
|
|
|
|
assert_output --partial 1.2.3.4
|
|
|
|
assert_output --partial 1.2.3.5
|
|
|
|
}
|