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"
|
2023-08-25 14:15:28 +00:00
|
|
|
is_package_testing && return
|
2022-03-29 15:06:49 +00:00
|
|
|
|
2022-03-16 08:30:04 +00:00
|
|
|
./instance-data load
|
|
|
|
|
|
|
|
tempfile=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
|
|
|
|
export tempfile
|
|
|
|
|
2022-05-19 07:54:26 +00:00
|
|
|
tempfile2=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
|
|
|
|
export tempfile2
|
|
|
|
|
2022-07-01 20:45:55 +00:00
|
|
|
DUMMY_YAML="$(config_get '.config_paths.notification_dir')/dummy.yaml"
|
2022-05-19 07:54:26 +00:00
|
|
|
|
2022-07-01 20:45:55 +00:00
|
|
|
config_set "${DUMMY_YAML}" '
|
2022-03-29 15:06:49 +00:00
|
|
|
.group_wait="5s" |
|
|
|
|
.group_threshold=2 |
|
2022-05-19 07:54:26 +00:00
|
|
|
.output_file=strenv(tempfile) |
|
|
|
|
.format="{{.|toJson}}"
|
2022-07-01 20:45:55 +00:00
|
|
|
'
|
2022-05-19 07:54:26 +00:00
|
|
|
|
2022-06-13 19:54:47 +00:00
|
|
|
cat <<-EOT >>"${DUMMY_YAML}"
|
2022-05-19 07:54:26 +00:00
|
|
|
---
|
|
|
|
type: dummy
|
|
|
|
name: dummy_2
|
|
|
|
log_level: info
|
|
|
|
format: secondfile
|
|
|
|
output_file: ${tempfile2}
|
|
|
|
EOT
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2022-07-01 20:45:55 +00:00
|
|
|
config_set "$(config_get '.api.server.profiles_path')" '
|
2022-05-19 07:54:26 +00:00
|
|
|
.notifications=["dummy_default","dummy_2"] |
|
2022-03-29 15:06:49 +00:00
|
|
|
.filters=["Alert.GetScope() == \"Ip\""]
|
2022-07-01 20:45:55 +00:00
|
|
|
'
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2022-07-01 20:45:55 +00:00
|
|
|
config_set '
|
2022-03-29 15:06:49 +00:00
|
|
|
.plugin_config.user="" |
|
|
|
|
.plugin_config.group=""
|
2022-07-01 20:45:55 +00:00
|
|
|
'
|
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() {
|
2023-08-25 14:15:28 +00:00
|
|
|
is_package_testing && skip
|
2022-03-16 08:30:04 +00:00
|
|
|
load "../lib/setup.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-07-01 08:16:45 +00:00
|
|
|
@test "add two bans" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions add --ip 1.2.3.4 --duration 30s
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial 'Decision successfully added'
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions add --ip 1.2.3.5 --duration 30s
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial 'Decision successfully added'
|
2022-03-16 08:30:04 +00:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2022-07-01 08:16:45 +00:00
|
|
|
@test "expected 1 notification" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cat "${tempfile}"
|
2022-03-16 08:30:04 +00:00
|
|
|
assert_output --partial 1.2.3.4
|
|
|
|
assert_output --partial 1.2.3.5
|
|
|
|
}
|
2022-05-19 07:54:26 +00:00
|
|
|
|
2022-07-01 08:16:45 +00:00
|
|
|
@test "second notification works too" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cat "${tempfile2}"
|
2022-05-19 07:54:26 +00:00
|
|
|
assert_output --partial secondfile
|
|
|
|
}
|