commit e34163db5d5330e5726fcc06cea06e3be4fd59c8d304ff0a9160557c65644a66 from: Stefan Sperling date: Mon Sep 22 19:52:43 2025 UTC implement initial gotwebd authentication regression tests ok op@ commit - e54351df48b1ca1473604b22b1ede0f1145340d0463c4bcc2775418330203b54 commit + e34163db5d5330e5726fcc06cea06e3be4fd59c8d304ff0a9160557c65644a66 blob - 517df7e0398cebfd59dee52ca60ebe89de96afb23a1de8ca4826319f4f2a001c blob + e4f052bdd7ed80449316fcfbd2dc1770bbcc2b0b27fa079246c25c8613990d3d --- regress/gotsysd/Makefile +++ regress/gotsysd/Makefile @@ -1,6 +1,6 @@ .include "../../got-version.mk" -REGRESS_TARGETS=test_gotsysd +REGRESS_TARGETS=test_gotsysd test_gotwebd REGRESS_SETUP_ONCE=setup_test_vm REGRESS_CLEANUP=stop_test_vm @@ -220,8 +220,27 @@ $(HTTPD_CONF): @${UNPRIV} 'echo } >> $@' $(GOTWEBD_CONF): - @${UNPRIV} 'echo server "VMIP" { > $@' + @${UNPRIV} 'echo prefork 1 > $@' + @${UNPRIV} 'echo enable authentication insecure >> $@' + @${UNPRIV} 'echo permit ${GOTSYSD_TEST_USER} >> $@' + @${UNPRIV} 'echo deny ${GOTSYSD_DEV_USER} >> $@' + @${UNPRIV} 'echo server \"VMIP\" { >> $@' @${UNPRIV} 'echo \ \ repos_path \"/git\" >> $@' + @${UNPRIV} 'echo \ \ show_repo_age off >> $@' + @${UNPRIV} 'echo \ \ show_repo_description off >> $@' + @${UNPRIV} 'echo \ \ show_repo_owner off >> $@' + @${UNPRIV} 'echo \ \ show_site_owner off >> $@' + @${UNPRIV} 'echo \ \ repository \"public\" { >> $@' + @${UNPRIV} 'echo \ \ \ \ disable authentication >> $@' + @${UNPRIV} 'echo \ \ } >> $@' + @${UNPRIV} 'echo \ \ repository \"gotdev\" { >> $@' + @${UNPRIV} 'echo \ \ \ \ permit ${GOTSYSD_DEV_USER} >> $@' + @${UNPRIV} 'echo \ \ \ \ deny ${GOTSYSD_TEST_USER} >> $@' + @${UNPRIV} 'echo \ \ } >> $@' + @${UNPRIV} 'echo \ \ repository \"gottest\" { >> $@' + @${UNPRIV} 'echo \ \ \ \ permit ${GOTSYSD_TEST_USER} >> $@' + @${UNPRIV} 'echo \ \ \ \ deny ${GOTSYSD_DEV_USER} >> $@' + @${UNPRIV} 'echo \ \ } >> $@' @${UNPRIV} 'echo } >> $@' build_got: @@ -313,5 +332,29 @@ test_gotsysd: GWIP="100.64.$$VMID.2"; \ ${UNPRIV} "env ${GOTSYSD_TEST_ENV} VMIP=$${VMIP} GWIP=$${GWIP} \ sh ./test_gotsysd.sh" +test_gotwebd: + @set -e; \ + VMID=`vmctl status ${GOTSYSD_VM_NAME} | tail -n1 | \ + awk '{print $$1}'`; \ + VMIP="100.64.$$VMID.3"; \ + GWIP="100.64.$$VMID.2"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} \ + 'rm -rf /git/gotsys.git /git/foo.git /tmp/gotsys'"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} \ + got init /git/${GOTSYS_REPO}"; \ + ${UNPRIV} "${GOTSYSD_SCP_CMD} \ + ${GOT_CONF} root@$${VMIP}:/git/${GOTSYS_REPO}/got.conf"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} mkdir /tmp/gotsys "; \ + ${UNPRIV} "${GOTSYSD_SCP_CMD} \ + ${GOTSYS_CONF} root@$${VMIP}:/tmp/gotsys/"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} \ + got import -m init -r /git/${GOTSYS_REPO} \ + /tmp/gotsys >/dev/null"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} \ + chown -R _gotd:_gotd /git"; \ + ${UNPRIV} "${GOTSYSD_SSH_CMD} root@$${VMIP} \ + gotsys apply -w > /dev/null"; \ + ${UNPRIV} "env ${GOTSYSD_TEST_ENV} VMIP=$${VMIP} GWIP=$${GWIP} \ + sh ./test_gotwebd.sh" .include blob - 6deb16a5651e838298d2b16042ef8faf41f55a13dffeb09b1226e5072fb3ae78 blob + 44d6bd9efdcf5e594c2e37f8920ede92324277b62fffe95dafad38a770e8ef4a --- regress/gotsysd/README +++ regress/gotsysd/README @@ -44,6 +44,11 @@ the VM can be shut down from the host: # vmctl stop gotsysd-test +The gotsysd test suite also tests gotwebd user authentication. These tests +require the w3m browser to be installed: + + # pkg_add w3m + Now the actual test suite can be run with: # make blob - /dev/null blob + e9ca6d854652c096479d73bb5d55940fbfceba24f969a195e35b05fd9383c8a0 (mode 755) --- /dev/null +++ regress/gotsysd/test_gotwebd.sh @@ -0,0 +1,412 @@ +#!/bin/sh +# +# Copyright (c) 2025 Stefan Sperling +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +. ../cmdline/common.sh +. ./common.sh + +test_login() { + local testroot=`test_init login 1` + + # Attempt unauthorized access. + w3m "http://${VMIP}/" -dump > $testroot/stdout + cat > $testroot/stdout.expected < $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "ssh login failed failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + # Request the index page again using the login token and + # storing the cookie sent by gotwebd. + url=$(cut -d: -f 2,3 < $testroot/stdout | sed -e 's/ https:/http:/') + w3m -cookie-jar "$testroot/cookies" "$url" -dump > $testroot/stdout + cat > $testroot/stdout.expected < $testroot/stdout + + local commit_id=`git_show_head $testroot/${GOTSYS_REPO}` + local commit_time=`git_show_author_time $testroot/${GOTSYS_REPO} $commit_id` + local d=$(env LC_ALL=C date -u -r "$commit_time" \ + +"%a %b %e %H:%M:%S %Y UTC") + local tree_id=$(got cat -r $testroot/${GOTSYS_REPO} $commit_id | \ + grep 'tree ' | cut -d ' ' -f2) + + cat > $testroot/stdout.expected < $testroot/stdout + + local commit_id=`git_show_head $testroot/${GOTSYS_REPO}` + local tree_id=$(got cat -r $testroot/${GOTSYS_REPO} $commit_id | \ + grep 'tree ' | cut -d ' ' -f2) + + cat > $testroot/stdout.expected <