Commit dd9c6f3d authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

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's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 9a03c7fb
......@@ -90,20 +90,23 @@ echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES (2,
echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (1, '$AUTH_FINGERPRINT_USER', '$AUTH_KEYTYPE_USER $AUTH_KEYTEXT_USER');" | sqlite3 aur.db
echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (2, '$AUTH_FINGERPRINT_TU', '$AUTH_KEYTYPE_TU $AUTH_KEYTEXT_TU');" | sqlite3 aur.db
# Initialize a Git repository to store test packages in.
(
GIT_AUTHOR_EMAIL=author@example.com
GIT_AUTHOR_NAME='A U Thor'
GIT_COMMITTER_EMAIL=committer@example.com
GIT_COMMITTER_NAME='C O Mitter'
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
echo "INSERT INTO PackageBlacklist (Name) VALUES ('forbidden');" | sqlite3 aur.db
echo "INSERT INTO OfficialProviders (Name, Repo, Provides) VALUES ('official', 'core', 'official');" | sqlite3 aur.db
# Initialize a Git repository and test packages.
GIT_AUTHOR_EMAIL=author@example.com
GIT_AUTHOR_NAME='A U Thor'
GIT_COMMITTER_EMAIL=committer@example.com
GIT_COMMITTER_NAME='C O Mitter'
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
(
mkdir aur.git
cd aur.git
git init -q
git checkout -q -b refs/namespaces/foobar/refs/heads/master
git checkout -q --orphan refs/namespaces/foobar/refs/heads/master
cat >PKGBUILD <<-EOF
pkgname=foobar
......@@ -136,5 +139,48 @@ echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (2, '$AUTH_FIN
EOF
git add PKGBUILD .SRCINFO
git commit -q -am 'Initial import'
git commit -q -m 'Initial import'
sed 's/\(pkgrel.*\)1/\12/' PKGBUILD >PKGBUILD.new
sed 's/\(pkgrel.*\)1/\12/' .SRCINFO >.SRCINFO.new
mv PKGBUILD.new PKGBUILD
mv .SRCINFO.new .SRCINFO
git commit -q -am 'Bump pkgrel'
git checkout -q --orphan refs/namespaces/foobar2/refs/heads/master
cat >PKGBUILD <<-EOF
pkgname=foobar2
pkgver=1
pkgrel=1
pkgdesc='aurweb test package.'
url='https://aur.archlinux.org/'
license=('MIT')
arch=('any')
depends=('python-pygit2')
source=()
md5sums=()
package() {
echo 'Hello world!'
}
EOF
cat >.SRCINFO <<-EOF
pkgbase = foobar2
pkgdesc = aurweb test package.
pkgver = 1
pkgrel = 1
url = https://aur.archlinux.org/
arch = any
license = MIT
depends = python-pygit2
pkgname = foobar2
EOF
git add PKGBUILD .SRCINFO
git commit -q -m 'Initial import'
git checkout -q refs/namespaces/foobar/refs/heads/master
)
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment