[aur-dev] [PATCH 0/3] More tests
This is a follow-up to the series I submitted earlier today. All patches are based on pu. Lukas Fleischer (3): t0001: Add more git-auth tests t0002: Add more git-serve tests t0003: Add more git-update tests git-interface/test/setup.sh | 91 ++++++++-- git-interface/test/t0001-auth.sh | 9 + git-interface/test/t0002-serve.sh | 62 +++++++ git-interface/test/t0003-update.sh | 350 ++++++++++++++++++++++++++++++++++++- 4 files changed, 496 insertions(+), 16 deletions(-) -- 2.9.2
Test the authentication script with an invalid key type and with a key that does not exist in the database. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/test/setup.sh | 4 ++++ git-interface/test/t0001-auth.sh | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/git-interface/test/setup.sh b/git-interface/test/setup.sh index eecb4d5..4512978 100644 --- a/git-interface/test/setup.sh +++ b/git-interface/test/setup.sh @@ -54,6 +54,10 @@ AUTH_KEYTYPE_TU=ssh-rsa AUTH_KEYTEXT_TU=AAAAB3NzaC1yc2EAAAADAQABAAABAQC4Q2Beg6jf2r1LZ4vwT5y10dK8+/c5RaNyTwv77wF2OSLXh32xW0ovhE2lW2gqoakdGsxgM2fTtqMTl29WOsAxlGF7x9XbWhFXFUT88Daq1fAeuihkiRjfBbInSW/WcrFZ+biLBch67addtfkkd4PmAafDeeCtszAXqza+ltBG1oxAGiTXgI3LOhA1/GtLLxsi5sPUO3ZlhvwDn4Sy0aXYx8l9hop/PU4Cjn82hyRa9r+SRxQ3KtjKxcVMnZ8IyXOrBwXTukgSBR/6nSdEmO0JPkYUFuNwh3UGFKuNkrPguL5T+4YDym6czYmZJzQ7NNl2pLKYmYgBwBe5rORlWfN5 AUTH_FINGERPRINT_TU=SHA256:xQGC6j/U1Q3NDXLl04pm+Shr1mjYUXbGMUzlm9vby4k +AUTH_KEYTYPE_MISSING=sha-rsa +AUTH_KEYTEXT_MISSING=AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UTpssBunuTBCT3KFtv+yb+cN0VmI2C9O9U7wHlkEZWxNBK8is6tnDHXBxRuvRk0LHILkTidLLFX22ZF0+TFgSz7uuEvGZVNpa2Fn2+vKJJYMvZEvb/f8VHF5/Jddt21VOyu23royTN/duiT7WIZdCtEmq5C9Y43NPfsB8FbUc+FVSYT2Lq7g1/bzvFF+CZxwCrGjC3qC7p3pshICfFR8bbWgRN33ClxIQ7MvkcDtfNu38dLotJqdfEa7NdQgba5/S586f1A4OWKc/mQJFyTaGhRBxw/cBSjqonvO0442VYLHFxlrTHoUunKyOJ8+BJfKgjWmfENC9ESY3mL/IEn5 +AUTH_FINGERPRINT_MISSING=SHA256:uB0B+30r2WA1TDMUmFcaEBjosjnFGzn33XFhiyvTL9w + # Initialize the test database. rm -f aur.db sed \ diff --git a/git-interface/test/t0001-auth.sh b/git-interface/test/t0001-auth.sh index 50ef510..71d526f 100755 --- a/git-interface/test/t0001-auth.sh +++ b/git-interface/test/t0001-auth.sh @@ -16,4 +16,13 @@ test_expect_success 'Test Trusted User authentication.' ' grep -q AUR_PRIVILEGED=1 out ' +test_expect_success 'Test authentication with an unsupported key type.' ' + test_must_fail "$GIT_AUTH" ssh-xxx "$AUTH_KEYTEXT_USER" +' + +test_expect_success 'Test authentication with a wrong key.' ' + "$GIT_AUTH" "$AUTH_KEYTYPE_MISSING" "$AUTH_KEYTEXT_MISSING" >out + test_must_be_empty out +' + test_done -- 2.9.2
Add tests for common scenarios that should be detected/handled by the git-serve script. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/test/setup.sh | 19 ++++++++++-- git-interface/test/t0002-serve.sh | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/git-interface/test/setup.sh b/git-interface/test/setup.sh index 4512978..cb1e250 100644 --- a/git-interface/test/setup.sh +++ b/git-interface/test/setup.sh @@ -29,8 +29,8 @@ ssh-options = restrict [serve] repo-path = ./aur.git/ repo-regex = [a-z0-9][a-z0-9.+_-]*$ -git-shell-cmd = /usr/bin/git-shell -git-update-cmd = /srv/http/aurweb/git-interface/git-update.py +git-shell-cmd = ./git-shell.sh +git-update-cmd = ./update.sh ssh-cmdline = ssh aur@aur.archlinux.org [update] @@ -42,6 +42,21 @@ cat >notify.sh <<-EOF EOF chmod +x notify.sh +cat >git-shell.sh <<-\EOF +#!/bin/sh +echo $AUR_USER +echo $AUR_PKGBASE +echo $GIT_NAMESPACE +EOF +chmod +x git-shell.sh + +cat >update.sh <<-\EOF +#!/bin/sh +echo $AUR_USER +echo $AUR_PKGBASE +EOF +chmod +x update.sh + AUR_CONFIG=config export AUR_CONFIG diff --git a/git-interface/test/t0002-serve.sh b/git-interface/test/t0002-serve.sh index 7e17bcb..f36f1d8 100755 --- a/git-interface/test/t0002-serve.sh +++ b/git-interface/test/t0002-serve.sh @@ -15,6 +15,8 @@ test_expect_success 'Test help.' ' test_expect_success 'Test setup-repo and list-repos.' ' SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user \ "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=tu \ + "$GIT_SERVE" 2>&1 && cat >expected <<-EOF && *foobar EOF @@ -23,4 +25,64 @@ test_expect_success 'Test setup-repo and list-repos.' ' test_cmp expected actual ' +test_expect_success 'Test git-receive-pack.' ' + cat >expected <<-EOF && + user + foobar + foobar + EOF + SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success 'Test git-receive-pack with an invalid repository name.' ' + SSH_ORIGINAL_COMMAND="git-receive-pack /!.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + test_must_fail "$GIT_SERVE" 2>&1 >actual +' + +test_expect_success "Test git-upload-pack." ' + cat >expected <<-EOF && + user + foobar + foobar + EOF + SSH_ORIGINAL_COMMAND="git-upload-pack /foobar.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Try to pull from someone else's repository." ' + cat >expected <<-EOF && + user + foobar2 + foobar2 + EOF + SSH_ORIGINAL_COMMAND="git-upload-pack /foobar2.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Try to push to someone else's repository." ' + SSH_ORIGINAL_COMMAND="git-receive-pack /foobar2.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + test_must_fail "$GIT_SERVE" 2>&1 +' + +test_expect_success "Try to push to someone else's repository as Trusted User." ' + cat >expected <<-EOF && + tu + foobar + foobar + EOF + SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \ + AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + test_done -- 2.9.2
Add tests for common scenarios that should be detected/handled by the update hook. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/test/setup.sh | 68 +++++-- git-interface/test/t0003-update.sh | 350 ++++++++++++++++++++++++++++++++++++- 2 files changed, 404 insertions(+), 14 deletions(-) diff --git a/git-interface/test/setup.sh b/git-interface/test/setup.sh index cb1e250..7f3d45a 100644 --- a/git-interface/test/setup.sh +++ b/git-interface/test/setup.sh @@ -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 ) diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index 0e8962c..810b860 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 -- 2.9.2
Test the restore mode of git-serve and git-update. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- Another bunch of tests that will land on pu. git-interface/test/t0002-serve.sh | 17 +++++++++++++++++ git-interface/test/t0003-update.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/git-interface/test/t0002-serve.sh b/git-interface/test/t0002-serve.sh index f36f1d8..52fdcd1 100755 --- a/git-interface/test/t0002-serve.sh +++ b/git-interface/test/t0002-serve.sh @@ -85,4 +85,21 @@ test_expect_success "Try to push to someone else's repository as Trusted User." test_cmp expected actual ' +test_expect_success "Test restore." ' + echo "DELETE FROM PackageBases WHERE Name = \"foobar\";" | \ + sqlite3 aur.db && + cat >expected <<-EOF && + user + foobar + EOF + SSH_ORIGINAL_COMMAND="restore foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual + test_cmp expected actual +' + +test_expect_success "Try to restore an existing package base." ' + SSH_ORIGINAL_COMMAND="restore foobar2" AUR_USER=user AUR_PRIVILEGED=0 \ + test_must_fail "$GIT_SERVE" 2>&1 +' + test_done diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index 810b860..81c5687 100755 --- a/git-interface/test/t0003-update.sh +++ b/git-interface/test/t0003-update.sh @@ -85,6 +85,35 @@ test_expect_success 'Test update hook on an updated repository.' ' test_cmp expected actual ' +test_expect_success 'Test restore mode.' ' + AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" restore 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 'Test restore mode on a non-existent repository.' ' + AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \ + test_must_fail "$GIT_UPDATE" restore 2>&1 +' + test_expect_success 'Pushing to a branch other than master.' ' old=0000000000000000000000000000000000000000 && new=$(git -C aur.git rev-parse HEAD) && -- 2.9.2
participants (1)
-
Lukas Fleischer