disable capi for tests by default (#1633)

This commit is contained in:
mmetc 2022-07-04 11:26:39 +02:00 committed by GitHub
parent e868adee2f
commit e05515f79d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 25 deletions

View file

@ -89,6 +89,8 @@ declare stderr
}
@test "cscli capi status" {
config_enable_capi
run -0 cscli capi status
assert_output --partial "Loaded credentials from"
assert_output --partial "Trying to authenticate with username"

View file

@ -35,7 +35,7 @@ declare stderr
}
@test "crowdsec should not run without LAPI (no api.server in configuration file)" {
config_set 'del(.api.server)'
config_disable_lapi
run -1 --separate-stderr timeout 2s "${CROWDSEC}"
run -0 echo "${stderr}"
@ -43,7 +43,7 @@ declare stderr
}
@test "capi status shouldn't be ok without api.server" {
config_set 'del(.api.server)'
config_disable_lapi
run -1 --separate-stderr cscli capi status
run -0 echo "${stderr}"
@ -52,7 +52,7 @@ declare stderr
}
@test "cscli config show -o human" {
config_set 'del(.api.server)'
config_disable_lapi
run -0 cscli config show -o human
assert_output --partial "Global:"
assert_output --partial "Crowdsec:"
@ -61,7 +61,7 @@ declare stderr
}
@test "cscli config backup" {
config_set 'del(.api.server)'
config_disable_lapi
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
@ -74,7 +74,7 @@ declare stderr
}
@test "lapi status shouldn't be ok without api.server" {
config_set 'del(.api.server)'
config_disable_lapi
./instance-crowdsec start || true
run -1 --separate-stderr cscli machines list
run -0 echo "${stderr}"
@ -83,7 +83,7 @@ declare stderr
@test "cscli metrics" {
skip 'need to trigger metrics with a live parse'
config_set 'del(.api.server)'
config_disable_lapi
./instance-crowdsec start
run -0 --separate-stderr cscli metrics
assert_output --partial "ROUTE"

View file

@ -24,10 +24,6 @@ declare stderr
#----------
config_disable_agent() {
config_set 'del(.crowdsec_service)'
}
@test "with agent: test without -no-cs flag" {
run -124 timeout 2s "${CROWDSEC}"
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
@ -47,6 +43,7 @@ config_disable_agent() {
@test "no agent: capi status should be ok" {
config_disable_agent
config_enable_capi
./instance-crowdsec start
run -0 --separate-stderr cscli capi status

View file

@ -24,12 +24,8 @@ declare stderr
#----------
config_disable_capi() {
config_set 'del(.api.server.online_client)'
}
@test "without capi: crowdsec LAPI should run without capi (-no-capi flag)" {
yq e '.common.log_media="stdout"' -i "${CONFIG_YAML}"
config_set '.common.log_media="stdout"'
run -124 --separate-stderr timeout 1s "${CROWDSEC}" -no-capi

View file

@ -54,7 +54,7 @@ teardown() {
@test "config.yaml.local - crowdsec (listen_url)" {
# disable the agent or we'll need to patch api client credentials too
run -0 config_set 'del(.crowdsec_service)'
run -0 config_disable_agent
./instance-crowdsec start
run -0 ./lib/util/wait-for-port -q 8080
./instance-crowdsec stop
@ -74,7 +74,7 @@ teardown() {
}
@test "local_api_credentials.yaml.local" {
run -0 config_set 'del(.crowdsec_service)'
run -0 config_disable_agent
echo "{'api':{'server':{'listen_uri':127.0.0.1:8083}}}" >"${CONFIG_YAML}.local"
./instance-crowdsec start
run -0 ./lib/util/wait-for-port -q 8083

View file

@ -3,10 +3,6 @@
set -u
config_disable_agent() {
config_set 'del(.crowdsec_service)'
}
setup_file() {
load "../lib/setup_file.sh"
[[ "${PACKAGE_TESTING}" == "true" ]] && return

View file

@ -3,10 +3,6 @@
set -u
config_disable_agent() {
config_set 'del(.crowdsec_service)'
}
setup_file() {
load "../lib/setup_file.sh"
[[ "${PACKAGE_TESTING}" == "true" ]] && return

View file

@ -66,6 +66,10 @@ make_init_data() {
./instance-db dump "${LOCAL_INIT_DIR}/database"
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
# disable CAPI by default
yq e 'del(.api.server.online_client)' -i "${CONFIG_DIR}/config.yaml"
tar -C "${LOCAL_DIR}" --create \
--exclude "${REL_DATA_DIR}"/crowdsec.db \
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"

View file

@ -81,6 +81,7 @@ config_generate() {
' ../config/config.yaml >"${CONFIG_DIR}/config.yaml"
}
make_init_data() {
remove_init_data
@ -122,6 +123,9 @@ make_init_data() {
./instance-db dump "${LOCAL_INIT_DIR}/database"
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
# disable CAPI by default
yq e 'del(.api.server.online_client)' -i "${CONFIG_DIR}/config.yaml"
tar -C "${LOCAL_DIR}" --create \
--exclude "${REL_DATA_DIR}"/crowdsec.db \
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"

View file

@ -70,6 +70,27 @@ config_set() {
}
export -f config_set
config_disable_agent() {
config_set 'del(.crowdsec_service)'
}
export -f config_disable_agent
config_disable_lapi() {
config_set 'del(.api.server)'
}
export -f config_disable_lapi
config_disable_capi() {
config_set 'del(.api.server.online_client)'
}
export -f config_disable_capi
config_enable_capi() {
online_api_credentials="$(dirname "${CONFIG_YAML}")/online_api_credentials.yaml" \
config_set '.api.server.online_client.credentials_path=strenv(online_api_credentials)'
}
export -f config_enable_capi
# We use these functions like this:
# somecommand <(stderr)
# to provide a standard input to "somecommand".