summaryrefslogtreecommitdiffstats
path: root/git-interface/test/t0003-update.sh
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-08-05 14:01:22 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-08-05 21:23:20 +0200
commitdd9c6f3ddca37479ce14425c0a82a4b46d7a727a (patch)
tree8c86ac884408a842e4b4785d9b337c5016783205 /git-interface/test/t0003-update.sh
parent9a03c7fbdd9a1eff197d9c14301ab23aabc88109 (diff)
downloadaur-dd9c6f3ddca37479ce14425c0a82a4b46d7a727a.tar.gz
aur-dd9c6f3ddca37479ce14425c0a82a4b46d7a727a.tar.xz
t0003: Add more git-update tests
Add tests for common scenarios that should be detected/handled by the update hook. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'git-interface/test/t0003-update.sh')
-rwxr-xr-xgit-interface/test/t0003-update.sh350
1 files changed, 347 insertions, 3 deletions
diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh
index 0e8962c1..810b860c 100755
--- a/git-interface/test/t0003-update.sh
+++ b/git-interface/test/t0003-update.sh
@@ -4,17 +4,361 @@ test_description='git-update tests'
. ./setup.sh
-test_expect_success 'Test update hook.' '
+test_expect_success 'Setup repositories and create package bases.' '
+ SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user "$GIT_SERVE"
+ SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=user "$GIT_SERVE"
+'
+
+test_expect_success 'Test update hook on a fresh repository.' '
old=0000000000000000000000000000000000000000 &&
- new=$(git -C aur.git rev-parse HEAD) &&
- SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user "$GIT_SERVE" &&
+ new=$(git -C aur.git rev-parse HEAD^) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
cat >expected <<-EOF &&
1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
+ 1|GPL
+ 1|1
+ 1|1|python-pygit2||
+ 1|1
+ 2|1
+ EOF
+ >actual &&
+ for t in Packages Licenses PackageLicenses Groups PackageGroups \
+ PackageDepends PackageRelations PackageSources \
+ PackageNotifications; do
+ echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
+ done &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Test update hook on another fresh repository.' '
+ old=0000000000000000000000000000000000000000 &&
+ test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
+ git -C aur.git checkout -q refs/namespaces/foobar2/refs/heads/master &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
+ cat >expected <<-EOF &&
+ 1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
+ 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
+ 1|GPL
+ 2|MIT
+ 1|1
+ 2|2
+ 1|1|python-pygit2||
+ 2|1|python-pygit2||
+ 1|1
+ 2|1
+ EOF
+ >actual &&
+ for t in Packages Licenses PackageLicenses Groups PackageGroups \
+ PackageDepends PackageRelations PackageSources \
+ PackageNotifications; do
+ echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
+ done &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Test update hook on an updated repository.' '
+ old=$(git -C aur.git rev-parse HEAD^) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
+ cat >expected <<-EOF &&
+ 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
+ 3|1|foobar|1-2|aurweb test package.|https://aur.archlinux.org/
+ 1|GPL
+ 2|MIT
+ 2|2
+ 3|1
+ 2|1|python-pygit2||
+ 3|1|python-pygit2||
+ 1|1
+ 2|1
+ EOF
+ >actual &&
+ for t in Packages Licenses PackageLicenses Groups PackageGroups \
+ PackageDepends PackageRelations PackageSources \
+ PackageNotifications; do
+ echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
+ done &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Pushing to a branch other than master.' '
+ old=0000000000000000000000000000000000000000 &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/pu "$old" "$new" 2>&1
+'
+
+test_expect_success 'Performing a non-fast-forward ref update.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ new=$(git -C aur.git rev-parse HEAD^) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Performing a non-fast-forward ref update as Trusted User.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ new=$(git -C aur.git rev-parse HEAD^) &&
+ AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Removing .SRCINFO.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ git -C aur.git rm -q .SRCINFO &&
+ git -C aur.git commit -q -m "Remove .SRCINFO" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Removing .SRCINFO with a follow-up fix.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ git -C aur.git rm -q .SRCINFO &&
+ git -C aur.git commit -q -m "Remove .SRCINFO" &&
+ git -C aur.git revert --no-edit HEAD &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Removing PKGBUILD.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ git -C aur.git rm -q PKGBUILD &&
+ git -C aur.git commit -q -m "Remove PKGBUILD" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing a tree with a subdirectory.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ mkdir aur.git/subdir &&
+ touch aur.git/subdir/file &&
+ git -C aur.git add subdir/file &&
+ git -C aur.git commit -q -m "Add subdirectory" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing a tree with a large blob.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ printf "%256001s" x >aur.git/file &&
+ git -C aur.git add file &&
+ git -C aur.git commit -q -m "Add large blob" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO with a non-matching package base.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/\(pkgbase.*\)foobar/\1foobar2/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Change package base"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO with invalid syntax.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/=//" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Break .SRCINFO"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO without pkgver.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "/pkgver/d" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Remove pkgver"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO without pkgrel.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "/pkgrel/d" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Remove pkgrel"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO with epoch.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/.*pkgrel.*/\\0\\nepoch = 1/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Add epoch"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
+ cat >expected <<-EOF &&
+ 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
+ 3|1|foobar|1:1-2|aurweb test package.|https://aur.archlinux.org/
EOF
echo "SELECT * FROM Packages;" | sqlite3 aur.db >actual &&
test_cmp expected actual
'
+test_expect_success 'Pushing .SRCINFO with invalid pkgname.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/\(pkgname.*\)foobar/\1!/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Change pkgname"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing .SRCINFO with invalid epoch.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/.*pkgrel.*/\\0\\nepoch = !/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Change epoch"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Missing install file.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/.*depends.*/\\0\\ninstall = install/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Add install field"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Missing changelog file.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/.*depends.*/\\0\\nchangelog = changelog/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Add changelog field"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Missing source file.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ (
+ cd aur.git &&
+ sed "s/.*depends.*/\\0\\nsource = file/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Add file to the source array"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing a blacklisted package.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
+ git -C aur.git commit -q -am "Add blacklisted package" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing a blacklisted package as Trusted User.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
+ git -C aur.git commit -q -am "Add blacklisted package" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning:
+'
+
+test_expect_success 'Pushing a package already in the official repositories.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ echo "pkgname = official" >>aur.git/.SRCINFO &&
+ git -C aur.git commit -q -am "Add official package" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
+test_expect_success 'Pushing a package already in the official repositories as Trusted User.' '
+ old=$(git -C aur.git rev-parse HEAD) &&
+ test_when_finished "git -C aur.git reset --hard $old" &&
+ echo "pkgname = official" >>aur.git/.SRCINFO &&
+ git -C aur.git commit -q -am "Add official package" &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
+ "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning:
+'
+
+test_expect_success 'Trying to hijack a package.' '
+ old=0000000000000000000000000000000000000000 &&
+ test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
+ (
+ cd aur.git &&
+ git checkout -q refs/namespaces/foobar2/refs/heads/master &&
+ sed "s/\\(.*pkgname.*\\)2/\\1/" .SRCINFO >.SRCINFO.new
+ mv .SRCINFO.new .SRCINFO
+ git commit -q -am "Change package name"
+ ) &&
+ new=$(git -C aur.git rev-parse HEAD) &&
+ AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
+ test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
+'
+
test_done