github.com/crowdsecurity/crowdsec@v1.6.1/test/bats/71_plugin_dummy.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      is_package_testing && return
     9  
    10      ./instance-data load
    11  
    12      tempfile=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
    13      export tempfile
    14  
    15      tempfile2=$(TMPDIR="${BATS_FILE_TMPDIR}" mktemp)
    16      export tempfile2
    17  
    18      DUMMY_YAML="$(config_get '.config_paths.notification_dir')/dummy.yaml"
    19  
    20      config_set "${DUMMY_YAML}" '
    21         .group_wait="5s" |
    22         .group_threshold=2 |
    23         .output_file=strenv(tempfile) |
    24         .format="{{.|toJson}}"
    25      '
    26  
    27      cat <<-EOT >>"${DUMMY_YAML}"
    28  	---
    29  	type: dummy
    30  	name: dummy_2
    31  	log_level: info
    32  	format: secondfile
    33  	output_file: ${tempfile2}
    34  	EOT
    35  
    36      config_set "$(config_get '.api.server.profiles_path')" '
    37         .notifications=["dummy_default","dummy_2"] |
    38         .filters=["Alert.GetScope() == \"Ip\""]
    39      '
    40  
    41      config_set '
    42         .plugin_config.user="" |
    43         .plugin_config.group=""
    44      '
    45  
    46      ./instance-crowdsec start
    47  }
    48  
    49  teardown_file() {
    50      load "../lib/teardown_file.sh"
    51  }
    52  
    53  setup() {
    54      is_package_testing && skip
    55      load "../lib/setup.sh"
    56  }
    57  
    58  #----------
    59  
    60  @test "add two bans" {
    61      rune -0 cscli decisions add --ip 1.2.3.4 --duration 30s
    62      assert_stderr --partial 'Decision successfully added'
    63  
    64      rune -0 cscli decisions add --ip 1.2.3.5 --duration 30s
    65      assert_stderr --partial 'Decision successfully added'
    66      sleep 2
    67  }
    68  
    69  @test "expected 1 notification" {
    70      rune -0 cat "${tempfile}"
    71      assert_output --partial 1.2.3.4
    72      assert_output --partial 1.2.3.5
    73  }
    74  
    75  @test "second notification works too" {
    76      rune -0 cat "${tempfile2}"
    77      assert_output --partial secondfile
    78  }