tests_post-install_5simulation.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/env bash
  2. # -*- coding: utf-8 -*-
  3. source tests_base.sh
  4. COLLECTION=crowdsecurity/sshd
  5. SCENARIO=crowdsecurity/ssh-bf
  6. # install sshd collection
  7. ${CSCLI} collections install $COLLECTION
  8. ${CSCLI} decisions delete --all
  9. ${SYSTEMCTL} reload crowdsec
  10. # generate a fake bf log -> cold logs processing
  11. rm -f ssh-bf.log
  12. sync
  13. for i in `seq 1 10` ; do
  14. echo `LC_ALL=C date '+%b %d %H:%M:%S '`'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.174 port 35424' >> ssh-bf.log
  15. done;
  16. sync
  17. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  18. sleep 1s
  19. ${CSCLI} decisions list -o=json | ${JQ} '. | length == 1' || fail "expected exactly one decision"
  20. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].value == "1.1.1.174"' || fail "(exact) expected ban on 1.1.1.174"
  21. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].simulated == false' || fail "(exact) expected simulated on false"
  22. sleep 1s
  23. # enable simulation on specific scenario and try with same logs
  24. ${CSCLI} decisions delete --all
  25. ${CSCLI} simulation enable $SCENARIO
  26. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  27. ${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"
  28. sleep 1s
  29. # enable global simulation and try with same logs
  30. ${CSCLI} decisions delete --all
  31. ${CSCLI} simulation disable $SCENARIO
  32. ${CSCLI} simulation enable --global
  33. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  34. sleep 1s
  35. ${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"