commit - 59ec6f30d83e4bdac0699743000c51dc4a55230de4ac589d4d6ff2dc3d432315
commit + f05467224f503defae2df3307dee4164a17153c24983ac91d86889cad02564bb
blob - 9171a9ae307f324ed57415a349f60aa7870b05f23d276988ba0a96d083fea977
blob + 9eee6d0f402e06fef3af1417c73a3e825f02ec0a4ec92b5e3908fd0f88c5a1d9
--- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
+++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
write_webrepo(int *show_repo_description, int *login_hint_user_access,
int fd, const char *path, struct gotsys_webrepo *webrepo,
enum gotsysd_web_auth_config webd_auth_config,
- int hide_repositories)
+ int hide_repositories, const char *server_name)
{
const struct got_error *err;
struct gotsys_repo *repo;
char repo_name[_POSIX_PATH_MAX];
size_t namelen;
int have_login_hint_user = 0;
+ int login_hint_user_has_repo_access = 0;
namelen = strlcpy(repo_name, webrepo->repo_name, sizeof(repo_name));
if (namelen >= sizeof(repo_name)) {
*show_repo_description = 1;
}
+ if (repo) {
+ struct gotsys_access_rule *rule;
+
+ STAILQ_FOREACH(rule, &repo->access_rules, entry) {
+ if (rule->access == GOTSYS_ACCESS_PERMITTED &&
+ strcmp(rule->identifier,
+ webcfg.login_hint_user) == 0) {
+ login_hint_user_has_repo_access = 1;
+ break;
+ }
+ }
+ }
+
+ if (!login_hint_user_has_repo_access) {
+ struct gotsys_access_rule *rule;
+
+ STAILQ_FOREACH(rule, &global_repo_access_rules, entry) {
+ if (rule->access == GOTSYS_ACCESS_PERMITTED &&
+ strcmp(rule->identifier,
+ webcfg.login_hint_user) == 0) {
+ login_hint_user_has_repo_access = 1;
+ break;
+ }
+ }
+ }
+
+ if (login_hint_user_has_repo_access) {
+ char *clone_url;
+
+ if (asprintf(&clone_url, "ssh://%s@%s%s%s/%s.git",
+ webcfg.login_hint_user, server_name,
+ webcfg.login_hint_port[0] ? ":" : "",
+ webcfg.login_hint_port[0] ? webcfg.login_hint_port : "",
+ repo_name) == -1)
+ return got_error_from_errno("asprintf");
+
+ ret = dprintf(fd, "\t\tclone_url \"%s\"\n", clone_url);
+ if (ret == -1) {
+ free(clone_url);
+ return got_error_from_errno2("dprintf", path);
+ }
+ if (ret != 14 + strlen(clone_url) + 1) {
+ free(clone_url);
+ return got_error_fmt(GOT_ERR_IO,
+ "short write to %s", path);
+ }
+ free(clone_url);
+ }
+
ret = dprintf(fd, "\t}\n");
if (ret == -1)
return got_error_from_errno2("dprintf", path);
err = write_webrepo(&show_repo_description,
&login_hint_user_access,
fd, path, webrepo, srv_cfg->auth_config,
- hide_repositories);
+ hide_repositories, srv_cfg->server_name);
if (err)
return err;
}
blob - 103ef52df64b6f7a3c9db31d17bcdaec4dbfe439e5458b9790f50369f9df9d3a
blob + 1bdaac536d1e89109c9deae62efed0bc5d32cf7725b59a766bd7dddb530389a1
--- regress/gotsysd/test_gotwebd.sh
+++ regress/gotsysd/test_gotwebd.sh
test_done "$testroot" "$ret"
}
+test_summary_page() {
+ local testroot=`test_init summary_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 gottestdev.git {
+ permit rw ${GOTSYSD_DEV_USER}
+}
+repository gottest.git {
+ permit rw ${GOTSYSD_TEST_USER}
+}
+repository hidden.git {
+ permit rw ${GOTSYSD_TEST_USER}
+}
+web server "${VMIP}" {
+ repository public {
+ disable authentication
+ }
+ repository gottestdev.git {
+ permit ${GOTSYSD_DEV_USER}
+ deny ${GOTSYSD_TEST_USER}
+ }
+ repository gottest.git {
+ permit ${GOTSYSD_TEST_USER}
+ }
+ repository hidden {
+ permit ${GOTSYSD_TEST_USER}
+ deny ${GOTSYSD_DEV_USER}
+ hide repository on
+ }
+}
+EOF
+ (cd ${testroot}/wt && gotsys check -q)
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "bad gotsys.conf written by test" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ (cd ${testroot}/wt && got commit -m "no-op change" >/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
+
+ got init $testroot/public.git > /dev/null
+ mkdir -p $testroot/public
+
+ cat > $testroot/public/readme.txt <<EOF
+Testing the summary page of gotwebd
+EOF
+ got import -m init -r $testroot/public.git $testroot/public > /dev/null
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "got import failed unexpectedly" >&2
+ return 1
+ fi
+ local commit_id=`git_show_head $testroot/public.git`
+ local short_commit_id=`trim_obj_id 10 $commit_id`
+
+ cat > $testroot/public.git/got.conf <<EOF
+remote "origin" {
+ server "${GOTSYSD_DEV_USER}@$VMIP"
+ protocol ssh
+ repository "public"
+}
+EOF
+ got send -q -i ${GOTSYSD_SSH_KEY} -b main -f -r $testroot/public.git
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "got send failed unexpectedly" >&2
+ return 1
+ fi
+
+ # Attempt to access a public repository's summary
+ w3m "http://${VMIP}/?action=summary&path=public.git" -dump \
+ > $testroot/stdout
+
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Repositories / public.git / summary
+
+Clone URL:
+
+ ssh://${GOTSYSD_TEST_USER}@${VMIP}/public.git
+
+Commit Briefs
+
+right now $short_commit_id Flan Hacker
+
+init (main)
+
+diff | patch | tree
+-------------------------------------------------------------------------------
+
+Branches
+
+right now
+main
+summary | commit briefs | commits
+-------------------------------------------------------------------------------
+
+Tags
+
+This repository contains no tags
+
+Tree
+
+readme.txt commits | blame
+
+readme.txt
+
+Testing the summary page of gotwebd
+
+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
+run_test test_summary_page