From 81cf38ec13e10e4fb7893993e616f6b4c3e04ce9 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Wed, 29 Nov 2023 14:09:12 -0700 Subject: [PATCH] add more traps --- func/core/pkg_freeradius/10-test-freeradius.sh | 13 ++++++++----- func/core/pkg_git/11-test-clone-log.sh | 1 + func/core/pkg_httpd/30-test-basic-auth.sh | 4 +--- func/core/pkg_httpd/40-test-basic-vhost.sh | 11 +++++++---- func/core/pkg_shadow-utils/40-pw.sh | 9 ++++++++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/func/core/pkg_freeradius/10-test-freeradius.sh b/func/core/pkg_freeradius/10-test-freeradius.sh index 4480e86..39e29c8 100755 --- a/func/core/pkg_freeradius/10-test-freeradius.sh +++ b/func/core/pkg_freeradius/10-test-freeradius.sh @@ -1,7 +1,14 @@ #!/bin/bash -r_log "freeradius" "Test basic freeradius functionality" +function cleanup() { + cp /etc/raddb/users.backup /etc/raddb/users + rm -rf /etc/raddb/users.backup + systemctl stop radiusd.service +} +r_log "freeradius" "Test basic freeradius functionality" r_log "freeradius" "Configure freeradius" +trap cleanup EXIT + cp /etc/raddb/users /etc/raddb/users.backup cat >> /etc/raddb/users << EOF rocky Cleartext-Password := "rocky" @@ -13,7 +20,3 @@ systemctl start radiusd.service sleep 1 echo "User-Name=rocky,User-Password=rocky " | radclient -x localhost:1812 auth testing123 | grep -q 'Access-Accept' r_checkExitStatus $? - -cp /etc/raddb/users.backup /etc/raddb/users -rm -rf /etc/raddb/users.backup -systemctl stop radiusd.service diff --git a/func/core/pkg_git/11-test-clone-log.sh b/func/core/pkg_git/11-test-clone-log.sh index 6d00343..ce02584 100755 --- a/func/core/pkg_git/11-test-clone-log.sh +++ b/func/core/pkg_git/11-test-clone-log.sh @@ -1,5 +1,6 @@ #!/bin/bash r_log "git" "Test basic git clones" +trap 'rm -rf $TMPREPO' EXIT WORKDIR=$(pwd) TMPREPO=/var/tmp/repo diff --git a/func/core/pkg_httpd/30-test-basic-auth.sh b/func/core/pkg_httpd/30-test-basic-auth.sh index ca88b2a..ca9ac33 100755 --- a/func/core/pkg_httpd/30-test-basic-auth.sh +++ b/func/core/pkg_httpd/30-test-basic-auth.sh @@ -1,5 +1,6 @@ #!/bin/bash r_log "httpd" "Test basic authentication functionality" +trap "rm /etc/httpd/conf.d/test-basic-auth.conf ; m_serviceCycler httpd reload" EXIT cat > /etc/httpd/conf.d/test-basic-auth.conf < /var/www/html/basic_auth/index.html m_serviceCycler httpd cycle curl -s -u tester:tester http://localhost/basic_auth/ | grep -q 'Basic Auth Test' > /dev/null 2>&1 r_checkExitStatus $? - -rm /etc/httpd/conf.d/test-basic-auth.conf -m_serviceCycler httpd reload diff --git a/func/core/pkg_httpd/40-test-basic-vhost.sh b/func/core/pkg_httpd/40-test-basic-vhost.sh index d011963..52b578d 100755 --- a/func/core/pkg_httpd/40-test-basic-vhost.sh +++ b/func/core/pkg_httpd/40-test-basic-vhost.sh @@ -1,5 +1,12 @@ #!/bin/bash +function cleanup() { + rm /etc/httpd/conf.d/vhost.conf + sed -i '/127.0.0.1 coretest/d' /etc/hosts + m_serviceCycler httpd reload +} + r_log "httpd" "Test basic vhost functionality" +trap cleanup EXIT echo "127.0.0.1 coretest" >> /etc/hosts cat > /etc/httpd/conf.d/vhost.conf << EOF @@ -19,7 +26,3 @@ m_serviceCycler httpd cycle curl -s http://coretest/ | grep -q 'core vhost test page' > /dev/null 2>&1 r_checkExitStatus $? - -rm /etc/httpd/conf.d/vhost.conf -sed -i '/127.0.0.1 coretest/d' /etc/hosts -m_serviceCycler httpd reload diff --git a/func/core/pkg_shadow-utils/40-pw.sh b/func/core/pkg_shadow-utils/40-pw.sh index 7f250f4..da0aa9f 100755 --- a/func/core/pkg_shadow-utils/40-pw.sh +++ b/func/core/pkg_shadow-utils/40-pw.sh @@ -1,4 +1,11 @@ #!/bin/bash +function cleanup() { + pwconv + rm -rf /var/tmp/pwunconv /var/tmp/pwconv +} + +trap cleanup EXIT + r_log "shadow" "Check that pwck can use correct files" pwck -rq ./common/files/correct-passwd ./common/files/correct-shadow r_checkExitStatus $? @@ -10,7 +17,7 @@ if [ "$ret_val" -eq 0 ]; then r_log "shadow" "They're correct." exit 1 fi -r_checkExitStatus 0 +r_checkExitStatus $ret_val r_log "shadow" "Check that pwconv is functional" mkdir -p /var/tmp/pwconv