updated bats to 1.7.0; shellcheck fixes and moved cfssl dir under testdata/ (#1584)
This commit is contained in:
parent
9c1b78395a
commit
67841d54ee
1
.gitmodules
vendored
1
.gitmodules
vendored
|
@ -1,6 +1,7 @@
|
||||||
[submodule "tests/lib/bats-core"]
|
[submodule "tests/lib/bats-core"]
|
||||||
path = tests/lib/bats-core
|
path = tests/lib/bats-core
|
||||||
url = https://github.com/crowdsecurity/bats-core.git
|
url = https://github.com/crowdsecurity/bats-core.git
|
||||||
|
branch = v1.7.0
|
||||||
[submodule "tests/lib/bats-file"]
|
[submodule "tests/lib/bats-file"]
|
||||||
path = tests/lib/bats-file
|
path = tests/lib/bats-file
|
||||||
url = https://github.com/crowdsecurity/bats-file.git
|
url = https://github.com/crowdsecurity/bats-file.git
|
||||||
|
|
|
@ -71,7 +71,8 @@ To repeat test runs without rebuilding crowdsec, use `make bats-test`.
|
||||||
|
|
||||||
See `./tests/run-tests --help` to run/debug specific tests.
|
See `./tests/run-tests --help` to run/debug specific tests.
|
||||||
|
|
||||||
Example: `./tests/run-tests tests/bats/02_nolapi.bats -f "cscli config backup"` (the string is a regexp)
|
Example: `./tests/run-tests tests/bats/02_nolapi.bats -f "cscli config backup"` (the string is a regexp).
|
||||||
|
You need to provide a path for a test file or directory (even if it's the full 'tests/bats') to use the `-f` option.
|
||||||
|
|
||||||
|
|
||||||
# How does it work?
|
# How does it work?
|
||||||
|
|
|
@ -13,14 +13,14 @@ is_crowdsec_running || exit 0
|
||||||
sleep 2
|
sleep 2
|
||||||
is_crowdsec_running || exit 0
|
is_crowdsec_running || exit 0
|
||||||
|
|
||||||
PIDS=$(echo "$PIDS" | sed ':a;N;$!ba;s/\n/ /g')
|
PIDS=$(echo "${PIDS}" | sed ':a;N;$!ba;s/\n/ /g')
|
||||||
msg="CrowdSec is already running (PID $PIDS). Please terminate it and run the tests again."
|
msg="CrowdSec is already running (PID ${PIDS}). Please terminate it and run the tests again."
|
||||||
|
|
||||||
# Are we inside a setup() or @test? Is file descriptor 3 open?
|
# Are we inside a setup() or @test? Is file descriptor 3 open?
|
||||||
if { true >&3; } 2>/dev/null; then
|
if { true >&3; } 2>/dev/null; then
|
||||||
echo "$msg" >&3
|
echo "${msg}" >&3
|
||||||
else
|
else
|
||||||
echo "$msg" >&2
|
echo "${msg}" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cause the calling setup() or @test to fail
|
# cause the calling setup() or @test to fail
|
||||||
|
|
|
@ -54,4 +54,3 @@ declare stderr
|
||||||
run -0 echo "${stderr}"
|
run -0 echo "${stderr}"
|
||||||
assert_line --partial "You must run at least the API Server or crowdsec"
|
assert_line --partial "You must run at least the API Server or crowdsec"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ teardown() {
|
||||||
./instance-crowdsec stop
|
./instance-crowdsec stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
@test "${FILE} config.yaml.local - cscli (log_level)" {
|
@test "${FILE} config.yaml.local - cscli (log_level)" {
|
||||||
|
@ -102,7 +101,6 @@ teardown() {
|
||||||
assert_output --partial "global simulation: enabled"
|
assert_output --partial "global simulation: enabled"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "${FILE} profiles.yaml.local" {
|
@test "${FILE} profiles.yaml.local" {
|
||||||
run -0 yq e '.api.server.profiles_path' <"${CONFIG_YAML}"
|
run -0 yq e '.api.server.profiles_path' <"${CONFIG_YAML}"
|
||||||
refute_output null
|
refute_output null
|
||||||
|
|
0
tests/bats/06_crowdsec.bats
Executable file → Normal file
0
tests/bats/06_crowdsec.bats
Executable file → Normal file
|
@ -12,26 +12,29 @@ setup_file() {
|
||||||
./instance-data load
|
./instance-data load
|
||||||
tmpdir=$(mktemp -d)
|
tmpdir=$(mktemp -d)
|
||||||
export tmpdir
|
export tmpdir
|
||||||
|
|
||||||
|
CFDIR="${BATS_TEST_DIRNAME}/testdata/cfssl"
|
||||||
|
export CFDIR
|
||||||
|
|
||||||
#gen the CA
|
#gen the CA
|
||||||
cfssl gencert --initca ./cfssl/ca.json 2>/dev/null | cfssljson --bare "${tmpdir}/ca"
|
cfssl gencert --initca "${CFDIR}/ca.json" 2>/dev/null | cfssljson --bare "${tmpdir}/ca"
|
||||||
#gen an intermediate
|
#gen an intermediate
|
||||||
cfssl gencert --initca ./cfssl/intermediate.json 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
cfssl gencert --initca "${CFDIR}/intermediate.json" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
||||||
cfssl sign -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config ./cfssl/profiles.json -profile intermediate_ca "${tmpdir}/inter.csr" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
cfssl sign -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config "${CFDIR}/profiles.json" -profile intermediate_ca "${tmpdir}/inter.csr" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
||||||
#gen server cert for crowdsec with the intermediate
|
#gen server cert for crowdsec with the intermediate
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=server ./cfssl/server.json 2>/dev/null | cfssljson --bare "${tmpdir}/server"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=server "${CFDIR}/server.json" 2>/dev/null | cfssljson --bare "${tmpdir}/server"
|
||||||
#gen client cert for the bouncer
|
#gen client cert for the bouncer
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/bouncer.json 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/bouncer.json" 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer"
|
||||||
#gen client cert for the bouncer with an invalid OU
|
#gen client cert for the bouncer with an invalid OU
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/bouncer_invalid.json 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_bad_ou"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/bouncer_invalid.json" 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_bad_ou"
|
||||||
#gen client cert for the bouncer directly signed by the CA, it should be refused by crowdsec as uses the intermediate
|
#gen client cert for the bouncer directly signed by the CA, it should be refused by crowdsec as uses the intermediate
|
||||||
cfssl gencert -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/bouncer.json 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_invalid"
|
cfssl gencert -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/bouncer.json" 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_invalid"
|
||||||
|
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/bouncer.json 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_revoked"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/bouncer.json" 2>/dev/null | cfssljson --bare "${tmpdir}/bouncer_revoked"
|
||||||
serial="$(openssl x509 -noout -serial -in ${tmpdir}/bouncer_revoked.pem | cut -d '=' -f2)"
|
serial="$(openssl x509 -noout -serial -in "${tmpdir}/bouncer_revoked.pem" | cut -d '=' -f2)"
|
||||||
echo "ibase=16; $serial" | bc > "${tmpdir}/serials.txt"
|
echo "ibase=16; ${serial}" | bc >"${tmpdir}/serials.txt"
|
||||||
cfssl gencrl "${tmpdir}/serials.txt" "${tmpdir}/ca.pem" "${tmpdir}/ca-key.pem" | base64 -d | openssl crl -inform DER -out "${tmpdir}/crl.pem"
|
cfssl gencrl "${tmpdir}/serials.txt" "${tmpdir}/ca.pem" "${tmpdir}/ca-key.pem" | base64 -d | openssl crl -inform DER -out "${tmpdir}/crl.pem"
|
||||||
|
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.api.server.tls.cert_file=strenv(tmpdir) + "/server.pem" |
|
.api.server.tls.cert_file=strenv(tmpdir) + "/server.pem" |
|
||||||
.api.server.tls.key_file=strenv(tmpdir) + "/server-key.pem" |
|
.api.server.tls.key_file=strenv(tmpdir) + "/server-key.pem" |
|
||||||
|
@ -43,10 +46,9 @@ setup_file() {
|
||||||
config_disable_agent
|
config_disable_agent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
teardown_file() {
|
teardown_file() {
|
||||||
load "../lib/teardown_file.sh"
|
load "../lib/teardown_file.sh"
|
||||||
rm -rf $tmpdir
|
rm -rf "${tmpdir}"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -60,12 +62,12 @@ teardown() {
|
||||||
|
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
@test "$FILE there are 0 bouncers" {
|
@test "${FILE} there are 0 bouncers" {
|
||||||
run -0 cscli bouncers list -o json
|
run -0 cscli bouncers list -o json
|
||||||
assert_output "[]"
|
assert_output "[]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE simulate one bouncer request with a valid cert" {
|
@test "${FILE} simulate one bouncer request with a valid cert" {
|
||||||
run -0 curl -s --cert "${tmpdir}/bouncer.pem" --key "${tmpdir}/bouncer-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
run -0 curl -s --cert "${tmpdir}/bouncer.pem" --key "${tmpdir}/bouncer-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
||||||
assert_output "null"
|
assert_output "null"
|
||||||
run -0 cscli bouncers list -o json
|
run -0 cscli bouncers list -o json
|
||||||
|
@ -77,19 +79,19 @@ teardown() {
|
||||||
run cscli bouncers delete localhost@127.0.0.1
|
run cscli bouncers delete localhost@127.0.0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE simulate one bouncer request with an invalid cert" {
|
@test "${FILE} simulate one bouncer request with an invalid cert" {
|
||||||
run curl -s --cert "${tmpdir}/bouncer_invalid.pem" --key "${tmpdir}/bouncer_invalid-key.pem" --cacert "${tmpdir}/ca-key.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
run curl -s --cert "${tmpdir}/bouncer_invalid.pem" --key "${tmpdir}/bouncer_invalid-key.pem" --cacert "${tmpdir}/ca-key.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
||||||
run -0 cscli bouncers list -o json
|
run -0 cscli bouncers list -o json
|
||||||
assert_output "[]"
|
assert_output "[]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE simulate one bouncer request with an invalid OU" {
|
@test "${FILE} simulate one bouncer request with an invalid OU" {
|
||||||
run curl -s --cert "${tmpdir}/bouncer_bad_ou.pem" --key "${tmpdir}/bouncer_bad_ou-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
run curl -s --cert "${tmpdir}/bouncer_bad_ou.pem" --key "${tmpdir}/bouncer_bad_ou-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
||||||
run -0 cscli bouncers list -o json
|
run -0 cscli bouncers list -o json
|
||||||
assert_output "[]"
|
assert_output "[]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE simulate one bouncer request with a revoked certificate" {
|
@test "${FILE} simulate one bouncer request with a revoked certificate" {
|
||||||
run -0 curl -i -s --cert "${tmpdir}/bouncer_revoked.pem" --key "${tmpdir}/bouncer_revoked-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
run -0 curl -i -s --cert "${tmpdir}/bouncer_revoked.pem" --key "${tmpdir}/bouncer_revoked-key.pem" --cacert "${tmpdir}/inter.pem" https://localhost:8080/v1/decisions\?ip=42.42.42.42
|
||||||
assert_output --partial "access forbidden"
|
assert_output --partial "access forbidden"
|
||||||
run -0 cscli bouncers list -o json
|
run -0 cscli bouncers list -o json
|
||||||
|
|
|
@ -6,28 +6,32 @@ set -u
|
||||||
setup_file() {
|
setup_file() {
|
||||||
load "../lib/setup_file.sh"
|
load "../lib/setup_file.sh"
|
||||||
./instance-data load
|
./instance-data load
|
||||||
|
|
||||||
tmpdir=$(mktemp -d)
|
tmpdir=$(mktemp -d)
|
||||||
export tmpdir
|
export tmpdir
|
||||||
|
|
||||||
|
CFDIR="${BATS_TEST_DIRNAME}/testdata/cfssl"
|
||||||
|
export CFDIR
|
||||||
|
|
||||||
#gen the CA
|
#gen the CA
|
||||||
cfssl gencert --initca ./cfssl/ca.json 2>/dev/null | cfssljson --bare "${tmpdir}/ca"
|
cfssl gencert --initca "${CFDIR}/ca.json" 2>/dev/null | cfssljson --bare "${tmpdir}/ca"
|
||||||
#gen an intermediate
|
#gen an intermediate
|
||||||
cfssl gencert --initca ./cfssl/intermediate.json 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
cfssl gencert --initca "${CFDIR}/intermediate.json" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
||||||
cfssl sign -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config ./cfssl/profiles.json -profile intermediate_ca "${tmpdir}/inter.csr" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
cfssl sign -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config "${CFDIR}/profiles.json" -profile intermediate_ca "${tmpdir}/inter.csr" 2>/dev/null | cfssljson --bare "${tmpdir}/inter"
|
||||||
#gen server cert for crowdsec with the intermediate
|
#gen server cert for crowdsec with the intermediate
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=server ./cfssl/server.json 2>/dev/null | cfssljson --bare "${tmpdir}/server"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=server "${CFDIR}/server.json" 2>/dev/null | cfssljson --bare "${tmpdir}/server"
|
||||||
#gen client cert for the agent
|
#gen client cert for the agent
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/agent.json 2>/dev/null | cfssljson --bare "${tmpdir}/agent"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/agent.json" 2>/dev/null | cfssljson --bare "${tmpdir}/agent"
|
||||||
#gen client cert for the agent with an invalid OU
|
#gen client cert for the agent with an invalid OU
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/agent_invalid.json 2>/dev/null | cfssljson --bare "${tmpdir}/agent_bad_ou"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/agent_invalid.json" 2>/dev/null | cfssljson --bare "${tmpdir}/agent_bad_ou"
|
||||||
#gen client cert for the agent directly signed by the CA, it should be refused by crowdsec as uses the intermediate
|
#gen client cert for the agent directly signed by the CA, it should be refused by crowdsec as uses the intermediate
|
||||||
cfssl gencert -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/agent.json 2>/dev/null | cfssljson --bare "${tmpdir}/agent_invalid"
|
cfssl gencert -ca "${tmpdir}/ca.pem" -ca-key "${tmpdir}/ca-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/agent.json" 2>/dev/null | cfssljson --bare "${tmpdir}/agent_invalid"
|
||||||
|
|
||||||
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config ./cfssl/profiles.json -profile=client ./cfssl/agent.json 2>/dev/null | cfssljson --bare "${tmpdir}/agent_revoked"
|
cfssl gencert -ca "${tmpdir}/inter.pem" -ca-key "${tmpdir}/inter-key.pem" -config "${CFDIR}/profiles.json" -profile=client "${CFDIR}/agent.json" 2>/dev/null | cfssljson --bare "${tmpdir}/agent_revoked"
|
||||||
serial="$(openssl x509 -noout -serial -in ${tmpdir}/agent_revoked.pem | cut -d '=' -f2)"
|
serial="$(openssl x509 -noout -serial -in "${tmpdir}/agent_revoked.pem" | cut -d '=' -f2)"
|
||||||
echo "ibase=16; $serial" | bc > "${tmpdir}/serials.txt"
|
echo "ibase=16; ${serial}" | bc >"${tmpdir}/serials.txt"
|
||||||
cfssl gencrl "${tmpdir}/serials.txt" "${tmpdir}/ca.pem" "${tmpdir}/ca-key.pem" | base64 -d | openssl crl -inform DER -out "${tmpdir}/crl.pem"
|
cfssl gencrl "${tmpdir}/serials.txt" "${tmpdir}/ca.pem" "${tmpdir}/ca-key.pem" | base64 -d | openssl crl -inform DER -out "${tmpdir}/crl.pem"
|
||||||
|
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.api.server.tls.cert_file=strenv(tmpdir) + "/server.pem" |
|
.api.server.tls.cert_file=strenv(tmpdir) + "/server.pem" |
|
||||||
.api.server.tls.key_file=strenv(tmpdir) + "/server-key.pem" |
|
.api.server.tls.key_file=strenv(tmpdir) + "/server-key.pem" |
|
||||||
|
@ -53,8 +57,8 @@ teardown() {
|
||||||
|
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
@test "$FILE invalid OU for agent" {
|
@test "${FILE} invalid OU for agent" {
|
||||||
CONFIG_DIR=$(dirname ${CONFIG_YAML})
|
CONFIG_DIR=$(dirname "${CONFIG_YAML}")
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
||||||
|
@ -72,8 +76,8 @@ teardown() {
|
||||||
assert_output '[]'
|
assert_output '[]'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE we have exactly one machine registered with TLS" {
|
@test "${FILE} we have exactly one machine registered with TLS" {
|
||||||
CONFIG_DIR=$(dirname ${CONFIG_YAML})
|
CONFIG_DIR=$(dirname "${CONFIG_YAML}")
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
||||||
|
@ -96,9 +100,8 @@ teardown() {
|
||||||
./instance-crowdsec stop
|
./instance-crowdsec stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "${FILE} invalid cert for agent" {
|
||||||
@test "$FILE invalid cert for agent" {
|
CONFIG_DIR=$(dirname "${CONFIG_YAML}")
|
||||||
CONFIG_DIR=$(dirname ${CONFIG_YAML})
|
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
||||||
|
@ -116,8 +119,8 @@ teardown() {
|
||||||
assert_output '[]'
|
assert_output '[]'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE revoked cert for agent" {
|
@test "${FILE} revoked cert for agent" {
|
||||||
CONFIG_DIR=$(dirname ${CONFIG_YAML})
|
CONFIG_DIR=$(dirname "${CONFIG_YAML}")
|
||||||
|
|
||||||
yq '
|
yq '
|
||||||
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
.ca_cert_path=strenv(tmpdir) + "/inter.pem" |
|
||||||
|
|
|
@ -84,4 +84,3 @@ setup() {
|
||||||
run -0 jq -r '.request_body[1].decisions[0].value' <"${MOCK_OUT}"
|
run -0 jq -r '.request_body[1].decisions[0].value' <"${MOCK_OUT}"
|
||||||
assert_output 1.2.3.5
|
assert_output 1.2.3.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,4 +117,3 @@ teardown() {
|
||||||
run -0 echo "${stderr}"
|
run -0 echo "${stderr}"
|
||||||
assert_output --partial "api server init: unable to run local API: while loading plugin config: open /this/path/does/not/exist: no such file or directory"
|
assert_output --partial "api server init: unable to run local API: while loading plugin config: open /this/path/does/not/exist: no such file or directory"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# from https://github.com/bats-core/bats-core/issues/192#issuecomment-528315083
|
# from https://github.com/bats-core/bats-core/issues/192#issuecomment-528315083
|
||||||
# thanks Sean Leather
|
# thanks Sean Leather
|
||||||
|
@ -7,10 +8,10 @@ perl -pi -e 's/^(\@test.*) \{$/$1\n{/' ./*.bats
|
||||||
|
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
for file in *bats; do
|
for file in *bats; do
|
||||||
shfmt -i 4 -ln bash -s $file >$tmpfile
|
shfmt -i 4 -ln bash -s "${file}" > "${tmpfile}"
|
||||||
mv $tmpfile $file
|
mv "${tmpfile}" "${file}"
|
||||||
done
|
done
|
||||||
rm -f $tmpfile
|
rm -f "${tmpfile}"
|
||||||
|
|
||||||
# Undo the changes to the Bats scripts in-place so that they work with Bats
|
# Undo the changes to the Bats scripts in-place so that they work with Bats
|
||||||
perl -pi -e 's/^\{\R//; s/(\@test.*$)/$1 {/' ./*.bats
|
perl -pi -e 's/^\{\R//; s/(\@test.*$)/$1 {/' ./*.bats
|
||||||
|
|
|
@ -42,10 +42,10 @@ check_yq() {
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
howto_install='You can install it with your favorite package manager (including snap) or with "GO111MODULE=on go get github.com/mikefarah/yq/v4" and add ~/go/bin to $PATH.'
|
howto_install='You can install it with your favorite package manager (including snap) or with "GO111MODULE=on go get github.com/mikefarah/yq/v4" and add ~/go/bin to $PATH.'
|
||||||
if ! command -v yq >/dev/null; then
|
if ! command -v yq >/dev/null; then
|
||||||
die "Missing required program 'yq'. $howto_install"
|
die "Missing required program 'yq'. ${howto_install}"
|
||||||
fi
|
fi
|
||||||
if ! (yq --version | grep mikefarah >/dev/null); then
|
if ! (yq --version | grep mikefarah >/dev/null); then
|
||||||
die "yq exists but it's not the one we need (mikefarah/yq). $howto_install"
|
die "yq exists but it's not the one we need (mikefarah/yq). ${howto_install}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ check_daemonizer() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
die "unsupported system: $SYSTEM"
|
die "unsupported system: ${SYSTEM}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ check_cfssl() {
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
howto_install='You can install it with "go get -u github.com/cloudflare/cfssl/cmd/cfssl" and add ~/go/bin to $PATH.'
|
howto_install='You can install it with "go get -u github.com/cloudflare/cfssl/cmd/cfssl" and add ~/go/bin to $PATH.'
|
||||||
if ! command -v cfssl >/dev/null; then
|
if ! command -v cfssl >/dev/null; then
|
||||||
die "Missing required program 'cfssl'. $howto_install"
|
die "Missing required program 'cfssl'. ${howto_install}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ check_cfssljson() {
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
howto_install='You can install it with "go get -u github.com/cloudflare/cfssl/cmd/cfssljson" and add ~/go/bin to $PATH.'
|
howto_install='You can install it with "go get -u github.com/cloudflare/cfssl/cmd/cfssljson" and add ~/go/bin to $PATH.'
|
||||||
if ! command -v cfssljson >/dev/null; then
|
if ! command -v cfssljson >/dev/null; then
|
||||||
die "Missing required program 'cfssljson'. $howto_install"
|
die "Missing required program 'cfssljson'. ${howto_install}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ check_jq
|
||||||
check_nc
|
check_nc
|
||||||
check_python3
|
check_python3
|
||||||
check_yq
|
check_yq
|
||||||
if [ -n "${TEST_COVERAGE}" ]; then
|
if [[ -n "${TEST_COVERAGE}" ]]; then
|
||||||
check_gocovmerge
|
check_gocovmerge
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ coverage() {
|
||||||
"${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest coverage --"$1" --percent
|
"${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest coverage --"$1" --percent
|
||||||
}
|
}
|
||||||
|
|
||||||
cd "$hubdir" || die "Could not find hub test results"
|
cd "${hubdir}" || die "Could not find hub test results"
|
||||||
|
|
||||||
|
shopt -s inherit_errexit
|
||||||
|
|
||||||
echo "PARSERS_COV=$(coverage parsers | cut -d = -f2)"
|
echo "PARSERS_COV=$(coverage parsers | cut -d = -f2)"
|
||||||
echo "SCENARIOS_COV=$(coverage scenarios | cut -d = -f2)"
|
echo "SCENARIOS_COV=$(coverage scenarios | cut -d = -f2)"
|
||||||
|
|
|
@ -26,7 +26,7 @@ set +e
|
||||||
output=$("${BIN_DIR}/crowdsec.cover" \
|
output=$("${BIN_DIR}/crowdsec.cover" \
|
||||||
-test.run="^TestBincoverRunMain$" \
|
-test.run="^TestBincoverRunMain$" \
|
||||||
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/crowdsec-$(date +'%s')-$$-${RANDOM}.out" \
|
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/crowdsec-$(date +'%s')-$$-${RANDOM}.out" \
|
||||||
-args-file=<(for i; do echo "$i"; done))
|
-args-file=<(for i; do echo "${i}"; done))
|
||||||
rc=$?
|
rc=$?
|
||||||
|
|
||||||
# If there is bincover metadata, we take the status code from there. Otherwise,
|
# If there is bincover metadata, we take the status code from there. Otherwise,
|
||||||
|
|
|
@ -40,7 +40,7 @@ echo "Generating hub tests..."
|
||||||
for testname in $("${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest --hub "${hubdir}" list -o json | grep -v NAME | grep -v -- '-------' | awk '{print $1}'); do
|
for testname in $("${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest --hub "${hubdir}" list -o json | grep -v NAME | grep -v -- '-------' | awk '{print $1}'); do
|
||||||
cat << EOT >> "${HUBTESTS_BATS}"
|
cat << EOT >> "${HUBTESTS_BATS}"
|
||||||
|
|
||||||
@test "\$FILE $testname" {
|
@test "\$FILE ${testname}" {
|
||||||
run "\${CSCLI}" --crowdsec "\${CROWDSEC}" --cscli "\${CSCLI}" --hub "${hubdir}" hubtest run "${testname}" --clean
|
run "\${CSCLI}" --crowdsec "\${CROWDSEC}" --cscli "\${CSCLI}" --hub "${hubdir}" hubtest run "${testname}" --clean
|
||||||
# in case of error, need to see what went wrong
|
# in case of error, need to see what went wrong
|
||||||
echo "\$output"
|
echo "\$output"
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
cd "${THIS_DIR}"
|
cd "${THIS_DIR}" || exit 1
|
||||||
#shellcheck disable=SC1090
|
#shellcheck disable=SC1090
|
||||||
. ./.environment.sh
|
. ./.environment.sh
|
||||||
|
|
||||||
backend_script="./lib/init/crowdsec-${INIT_BACKEND}"
|
backend_script="./lib/init/crowdsec-${INIT_BACKEND}"
|
||||||
|
|
||||||
if [ ! -x "$backend_script" ]; then
|
if [[ ! -x "${backend_script}" ]]; then
|
||||||
echo "unknown init system '$INIT_BACKEND'" >&2
|
echo "unknown init system '${INIT_BACKEND}'" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "$backend_script" "$@"
|
exec "${backend_script}" "$@"
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
cd "${THIS_DIR}"
|
cd "${THIS_DIR}" || exit 1
|
||||||
#shellcheck disable=SC1090
|
#shellcheck disable=SC1090
|
||||||
. ./.environment.sh
|
. ./.environment.sh
|
||||||
|
|
||||||
backend_script="./lib/config/config-${CONFIG_BACKEND}"
|
backend_script="./lib/config/config-${CONFIG_BACKEND}"
|
||||||
|
|
||||||
if [ ! -x "$backend_script" ]; then
|
if [[ ! -x "${backend_script}" ]]; then
|
||||||
echo "unknown config backend '$CONFIG_BACKEND'" >&2
|
echo "unknown config backend '${CONFIG_BACKEND}'" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "$backend_script" "$@"
|
exec "${backend_script}" "$@"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
cd "${THIS_DIR}"
|
cd "${THIS_DIR}" || exit 1
|
||||||
#shellcheck disable=SC1090
|
#shellcheck disable=SC1090
|
||||||
. ./.environment.sh
|
. ./.environment.sh
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@ cd "${THIS_DIR}"
|
||||||
|
|
||||||
backend_script="./lib/db/instance-${DB_BACKEND}"
|
backend_script="./lib/db/instance-${DB_BACKEND}"
|
||||||
|
|
||||||
if [ ! -x "$backend_script" ]; then
|
if [[ ! -x "${backend_script}" ]]; then
|
||||||
echo "unknown database '$DB_BACKEND'" >&2
|
echo "unknown database '${DB_BACKEND}'" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "$backend_script" "$@"
|
exec "${backend_script}" "$@"
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4bdd58d3fbcdce3209033d44d884e87add1d8405
|
Subproject commit 397c735212bf1a06cfdd0cb7806c5a6ea79582bf
|
|
@ -1 +1 @@
|
||||||
Subproject commit 210acf3a8ed318ddedad3137c15451739beba7d4
|
Subproject commit 410dd229a5ed005c68167cc90ed0712ad2a1c909
|
|
@ -9,7 +9,7 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [make | load | clean]"
|
die "usage: ${script_name} [make | load | clean]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
|
@ -20,14 +20,14 @@ cd "${THIS_DIR}"/../../
|
||||||
|
|
||||||
# you have not removed set -u above, have you?
|
# you have not removed set -u above, have you?
|
||||||
|
|
||||||
[ -z "${TEST_DIR-}" ] && die "\$TEST_DIR must be defined."
|
[[ -z "${TEST_DIR-}" ]] && die "\$TEST_DIR must be defined."
|
||||||
[ -z "${LOCAL_DIR-}" ] && die "\$LOCAL_DIR must be defined."
|
[[ -z "${LOCAL_DIR-}" ]] && die "\$LOCAL_DIR must be defined."
|
||||||
[ -z "${CSCLI-}" ] && die "\$CSCLI must be defined."
|
[[ -z "${CSCLI-}" ]] && die "\$CSCLI must be defined."
|
||||||
[ -z "${LOCAL_INIT_DIR-}" ] && die "\$LOCAL_INIT_DIR must be defined."
|
[[ -z "${LOCAL_INIT_DIR-}" ]] && die "\$LOCAL_INIT_DIR must be defined."
|
||||||
[ -z "${PLUGIN_DIR-}" ] && die "\$PLUGIN_DIR must be defined."
|
[[ -z "${PLUGIN_DIR-}" ]] && die "\$PLUGIN_DIR must be defined."
|
||||||
[ -z "${DB_BACKEND-}" ] && die "\$DB_BACKEND must be defined."
|
[[ -z "${DB_BACKEND-}" ]] && die "\$DB_BACKEND must be defined."
|
||||||
|
|
||||||
if [ ! -f "${CSCLI}" ]; then
|
if [[ ! -f "${CSCLI}" ]]; then
|
||||||
die "${CSCLI} is missing. Please build (with 'make bats-build') or install it."
|
die "${CSCLI} is missing. Please build (with 'make bats-build') or install it."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -54,36 +54,34 @@ make_init_data() {
|
||||||
# when installed packages are always using sqlite, so no need to regenerate
|
# when installed packages are always using sqlite, so no need to regenerate
|
||||||
# local credz for sqlite
|
# local credz for sqlite
|
||||||
|
|
||||||
[ "${DB_BACKEND}" == "sqlite" ] || ${CSCLI} machines add --auto
|
[[ "${DB_BACKEND}" == "sqlite" ]] || ${CSCLI} machines add --auto
|
||||||
|
|
||||||
"${TEST_DIR}/instance-crowdsec" start
|
"${TEST_DIR}/instance-crowdsec" start
|
||||||
"${CSCLI}" lapi status
|
"${CSCLI}" lapi status
|
||||||
[ -z "{PACKAGE_TESTING}" ] && "${CSCLI}" decisions delete --all
|
[[ -z "${PACKAGE_TESTING}" ]] && "${CSCLI}" decisions delete --all
|
||||||
"${TEST_DIR}/instance-crowdsec" stop
|
"${TEST_DIR}/instance-crowdsec" stop
|
||||||
|
|
||||||
|
|
||||||
mkdir -p "${LOCAL_INIT_DIR}"
|
mkdir -p "${LOCAL_INIT_DIR}"
|
||||||
|
|
||||||
./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"
|
||||||
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}"
|
||||||
|
|
||||||
./instance-db setup
|
./instance-db setup
|
||||||
remove_init_data
|
remove_init_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
load_init_data() {
|
load_init_data() {
|
||||||
if [ ! -f "${LOCAL_INIT_DIR}/init-config-data.tar" ]; then
|
if [[ ! -f "${LOCAL_INIT_DIR}/init-config-data.tar" ]]; then
|
||||||
die "Initial data not found; did you run '$script_name make' ?"
|
die "Initial data not found; did you run '${script_name} make' ?"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
||||||
if [ "$DB_BACKEND" != "$dump_backend" ]; then
|
if [[ "${DB_BACKEND}" != "${dump_backend}" ]]; then
|
||||||
die "Can't run with backend '$DB_BACKEND' because the test data was build with '$dump_backend'"
|
die "Can't run with backend '${DB_BACKEND}' because the test data was build with '${dump_backend}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remove_init_data
|
remove_init_data
|
||||||
|
@ -97,7 +95,7 @@ load_init_data() {
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
|
@ -9,7 +9,7 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [make | load | clean]"
|
die "usage: ${script_name} [make | load | clean]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
|
@ -20,14 +20,14 @@ cd "${THIS_DIR}"/../../
|
||||||
|
|
||||||
# you have not removed set -u above, have you?
|
# you have not removed set -u above, have you?
|
||||||
|
|
||||||
[ -z "${TEST_DIR-}" ] && die "\$TEST_DIR must be defined."
|
[[ -z "${TEST_DIR-}" ]] && die "\$TEST_DIR must be defined."
|
||||||
[ -z "${LOCAL_DIR-}" ] && die "\$LOCAL_DIR must be defined."
|
[[ -z "${LOCAL_DIR-}" ]] && die "\$LOCAL_DIR must be defined."
|
||||||
[ -z "${CSCLI-}" ] && die "\$CSCLI must be defined."
|
[[ -z "${CSCLI-}" ]] && die "\$CSCLI must be defined."
|
||||||
[ -z "${LOCAL_INIT_DIR-}" ] && die "\$LOCAL_INIT_DIR must be defined."
|
[[ -z "${LOCAL_INIT_DIR-}" ]] && die "\$LOCAL_INIT_DIR must be defined."
|
||||||
[ -z "${PLUGIN_DIR-}" ] && die "\$PLUGIN_DIR must be defined."
|
[[ -z "${PLUGIN_DIR-}" ]] && die "\$PLUGIN_DIR must be defined."
|
||||||
[ -z "${DB_BACKEND-}" ] && die "\$DB_BACKEND must be defined."
|
[[ -z "${DB_BACKEND-}" ]] && die "\$DB_BACKEND must be defined."
|
||||||
|
|
||||||
if [ ! -f "${CSCLI}" ]; then
|
if [[ ! -f "${CSCLI}" ]]; then
|
||||||
die "${CSCLI} is missing. Please build (with 'make bats-build') or install it."
|
die "${CSCLI} is missing. Please build (with 'make bats-build') or install it."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ make_init_data() {
|
||||||
"${CSCLI}" collections install crowdsecurity/linux
|
"${CSCLI}" collections install crowdsecurity/linux
|
||||||
|
|
||||||
"${TEST_DIR}/instance-crowdsec" start
|
"${TEST_DIR}/instance-crowdsec" start
|
||||||
[[ "$DB_BACKEND" =~ ^postgres|pgx$ ]] && sleep 4
|
[[ "${DB_BACKEND}" =~ ^postgres|pgx$ ]] && sleep 4
|
||||||
"${CSCLI}" lapi status
|
"${CSCLI}" lapi status
|
||||||
|
|
||||||
# a restart is required to receive community pull
|
# a restart is required to receive community pull
|
||||||
|
@ -119,20 +119,20 @@ make_init_data() {
|
||||||
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
|
echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend"
|
||||||
|
|
||||||
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}"
|
||||||
|
|
||||||
remove_init_data
|
remove_init_data
|
||||||
}
|
}
|
||||||
|
|
||||||
load_init_data() {
|
load_init_data() {
|
||||||
if [ ! -f "${LOCAL_INIT_DIR}/init-config-data.tar" ]; then
|
if [[ ! -f "${LOCAL_INIT_DIR}/init-config-data.tar" ]]; then
|
||||||
die "Initial data not found; did you run '$script_name make' ?"
|
die "Initial data not found; did you run '${script_name} make' ?"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
||||||
if [ "$DB_BACKEND" != "$dump_backend" ]; then
|
if [[ "${DB_BACKEND}" != "${dump_backend}" ]]; then
|
||||||
die "Can't run with backend '$DB_BACKEND' because the test data was build with '$dump_backend'"
|
die "Can't run with backend '${DB_BACKEND}' because the test data was build with '${dump_backend}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remove_init_data
|
remove_init_data
|
||||||
|
@ -144,7 +144,7 @@ load_init_data() {
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
script_name=$0
|
script_name=$0
|
||||||
DB_BACKEND=$(echo $script_name | cut -d- -f2)
|
DB_BACKEND=$(echo "${script_name}" | cut -d- -f2)
|
||||||
export DB_BACKEND
|
export DB_BACKEND
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
|
@ -16,7 +16,7 @@ MYSQL_PASSWORD=${MYSQL_PASSWORD:-password}
|
||||||
MYSQL_USER=${MYSQL_USER:-root}
|
MYSQL_USER=${MYSQL_USER:-root}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
die "usage: ${script_name} [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_requirements() {
|
check_requirements() {
|
||||||
|
@ -27,7 +27,7 @@ check_requirements() {
|
||||||
|
|
||||||
silence_password_warning() {
|
silence_password_warning() {
|
||||||
( ( ( "$@" >&9 ) 2>&1 \
|
( ( ( "$@" >&9 ) 2>&1 \
|
||||||
| fgrep -v "[Warning] Using a password on the command line interface can be insecure." ) >&2 ) 9>&1 || [[ $? == 1 ]]
|
| grep -F -v "[Warning] Using a password on the command line interface can be insecure." ) >&2 ) 9>&1 || [[ $? == 1 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_sql() {
|
exec_sql() {
|
||||||
|
@ -38,7 +38,7 @@ exec_sql() {
|
||||||
"--host=${MYSQL_HOST}" \
|
"--host=${MYSQL_HOST}" \
|
||||||
"--user=${MYSQL_USER}" \
|
"--user=${MYSQL_USER}" \
|
||||||
"--port=${MYSQL_PORT}" \
|
"--port=${MYSQL_PORT}" \
|
||||||
"--password=${MYSQL_PASSWORD}" <<< "$cmd"
|
"--password=${MYSQL_PASSWORD}" <<< "${cmd}"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -58,24 +58,24 @@ dump() {
|
||||||
|
|
||||||
silence_password_warning \
|
silence_password_warning \
|
||||||
mysqldump \
|
mysqldump \
|
||||||
$COLUMN_STATISTICS \
|
"${COLUMN_STATISTICS}" \
|
||||||
"--host=${MYSQL_HOST}" \
|
"--host=${MYSQL_HOST}" \
|
||||||
"--port=${MYSQL_PORT}" \
|
"--port=${MYSQL_PORT}" \
|
||||||
"--user=${MYSQL_USER}" \
|
"--user=${MYSQL_USER}" \
|
||||||
"--password=${MYSQL_PASSWORD}" \
|
"--password=${MYSQL_PASSWORD}" \
|
||||||
--databases crowdsec_test > "$backup_file"
|
--databases crowdsec_test > "${backup_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
restore() {
|
||||||
backup_file="${1?missing file to restore database from}"
|
backup_file="${1?missing file to restore database from}"
|
||||||
[ -f "$backup_file" ] || die "Backup file $backup_file doesn't exist"
|
[[ -f "${backup_file}" ]] || die "Backup file ${backup_file} doesn't exist"
|
||||||
|
|
||||||
silence_password_warning \
|
silence_password_warning \
|
||||||
mysql \
|
mysql \
|
||||||
"--host=${MYSQL_HOST}" \
|
"--host=${MYSQL_HOST}" \
|
||||||
"--user=${MYSQL_USER}" \
|
"--user=${MYSQL_USER}" \
|
||||||
"--port=${MYSQL_PORT}" \
|
"--port=${MYSQL_PORT}" \
|
||||||
"--password=${MYSQL_PASSWORD}" < "$backup_file"
|
"--password=${MYSQL_PASSWORD}" < "${backup_file}"
|
||||||
|
|
||||||
exec_sql "DROP USER IF EXISTS 'crowdsec_test';"
|
exec_sql "DROP USER IF EXISTS 'crowdsec_test';"
|
||||||
exec_sql "CREATE USER 'crowdsec_test' IDENTIFIED BY 'crowdsec_test';"
|
exec_sql "CREATE USER 'crowdsec_test' IDENTIFIED BY 'crowdsec_test';"
|
||||||
|
@ -94,7 +94,7 @@ config_yaml() {
|
||||||
' -i "${CONFIG_YAML}"
|
' -i "${CONFIG_YAML}"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
check_requirements
|
check_requirements
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
script_name=$0
|
script_name=$0
|
||||||
DB_BACKEND=$(echo $script_name | cut -d- -f2)
|
DB_BACKEND=$(echo "${script_name}" | cut -d- -f2)
|
||||||
export DB_BACKEND
|
export DB_BACKEND
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
|
@ -20,7 +20,7 @@ export PGPASSWORD
|
||||||
export PGUSER
|
export PGUSER
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
die "usage: ${script_name} [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_requirements() {
|
check_requirements() {
|
||||||
|
@ -37,7 +37,7 @@ check_requirements() {
|
||||||
|
|
||||||
exec_sql() {
|
exec_sql() {
|
||||||
cmd="${1?Missing required sql command}"
|
cmd="${1?Missing required sql command}"
|
||||||
psql <<< "$cmd"
|
psql <<< "${cmd}"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -50,13 +50,13 @@ setup() {
|
||||||
|
|
||||||
dump() {
|
dump() {
|
||||||
backup_file="${1?Missing file to backup database to}"
|
backup_file="${1?Missing file to backup database to}"
|
||||||
pg_dump -Ft --dbname crowdsec_test --clean --create --file "$backup_file"
|
pg_dump -Ft --dbname crowdsec_test --clean --create --file "${backup_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
restore() {
|
||||||
backup_file="${1?missing file to restore database from}"
|
backup_file="${1?missing file to restore database from}"
|
||||||
[ -f "$backup_file" ] || die "Backup file $backup_file doesn't exist"
|
[[ -f "${backup_file}" ]] || die "Backup file ${backup_file} doesn't exist"
|
||||||
pg_restore --dbname crowdsec_test --clean "$backup_file"
|
pg_restore --dbname crowdsec_test --clean "${backup_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
config_yaml() {
|
config_yaml() {
|
||||||
|
@ -72,7 +72,7 @@ config_yaml() {
|
||||||
' -i "${CONFIG_YAML}"
|
' -i "${CONFIG_YAML}"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
check_requirements
|
check_requirements
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
script_name=$0
|
script_name=$0
|
||||||
DB_BACKEND=$(echo $script_name | cut -d- -f2)
|
DB_BACKEND=$(echo "${script_name}" | cut -d- -f2)
|
||||||
export DB_BACKEND
|
export DB_BACKEND
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
|
@ -11,7 +11,7 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [ config-yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
die "usage: ${script_name} [ config-yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
|
@ -21,7 +21,6 @@ cd "${THIS_DIR}"/../../
|
||||||
. ./.environment.sh
|
. ./.environment.sh
|
||||||
|
|
||||||
exec_sql() {
|
exec_sql() {
|
||||||
cmd="${1?Missing required sql command}"
|
|
||||||
sqlite3 "${DB_FILE}" "$@"
|
sqlite3 "${DB_FILE}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,35 +31,36 @@ setup() {
|
||||||
dump() {
|
dump() {
|
||||||
backup_file="${1?Missing file to backup database to}"
|
backup_file="${1?Missing file to backup database to}"
|
||||||
# dirty fast cp. nothing should be accessing it right now, anyway.
|
# dirty fast cp. nothing should be accessing it right now, anyway.
|
||||||
[ -f "${DB_FILE}" ] || die "missing file ${DB_FILE}"
|
[[ -f "${DB_FILE}" ]] || die "missing file ${DB_FILE}"
|
||||||
cp "${DB_FILE}" "$backup_file"
|
cp "${DB_FILE}" "${backup_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
restore() {
|
restore() {
|
||||||
backup_file="${1?missing file to restore database from}"
|
backup_file="${1?missing file to restore database from}"
|
||||||
[ -f "$backup_file" ] || die "Backup file $backup_file doesn't exist"
|
[[ -f "${backup_file}" ]] || die "Backup file ${backup_file} doesn't exist"
|
||||||
cp "$backup_file" "${DB_FILE}"
|
cp "${backup_file}" "${DB_FILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# you have not removed set -u above, have you?
|
# you have not removed set -u above, have you?
|
||||||
|
|
||||||
[ -z "${CONFIG_YAML-}" ] && die "\$CONFIG_YAML must be defined."
|
[[ -z "${CONFIG_YAML-}" ]] && die "\$CONFIG_YAML must be defined."
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# In most cases this is called with setup argument, and it shouldn't fail for missing config file.
|
# In most cases this is called with setup argument, and it shouldn't fail for missing config file.
|
||||||
if [ -f "${CONFIG_YAML}" ] ; then
|
if [[ -f "${CONFIG_YAML}" ]]; then
|
||||||
DATA_DIR=$(yq e '.config_paths.data_dir' - <"${CONFIG_YAML}")
|
DATA_DIR=$(yq e '.config_paths.data_dir' - <"${CONFIG_YAML}")
|
||||||
DB_FILE="${DATA_DIR}/crowdsec.db"
|
DB_FILE="${DATA_DIR}/crowdsec.db"
|
||||||
|
export DB_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
config_yaml() {
|
config_yaml() {
|
||||||
yq e '
|
yq e '
|
||||||
.db_config.type=strenv(DB_BACKEND) |
|
.db_config.type=strenv(DB_BACKEND) |
|
||||||
.db_config.db_path="${DB_FILE}"
|
.db_config.db_path=strenv(DB_FILE)
|
||||||
' -i "${CONFIG_YAML}"
|
' -i "${CONFIG_YAML}"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
config-yaml)
|
config-yaml)
|
||||||
|
|
|
@ -9,7 +9,7 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [ start | stop ]"
|
die "usage: ${script_name} [ start | stop ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
|
@ -20,11 +20,11 @@ cd "${THIS_DIR}"/../../
|
||||||
|
|
||||||
# you have not removed set -u above, have you?
|
# you have not removed set -u above, have you?
|
||||||
|
|
||||||
[ -z "${CROWDSEC-}" ] && die "\$CROWDSEC must be defined."
|
[[ -z "${CROWDSEC-}" ]] && die "\$CROWDSEC must be defined."
|
||||||
[ -z "${LOG_DIR-}" ] && die "\$LOG_DIR must be defined."
|
[[ -z "${LOG_DIR-}" ]] && die "\$LOG_DIR must be defined."
|
||||||
[ -z "${PID_DIR-}" ] && die "\$PID_DIR must be defined."
|
[[ -z "${PID_DIR-}" ]] && die "\$PID_DIR must be defined."
|
||||||
|
|
||||||
if [ ! -f "${CROWDSEC}" ]; then
|
if [[ ! -f "${CROWDSEC}" ]]; then
|
||||||
die "${CROWDSEC} is missing. Please build (with 'make bats-build') or install it."
|
die "${CROWDSEC} is missing. Please build (with 'make bats-build') or install it."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if [ -f "${DAEMON_PID}" ]; then
|
if [[ -f "${DAEMON_PID}" ]]; then
|
||||||
# terminate quickly with extreme prejudice, all the application data will be
|
# terminate quickly with extreme prejudice, all the application data will be
|
||||||
# thrown away anyway. also terminate the child processes (notification plugin).
|
# thrown away anyway. also terminate the child processes (notification plugin).
|
||||||
PGID="$(ps -o pgid= -p "$(cat "${DAEMON_PID}")" | tr -d ' ')"
|
PGID="$(ps -o pgid= -p "$(cat "${DAEMON_PID}")" | tr -d ' ')"
|
||||||
# ps above should work on linux, freebsd, busybox..
|
# ps above should work on linux, freebsd, busybox..
|
||||||
if [ -n "${PGID}" ]; then
|
if [[ -n "${PGID}" ]]; then
|
||||||
kill -- "-${PGID}"
|
kill -- "-${PGID}"
|
||||||
fi
|
fi
|
||||||
rm -f -- "${DAEMON_PID}"
|
rm -f -- "${DAEMON_PID}"
|
||||||
|
@ -53,7 +53,7 @@ stop() {
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
|
|
|
@ -9,7 +9,7 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
die "usage: $script_name [ start | stop ]"
|
die "usage: ${script_name} [ start | stop ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#shellcheck disable=SC1007
|
#shellcheck disable=SC1007
|
||||||
|
@ -20,13 +20,13 @@ cd "${THIS_DIR}"/../../
|
||||||
|
|
||||||
# you have not removed set -u above, have you?
|
# you have not removed set -u above, have you?
|
||||||
|
|
||||||
[ -z "${CROWDSEC-}" ] && die "\$CROWDSEC must be defined."
|
[[ -z "${CROWDSEC-}" ]] && die "\$CROWDSEC must be defined."
|
||||||
[ -z "${CSCLI-}" ] && die "\$CSCLI must be defined."
|
[[ -z "${CSCLI-}" ]] && die "\$CSCLI must be defined."
|
||||||
[ -z "${LOG_DIR-}" ] && die "\$LOG_DIR must be defined."
|
[[ -z "${LOG_DIR-}" ]] && die "\$LOG_DIR must be defined."
|
||||||
[ -z "${PID_DIR-}" ] && die "\$PID_DIR must be defined."
|
[[ -z "${PID_DIR-}" ]] && die "\$PID_DIR must be defined."
|
||||||
|
|
||||||
|
|
||||||
if [ ! -f "${CROWDSEC}" ]; then
|
if [[ ! -f "${CROWDSEC}" ]]; then
|
||||||
die "${CROWDSEC} is missing. Please build (with 'make bats-build') or install it."
|
die "${CROWDSEC} is missing. Please build (with 'make bats-build') or install it."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ stop() {
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
|
|
1
tests/lib/setup.sh
Normal file → Executable file
1
tests/lib/setup.sh
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# these plugins are always available
|
# these plugins are always available
|
||||||
|
|
||||||
|
|
11
tests/lib/setup_file.sh
Normal file → Executable file
11
tests/lib/setup_file.sh
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
debug() {
|
debug() {
|
||||||
echo 'exec 1<&-; exec 2<&-; exec 1>&3; exec 2>&1'
|
echo 'exec 1<&-; exec 2<&-; exec 1>&3; exec 2>&1'
|
||||||
|
@ -48,28 +49,28 @@ export -f config_yq
|
||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
stderr() {
|
stderr() {
|
||||||
printf '%s' "$stderr"
|
printf '%s' "${stderr}"
|
||||||
}
|
}
|
||||||
export -f stderr
|
export -f stderr
|
||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
output() {
|
output() {
|
||||||
printf '%s' "$output"
|
printf '%s' "${output}"
|
||||||
}
|
}
|
||||||
export -f output
|
export -f output
|
||||||
|
|
||||||
is_db_postgres() {
|
is_db_postgres() {
|
||||||
[[ "$DB_BACKEND" =~ ^postgres|pgx$ ]]
|
[[ "${DB_BACKEND}" =~ ^postgres|pgx$ ]]
|
||||||
}
|
}
|
||||||
export -f is_db_postgres
|
export -f is_db_postgres
|
||||||
|
|
||||||
is_db_mysql() {
|
is_db_mysql() {
|
||||||
[[ "$DB_BACKEND" == "mysql" ]]
|
[[ "${DB_BACKEND}" == "mysql" ]]
|
||||||
}
|
}
|
||||||
export -f is_db_mysql
|
export -f is_db_mysql
|
||||||
|
|
||||||
is_db_sqlite() {
|
is_db_sqlite() {
|
||||||
[[ "$DB_BACKEND" == "sqlite" ]]
|
[[ "${DB_BACKEND}" == "sqlite" ]]
|
||||||
}
|
}
|
||||||
export -f is_db_sqlite
|
export -f is_db_sqlite
|
||||||
|
|
||||||
|
|
1
tests/lib/teardown_file.sh
Normal file → Executable file
1
tests/lib/teardown_file.sh
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# any stdout, stderr from now on will go to &3
|
# any stdout, stderr from now on will go to &3
|
||||||
eval "$(debug)"
|
eval "$(debug)"
|
||||||
|
|
|
@ -13,7 +13,7 @@ about() {
|
||||||
die "usage: ${script_name} [-q] <port_number>"
|
die "usage: ${script_name} [-q] <port_number>"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
QUIET=
|
QUIET=
|
||||||
if [[ "$1" == "-q" ]]; then
|
if [[ "$1" == "-q" ]]; then
|
||||||
|
@ -21,7 +21,7 @@ if [[ "$1" == "-q" ]]; then
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ $# -lt 1 ] && about
|
[[ $# -lt 1 ]] && about
|
||||||
|
|
||||||
port_number=$1
|
port_number=$1
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@ die() {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[ -n "${DAEMON_PID}" ]] || die "\$DAEMON_PID is required and must be the path of the pid file"
|
||||||
|
[[ -n "${OUT_FILE}" ]] || die "\$OUT_FILE is required and must be the path of the resulting stdout"
|
||||||
|
|
||||||
# Simplified dudeist daemonizer. Don't care about lock files, separate
|
# Simplified dudeist daemonizer. Don't care about lock files, separate
|
||||||
# stdout/stderr and fancy stuff. #YOLO
|
# stdout/stderr and fancy stuff. #YOLO
|
||||||
|
|
||||||
|
@ -18,7 +21,7 @@ case "${SYSTEM,,}" in
|
||||||
daemon -p "${DAEMON_PID}" -o "${OUT_FILE}" "$@"
|
daemon -p "${DAEMON_PID}" -o "${OUT_FILE}" "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
die "unsupported system: $SYSTEM"
|
die "unsupported system: ${SYSTEM}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ TEST_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
"${TEST_DIR}/check-requirements"
|
"${TEST_DIR}/check-requirements"
|
||||||
|
|
||||||
echo "Running tests..."
|
echo "Running tests..."
|
||||||
echo "DB_BACKEND: $DB_BACKEND"
|
echo "DB_BACKEND: ${DB_BACKEND}"
|
||||||
if [ -z "$TEST_COVERAGE" ]; then
|
if [[ -z "${TEST_COVERAGE}" ]]; then
|
||||||
echo "Coverage report: no"
|
echo "Coverage report: no"
|
||||||
else
|
else
|
||||||
echo "Coverage report: yes"
|
echo "Coverage report: yes"
|
||||||
|
@ -26,15 +26,16 @@ fi
|
||||||
|
|
||||||
|
|
||||||
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
||||||
if [ "$DB_BACKEND" != "$dump_backend" ]; then
|
if [[ "${DB_BACKEND}" != "${dump_backend}" ]]; then
|
||||||
die "Can't run with backend '$DB_BACKEND' because the test data was build with '$dump_backend'"
|
die "Can't run with backend '${DB_BACKEND}' because the test data was build with '${dump_backend}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -ge 1 ]; then
|
if [[ $# -ge 1 ]]; then
|
||||||
echo "test files: $*"
|
echo "test files: $*"
|
||||||
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
||||||
--jobs 1 \
|
--jobs 1 \
|
||||||
--print-output-on-failure \
|
--print-output-on-failure \
|
||||||
|
--timing \
|
||||||
"$@"
|
"$@"
|
||||||
else
|
else
|
||||||
echo "test files: ${TEST_DIR}/bats ${TEST_DIR}/dyn-bats"
|
echo "test files: ${TEST_DIR}/bats ${TEST_DIR}/dyn-bats"
|
||||||
|
@ -44,7 +45,7 @@ else
|
||||||
-T "${TEST_DIR}/bats" "${TEST_DIR}/dyn-bats"
|
-T "${TEST_DIR}/bats" "${TEST_DIR}/dyn-bats"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$TEST_COVERAGE" ]; then
|
if [[ -n "${TEST_COVERAGE}" ]]; then
|
||||||
# empty files just to avoid merge errors
|
# empty files just to avoid merge errors
|
||||||
touch "${LOCAL_DIR}"/var/lib/coverage/crowdsec-
|
touch "${LOCAL_DIR}"/var/lib/coverage/crowdsec-
|
||||||
touch "${LOCAL_DIR}"/var/lib/coverage/cscli-
|
touch "${LOCAL_DIR}"/var/lib/coverage/cscli-
|
||||||
|
|
Loading…
Reference in a new issue