github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/02_nolapi.bats (about) 1 #!/usr/bin/env bats 2 # vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si: 3 4 set -u 5 6 setup_file() { 7 load "../lib/setup_file.sh" 8 } 9 10 teardown_file() { 11 load "../lib/teardown_file.sh" 12 } 13 14 setup() { 15 load "../lib/setup.sh" 16 # always reset config and data, but run the daemon only if one test requires it 17 ./instance-data load 18 } 19 20 teardown() { 21 ./instance-crowdsec stop 22 } 23 24 #---------- 25 26 @test "test without -no-api flag" { 27 config_set '.common.log_media="stdout"' 28 rune -0 wait-for \ 29 --err "CrowdSec Local API listening" \ 30 "${CROWDSEC}" 31 } 32 33 @test "crowdsec should not run without LAPI (-no-api flag)" { 34 config_set '.common.log_media="stdout"' 35 rune -1 wait-for "${CROWDSEC}" -no-api 36 } 37 38 @test "crowdsec should not run without LAPI (no api.server in configuration file)" { 39 config_disable_lapi 40 config_log_stderr 41 rune -0 wait-for \ 42 --err "crowdsec local API is disabled" \ 43 "${CROWDSEC}" 44 } 45 46 @test "capi status shouldn't be ok without api.server" { 47 config_disable_lapi 48 rune -1 cscli capi status 49 assert_stderr --partial "crowdsec local API is disabled" 50 assert_stderr --partial "local API is disabled -- this command must be run on the local API machine" 51 } 52 53 @test "no lapi: cscli config show -o human" { 54 config_set '.api.server.enable=false' 55 rune -0 cscli config show -o human 56 assert_output --partial "Global:" 57 assert_output --partial "Crowdsec:" 58 assert_output --partial "cscli:" 59 assert_output --partial "Local API Server (disabled):" 60 61 config_set 'del(.api.server)' 62 rune -0 cscli config show -o human 63 assert_output --partial "Global:" 64 assert_output --partial "Crowdsec:" 65 assert_output --partial "cscli:" 66 refute_output --partial "Local API Server" 67 } 68 69 @test "cscli config backup" { 70 config_disable_lapi 71 backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u) 72 rune -0 cscli config backup "${backupdir}" 73 assert_stderr --partial "Starting configuration backup" 74 rune -1 cscli config backup "${backupdir}" 75 rm -rf -- "${backupdir:?}" 76 77 assert_stderr --partial "failed to backup config" 78 assert_stderr --partial "file exists" 79 } 80 81 @test "lapi status shouldn't be ok without api.server" { 82 config_disable_lapi 83 rune -1 cscli machines list 84 assert_stderr --partial "local API is disabled -- this command must be run on the local API machine" 85 } 86 87 @test "cscli metrics" { 88 skip 'need to trigger metrics with a live parse' 89 config_disable_lapi 90 ./instance-crowdsec start 91 rune -0 cscli metrics 92 assert_output --partial "ROUTE" 93 assert_output --partial "/v1/watchers/login" 94 95 assert_stderr --partial "crowdsec local API is disabled" 96 assert_stderr --partial "local API is disabled -- this command must be run on the local API machine" 97 }