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
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-07-01 14:56:13 +00:00
|
|
|
@test "without capi: crowdsec LAPI should run without capi (-no-capi flag)" {
|
2022-07-04 09:26:39 +00:00
|
|
|
config_set '.common.log_media="stdout"'
|
2022-07-01 14:56:13 +00:00
|
|
|
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -124 timeout 1s "${CROWDSEC}" -no-capi
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "Communication with CrowdSec Central API disabled from args"
|
2022-07-01 14:56:13 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "without capi: crowdsec LAPI should still work" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
2022-12-03 07:56:11 +00:00
|
|
|
config_set '.common.log_media="stdout"'
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -124 timeout 1s "${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-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "push and pull to Central API disabled"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "without capi: cscli capi status -> fail" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
|
|
|
./instance-crowdsec start
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -1 cscli capi status
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "no configuration for Central API in "
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "no capi: cscli config show" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli config show -o human
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output --partial "Global:"
|
|
|
|
assert_output --partial "cscli:"
|
|
|
|
assert_output --partial "Crowdsec:"
|
|
|
|
assert_output --partial "Local API Server:"
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "no agent: cscli config backup" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
2022-03-10 11:19:02 +00:00
|
|
|
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli config backup "${backupdir}"
|
|
|
|
assert_stderr --partial "Starting configuration backup"
|
|
|
|
rune -1 cscli config backup "${backupdir}"
|
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-10 11:19:02 +00:00
|
|
|
rm -rf -- "${backupdir:?}"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "without capi: cscli lapi status -> success" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
|
|
|
./instance-crowdsec start
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli lapi status
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "You can successfully interact with Local API (LAPI)"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "cscli metrics" {
|
2022-03-09 13:45:36 +00:00
|
|
|
config_disable_capi
|
|
|
|
./instance-crowdsec start
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli lapi status
|
|
|
|
rune -0 cscli metrics
|
2022-10-07 09:05:35 +00:00
|
|
|
assert_output --partial "Route"
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output --partial '/v1/watchers/login'
|
2023-07-21 21:23:24 +00:00
|
|
|
assert_output --partial "Local API Metrics:"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|