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
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
API_KEY=$(cscli bouncers add testbouncer -o raw)
|
|
|
|
export API_KEY
|
|
|
|
CROWDSEC_API_URL="http://localhost:8080"
|
|
|
|
export CROWDSEC_API_URL
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2024-02-01 21:36:21 +00:00
|
|
|
if is_db_mysql; then sleep 0.5; fi
|
2022-03-21 14:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 13:45:36 +00:00
|
|
|
api() {
|
|
|
|
URI="$1"
|
2024-03-12 14:29:59 +00:00
|
|
|
curl -f -s -H "X-Api-Key: ${API_KEY}" "${CROWDSEC_API_URL}${URI}"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 13:17:49 +00:00
|
|
|
#----------
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "cli - first decisions list: must be empty" {
|
2022-04-13 13:17:49 +00:00
|
|
|
# delete community pull
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions delete --all
|
|
|
|
rune -0 cscli decisions list -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-04-13 13:17:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "adding decision for ip 1111:2222:3333:4444:5555:6666:7777:8888" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions add -i '1111:2222:3333:4444:5555:6666:7777:8888'
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial 'Decision successfully added'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - all decisions" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -o json
|
|
|
|
rune -0 jq -r '.[].decisions[0].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - all decisions" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api "/v1/decisions"
|
|
|
|
rune -0 jq -r '.[].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip 1111:2222:3333:4444:5555:6666:7777:8888" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -i '1111:2222:3333:4444:5555:6666:7777:8888' -o json
|
|
|
|
rune -0 jq -r '.[].decisions[0].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for ip 1111:2222:3333:4444:5555:6666:7777:888" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?ip=1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
rune -0 jq -r '.[].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip 1211:2222:3333:4444:5555:6666:7777:8888" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -i '1211:2222:3333:4444:5555:6666:7777:8888' -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for ip 1211:2222:3333:4444:5555:6666:7777:888" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?ip=1211:2222:3333:4444:5555:6666:7777:8888'
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'null'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip 1111:2222:3333:4444:5555:6666:7777:8887" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -i '1111:2222:3333:4444:5555:6666:7777:8887' -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for ip 1111:2222:3333:4444:5555:6666:7777:8887" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?ip=1111:2222:3333:4444:5555:6666:7777:8887'
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'null'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/48" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -r '1111:2222:3333:4444:5555:6666:7777:8888/48' -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/48" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/48'
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'null'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/48" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -r '1111:2222:3333:4444:5555:6666:7777:8888/48' --contained -o json
|
|
|
|
rune -0 jq -r '.[].decisions[0].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/48" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/48&&contains=false'
|
|
|
|
rune -0 jq -r '.[].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/64" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -r '1111:2222:3333:4444:5555:6666:7777:8888/64' -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/64" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/64'
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'null'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/64" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -r '1111:2222:3333:4444:5555:6666:7777:8888/64' -o json --contained
|
|
|
|
rune -0 jq -r '.[].decisions[0].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "API - decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/64" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 api '/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/64&&contains=false'
|
|
|
|
rune -0 jq -r '.[].value' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '1111:2222:3333:4444:5555:6666:7777:8888'
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "adding decision for ip 1111:2222:3333:4444:5555:6666:7777:8889" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions add -i '1111:2222:3333:4444:5555:6666:7777:8889'
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial 'Decision successfully added'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "deleting decision for ip 1111:2222:3333:4444:5555:6666:7777:8889" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions delete -i '1111:2222:3333:4444:5555:6666:7777:8889'
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial '1 decision(s) deleted'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip 1111:2222:3333:4444:5555:6666:7777:8889 after delete" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -i '1111:2222:3333:4444:5555:6666:7777:8889' -o json
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "deleting decision for range 1111:2222:3333:4444:5555:6666:7777:8888/64" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions delete -r '1111:2222:3333:4444:5555:6666:7777:8888/64' --contained
|
2022-12-30 14:57:24 +00:00
|
|
|
assert_stderr --partial '1 decision(s) deleted'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "CLI - decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/64 after delete" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli decisions list -r '1111:2222:3333:4444:5555:6666:7777:8888/64' -o json --contained
|
2023-08-03 10:51:50 +00:00
|
|
|
assert_json '[]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|