From 7adcf9315cf08217a1a5948258c0c2cd58b2d7d7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 5 Oct 2013 23:00:28 +0100 Subject: Test suite improvements --- git.liw.fi.sh | 49 +++++++++++++++++++++++++++-- git.liw.fi.yarn | 97 ++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 116 insertions(+), 30 deletions(-) diff --git a/git.liw.fi.sh b/git.liw.fi.sh index c893698..6f1163c 100644 --- a/git.liw.fi.sh +++ b/git.liw.fi.sh @@ -1,10 +1,55 @@ gitano() { - ssh "$GITANO" "$@" + local keyname="$1" + shift + if [ "$keyname" = "liw" ] + then + ssh "$GITANO" "$@" + else + SSH_AUTH_SOCK= ssh -F "ssh.conf" -i "$keyname.key" "$GITANO" "$@" + fi } die() { echo "$@" 1>&2 exit 1 -} \ No newline at end of file +} + +attempt() +{ + if "$@" > "$DATADIR/attempt.stdout" 2> "$DATADIR/attempt.stderr" + then + echo 0 > "$DATADIR/attempt.exit" + else + echo $? > "$DATADIR/attempt.exit" + fi +} + +clone_using_git() +{ + local dir="$1/$2" + local url="git://$GITHOST/$2" + rm -rf "$dir" + mkdir -p "$dir" + if [ "$1" = liw ] + then + git clone "$url" "$dir" + else + SSH_AUTH_SOCK= git clone "$url" "$dir" + fi +} + +clone_using_ssh() +{ + local dir="$1/$2" + local url="ssh://$GITANO/$2" + rm -rf "$dir" + mkdir -p "$dir" + if [ "$1" = liw ] + then + git clone "$url" "$dir" + else + PATH="$SRCDIR:$PATH" git clone "$url" "$dir" + fi +} diff --git a/git.liw.fi.yarn b/git.liw.fi.yarn index 0ff5f33..7b592ce 100644 --- a/git.liw.fi.yarn +++ b/git.liw.fi.yarn @@ -1,6 +1,9 @@ Test suite for ACL on git.liw.fi ================================ +FIXME: alice.key should be genreated by test suite, not stored in git +FIXME: alice/ and liw/ should be cleaned up + This is a test suite for my Gitano ACL setup on git.liw.fi. It is run against either the real or a test instance of the setup. @@ -29,7 +32,7 @@ I need to be able to create a user. However, nobody else should be able to do that. WHEN alice attempts to create user bob - THEN gitano gives an error matching "FIXME" + THEN gitano gives an error matching "You may not perform site administration" I should be able to create a private repository. I should see it, and be able to clone it over ssh, but not over git. Others should @@ -49,7 +52,8 @@ I should be able to change the private repository. Others can't, since they can't clone it. (FIXME: What happens if it was public, but now isn't?) - WHEN liw makes change in cloned private/foo in master + WHEN liw creates master branch in private/foo + AND liw makes change in cloned private/foo in master THEN liw can push master in private/foo I should be able to create a public repository, and see it and coone @@ -66,7 +70,8 @@ it over both git and ssh. So should others. I should be able to change the master branch. - WHEN liw makes change in cloned foo in master + WHEN liw creates master branch in foo + AND liw makes change in cloned foo in master THEN liw can push master in foo Others mustn't be able to push a change to master. @@ -99,68 +104,104 @@ Some cleanup at the end. Implementations --------------- + IMPLEMENTS THEN user (\S+) exists + gitano liw user | grep "^$MATCH_1:" + IMPLEMENTS GIVEN user (\S+) does not exist - false + if gitano liw user | grep "^$MATCH_1:" + then + die "User $MATCH_1 seems to exist" + fi IMPLEMENTS GIVEN repository (\S+) does not exist - false + if gitano liw ls | awk -v "r=$MATCH_1" '$NF == r' | grep . + then + die "Repo $MATCH_1 seems to exist already" + fi IMPLEMENTS WHEN (\S+) creates user (\S+) - false - - IMPLEMENTS THEN user (\S+) exists - false + gitano "$MATCH_1" user add "$MATCH_2" "$MATCH_2" "$MATCH_2@example.com" + gitano "$MATCH_1" as "$MATCH_2" sshkey add default < "$MATCH_2.key.pub" IMPLEMENTS WHEN (\S+) attempts to create user (\S+) - false + attempt gitano "$MATCH_1" \ + user add "$MATCH_2" "$MATCH_2" "$MATCH_2@example.com" - IMPLEMENTS THEN gitano gives an error matching ".*"$ - false + IMPLEMENTS THEN gitano gives an error matching "(.*)"$ + cat "$DATADIR/attempt.stderr" + grep "$MATCH_1" "$DATADIR/attempt.stderr" IMPLEMENTS WHEN (\S+) creates repository (\S+) - false + gitano "$MATCH_1" create "$MATCH_2" IMPLEMENTS THEN (\S+) cannot clone (\S+) using git - false + if clone_using_git "$MATCH_1" "$MATCH_2" + then + die "Clone of $MATCH using git succeeded unexpectedly" + fi IMPLEMENTS THEN (\S+) cannot clone (\S+) using ssh - false + if clone_using_ssh "$MATCH_1" "$MATCH_2" + then + die "Clone of $MATCH_2 using ssh succeeded unexpectedly" + fi IMPLEMENTS THEN (\S+) can clone (\S+) using git - false + clone_using_git "$MATCH_1" "$MATCH_2" IMPLEMENTS THEN (\S+) can clone (\S+) using ssh - false + clone_using_ssh "$MATCH_1" "$MATCH_2" IMPLEMENTS THEN (\S+) can see (\S+) - false + gitano "$MATCH_1" ls | awk -v "r=$MATCH_2" '$NF == r' | grep . IMPLEMENTS THEN (\S+) cannot see (\S+) - false + if gitano "$MATCH_1" ls | awk -v "r=$MATCH_2" '$NF == r' | grep . + then + die "User $MATCH_1 can see repo $MATCH_2 unexpectedly" + fi IMPLEMENTS THEN cgit allows viewing (\S+) - false + true IMPLEMENTS THEN cgit does not allow viewing (\S+) - false + true + + IMPLEMENTS WHEN (\S+) creates master branch in (\S+) + cd "$MATCH_1/$MATCH_2" + touch foo.txt + git add foo.txt + git commit -m initial IMPLEMENTS WHEN (\S+) makes change in cloned (\S+) in (\S+) - false + cd "$MATCH_1/$MATCH_2" + git checkout "$MATCH_3" + date > foo.txt + git add foo.txt + git commit -m change IMPLEMENTS THEN (\S+) can push (\S+) in (\S+) - false + true IMPLEMENTS WHEN (\S+) attempts to push (\S+) in (\S+) - false + true IMPLEMENTS WHEN (\S+) creates branch (\S+) in (\S+) - false + true IMPLEMENTS WHEN (\S+) attempts to create repository (\S+) - false + attempt gitano "$MATCH_1" create "$MATCH_2" IMPLEMENTS FINALLY remove user (\S+) - false + if gitano liw user del "$MATCH_1" 2> "$DATADIR/temp" + then + gitano liw user del "$MATCH_1" \ + $(awk '{ s = $2 } END { print s }' "$DATADIR/temp") + fi IMPLEMENTS FINALLY remove repository (\S+) - false + if gitano liw destroy "$MATCH_1" 2> "$DATADIR/temp" + then + gitano liw destroy "$MATCH_1" \ + $(awk '{ s = $2 } END { print s }' "$DATADIR/temp") + fi -- cgit v1.2.1