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
|
|
|
|
|
|
|
|
setup_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/setup_file.sh"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "there are 0 bouncers" {
|
2022-03-09 13:45:36 +00:00
|
|
|
run -0 cscli bouncers list -o json
|
|
|
|
assert_output "[]"
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "we can add one bouncer, and delete it" {
|
2022-03-09 13:45:36 +00:00
|
|
|
run -0 cscli bouncers add ciTestBouncer
|
|
|
|
assert_output --partial "Api key for 'ciTestBouncer':"
|
|
|
|
run -0 cscli bouncers delete ciTestBouncer
|
|
|
|
run -0 cscli bouncers list -o json
|
|
|
|
assert_output '[]'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "we can't add the same bouncer twice" {
|
2022-03-09 13:45:36 +00:00
|
|
|
run -0 cscli bouncers add ciTestBouncer
|
|
|
|
run -1 --separate-stderr cscli bouncers add ciTestBouncer -o json
|
|
|
|
|
|
|
|
run -0 jq -r '.level' <(stderr)
|
|
|
|
assert_output 'fatal'
|
|
|
|
run -0 jq -r '.msg' <(stderr)
|
|
|
|
assert_output "unable to create bouncer: bouncer ciTestBouncer already exists"
|
|
|
|
|
|
|
|
run -0 cscli bouncers list -o json
|
|
|
|
run -0 jq '. | length' <(output)
|
|
|
|
assert_output 1
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "delete the bouncer multiple times, even if it does not exist" {
|
2022-03-09 13:45:36 +00:00
|
|
|
run -0 cscli bouncers add ciTestBouncer
|
|
|
|
run -0 cscli bouncers delete ciTestBouncer
|
|
|
|
run -0 cscli bouncers delete ciTestBouncer
|
|
|
|
run -0 cscli bouncers delete foobarbaz
|
|
|
|
}
|