clone

a personal forge on plain git: static pages, stacked-diff reviews, signed local ci, repo sites and releases

main
forge / test / scenarios / identity-can-read.sh
identity-can-read.sh 2.2K
1# Who may read a repo is decided in two places: can_read in bin/forge (ssh)2# and canRead in lib/access.ts (the private and events servers). Both get3# the same table of cases, and must agree with each other and with what it4# should be: public repos to anyone, private ones to the owner and the5# exact lines of forge/collaborators and forge/readers.6. "$(dirname "$0")/../lib.sh"7for u in dami ana bob cat r.a; do user "$u"; done8repo dami/open9repo --private dami/secret10repo --private dami/odd11repo --private ana/dir12s=$FORGE_ROOT/dami/secret.git13mkdir -p "$s/forge"14printf 'ana\n' >"$s/forge/collaborators"15printf 'bob\n\n' >"$s/forge/readers"16# Near misses: a trailing space, a carriage return, a name inside a longer17# line, a dot that a regex would let match, no newline at the end.18o=$FORGE_ROOT/dami/odd.git19mkdir -p "$o/forge"20printf 'ana \nbob\r\nxcatx\nr.a' >"$o/forge/readers"21# A directory is not a flag or a list.22d=$FORGE_ROOT/ana/dir.git23mkdir -p "$d/git-daemon-export-ok" "$d/forge/readers"2425# The function itself, from bin/forge.26eval "$(sed -n '/^can_read() {$/,/^}$/p' "$FORGE")"27type can_read >/dev/null 2>&1 || fail "no can_read in bin/forge"2829# repo user want30while read -r slug who want; do31 [ "$who" = - ] && who=32 g=$FORGE_ROOT/$slug.git33 if can_read "$g" "$who"; then sh_says=yes; else sh_says=no; fi34 if node "$T_HOME/lib/access.ts" can-read "$g" "$who"; then ts_says=yes; else ts_says=no; fi35 [ "$sh_says" = "$ts_says" ] || fail "$slug for '$who': can_read says $sh_says, lib/access.ts says $ts_says"36 [ "$sh_says" = "$want" ] || fail "$slug for '$who': both say $sh_says, want $want"37done <<'EOF'38dami/open dami yes39dami/open ana yes40dami/open nobody yes41dami/open - yes42dami/secret dami yes43dami/secret ana yes44dami/secret bob yes45dami/secret cat no46dami/secret - no47dami/secret secret no48dami/secret da no49dami/odd dami yes50dami/odd ana no51dami/odd bob no52dami/odd cat no53dami/odd r.a yes54dami/odd rxa no55ana/dir ana yes56ana/dir dami no57ana/dir readers no58EOF5960# A flag that is a symlink to a file counts, as test -f has it.61ln -s ../open.git/git-daemon-export-ok "$o/git-daemon-export-ok"62if can_read "$o" cat; then :; else fail "can_read: a symlinked flag should make dami/odd public"; fi63ok node "$T_HOME/lib/access.ts" can-read "$o" cat