|
@@ -26,14 +26,14 @@ declare stderr
|
|
|
|
|
|
#----------
|
|
|
|
|
|
-@test "$FILE cscli - usage" {
|
|
|
+@test "${FILE} cscli - usage" {
|
|
|
run -0 cscli
|
|
|
assert_output --partial "Usage:"
|
|
|
assert_output --partial "cscli [command]"
|
|
|
assert_output --partial "Available Commands:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli version" {
|
|
|
+@test "${FILE} cscli version" {
|
|
|
run -0 cscli version
|
|
|
assert_output --partial "version:"
|
|
|
assert_output --partial "Codename:"
|
|
@@ -51,7 +51,7 @@ declare stderr
|
|
|
assert_output --partial "version:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli help" {
|
|
|
+@test "${FILE} cscli help" {
|
|
|
run -0 cscli help
|
|
|
assert_line "Available Commands:"
|
|
|
assert_line --regexp ".* help .* Help about any command"
|
|
@@ -62,7 +62,7 @@ declare stderr
|
|
|
assert_line "Available Commands:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli alerts list: at startup returns at least one entry: community pull" {
|
|
|
+@test "${FILE} cscli alerts list: at startup returns at least one entry: community pull" {
|
|
|
is_db_postgres && skip
|
|
|
# it should have been received while preparing the fixture
|
|
|
run -0 cscli alerts list -o json
|
|
@@ -80,7 +80,7 @@ declare stderr
|
|
|
# refute_output 0
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli capi status" {
|
|
|
+@test "${FILE} cscli capi status" {
|
|
|
run -0 cscli capi status
|
|
|
assert_output --partial "Loaded credentials from"
|
|
|
assert_output --partial "Trying to authenticate with username"
|
|
@@ -88,7 +88,7 @@ declare stderr
|
|
|
assert_output --partial "You can successfully interact with Central API (CAPI)"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli config show -o human" {
|
|
|
+@test "${FILE} cscli config show -o human" {
|
|
|
run -0 cscli config show -o human
|
|
|
assert_output --partial "Global:"
|
|
|
assert_output --partial "Crowdsec:"
|
|
@@ -96,7 +96,7 @@ declare stderr
|
|
|
assert_output --partial "Local API Server:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli config show -o json" {
|
|
|
+@test "${FILE} cscli config show -o json" {
|
|
|
run -0 cscli config show -o json
|
|
|
assert_output --partial '"API":'
|
|
|
assert_output --partial '"Common":'
|
|
@@ -109,7 +109,7 @@ declare stderr
|
|
|
assert_output --partial '"Prometheus":'
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli config show -o raw" {
|
|
|
+@test "${FILE} cscli config show -o raw" {
|
|
|
run -0 cscli config show -o raw
|
|
|
assert_line "api:"
|
|
|
assert_line "common:"
|
|
@@ -121,45 +121,112 @@ declare stderr
|
|
|
assert_line "prometheus:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli config show --key" {
|
|
|
+@test "${FILE} cscli config show --key" {
|
|
|
run -0 cscli config show --key Config.API.Server.ListenURI
|
|
|
assert_output "127.0.0.1:8080"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli config backup" {
|
|
|
+@test "${FILE} cscli config backup" {
|
|
|
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
|
|
run -0 cscli config backup "${backupdir}"
|
|
|
assert_output --partial "Starting configuration backup"
|
|
|
run -1 --separate-stderr cscli config backup "${backupdir}"
|
|
|
|
|
|
- run -0 echo "$stderr"
|
|
|
+ run -0 echo "${stderr}"
|
|
|
assert_output --partial "Failed to backup configurations"
|
|
|
assert_output --partial "file exists"
|
|
|
rm -rf -- "${backupdir:?}"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli lapi status" {
|
|
|
+@test "${FILE} cscli lapi status" {
|
|
|
if is_db_postgres; then sleep 4; fi
|
|
|
run -0 --separate-stderr cscli lapi status
|
|
|
|
|
|
- run -0 echo "$stderr"
|
|
|
+ run -0 echo "${stderr}"
|
|
|
assert_output --partial "Loaded credentials from"
|
|
|
assert_output --partial "Trying to authenticate with username"
|
|
|
assert_output --partial " on http://127.0.0.1:8080/"
|
|
|
assert_output --partial "You can successfully interact with Local API (LAPI)"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli metrics" {
|
|
|
+@test "${FILE} cscli - missing LAPI credentials file" {
|
|
|
+ LOCAL_API_CREDENTIALS=$(config_yq '.api.client.credentials_path')
|
|
|
+ rm -f "${LOCAL_API_CREDENTIALS}"
|
|
|
+ run -1 --separate-stderr cscli lapi status
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli alerts list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli decisions list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
|
|
+}
|
|
|
+
|
|
|
+@test "${FILE} cscli - empty LAPI credentials file" {
|
|
|
+ LOCAL_API_CREDENTIALS=$(config_yq '.api.client.credentials_path')
|
|
|
+ truncate -s 0 "${LOCAL_API_CREDENTIALS}"
|
|
|
+ run -1 --separate-stderr cscli lapi status
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli alerts list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli decisions list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
|
|
+}
|
|
|
+
|
|
|
+@test "${FILE} cscli - missing LAPI client settings" {
|
|
|
+ yq e 'del(.api.client)' -i "${CONFIG_YAML}"
|
|
|
+ run -1 --separate-stderr cscli lapi status
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: no API client section in configuration"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli alerts list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: no API client section in configuration"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli decisions list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial "loading api client: no API client section in configuration"
|
|
|
+}
|
|
|
+
|
|
|
+@test "${FILE} cscli - malformed LAPI url" {
|
|
|
+ LOCAL_API_CREDENTIALS=$(config_yq '.api.client.credentials_path')
|
|
|
+ yq e '.url="https://127.0.0.1:-80"' -i "${LOCAL_API_CREDENTIALS}"
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli lapi status
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial 'parsing api url'
|
|
|
+ assert_output --partial 'invalid port \":-80\" after host'
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli alerts list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial 'parsing api url'
|
|
|
+ assert_output --partial 'invalid port ":-80" after host'
|
|
|
+
|
|
|
+ run -1 --separate-stderr cscli decisions list
|
|
|
+ run -0 echo "${stderr}"
|
|
|
+ assert_output --partial 'parsing api url'
|
|
|
+ assert_output --partial 'invalid port ":-80" after host'
|
|
|
+}
|
|
|
+
|
|
|
+@test "${FILE} cscli metrics" {
|
|
|
run -0 cscli lapi status
|
|
|
run -0 --separate-stderr cscli metrics
|
|
|
assert_output --partial "ROUTE"
|
|
|
assert_output --partial '/v1/watchers/login'
|
|
|
|
|
|
- run -0 echo "$stderr"
|
|
|
+ run -0 echo "${stderr}"
|
|
|
assert_output --partial "Local Api Metrics:"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE 'cscli completion' with or without configuration file" {
|
|
|
+@test "${FILE} 'cscli completion' with or without configuration file" {
|
|
|
run -0 cscli completion bash
|
|
|
assert_output --partial "# bash completion for cscli"
|
|
|
run -0 cscli completion zsh
|
|
@@ -172,7 +239,7 @@ declare stderr
|
|
|
assert_output --partial "# zsh completion for cscli"
|
|
|
}
|
|
|
|
|
|
-@test "$FILE cscli hub list" {
|
|
|
+@test "${FILE} cscli hub list" {
|
|
|
# we check for the presence of some objects. There may be others when we
|
|
|
# use $PACKAGE_TESTING, so the order is not important.
|
|
|
|