disable capi for tests by default (#1633)
This commit is contained in:
parent
e868adee2f
commit
e05515f79d
|
@ -89,6 +89,8 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "cscli capi status" {
|
@test "cscli capi status" {
|
||||||
|
config_enable_capi
|
||||||
|
|
||||||
run -0 cscli capi status
|
run -0 cscli capi status
|
||||||
assert_output --partial "Loaded credentials from"
|
assert_output --partial "Loaded credentials from"
|
||||||
assert_output --partial "Trying to authenticate with username"
|
assert_output --partial "Trying to authenticate with username"
|
||||||
|
|
|
@ -35,7 +35,7 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "crowdsec should not run without LAPI (no api.server in configuration file)" {
|
@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 -1 --separate-stderr timeout 2s "${CROWDSEC}"
|
||||||
|
|
||||||
run -0 echo "${stderr}"
|
run -0 echo "${stderr}"
|
||||||
|
@ -43,7 +43,7 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "capi status shouldn't be ok without api.server" {
|
@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 -1 --separate-stderr cscli capi status
|
||||||
|
|
||||||
run -0 echo "${stderr}"
|
run -0 echo "${stderr}"
|
||||||
|
@ -52,7 +52,7 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "cscli config show -o human" {
|
@test "cscli config show -o human" {
|
||||||
config_set 'del(.api.server)'
|
config_disable_lapi
|
||||||
run -0 cscli config show -o human
|
run -0 cscli config show -o human
|
||||||
assert_output --partial "Global:"
|
assert_output --partial "Global:"
|
||||||
assert_output --partial "Crowdsec:"
|
assert_output --partial "Crowdsec:"
|
||||||
|
@ -61,7 +61,7 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "cscli config backup" {
|
@test "cscli config backup" {
|
||||||
config_set 'del(.api.server)'
|
config_disable_lapi
|
||||||
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
||||||
run -0 cscli config backup "${backupdir}"
|
run -0 cscli config backup "${backupdir}"
|
||||||
assert_output --partial "Starting configuration backup"
|
assert_output --partial "Starting configuration backup"
|
||||||
|
@ -74,7 +74,7 @@ declare stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "lapi status shouldn't be ok without api.server" {
|
@test "lapi status shouldn't be ok without api.server" {
|
||||||
config_set 'del(.api.server)'
|
config_disable_lapi
|
||||||
./instance-crowdsec start || true
|
./instance-crowdsec start || true
|
||||||
run -1 --separate-stderr cscli machines list
|
run -1 --separate-stderr cscli machines list
|
||||||
run -0 echo "${stderr}"
|
run -0 echo "${stderr}"
|
||||||
|
@ -83,7 +83,7 @@ declare stderr
|
||||||
|
|
||||||
@test "cscli metrics" {
|
@test "cscli metrics" {
|
||||||
skip 'need to trigger metrics with a live parse'
|
skip 'need to trigger metrics with a live parse'
|
||||||
config_set 'del(.api.server)'
|
config_disable_lapi
|
||||||
./instance-crowdsec start
|
./instance-crowdsec start
|
||||||
run -0 --separate-stderr cscli metrics
|
run -0 --separate-stderr cscli metrics
|
||||||
assert_output --partial "ROUTE"
|
assert_output --partial "ROUTE"
|
||||||
|
|
|
@ -24,10 +24,6 @@ declare stderr
|
||||||
|
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
config_disable_agent() {
|
|
||||||
config_set 'del(.crowdsec_service)'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "with agent: test without -no-cs flag" {
|
@test "with agent: test without -no-cs flag" {
|
||||||
run -124 timeout 2s "${CROWDSEC}"
|
run -124 timeout 2s "${CROWDSEC}"
|
||||||
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
# 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" {
|
@test "no agent: capi status should be ok" {
|
||||||
config_disable_agent
|
config_disable_agent
|
||||||
|
config_enable_capi
|
||||||
./instance-crowdsec start
|
./instance-crowdsec start
|
||||||
run -0 --separate-stderr cscli capi status
|
run -0 --separate-stderr cscli capi status
|
||||||
|
|
||||||
|
|
|
@ -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)" {
|
@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
|
run -124 --separate-stderr timeout 1s "${CROWDSEC}" -no-capi
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ teardown() {
|
||||||
|
|
||||||
@test "config.yaml.local - crowdsec (listen_url)" {
|
@test "config.yaml.local - crowdsec (listen_url)" {
|
||||||
# disable the agent or we'll need to patch api client credentials too
|
# 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
|
./instance-crowdsec start
|
||||||
run -0 ./lib/util/wait-for-port -q 8080
|
run -0 ./lib/util/wait-for-port -q 8080
|
||||||
./instance-crowdsec stop
|
./instance-crowdsec stop
|
||||||
|
@ -74,7 +74,7 @@ teardown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "local_api_credentials.yaml.local" {
|
@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"
|
echo "{'api':{'server':{'listen_uri':127.0.0.1:8083}}}" >"${CONFIG_YAML}.local"
|
||||||
./instance-crowdsec start
|
./instance-crowdsec start
|
||||||
run -0 ./lib/util/wait-for-port -q 8083
|
run -0 ./lib/util/wait-for-port -q 8083
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
config_disable_agent() {
|
|
||||||
config_set 'del(.crowdsec_service)'
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_file() {
|
setup_file() {
|
||||||
load "../lib/setup_file.sh"
|
load "../lib/setup_file.sh"
|
||||||
[[ "${PACKAGE_TESTING}" == "true" ]] && return
|
[[ "${PACKAGE_TESTING}" == "true" ]] && return
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
config_disable_agent() {
|
|
||||||
config_set 'del(.crowdsec_service)'
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_file() {
|
setup_file() {
|
||||||
load "../lib/setup_file.sh"
|
load "../lib/setup_file.sh"
|
||||||
[[ "${PACKAGE_TESTING}" == "true" ]] && return
|
[[ "${PACKAGE_TESTING}" == "true" ]] && return
|
||||||
|
|
|
@ -66,6 +66,10 @@ make_init_data() {
|
||||||
./instance-db dump "${LOCAL_INIT_DIR}/database"
|
./instance-db dump "${LOCAL_INIT_DIR}/database"
|
||||||
|
|
||||||
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
|
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 \
|
tar -C "${LOCAL_DIR}" --create \
|
||||||
--exclude "${REL_DATA_DIR}"/crowdsec.db \
|
--exclude "${REL_DATA_DIR}"/crowdsec.db \
|
||||||
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"
|
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"
|
||||||
|
|
|
@ -81,6 +81,7 @@ config_generate() {
|
||||||
' ../config/config.yaml >"${CONFIG_DIR}/config.yaml"
|
' ../config/config.yaml >"${CONFIG_DIR}/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make_init_data() {
|
make_init_data() {
|
||||||
remove_init_data
|
remove_init_data
|
||||||
|
|
||||||
|
@ -122,6 +123,9 @@ make_init_data() {
|
||||||
./instance-db dump "${LOCAL_INIT_DIR}/database"
|
./instance-db dump "${LOCAL_INIT_DIR}/database"
|
||||||
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
|
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 \
|
tar -C "${LOCAL_DIR}" --create \
|
||||||
--exclude "${REL_DATA_DIR}"/crowdsec.db \
|
--exclude "${REL_DATA_DIR}"/crowdsec.db \
|
||||||
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"
|
--file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"
|
||||||
|
|
|
@ -70,6 +70,27 @@ config_set() {
|
||||||
}
|
}
|
||||||
export -f 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:
|
# We use these functions like this:
|
||||||
# somecommand <(stderr)
|
# somecommand <(stderr)
|
||||||
# to provide a standard input to "somecommand".
|
# to provide a standard input to "somecommand".
|
||||||
|
|
Loading…
Reference in a new issue