github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/99_lapi-stream-mode-scopes.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      ./instance-data load
     9      ./instance-crowdsec start
    10      API_KEY=$(cscli bouncers add testbouncer -o raw)
    11      export API_KEY
    12      CROWDSEC_API_URL="http://localhost:8080"
    13      export CROWDSEC_API_URL
    14  }
    15  
    16  teardown_file() {
    17      load "../lib/teardown_file.sh"
    18  }
    19  
    20  setup() {
    21      load "../lib/setup.sh"
    22  }
    23  
    24  #----------
    25  
    26  api() {
    27      URI="$1"
    28      curl -s -H "X-Api-Key: ${API_KEY}" "${CROWDSEC_API_URL}${URI}"
    29  }
    30  
    31  @test "adding decisions for multiple scopes" {
    32      rune -0 cscli decisions add -i '1.2.3.6'
    33      assert_stderr --partial 'Decision successfully added'
    34      rune -0 cscli decisions add --scope user --value toto
    35      assert_stderr --partial 'Decision successfully added'
    36  }
    37  
    38  @test "stream start (implicit ip scope)" {
    39      rune -0 api "/v1/decisions/stream?startup=true"
    40      rune -0 jq -r '.new' <(output)
    41      assert_output --partial '1.2.3.6'
    42      refute_output --partial 'toto'
    43  }
    44  
    45  @test "stream start (explicit ip scope)" {
    46      rune -0 api "/v1/decisions/stream?startup=true&scopes=ip"
    47      rune -0 jq -r '.new' <(output)
    48      assert_output --partial '1.2.3.6'
    49      refute_output --partial 'toto'
    50  }
    51  
    52  @test "stream start (user scope)" {
    53      rune -0 api "/v1/decisions/stream?startup=true&scopes=user"
    54      rune -0 jq -r '.new' <(output)
    55      refute_output --partial '1.2.3.6'
    56      assert_output --partial 'toto'
    57  }
    58  
    59  @test "stream start (user+ip scope)" {
    60      rune -0 api "/v1/decisions/stream?startup=true&scopes=user,ip"
    61      rune -0 jq -r '.new' <(output)
    62      assert_output --partial '1.2.3.6'
    63      assert_output --partial 'toto'
    64  }