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"
|
|
|
|
# always reset config and data, but run the daemon only if one test requires it
|
|
|
|
./instance-data load
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "test without -no-api flag" {
|
2022-03-18 13:46:05 +00:00
|
|
|
run -124 --separate-stderr timeout 2s "${CROWDSEC}"
|
2022-03-09 13:45:36 +00:00
|
|
|
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec should not run without LAPI (-no-api flag)" {
|
2022-07-26 07:47:56 +00:00
|
|
|
# really needs 4 secs on slow boxes
|
|
|
|
run -1 --separate-stderr timeout 4s "${CROWDSEC}" -no-api
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "crowdsec should not run without LAPI (no api.server in configuration file)" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-07-26 07:47:56 +00:00
|
|
|
# really needs 4 secs on slow boxes
|
|
|
|
run -1 --separate-stderr timeout 4s "${CROWDSEC}"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "crowdsec local API is disabled"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "capi status shouldn't be ok without api.server" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-03-09 13:45:36 +00:00
|
|
|
run -1 --separate-stderr cscli capi status
|
|
|
|
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "crowdsec local API is disabled"
|
|
|
|
assert_stderr --partial "There is no configuration on 'api.server:'"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli config show -o human" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-03-09 13:45:36 +00:00
|
|
|
run -0 cscli config show -o human
|
|
|
|
assert_output --partial "Global:"
|
|
|
|
assert_output --partial "Crowdsec:"
|
|
|
|
assert_output --partial "cscli:"
|
|
|
|
refute_output --partial "Local API Server:"
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli config backup" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-03-10 11:19:02 +00:00
|
|
|
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
|
|
|
run -0 cscli config backup "${backupdir}"
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output --partial "Starting configuration backup"
|
2022-03-10 11:19:02 +00:00
|
|
|
run -1 --separate-stderr cscli config backup "${backupdir}"
|
|
|
|
rm -rf -- "${backupdir:?}"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-12-22 11:22:55 +00:00
|
|
|
assert_stderr --partial "failed to backup config"
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "file exists"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "lapi status shouldn't be ok without api.server" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-06-13 19:54:47 +00:00
|
|
|
./instance-crowdsec start || true
|
2022-03-09 13:45:36 +00:00
|
|
|
run -1 --separate-stderr cscli machines list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "Local API is disabled, please run this command on the local API machine"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli metrics" {
|
2022-03-09 13:45:36 +00:00
|
|
|
skip 'need to trigger metrics with a live parse'
|
2022-07-04 09:26:39 +00:00
|
|
|
config_disable_lapi
|
2022-03-09 13:45:36 +00:00
|
|
|
./instance-crowdsec start
|
|
|
|
run -0 --separate-stderr cscli metrics
|
|
|
|
assert_output --partial "ROUTE"
|
|
|
|
assert_output --partial "/v1/watchers/login"
|
|
|
|
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "crowdsec local API is disabled"
|
|
|
|
assert_stderr --partial "Local API is disabled, please run this command on the local API machine"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|