commit - e54351df48b1ca1473604b22b1ede0f1145340d0463c4bcc2775418330203b54
commit + e34163db5d5330e5726fcc06cea06e3be4fd59c8d304ff0a9160557c65644a66
blob - 517df7e0398cebfd59dee52ca60ebe89de96afb23a1de8ca4826319f4f2a001c
blob + e4f052bdd7ed80449316fcfbd2dc1770bbcc2b0b27fa079246c25c8613990d3d
--- regress/gotsysd/Makefile
+++ regress/gotsysd/Makefile
.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
@${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:
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 <bsd.regress.mk>
blob - 6deb16a5651e838298d2b16042ef8faf41f55a13dffeb09b1226e5072fb3ae78
blob + 44d6bd9efdcf5e594c2e37f8920ede92324277b62fffe95dafad38a770e8ef4a
--- regress/gotsysd/README
+++ regress/gotsysd/README
# 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
+#!/bin/sh
+#
+# Copyright (c) 2025 Stefan Sperling <stsp@openbsd.org>
+#
+# 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 <<EOF
+[got]
+Repos
+login failed
+
+EOF
+ 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
+
+ # Obtain a login token over ssh.
+ ssh -q -i ${GOTSYSD_SSH_KEY} ${GOTSYSD_TEST_USER}@${VMIP} \
+ 'gotsh -c weblogin' > $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 <<EOF
+[got]
+Repos
+Project
+gotsys.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+ 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
+
+ # Request a tree page using the stored cookie.
+ w3m -cookie-jar "$testroot/cookies" \
+ "http://${VMIP}/?action=tree&path=gotsys.git" -dump \
+ > $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 <<EOF
+[got]
+Repos / gotsys.git / tree /
+
+Tree
+
+Tree:
+ $tree_id
+Date:
+ $d
+Message:
+ init
+
+-------------------------------------------------------------------------------
+
+gotsys.conf commits | blame
+
+EOF
+ 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
+
+ # Attempt to access the same page again without the cookie.
+ w3m "http://${VMIP}/?action=tree&path=gotsys.git" -dump \
+ > $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 <<EOF
+[got]
+Repos / gotsys.git / tree /
+login failed
+
+EOF
+ 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
+
+ # Attempt to access a non-existent repository without the cookie.
+ # Observable behaviour should match the case where the name of a
+ # hidden and existing repository was guessed correctly.
+ w3m "http://${VMIP}/?action=tree&path=nonexistent.git" -dump \
+ > $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 <<EOF
+[got]
+Repos / nonexistent.git / tree /
+login failed
+
+EOF
+ 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
+
+ test_done "$testroot" "0"
+}
+
+test_access_rules_index_page() {
+ local testroot=`test_init access_rules_index_page 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 <<EOF
+user ${GOTSYSD_TEST_USER} {
+ password "${crypted_vm_pw}"
+ authorized key ${sshkey}
+}
+user ${GOTSYSD_DEV_USER} {
+ password "${crypted_pw}"
+ authorized key ${sshkey}
+}
+repository gotsys.git {
+ permit rw ${GOTSYSD_TEST_USER}
+ permit rw ${GOTSYSD_DEV_USER}
+}
+repository public.git {
+ permit rw ${GOTSYSD_TEST_USER}
+ permit rw ${GOTSYSD_DEV_USER}
+}
+repository gotdev.git {
+ permit rw ${GOTSYSD_DEV_USER}
+}
+repository gottest.git {
+ permit rw ${GOTSYSD_TEST_USER}
+}
+EOF
+ (cd ${testroot}/wt && got commit \
+ -m "create user ${GOTSYSD_DEV_USER}" >/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
+
+ # Request the index page without being logged in.
+ # Repositories we do not have access to should not be listed.
+ w3m "http://${VMIP}/" -dump > $testroot/stdout
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Repos
+Project
+public.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+
+ # Obtain a login token over ssh.
+ ssh -q -i ${GOTSYSD_SSH_KEY} ${GOTSYSD_TEST_USER}@${VMIP} \
+ 'gotsh -c weblogin' > $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. Repositories we do not have access
+ # to should not be listed.
+ 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 <<EOF
+[got]
+Repos
+Project
+gotsys.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+gottest.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+public.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+ 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
+
+ # Obtain a different login token over ssh.
+ ssh -q -i ${GOTSYSD_SSH_KEY} ${GOTSYSD_DEV_USER}@${VMIP} \
+ 'weblogin' > $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. Repositories we do not have access
+ # to should not be listed.
+ 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 <<EOF
+[got]
+Repos
+Project
+gotdev.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+public.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+ 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
+ test_done "$testroot" "0"
+}
+
+test_access_rules_tree_page() {
+ local testroot=`test_init access_rules_tree_page 1`
+
+ # Attempt to access a public repository's tree
+ w3m "http://${VMIP}/?action=tree&path=public.git" -dump \
+ > $testroot/stdout
+
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Repos / public.git / tree /
+reference refs/heads/main not found
+
+EOF
+ 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
+
+ # Attempt to access a private repository's tree
+ w3m "http://${VMIP}/?action=tree&path=gottest.git" -dump \
+ > $testroot/stdout
+
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Repos / gottest.git / tree /
+login failed
+
+EOF
+ 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
+
+ # Obtain a login token over ssh.
+ ssh -q -i ${GOTSYSD_SSH_KEY} ${GOTSYSD_TEST_USER}@${VMIP} \
+ 'gotsh -c weblogin' > $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "ssh login failed failed unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ 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 <<EOF
+[got]
+Repos
+Project
+gotsys.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+gottest.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+public.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+ 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
+
+ # Attempt to access the private repository's tree again with cookie
+ w3m -cookie-jar $testroot/cookies \
+ "http://${VMIP}/?action=tree&path=gottest.git" -dump \
+ > $testroot/stdout
+
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Repos / gottest.git / tree /
+reference refs/heads/main not found
+
+EOF
+ 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
+
+
+ test_done "$testroot" "$ret"
+}
+
+test_parseargs "$@"
+run_test test_login
+run_test test_access_rules_index_page
+run_test test_access_rules_tree_page