github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/01_crowdsec_lapi.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 load "../lib/bats-file/load.bash" 17 ./instance-data load 18 } 19 20 teardown() { 21 ./instance-crowdsec stop 22 } 23 24 #---------- 25 26 # Tests for LAPI configuration and startup 27 28 @test "lapi (.api.server.enable=false)" { 29 rune -0 config_set '.api.server.enable=false' 30 rune -1 "${CROWDSEC}" -no-cs 31 assert_stderr --partial "you must run at least the API Server or crowdsec" 32 } 33 34 @test "lapi (no .api.server.listen_uri)" { 35 rune -0 config_set 'del(.api.server.listen_socket) | del(.api.server.listen_uri)' 36 rune -1 "${CROWDSEC}" -no-cs 37 assert_stderr --partial "no listen_uri or listen_socket specified" 38 } 39 40 @test "lapi (bad .api.server.listen_uri)" { 41 rune -0 config_set 'del(.api.server.listen_socket) | .api.server.listen_uri="127.0.0.1:-80"' 42 rune -1 "${CROWDSEC}" -no-cs 43 assert_stderr --partial "local API server stopped with error: listening on 127.0.0.1:-80: listen tcp: address -80: invalid port" 44 } 45 46 @test "lapi (listen on random port)" { 47 config_set '.common.log_media="stdout"' 48 rune -0 config_set 'del(.api.server.listen_socket) | .api.server.listen_uri="127.0.0.1:0"' 49 rune -0 wait-for --err "CrowdSec Local API listening on 127.0.0.1:" "${CROWDSEC}" -no-cs 50 } 51