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"
|
2022-06-06 13:24:48 +00:00
|
|
|
load "../lib/bats-file/load.bash"
|
2022-03-09 13:45:36 +00:00
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2023-02-20 14:05:42 +00:00
|
|
|
cd "$TEST_DIR" || exit 1
|
2022-03-09 13:45:36 +00:00
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli - usage" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli
|
2022-03-31 14:50:38 +00:00
|
|
|
assert_output --partial "Usage:"
|
|
|
|
assert_output --partial "cscli [command]"
|
|
|
|
assert_output --partial "Available Commands:"
|
2022-05-19 11:42:44 +00:00
|
|
|
|
|
|
|
# no "usage" output after every error
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli blahblah
|
2022-05-19 11:42:44 +00:00
|
|
|
# error is displayed as log entry, not with print
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial 'level=fatal msg="unknown command \"blahblah\" for \"cscli\""'
|
|
|
|
refute_stderr --partial 'unknown command "blahblah" for "cscli"'
|
2022-03-31 14:50:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli version" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli version
|
|
|
|
assert_stderr --partial "version:"
|
|
|
|
assert_stderr --partial "Codename:"
|
|
|
|
assert_stderr --partial "BuildDate:"
|
|
|
|
assert_stderr --partial "GoVersion:"
|
|
|
|
assert_stderr --partial "Platform:"
|
|
|
|
assert_stderr --partial "Constraint_parser:"
|
|
|
|
assert_stderr --partial "Constraint_scenario:"
|
|
|
|
assert_stderr --partial "Constraint_api:"
|
|
|
|
assert_stderr --partial "Constraint_acquis:"
|
2022-04-13 13:44:23 +00:00
|
|
|
|
|
|
|
# should work without configuration file
|
|
|
|
rm "${CONFIG_YAML}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli version
|
|
|
|
assert_stderr --partial "version:"
|
2022-04-13 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli help" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli help
|
2022-04-13 13:44:23 +00:00
|
|
|
assert_line "Available Commands:"
|
|
|
|
assert_line --regexp ".* help .* Help about any command"
|
|
|
|
|
|
|
|
# should work without configuration file
|
|
|
|
rm "${CONFIG_YAML}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli help
|
2022-04-13 13:44:23 +00:00
|
|
|
assert_line "Available Commands:"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
@test "cscli config show" {
|
|
|
|
rune -0 cscli config show -o human
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output --partial "Global:"
|
|
|
|
assert_output --partial "Crowdsec:"
|
|
|
|
assert_output --partial "cscli:"
|
|
|
|
assert_output --partial "Local API Server:"
|
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli config show -o json
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output --partial '"API":'
|
|
|
|
assert_output --partial '"Common":'
|
|
|
|
assert_output --partial '"ConfigPaths":'
|
|
|
|
assert_output --partial '"Crowdsec":'
|
|
|
|
assert_output --partial '"Cscli":'
|
|
|
|
assert_output --partial '"DbConfig":'
|
|
|
|
assert_output --partial '"Hub":'
|
|
|
|
assert_output --partial '"PluginConfig":'
|
|
|
|
assert_output --partial '"Prometheus":'
|
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli config show -o raw
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_line "api:"
|
|
|
|
assert_line "common:"
|
|
|
|
assert_line "config_paths:"
|
|
|
|
assert_line "crowdsec_service:"
|
|
|
|
assert_line "cscli:"
|
|
|
|
assert_line "db_config:"
|
|
|
|
assert_line "plugin_config:"
|
|
|
|
assert_line "prometheus:"
|
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli config show --key Config.API.Server.ListenURI
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output "127.0.0.1:8080"
|
2023-03-08 21:47:25 +00:00
|
|
|
|
|
|
|
# check that LAPI configuration is loaded (human and json, not shows in raw)
|
|
|
|
|
|
|
|
rune -0 cscli config show -o human
|
2023-06-29 14:35:19 +00:00
|
|
|
assert_line --regexp ".*- URL +: http://127.0.0.1:8080/"
|
2023-08-25 14:15:28 +00:00
|
|
|
assert_line --regexp ".*- Login +: githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?"
|
2023-06-29 14:35:19 +00:00
|
|
|
assert_line --regexp ".*- Credentials File +: .*/local_api_credentials.yaml"
|
2023-03-08 21:47:25 +00:00
|
|
|
|
|
|
|
rune -0 cscli config show -o json
|
2023-08-25 14:15:28 +00:00
|
|
|
rune -0 jq -c '.API.Client.Credentials | [.url,.login[0:32]]' <(output)
|
|
|
|
assert_json '["http://127.0.0.1:8080/","githubciXXXXXXXXXXXXXXXXXXXXXXXX"]'
|
2023-12-05 09:38:21 +00:00
|
|
|
|
|
|
|
# pointer to boolean
|
|
|
|
|
|
|
|
rune -0 cscli config show --key Config.API.Client.InsecureSkipVerify
|
|
|
|
assert_output "&false"
|
|
|
|
|
|
|
|
# complex type
|
|
|
|
rune -0 cscli config show --key Config.PluginConfig
|
|
|
|
assert_output - <<-EOT
|
|
|
|
&csconfig.PluginCfg{
|
|
|
|
User: "nobody",
|
|
|
|
Group: "nogroup",
|
|
|
|
}
|
|
|
|
EOT
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
@test "cscli - required configuration paths" {
|
|
|
|
config=$(cat "${CONFIG_YAML}")
|
|
|
|
configdir=$(config_get '.config_paths.config_dir')
|
|
|
|
|
|
|
|
# required configuration paths with no defaults
|
|
|
|
|
|
|
|
config_set 'del(.config_paths)'
|
|
|
|
rune -1 cscli hub list
|
|
|
|
assert_stderr --partial 'no configuration paths provided'
|
|
|
|
echo "$config" > "${CONFIG_YAML}"
|
|
|
|
|
|
|
|
config_set 'del(.config_paths.data_dir)'
|
|
|
|
rune -1 cscli hub list
|
|
|
|
assert_stderr --partial "please provide a data directory with the 'data_dir' directive in the 'config_paths' section"
|
|
|
|
echo "$config" > "${CONFIG_YAML}"
|
|
|
|
|
|
|
|
# defaults
|
|
|
|
|
|
|
|
config_set 'del(.config_paths.hub_dir)'
|
|
|
|
rune -0 cscli hub list
|
|
|
|
rune -0 cscli config show --key Config.ConfigPaths.HubDir
|
|
|
|
assert_output "$configdir/hub"
|
|
|
|
echo "$config" > "${CONFIG_YAML}"
|
|
|
|
|
|
|
|
config_set 'del(.config_paths.index_path)'
|
|
|
|
rune -0 cscli hub list
|
|
|
|
rune -0 cscli config show --key Config.ConfigPaths.HubIndexFile
|
|
|
|
assert_output "$configdir/hub/.index.json"
|
|
|
|
echo "$config" > "${CONFIG_YAML}"
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:01:13 +00:00
|
|
|
@test "cscli config show-yaml" {
|
|
|
|
rune -0 cscli config show-yaml
|
|
|
|
rune -0 yq .common.log_level <(output)
|
|
|
|
assert_output "info"
|
|
|
|
echo 'common: {"log_level": "debug"}' >> "${CONFIG_YAML}.local"
|
|
|
|
rune -0 cscli config show-yaml
|
|
|
|
rune -0 yq .common.log_level <(output)
|
|
|
|
assert_output "debug"
|
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli config backup / restore" {
|
2022-06-06 13:24:48 +00:00
|
|
|
# test that we need a valid path
|
|
|
|
# disabled because in CI, the empty string is not passed as a parameter
|
2023-03-01 09:56:25 +00:00
|
|
|
#rune -1 cscli config backup ""
|
2022-12-22 11:22:55 +00:00
|
|
|
#assert_stderr --partial "failed to backup config: directory path can't be empty"
|
2022-06-06 13:24:48 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli config backup "/dev/null/blah"
|
2022-12-22 11:22:55 +00:00
|
|
|
assert_stderr --partial "failed to backup config: while creating /dev/null/blah: mkdir /dev/null/blah: not a directory"
|
2022-06-06 13:24:48 +00:00
|
|
|
|
|
|
|
# pick a dirpath
|
2022-03-10 11:19:02 +00:00
|
|
|
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
|
2022-06-06 13:24:48 +00:00
|
|
|
|
|
|
|
# succeed the first time
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli config backup "${backupdir}"
|
|
|
|
assert_stderr --partial "Starting configuration backup"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-06-06 13:24:48 +00:00
|
|
|
# don't overwrite an existing backup
|
2023-03-01 09:56:25 +00:00
|
|
|
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-06-06 13:24:48 +00:00
|
|
|
|
2022-07-01 20:45:55 +00:00
|
|
|
SIMULATION_YAML="$(config_get '.config_paths.simulation_path')"
|
2022-06-06 13:24:48 +00:00
|
|
|
|
|
|
|
# restore
|
|
|
|
rm "${SIMULATION_YAML}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli config restore "${backupdir}"
|
2023-08-25 14:15:28 +00:00
|
|
|
assert_file_exists "${SIMULATION_YAML}"
|
2022-06-06 13:24:48 +00:00
|
|
|
|
|
|
|
# cleanup
|
|
|
|
rm -rf -- "${backupdir:?}"
|
|
|
|
|
|
|
|
# backup: detect missing files
|
|
|
|
rm "${SIMULATION_YAML}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli config backup "${backupdir}"
|
2022-12-22 11:22:55 +00:00
|
|
|
assert_stderr --regexp "failed to backup config: failed copy .* to .*: stat .*: no such file or directory"
|
2022-03-10 11:19:02 +00:00
|
|
|
rm -rf -- "${backupdir:?}"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli lapi status" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli lapi status
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
assert_stderr --partial "Loaded credentials from"
|
|
|
|
assert_stderr --partial "Trying to authenticate with username"
|
|
|
|
assert_stderr --partial " on http://127.0.0.1:8080/"
|
|
|
|
assert_stderr --partial "You can successfully interact with Local API (LAPI)"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli - missing LAPI credentials file" {
|
2022-07-01 20:45:55 +00:00
|
|
|
LOCAL_API_CREDENTIALS=$(config_get '.api.client.credentials_path')
|
2022-05-19 08:48:08 +00:00
|
|
|
rm -f "${LOCAL_API_CREDENTIALS}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli lapi status
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli alerts list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli decisions list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: while reading yaml file: open ${LOCAL_API_CREDENTIALS}: no such file or directory"
|
2022-05-19 08:48:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli - empty LAPI credentials file" {
|
2022-07-01 20:45:55 +00:00
|
|
|
LOCAL_API_CREDENTIALS=$(config_get '.api.client.credentials_path')
|
2023-07-04 10:26:32 +00:00
|
|
|
: > "${LOCAL_API_CREDENTIALS}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli lapi status
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli alerts list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli decisions list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "no credentials or URL found in api client configuration '${LOCAL_API_CREDENTIALS}'"
|
2022-05-19 08:48:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli - missing LAPI client settings" {
|
2022-07-01 20:45:55 +00:00
|
|
|
config_set 'del(.api.client)'
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli lapi status
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: no API client section in configuration"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli alerts list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: no API client section in configuration"
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -1 cscli decisions list
|
2022-08-05 08:54:49 +00:00
|
|
|
assert_stderr --partial "loading api client: no API client section in configuration"
|
2022-05-19 08:48:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli - malformed LAPI url" {
|
2022-07-01 20:45:55 +00:00
|
|
|
LOCAL_API_CREDENTIALS=$(config_get '.api.client.credentials_path')
|
2023-12-07 15:20:13 +00:00
|
|
|
config_set "${LOCAL_API_CREDENTIALS}" '.url="http://127.0.0.1:-80"'
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-12-07 15:20:13 +00:00
|
|
|
rune -1 cscli lapi status -o json
|
|
|
|
rune -0 jq -r '.msg' <(stderr)
|
|
|
|
assert_output 'parsing api url: parse "http://127.0.0.1:-80/": invalid port ":-80" after host'
|
|
|
|
}
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-12-07 15:20:13 +00:00
|
|
|
@test "cscli - bad LAPI password" {
|
|
|
|
LOCAL_API_CREDENTIALS=$(config_get '.api.client.credentials_path')
|
|
|
|
config_set "${LOCAL_API_CREDENTIALS}" '.password="meh"'
|
2022-05-19 08:48:08 +00:00
|
|
|
|
2023-12-07 15:20:13 +00:00
|
|
|
rune -1 cscli lapi status -o json
|
|
|
|
rune -0 jq -r '.msg' <(stderr)
|
|
|
|
assert_output 'failed to authenticate to Local API (LAPI): API error: incorrect Username or Password'
|
2022-05-19 08:48:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "cscli metrics" {
|
2023-03-01 09:56:25 +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
|
|
|
}
|
2022-03-10 13:57:14 +00:00
|
|
|
|
2022-06-17 14:12:49 +00:00
|
|
|
@test "'cscli completion' with or without configuration file" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli completion bash
|
2022-03-10 13:57:14 +00:00
|
|
|
assert_output --partial "# bash completion for cscli"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli completion zsh
|
2022-03-10 13:57:14 +00:00
|
|
|
assert_output --partial "# zsh completion for cscli"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli completion powershell
|
2022-06-06 13:24:48 +00:00
|
|
|
assert_output --partial "# powershell completion for cscli"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli completion fish
|
2022-06-06 13:24:48 +00:00
|
|
|
assert_output --partial "# fish completion for cscli"
|
2022-03-18 09:13:12 +00:00
|
|
|
|
|
|
|
rm "${CONFIG_YAML}"
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli completion bash
|
2022-03-10 13:57:14 +00:00
|
|
|
assert_output --partial "# bash completion for cscli"
|
|
|
|
}
|
2022-04-13 13:44:23 +00:00
|
|
|
|
2022-12-20 15:11:51 +00:00
|
|
|
@test "cscli support dump (smoke test)" {
|
2023-03-01 09:56:25 +00:00
|
|
|
rune -0 cscli support dump -f "$BATS_TEST_TMPDIR"/dump.zip
|
2023-08-25 14:15:28 +00:00
|
|
|
assert_file_exists "$BATS_TEST_TMPDIR"/dump.zip
|
2022-12-20 15:11:51 +00:00
|
|
|
}
|
2023-01-12 16:04:28 +00:00
|
|
|
|
|
|
|
@test "cscli explain" {
|
2023-11-24 14:57:32 +00:00
|
|
|
line="Sep 19 18:33:22 scw-d95986 sshd[24347]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=1.2.3.4"
|
|
|
|
|
|
|
|
rune -0 cscli parsers install crowdsecurity/syslog-logs
|
|
|
|
rune -0 cscli collections install crowdsecurity/sshd
|
|
|
|
|
|
|
|
rune -0 cscli explain --log "$line" --type syslog --only-successful-parsers --crowdsec "$CROWDSEC"
|
2023-01-12 16:04:28 +00:00
|
|
|
assert_output - <"$BATS_TEST_DIRNAME"/testdata/explain/explain-log.txt
|
2023-11-24 14:57:32 +00:00
|
|
|
|
|
|
|
rune -0 cscli parsers remove --all --purge
|
|
|
|
rune -1 cscli explain --log "$line" --type syslog --crowdsec "$CROWDSEC"
|
|
|
|
assert_stderr --partial "unable to load parser dump result: no parser found. Please install the appropriate parser and retry"
|
2023-01-12 16:04:28 +00:00
|
|
|
}
|
2023-01-23 09:29:29 +00:00
|
|
|
|
2023-04-03 08:11:56 +00:00
|
|
|
@test 'Allow variable expansion and literal $ characters in passwords' {
|
2023-01-23 09:29:29 +00:00
|
|
|
export DB_PASSWORD='P@ssw0rd'
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
config_set '.db_config.password="$DB_PASSWORD"'
|
|
|
|
rune -0 cscli config show --key Config.DbConfig.Password
|
|
|
|
assert_output 'P@ssw0rd'
|
|
|
|
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
config_set '.db_config.password="$3cureP@ssw0rd"'
|
|
|
|
rune -0 cscli config show --key Config.DbConfig.Password
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
assert_output '$3cureP@ssw0rd'
|
|
|
|
|
|
|
|
config_set '.db_config.password="P@ssw0rd$"'
|
|
|
|
rune -0 cscli config show --key Config.DbConfig.Password
|
|
|
|
assert_output 'P@ssw0rd$'
|
|
|
|
}
|
2023-02-20 14:05:42 +00:00
|
|
|
|
|
|
|
@test "cscli doc" {
|
|
|
|
# generating documentation requires a directory named "doc"
|
|
|
|
|
|
|
|
cd "$BATS_TEST_TMPDIR"
|
|
|
|
rune -1 cscli doc
|
|
|
|
refute_output
|
2023-12-14 08:16:38 +00:00
|
|
|
assert_stderr --regexp 'failed to generate cobra doc: open doc/.*: no such file or directory'
|
2023-02-20 14:05:42 +00:00
|
|
|
|
|
|
|
mkdir -p doc
|
|
|
|
rune -0 cscli doc
|
|
|
|
refute_output
|
|
|
|
refute_stderr
|
2023-08-25 14:15:28 +00:00
|
|
|
assert_file_exists "doc/cscli.md"
|
2023-02-20 14:05:42 +00:00
|
|
|
assert_file_not_exist "doc/cscli_setup.md"
|
|
|
|
|
|
|
|
# commands guarded by feature flags are not documented unless the feature flag is set
|
|
|
|
|
|
|
|
export CROWDSEC_FEATURE_CSCLI_SETUP="true"
|
|
|
|
rune -0 cscli doc
|
2023-08-25 14:15:28 +00:00
|
|
|
assert_file_exists "doc/cscli_setup.md"
|
2023-02-20 14:05:42 +00:00
|
|
|
}
|
2023-04-03 08:11:56 +00:00
|
|
|
|
|
|
|
@test "feature.yaml for subcommands" {
|
|
|
|
# it is possible to enable subcommands with feature flags defined in feature.yaml
|
|
|
|
|
|
|
|
rune -1 cscli setup
|
|
|
|
assert_stderr --partial 'unknown command \"setup\" for \"cscli\"'
|
|
|
|
CONFIG_DIR=$(dirname "$CONFIG_YAML")
|
|
|
|
echo ' - cscli_setup' >> "$CONFIG_DIR"/feature.yaml
|
|
|
|
rune -0 cscli setup
|
|
|
|
assert_output --partial 'cscli setup [command]'
|
|
|
|
}
|