2022-06-06 13:24:48 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
# vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si:
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
setup_file() {
|
|
|
|
load "../lib/setup_file.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
|
|
|
load "../lib/teardown_file.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load "../lib/setup.sh"
|
|
|
|
./instance-data load
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
# to silence shellcheck
|
|
|
|
declare stderr
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec (usage)" {
|
2022-06-06 13:24:48 +00:00
|
|
|
run -0 --separate-stderr timeout 2s "${CROWDSEC}" -h
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_line --regexp "Usage of .*:"
|
|
|
|
|
|
|
|
run -0 --separate-stderr timeout 2s "${CROWDSEC}" --help
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_line --regexp "Usage of .*:"
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec (unknown flag)" {
|
2022-06-06 13:24:48 +00:00
|
|
|
run -2 --separate-stderr timeout 2s "${CROWDSEC}" --foobar
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_line "flag provided but not defined: -foobar"
|
|
|
|
assert_line --regexp "Usage of .*"
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec (unknown argument)" {
|
2022-06-06 13:24:48 +00:00
|
|
|
run -2 --separate-stderr timeout 2s "${CROWDSEC}" trololo
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_line "argument provided but not defined: trololo"
|
|
|
|
assert_line --regexp "Usage of .*"
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec (no api and no agent)" {
|
2022-06-06 13:24:48 +00:00
|
|
|
run -1 --separate-stderr timeout 2s "${CROWDSEC}" -no-api -no-cs
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_line --partial "You must run at least the API Server or crowdsec"
|
|
|
|
}
|
2022-07-01 08:16:45 +00:00
|
|
|
|
|
|
|
@test "crowdsec - print error on exit" {
|
|
|
|
# errors that cause program termination are printed to stderr, not only logs
|
|
|
|
yq e '.db_config.type="meh"' -i "${CONFIG_YAML}"
|
|
|
|
run -1 --separate-stderr "${BIN_DIR}/crowdsec"
|
|
|
|
refute_output
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_output --partial "unable to create database client: unknown database type 'meh'"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "CS_LAPI_SECRET not strong enough" {
|
|
|
|
CS_LAPI_SECRET=foo run -1 --separate-stderr timeout 2s "${CROWDSEC}"
|
|
|
|
run -0 echo "${stderr}"
|
|
|
|
assert_output --partial "api server init: unable to run local API: controller init: CS_LAPI_SECRET not strong enough"
|
|
|
|
}
|