github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/10_bouncers.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      ./instance-data load
    17      ./instance-crowdsec start
    18  }
    19  
    20  teardown() {
    21      ./instance-crowdsec stop
    22  }
    23  
    24  #----------
    25  
    26  @test "there are 0 bouncers" {
    27      rune -0 cscli bouncers list -o json
    28      assert_json '[]'
    29  
    30      rune -0 cscli bouncers list -o human
    31      assert_output --partial "Name"
    32  
    33      rune -0 cscli bouncers list -o raw
    34      assert_output --partial 'name'
    35  }
    36  
    37  @test "we can add one bouncer, and delete it" {
    38      rune -0 cscli bouncers add ciTestBouncer
    39      assert_output --partial "API key for 'ciTestBouncer':"
    40      rune -0 cscli bouncers delete ciTestBouncer
    41      rune -0 cscli bouncers list -o json
    42      assert_output '[]'
    43  }
    44  
    45  @test "we can create a bouncer with a known key" {
    46      # also test the output formats since we know the key
    47      rune -0 cscli bouncers add ciTestBouncer --key "foobarbaz" -o human
    48      assert_output --partial 'foobarbaz'
    49      rune -0 cscli bouncers delete ciTestBouncer
    50      rune -0 cscli bouncers add ciTestBouncer --key "foobarbaz" -o json
    51      assert_output '"foobarbaz"'
    52      rune -0 cscli bouncers delete ciTestBouncer
    53      rune -0 cscli bouncers add ciTestBouncer --key "foobarbaz" -o raw
    54      assert_output foobarbaz
    55  }
    56  
    57  @test "we can't add the same bouncer twice" {
    58      rune -0 cscli bouncers add ciTestBouncer
    59      rune -1 cscli bouncers add ciTestBouncer -o json
    60  
    61      # XXX temporary hack to filter out unwanted log lines that may appear before
    62      # log configuration (= not json)
    63      rune -0 jq -c '[.level,.msg]' <(stderr | grep "^{")
    64      assert_output '["fatal","unable to create bouncer: bouncer ciTestBouncer already exists"]'
    65  
    66      rune -0 cscli bouncers list -o json
    67      rune -0 jq '. | length' <(output)
    68      assert_output 1
    69  }
    70  
    71  @test "delete the bouncer multiple times, even if it does not exist" {
    72      rune -0 cscli bouncers add ciTestBouncer
    73      rune -0 cscli bouncers delete ciTestBouncer
    74      rune -1 cscli bouncers delete ciTestBouncer
    75      rune -1 cscli bouncers delete foobarbaz
    76  }
    77  
    78  @test "cscli bouncers prune" {
    79      rune -0 cscli bouncers prune
    80      assert_output 'No bouncers to prune.'
    81      rune -0 cscli bouncers add ciTestBouncer
    82  
    83      rune -0 cscli bouncers prune
    84      assert_output 'No bouncers to prune.'
    85  }
    86