From 4c63ca3cd8ce471ec418d449397ac15454b363c5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 6 Oct 2013 22:48:28 +0100 Subject: Test repository removal --- git.liw.fi.sh | 26 ++++++++++++++++++++++++++ git.liw.fi.yarn | 52 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 67 insertions(+), 11 deletions(-) diff --git a/git.liw.fi.sh b/git.liw.fi.sh index 304bfdb..1c52c2e 100644 --- a/git.liw.fi.sh +++ b/git.liw.fi.sh @@ -81,6 +81,32 @@ user_del() } +# Does a repository exist? + +repo_exists() +{ + run_gitano_as "$1" ls | awk -v "r=$2" '$NF == r' | grep . +} + + +# Clone repo over ssh. + +clone_with_ssh() +{ + localdir="$DATADIR/$1/$2" + rm -rf "$localdir" + mkdir -p "$localdir" + url="ssh://$GITANO@$GITHOST/$2" + if [ "$1" = admin ] + then + git clone "$url" "$localdir" + else + KEYFILE="$DATADIR/$1.key" \ + PATH="$SRCDIR:$PATH" git clone "$url" "$localdir" + fi +} + + # Remove a repository from the server. This is a two-step process. destroy_repo() diff --git a/git.liw.fi.yarn b/git.liw.fi.yarn index 7ce5e13..25c017a 100644 --- a/git.liw.fi.yarn +++ b/git.liw.fi.yarn @@ -85,6 +85,13 @@ be able to remove the repository. WHEN tstusr attempts to remove repository tstrepo THEN attempt failed with error matching "You may not destroy repositories you do not own" + + WHEN admin removes repository tstrepo + THEN admin can't see repository tstrepo + AND admin can't clone tstrepo using git + AND admin can't clone tstrepo using ssh + AND tstusr can't see repository tstrepo + AND tstusr can't clone tstrepo using ssh FINALLY remove repository tstrepo on server AND remove user tstusr on server @@ -213,10 +220,18 @@ Repositories can only be created by the admin. Repository listing ------------------ +Can a user see the desired repository in the `gitano ls` output? + IMPLEMENTS THEN (\S+) can see repository (\S+) - run_gitano_as "$MATCH_1" ls | - awk -v "r=$MATCH_2" '$NF == r' | - grep . + repo_exists "$MATCH_1" "$MATCH_2" + +And sometimes they shouldn't see it anymore. + + IMPLEMENTS THEN (\S+) can't see repository (\S+) + if repo_exists "$MATCH_1" "$MATCH_2" + then + die "$MATCH_1 can see repository $MATCH_2 but shouldn't" + fi Repository cloning ------------------ @@ -241,24 +256,39 @@ a ./ssh script that runs the real ssh, but adds a `-i` option to the desired keyfile. But we only do that for non-admin users. IMPLEMENTS THEN (\S+) can clone (\S+) using ssh - localdir="$DATADIR/admin/$MATCH_2" + clone_with_ssh "$MATCH_1" "$MATCH_2" + +We also need to be able to check we can't clone. + + IMPLEMENTS THEN admin can't clone (\S+) using git + localdir="$DATADIR/meh" rm -rf "$localdir" - mkdir -p "$localdir" - url="ssh://$GITANO@$GITHOST/$MATCH_2" - if [ "$MATCH_1" = admin ] + if git clone "git://$GITHOST/$MATCH_1" "$localdir" then - git clone "$url" "$localdir" - else - KEYFILE="$DATADIR/$MATCH_1.key" \ - PATH="$SRCDIR:$PATH" git clone "$url" "$localdir" + die "repository $MATCH_1 can be cloned over git, but shouldn't" fi + IMPLEMENTS THEN (\S+) can't clone (\S+) using ssh + if clone_with_ssh "$MATCH_1" "$MATCH_2" + then + die "$MATCH_1 can clone $MATCH_2 over ssh, but shouldn't" + fi + + Repository removal ------------------ At the end, we need to clean up repositories. IMPLEMENTS FINALLY remove repository (\S+) on server + if repo_exists admin "$MATCH_1" + then + destroy_repo admin "$MATCH_1" + fi + +An admin can remove a repository. + + IMPLEMENTS WHEN admin removes repository (\S+) destroy_repo admin "$MATCH_1" A non-admin may try to remove a repository. It should fail, but they -- cgit v1.2.1