clone

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

main
forge / test / scenarios / people-invite-bad-key.sh
people-invite-bad-key.sh 2.0K
1# An invite takes one SSH public key on one line: not text that isn't a2# key, not a key with a second line (which would add a line of its own to3# .forge/keys, as anyone), not a key someone here has already. Each is4# refused and the link still works for a good key. forge user add is held5# to the same.6. "$(dirname "$0")/../lib.sh"7user cat8export FORGE_BASE_URL=https://forge.test9private_server10ssh-keygen -q -t ed25519 -N '' -C fox -f "$T/keys/fox"11accept() {12 node -e 'console.log(JSON.stringify({ code: process.argv[1], key: process.argv[2] }))' -- "$1" "$2" >"$T/body"13 http -s -w '\n%{http_code}' -H 'Origin: https://forge.test' -H 'Content-Type: application/json' -d @"$T/body" "$PRIV/login/invite/accept"14}15ok forge user invite fox16code=$(sed -n 's/^ .*#invite=//p' "$T_LOG")17cp "$FORGE_ROOT/.forge/keys" "$T/keys.before"18fox=$(cat "$T/keys/fox.pub")1920for bad in "hello" "ssh-ed25519 not-base64!" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBogus fox" "-----BEGIN OPENSSH PRIVATE KEY-----"; do21 accept "$code" "$bad" >"$T/r"22 eq "$(tail -n 1 "$T/r")" 40023 has "$T/r" 'not an SSH public key'24done25accept "$code" "$fox26cat $fox" >"$T/r"27eq "$(tail -n 1 "$T/r")" 40028has "$T/r" 'Paste one SSH public key'29accept "$code" "$(cat "$T/keys/cat.pub")" >"$T/r"30eq "$(tail -n 1 "$T/r")" 40031has "$T/r" 'that key is already on this forge'32cmp "$FORGE_ROOT/.forge/keys" "$T/keys.before" || fail "a refused key changed .forge/keys"33# Over the shell side too, where the web's own check doesn't run.34printf '%s\n%s\ncat %s\n' "$code" "$fox" "$fox" | forge user accept >"$T_LOG" 2>&1 && fail "user accept took two lines"35has "$T_LOG" 'not an SSH public key'36fails_with "not an SSH public key" forge user add ana "$(printf '%s\ncat %s' "$fox" "$fox")"37fails_with "already on this forge, as cat's" forge user add ana "$T/keys/cat.pub"38cmp "$FORGE_ROOT/.forge/keys" "$T/keys.before" || fail "a refused key changed .forge/keys"3940accept "$code" "$fox" >"$T/r"41eq "$(tail -n 1 "$T/r")" 20042has "$FORGE_ROOT/.forge/keys" '^fox ssh-ed25519 '