2022-03-15 16:16:33 +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-15 16:16:33 +00:00
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
API_KEY=$(cscli bouncers add testbouncer -o raw)
|
|
|
|
export API_KEY
|
|
|
|
CROWDSEC_API_URL="http://localhost:8080"
|
|
|
|
export CROWDSEC_API_URL
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/teardown_file.sh"
|
2022-03-15 16:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load "../lib/setup.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
|
|
|
api() {
|
|
|
|
URI="$1"
|
|
|
|
curl -s -H "X-Api-Key: ${API_KEY}" "${CROWDSEC_API_URL}${URI}"
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "adding decisions for multiple scopes" {
|
2022-12-30 14:57:24 +00:00
|
|
|
run -0 --separate-stderr cscli decisions add -i '1.2.3.6'
|
|
|
|
assert_stderr --partial 'Decision successfully added'
|
|
|
|
run -0 --separate-stderr cscli decisions add --scope user --value toto
|
|
|
|
assert_stderr --partial 'Decision successfully added'
|
2022-03-15 16:16:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "stream start (implicit ip scope)" {
|
2022-03-15 16:16:33 +00:00
|
|
|
run -0 api "/v1/decisions/stream?startup=true"
|
|
|
|
run -0 jq -r '.new' <(output)
|
|
|
|
assert_output --partial '1.2.3.6'
|
|
|
|
refute_output --partial 'toto'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "stream start (explicit ip scope)" {
|
2022-03-15 16:16:33 +00:00
|
|
|
run -0 api "/v1/decisions/stream?startup=true&scopes=ip"
|
|
|
|
run -0 jq -r '.new' <(output)
|
|
|
|
assert_output --partial '1.2.3.6'
|
|
|
|
refute_output --partial 'toto'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "stream start (user scope)" {
|
2022-03-15 16:16:33 +00:00
|
|
|
run -0 api "/v1/decisions/stream?startup=true&scopes=user"
|
|
|
|
run -0 jq -r '.new' <(output)
|
|
|
|
refute_output --partial '1.2.3.6'
|
|
|
|
assert_output --partial 'toto'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "stream start (user+ip scope)" {
|
2022-03-15 16:16:33 +00:00
|
|
|
run -0 api "/v1/decisions/stream?startup=true&scopes=user,ip"
|
|
|
|
run -0 jq -r '.new' <(output)
|
|
|
|
assert_output --partial '1.2.3.6'
|
|
|
|
assert_output --partial 'toto'
|
|
|
|
}
|