2022-03-10 12:55:25 +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-10 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/teardown_file.sh"
|
2022-03-10 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load "../lib/setup.sh"
|
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
declare stderr
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
|
|
|
@test "$FILE 'decisions add' requires parameters" {
|
|
|
|
run -1 --separate-stderr cscli decisions add
|
|
|
|
assert_line "Usage:"
|
|
|
|
run echo "$stderr"
|
|
|
|
assert_output --partial "Missing arguments, a value is required (--ip, --range or --scope and --value)"
|
|
|
|
|
|
|
|
run -1 --separate-stderr cscli decisions add -o json
|
|
|
|
run echo "$stderr"
|
|
|
|
run -0 jq -c '[ .level, .msg]' <(output)
|
|
|
|
assert_output '["fatal","Missing arguments, a value is required (--ip, --range or --scope and --value)"]'
|
|
|
|
}
|
|
|
|
|
2022-03-17 11:20:08 +00:00
|
|
|
@test "$FILE cscli decisions list, with and without --machine" {
|
2022-04-13 13:17:49 +00:00
|
|
|
is_db_postgres && skip
|
2022-03-17 11:20:08 +00:00
|
|
|
run -0 cscli decisions add -i 10.20.30.40 -t ban
|
|
|
|
|
|
|
|
run -0 cscli decisions list
|
|
|
|
refute_output --partial 'MACHINE'
|
|
|
|
# machine name appears quoted in the "REASON" column
|
2022-03-29 15:06:49 +00:00
|
|
|
assert_output --regexp "\| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?' \|"
|
|
|
|
refute_output --regexp "\| githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})? \|"
|
2022-03-17 11:20:08 +00:00
|
|
|
|
|
|
|
run -0 cscli decisions list -m
|
|
|
|
assert_output --partial 'MACHINE'
|
2022-03-29 15:06:49 +00:00
|
|
|
assert_output --regexp "\| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?' \|"
|
|
|
|
assert_output --regexp "\| githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})? \|"
|
2022-03-17 11:20:08 +00:00
|
|
|
|
|
|
|
run -0 cscli decisions list --machine
|
|
|
|
assert_output --partial 'MACHINE'
|
2022-03-29 15:06:49 +00:00
|
|
|
assert_output --regexp "\| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?' \|"
|
|
|
|
assert_output --regexp "\| githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})? \|"
|
2022-03-17 11:20:08 +00:00
|
|
|
}
|