diff options
author | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-11-26 23:01:38 +0100 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-12-03 08:53:33 +0100 |
commit | 4c9178242385c3819a56d79321841668836eebad (patch) | |
tree | e4bf342f5b61f5feb6d35a2f3eafce6e119417c5 /tests | |
parent | tests/packaging/interactive: suppress some commands stdout (diff) | |
download | knot-resolver-4c9178242385c3819a56d79321841668836eebad.tar.xz knot-resolver-4c9178242385c3819a56d79321841668836eebad.zip |
tests/packaging/interactive: added watchdog test
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/packaging/interactive/watchdog.sh | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/packaging/interactive/watchdog.sh b/tests/packaging/interactive/watchdog.sh new file mode 100755 index 00000000..6e5e506a --- /dev/null +++ b/tests/packaging/interactive/watchdog.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +set -e + +gitroot=$(git rev-parse --show-toplevel) +cert_file=$gitroot/modules/http/test_tls/test.crt +key_file=$gitroot/modules/http/test_tls/test.key + +tls_certificate_conf=$(cat <<EOF +{ + "cert-file": "$cert_file", + "key-file": "$key_file" +} +EOF +) + +# configure TLS certificate files +kresctl config set -p /network/tls "$tls_certificate_conf" +if [ "$?" -ne "0" ]; then + echo "Could not set TLS certificate files." + exit 1 +fi + +function count_errors(){ + echo "$(journalctl -u knot-resolver.service | grep -c error)" +} + +function count_reloads(){ + echo "$(journalctl -u knot-resolver.service | grep -c "Reloading of TLS certificate files has finished")" +} + +# test modification +# {{ + +# modify certificate files with '-', it will trigger reload +err_count=$(count_errors) +rel_count=$(count_reloads) +echo "-----------" >> $cert_file +echo "-----------" >> $key_file + +# wait for files reload to finish +sleep 6 + +if [ $(count_errors) -ne $err_count ] || [ $(count_reloads) -eq $rel_count ]; then + echo "Could not reload modified TLS certificate files." + exit 1 +fi + +# }} + +# test replacement +# {{ + +rel_count=$(count_reloads) + +# copy cert files +cp $cert_file test.crt.new +cp $key_file test.key.new + +# edit new files +echo "-----------" >> test.crt.new +echo "-----------" >> test.key.new + +# replace files +mv -f test.crt.new $cert_file +mv -f test.key.new $key_file + +# wait for files reload to finish +sleep 6 + +if [ $(count_errors) -ne $err_count ] || [ $(count_reloads) -eq $rel_count ]; then + echo "Could not reload replaced TLS certificate files." + exit 1 +fi + +# }} + +# test recovery from deletion and creation +# {{ + +rel_count=$(count_reloads) + +# backup cert files +cp $cert_file test.crt.backup +cp $key_file test.key.backup + +# delete cert files +rm $cert_file $key_file + +# create cert files +mv test.crt.backup $cert_file +mv test.key.backup $key_file + +# wait for files reload to finish +sleep 6 + +if [ $(count_errors) -ne $err_count ] || [ $(count_reloads) -eq $rel_count ]; then + echo "Could not reload created TLS certificate files." + exit 1 +fi + +# }} |