tests_post-install_5simulation.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. for i in `seq 1 10` ; do
  13. 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
  14. done;
  15. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  16. ${CSCLI} decisions list -o=json | ${JQ} '. | length == 1' || fail "expected exactly one decision"
  17. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].value == "1.1.1.174"' || fail "(exact) expected ban on 1.1.1.174"
  18. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].simulated == false' || fail "(exact) expected simulated on false"
  19. # enable simulation on specific scenario and try with same logs
  20. ${CSCLI} decisions delete --all
  21. ${CSCLI} simulation enable $SCENARIO
  22. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  23. ${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"
  24. # enable global simulation and try with same logs
  25. ${CSCLI} decisions delete --all
  26. ${CSCLI} simulation disable $SCENARIO
  27. ${CSCLI} simulation enable --global
  28. ${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
  29. ${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"