mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
fix functional tests (#838)
* fix functional tests * add journal detection feature in wizard.sh Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
This commit is contained in:
parent
42bc31cf23
commit
bb37e2e70d
5 changed files with 56 additions and 11 deletions
|
@ -10,13 +10,31 @@ CSCLI_BIN="cscli"
|
|||
CSCLI="sudo ${CSCLI_BIN}"
|
||||
JQ="jq -e"
|
||||
|
||||
LC_ALL=C
|
||||
SYSTEMCTL="sudo systemctl --no-pager"
|
||||
|
||||
CROWDSEC="sudo crowdsec"
|
||||
CROWDSEC_PROCESS="crowdsec"
|
||||
|
||||
# helpers
|
||||
function fail {
|
||||
echo "ACTION FAILED, STOP : $@"
|
||||
caller
|
||||
exit 1
|
||||
}
|
||||
|
||||
function pathadd {
|
||||
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
|
||||
PATH="${PATH:+"$PATH:"}$1"
|
||||
fi
|
||||
}
|
||||
|
||||
pathadd /usr/sbin
|
||||
|
||||
if [ -f /etc/systemd/system/crowdsec.service ]; then
|
||||
SYSTEMD_SERVICE_FILE=/etc/systemd/system/crowdsec.service
|
||||
elif [ -f /usr/lib/systemd/system/crowdsec.service ]; then
|
||||
SYSTEMD_SERVICE_FILE=/usr/lib/systemd/system/crowdsec.service
|
||||
elif [ -f /lib/systemd/system/crowdsec.service ]; then
|
||||
SYSTEMD_SERVICE_FILE=/lib/systemd/system/crowdsec.service
|
||||
fi
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
source tests_base.sh
|
||||
|
||||
|
||||
echo $PATH
|
||||
|
||||
##########################
|
||||
## TEST AGENT/LAPI/CAPI ##
|
||||
|
@ -55,14 +55,18 @@ ${SYSTEMCTL} stop crowdsec || fail "crowdsec should be down"
|
|||
echo "CROWDSEC (AGENT)"
|
||||
|
||||
# test with -no-api flag
|
||||
sudo cp ./systemd/crowdsec_no_lapi.service /etc/systemd/system/crowdsec.service
|
||||
cp ${SYSTEMD_SERVICE_FILE} /tmp/crowdsec.service-orig
|
||||
sed '/^ExecStart/ s/$/ -no-api/' ${SYSTEMD_SERVICE_FILE} > /tmp/crowdsec.service
|
||||
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
|
||||
|
||||
${SYSTEMCTL} daemon-reload
|
||||
${SYSTEMCTL} start crowdsec
|
||||
sleep 1
|
||||
pidof crowdsec && fail "crowdsec shouldn't run without LAPI (in flag)"
|
||||
${SYSTEMCTL} stop crowdsec
|
||||
|
||||
sudo cp ./systemd/crowdsec.service /etc/systemd/system/crowdsec.service
|
||||
sudo cp /tmp/crowdsec.service-orig /etc/systemd/system/crowdsec.service
|
||||
|
||||
${SYSTEMCTL} daemon-reload
|
||||
|
||||
# test with no api server in configuration file
|
||||
|
@ -92,13 +96,18 @@ sudo cp ./config/config.yaml /etc/crowdsec/config.yaml
|
|||
echo "CROWDSEC (LAPI+CAPI)"
|
||||
|
||||
# test with -no-cs flag
|
||||
sudo cp ./systemd/crowdsec_no_agent.service /etc/systemd/system/crowdsec.service
|
||||
sed '/^ExecStart/ s/$/ -no-cs/' /etc/systemd/system/crowdsec.service > /tmp/crowdsec.service
|
||||
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
|
||||
|
||||
|
||||
${SYSTEMCTL} daemon-reload
|
||||
${SYSTEMCTL} start crowdsec
|
||||
pidof crowdsec || fail "crowdsec LAPI should run without agent (in flag)"
|
||||
${SYSTEMCTL} stop crowdsec
|
||||
|
||||
sudo cp ./systemd/crowdsec.service /etc/systemd/system/crowdsec.service
|
||||
sed '/^ExecStart/s/-no-cs//g' ${SYSTEMD_SERVICE_FILE} > /tmp/crowdsec.service
|
||||
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
|
||||
|
||||
${SYSTEMCTL} daemon-reload
|
||||
|
||||
# test with no crowdsec agent in configuration file
|
||||
|
@ -142,5 +151,6 @@ ${CSCLI} -c ./config/config_no_capi.yaml lapi status || fail "lapi status failed
|
|||
## metrics
|
||||
${CSCLI_BIN} -c ./config/config_no_capi.yaml metrics || fail "failed to get metrics"
|
||||
|
||||
sudo cp ./config/config.yaml /etc/crowdsec/config.yaml
|
||||
sudo mv /tmp/crowdsec.service-orig /etc/systemd/system/crowdsec.service
|
||||
|
||||
${SYSTEMCTL} restart crowdsec
|
||||
|
|
|
@ -15,7 +15,7 @@ ${SYSTEMCTL} reload crowdsec
|
|||
rm -f ssh-bf.log
|
||||
|
||||
for i in `seq 1 10` ; do
|
||||
echo `date '+%b %d %H:%M:%S '`'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.172 port 35424' >> ssh-bf.log
|
||||
echo `LC_ALL=C date '+%b %d %H:%M:%S '`'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.172 port 35424' >> ssh-bf.log
|
||||
done;
|
||||
|
||||
${CROWDSEC} -dsn "file://./ssh-bf.log" -type syslog -no-api
|
||||
|
|
|
@ -17,7 +17,7 @@ ${SYSTEMCTL} reload crowdsec
|
|||
rm -f ssh-bf.log
|
||||
|
||||
for i in `seq 1 10` ; do
|
||||
echo `date '+%b %d %H:%M:%S '`'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.174 port 35424' >> ssh-bf.log
|
||||
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
|
||||
done;
|
||||
|
||||
${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
|
||||
|
@ -44,4 +44,4 @@ ${CSCLI} simulation enable --global
|
|||
|
||||
${CROWDSEC} -dsn file://./ssh-bf.log -type syslog -no-api
|
||||
|
||||
${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"
|
||||
${CSCLI} decisions list --no-simu -o=json | ${JQ} '. == null' || fail "expected no decision (listing only non-simulated decisions)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue