commit 89c81c8e277632281595eb9a0780808f4806e69c92a9aae6fc51e6677b0efc95 from: Stefan Sperling date: Thu Jun 26 13:54:07 2025 UTC add a test case for deny rules in gotsys.conf Deny rules in gotsys.conf didn't actually work until recently and were lacking test coverage. commit - 1713708d4d22ed45a4bd7cbd93038c02bdecdd39dbdffdd2713969ea190e435b commit + 89c81c8e277632281595eb9a0780808f4806e69c92a9aae6fc51e6677b0efc95 blob - 95dd3a31375bd044b39db48fb6f59dbe1866e3dbb9b4d4467601a7fb9b1bffb9 blob + 3f47bc0848b9184e512968095b23182c21908c89c0e81c5d9251bbcda1989692 --- regress/gotsysd/test_gotsysd.sh +++ regress/gotsysd/test_gotsysd.sh @@ -1432,6 +1432,108 @@ EOF test_done "$testroot" "$ret" } +test_deny_access() { + local testroot=`test_init deny_access 1` + + got checkout -q $testroot/${GOTSYS_REPO} $testroot/wt >/dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got checkout failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + crypted_vm_pw=`echo ${GOTSYSD_VM_PASSWORD} | encrypt | tr -d '\n'` + crypted_pw=`echo ${GOTSYSD_DEV_PASSWORD} | encrypt | tr -d '\n'` + sshkey=`cat ${GOTSYSD_SSH_PUBKEY}` + cat > ${testroot}/wt/gotsys.conf </dev/null) + local commit_id=`git_show_head $testroot/${GOTSYS_REPO}` + + got send -q -i ${GOTSYSD_SSH_KEY} -r ${testroot}/${GOTSYS_REPO} + ret=$? + if [ $ret -ne 0 ]; then + echo "got send failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + # Wait for gotsysd to apply the new configuration. + echo "$commit_id" > $testroot/stdout.expected + for i in 1 2 3 4 5; do + sleep 1 + ssh -i ${GOTSYSD_SSH_KEY} root@${VMIP} \ + cat /var/db/gotsysd/commit > $testroot/stdout + if cmp -s $testroot/stdout.expected $testroot/stdout; then + break; + fi + done + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "gotsysd failed to apply configuration" >&2 + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Try to clone repository foo. Should fail. + got clone -q -i ${GOTSYSD_SSH_KEY} -b foo \ + ${GOTSYSD_DEV_USER}@${VMIP}:foo.git $testroot/foo.git \ + > $testroot/stdout 2> $testroot/stderr + ret=$? + if [ $ret -eq 0 ]; then + echo "got clone succeeded unexpectedly" >&2 + return 1 + fi + + echo -n "" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + echo "gotsh: foo: Permission denied" > $testroot/stderr.expected + grep '^gotsh:' $testroot/stderr > $testroot/stderr.filtered + cmp -s $testroot/stderr.expected $testroot/stderr.filtered + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stderr.expected $testroot/stderr.filtered + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_user_add run_test test_user_mod @@ -1443,3 +1545,4 @@ run_test test_user_anonymous run_test test_bad_gotsysconf run_test test_set_head run_test test_protect_refs +run_test test_deny_access