From e374a91febe53b72ff4cb73b153348f067374c68 Mon Sep 17 00:00:00 2001 From: Frédéric Mangano-Tarumi Date: Sun, 23 Feb 2020 19:53:13 +0100 Subject: Change the extension of TAP test suites to .t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the common convention for TAP, and makes harnesses like prove automatically detect them. Plus, test suites don’t have to be shell scripts anymore. Signed-off-by: Lukas Fleischer --- test/Makefile | 2 +- test/t1100-git-auth.sh | 28 --- test/t1100-git-auth.t | 28 +++ test/t1200-git-serve.sh | 524 ------------------------------------------- test/t1200-git-serve.t | 524 +++++++++++++++++++++++++++++++++++++++++++ test/t1300-git-update.sh | 498 ---------------------------------------- test/t1300-git-update.t | 498 ++++++++++++++++++++++++++++++++++++++++ test/t2100-mkpkglists.sh | 65 ------ test/t2100-mkpkglists.t | 65 ++++++ test/t2200-tuvotereminder.sh | 53 ----- test/t2200-tuvotereminder.t | 53 +++++ test/t2300-pkgmaint.sh | 26 --- test/t2300-pkgmaint.t | 26 +++ test/t2400-aurblup.sh | 53 ----- test/t2400-aurblup.t | 53 +++++ test/t2500-notify.sh | 404 --------------------------------- test/t2500-notify.t | 404 +++++++++++++++++++++++++++++++++ test/t2600-rendercomment.sh | 160 ------------- test/t2600-rendercomment.t | 160 +++++++++++++ test/t2700-usermaint.sh | 49 ---- test/t2700-usermaint.t | 49 ++++ 21 files changed, 1861 insertions(+), 1861 deletions(-) delete mode 100755 test/t1100-git-auth.sh create mode 100755 test/t1100-git-auth.t delete mode 100755 test/t1200-git-serve.sh create mode 100755 test/t1200-git-serve.t delete mode 100755 test/t1300-git-update.sh create mode 100755 test/t1300-git-update.t delete mode 100755 test/t2100-mkpkglists.sh create mode 100755 test/t2100-mkpkglists.t delete mode 100755 test/t2200-tuvotereminder.sh create mode 100755 test/t2200-tuvotereminder.t delete mode 100755 test/t2300-pkgmaint.sh create mode 100755 test/t2300-pkgmaint.t delete mode 100755 test/t2400-aurblup.sh create mode 100755 test/t2400-aurblup.t delete mode 100755 test/t2500-notify.sh create mode 100755 test/t2500-notify.t delete mode 100755 test/t2600-rendercomment.sh create mode 100755 test/t2600-rendercomment.t delete mode 100755 test/t2700-usermaint.sh create mode 100755 test/t2700-usermaint.t diff --git a/test/Makefile b/test/Makefile index f559e169..d310c8f5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) +T = $(sort $(wildcard *.t)) check: $(T) diff --git a/test/t1100-git-auth.sh b/test/t1100-git-auth.sh deleted file mode 100755 index 71d526f2..00000000 --- a/test/t1100-git-auth.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -test_description='git-auth tests' - -. ./setup.sh - -test_expect_success 'Test basic authentication.' ' - "$GIT_AUTH" "$AUTH_KEYTYPE_USER" "$AUTH_KEYTEXT_USER" >out && - grep -q AUR_USER=user out && - grep -q AUR_PRIVILEGED=0 out -' - -test_expect_success 'Test Trusted User authentication.' ' - "$GIT_AUTH" "$AUTH_KEYTYPE_TU" "$AUTH_KEYTEXT_TU" >out && - grep -q AUR_USER=tu out && - 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 diff --git a/test/t1100-git-auth.t b/test/t1100-git-auth.t new file mode 100755 index 00000000..71d526f2 --- /dev/null +++ b/test/t1100-git-auth.t @@ -0,0 +1,28 @@ +#!/bin/sh + +test_description='git-auth tests' + +. ./setup.sh + +test_expect_success 'Test basic authentication.' ' + "$GIT_AUTH" "$AUTH_KEYTYPE_USER" "$AUTH_KEYTEXT_USER" >out && + grep -q AUR_USER=user out && + grep -q AUR_PRIVILEGED=0 out +' + +test_expect_success 'Test Trusted User authentication.' ' + "$GIT_AUTH" "$AUTH_KEYTYPE_TU" "$AUTH_KEYTEXT_TU" >out && + grep -q AUR_USER=tu out && + 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 diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh deleted file mode 100755 index e817b2cf..00000000 --- a/test/t1200-git-serve.sh +++ /dev/null @@ -1,524 +0,0 @@ -#!/bin/sh - -test_description='git-serve tests' - -. ./setup.sh - -test_expect_success 'Test interactive shell.' ' - "$GIT_SERVE" 2>&1 | grep -q "Interactive shell is disabled." -' - -test_expect_success 'Test help.' ' - SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>actual && - save_IFS=$IFS - IFS= - while read -r line; do - echo $line | grep -q "^Commands:$" && continue - echo $line | grep -q "^ [a-z]" || return 1 - [ ${#line} -le 80 ] || return 1 - done config && - test_must_fail \ - env SSH_ORIGINAL_COMMAND=help \ - "$GIT_SERVE" 2>actual && - cat >expected <<-EOF && - The AUR is down due to maintenance. We will be back soon. - EOF - test_cmp expected actual && - mv config.old config -' - -test_expect_success 'Test IP address logging.' ' - SSH_ORIGINAL_COMMAND=help AUR_USER=user "$GIT_SERVE" 2>actual && - cat >expected <<-EOF && - 1.2.3.4 - EOF - echo "SELECT LastSSHLoginIPAddress FROM Users WHERE UserName = \"user\";" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success 'Test IP address bans.' ' - SSH_CLIENT_ORIG="$SSH_CLIENT" && - SSH_CLIENT="1.3.3.7 1337 22" && - test_must_fail \ - env SSH_ORIGINAL_COMMAND=help \ - "$GIT_SERVE" 2>actual && - cat >expected <<-EOF && - The SSH interface is disabled for your IP address. - EOF - test_cmp expected actual && - SSH_CLIENT="$SSH_CLIENT_ORIG" -' - -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 - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user \ - "$GIT_SERVE" 2>&1 >actual && - 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.' ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="git-receive-pack /!.git/" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$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." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="git-receive-pack /foobar2.git/" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$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_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." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="restore foobar2" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Disown all package bases." ' - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual -' - -test_expect_success "Adopt a package base as a regular user." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - *foobar - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual -' - -test_expect_success "Adopt an already adopted package base." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="adopt foobar" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Adopt a package base as a Trusted User." ' - SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - *foobar2 - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual -' - -test_expect_success "Disown one's own package base as a regular user." ' - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual -' - -test_expect_success "Disown one's own package base as a Trusted User." ' - SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual -' - -test_expect_success "Try to steal another user's package as a regular user." ' - SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - test_must_fail \ - env SSH_ORIGINAL_COMMAND="adopt foobar2" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - cat >expected <<-EOF && - *foobar2 - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Try to steal another user's package as a Trusted User." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - cat >expected <<-EOF && - *foobar - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Try to disown another user's package as a regular user." ' - SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - test_must_fail \ - env SSH_ORIGINAL_COMMAND="disown foobar2" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - *foobar2 - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Try to disown another user's package as a Trusted User." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 -' - -test_expect_success "Adopt a package base and add co-maintainers." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="set-comaintainers foobar user3 user4" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 5|3|1 - 6|3|2 - EOF - echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Update package base co-maintainers." ' - SSH_ORIGINAL_COMMAND="set-comaintainers foobar user2 user3 user4" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 4|3|1 - 5|3|2 - 6|3|3 - EOF - echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Try to add co-maintainers to an orphan package base." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="set-comaintainers foobar2 user2 user3 user4" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 4|3|1 - 5|3|2 - 6|3|3 - EOF - echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Disown a package base and check (co-)maintainer list." ' - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - *foobar - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - cat >expected <<-EOF && - 5|3|1 - 6|3|2 - EOF - echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Force-disown a package base and check (co-)maintainer list." ' - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user3 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 >actual && - test_cmp expected actual && - cat >expected <<-EOF && - EOF - echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Check whether package requests are closed when disowning." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (1, 2, 3, "foobar", 4, "", ""); - INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (2, 3, 3, "foobar", 5, "", ""); - INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (3, 2, 2, "foobar2", 6, "", ""); - EOD - >sendmail.out && - SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat <<-EOD >expected && - Subject: [PRQ#1] Orphan Request for foobar Accepted - EOD - grep "^Subject.*PRQ" sendmail.out >sendmail.parts && - test_cmp sendmail.parts expected && - cat <<-EOD >expected && - 1|2||The user user disowned the package. - EOD - echo "SELECT ID, Status, ClosedUID, ClosureComment FROM PackageRequests WHERE ClosedTS > 0;" | sqlite3 aur.db >actual && - test_cmp actual expected -' - -test_expect_success "Flag a package base out-of-date." ' - SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 1|Because. - EOF - echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Unflag a package base as flagger." ' - SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 0|Because. - EOF - echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Unflag a package base as maintainer." ' - SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 0|Because. - EOF - echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Unflag a package base as random user." ' - SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user3 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 1|Because. - EOF - echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Flag using a comment which is too short." ' - SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - test_must_fail \ - env SSH_ORIGINAL_COMMAND="flag foobar xx" \ - AUR_USER=user2 AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 0|Because. - EOF - echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Vote for a package base." ' - SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 3|1 - EOF - echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual && - cat >expected <<-EOF && - 1 - EOF - echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Vote for a package base twice." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - 3|1 - EOF - echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual && - cat >expected <<-EOF && - 1 - EOF - echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Remove vote from a package base." ' - SSH_ORIGINAL_COMMAND="unvote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual && - cat >expected <<-EOF && - 0 - EOF - echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_expect_success "Try to remove the vote again." ' - test_must_fail \ - env SSH_ORIGINAL_COMMAND="unvote foobar" \ - AUR_USER=user AUR_PRIVILEGED=0 \ - "$GIT_SERVE" 2>&1 && - cat >expected <<-EOF && - EOF - echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ - sqlite3 aur.db >actual && - test_cmp expected actual && - cat >expected <<-EOF && - 0 - EOF - echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ - sqlite3 aur.db >actual && - test_cmp expected actual -' - -test_done diff --git a/test/t1200-git-serve.t b/test/t1200-git-serve.t new file mode 100755 index 00000000..e817b2cf --- /dev/null +++ b/test/t1200-git-serve.t @@ -0,0 +1,524 @@ +#!/bin/sh + +test_description='git-serve tests' + +. ./setup.sh + +test_expect_success 'Test interactive shell.' ' + "$GIT_SERVE" 2>&1 | grep -q "Interactive shell is disabled." +' + +test_expect_success 'Test help.' ' + SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>actual && + save_IFS=$IFS + IFS= + while read -r line; do + echo $line | grep -q "^Commands:$" && continue + echo $line | grep -q "^ [a-z]" || return 1 + [ ${#line} -le 80 ] || return 1 + done config && + test_must_fail \ + env SSH_ORIGINAL_COMMAND=help \ + "$GIT_SERVE" 2>actual && + cat >expected <<-EOF && + The AUR is down due to maintenance. We will be back soon. + EOF + test_cmp expected actual && + mv config.old config +' + +test_expect_success 'Test IP address logging.' ' + SSH_ORIGINAL_COMMAND=help AUR_USER=user "$GIT_SERVE" 2>actual && + cat >expected <<-EOF && + 1.2.3.4 + EOF + echo "SELECT LastSSHLoginIPAddress FROM Users WHERE UserName = \"user\";" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success 'Test IP address bans.' ' + SSH_CLIENT_ORIG="$SSH_CLIENT" && + SSH_CLIENT="1.3.3.7 1337 22" && + test_must_fail \ + env SSH_ORIGINAL_COMMAND=help \ + "$GIT_SERVE" 2>actual && + cat >expected <<-EOF && + The SSH interface is disabled for your IP address. + EOF + test_cmp expected actual && + SSH_CLIENT="$SSH_CLIENT_ORIG" +' + +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 + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user \ + "$GIT_SERVE" 2>&1 >actual && + 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.' ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="git-receive-pack /!.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$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." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="git-receive-pack /foobar2.git/" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$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_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." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="restore foobar2" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Disown all package bases." ' + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Adopt a package base as a regular user." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + *foobar + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Adopt an already adopted package base." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="adopt foobar" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Adopt a package base as a Trusted User." ' + SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + *foobar2 + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Disown one's own package base as a regular user." ' + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Disown one's own package base as a Trusted User." ' + SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual +' + +test_expect_success "Try to steal another user's package as a regular user." ' + SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + test_must_fail \ + env SSH_ORIGINAL_COMMAND="adopt foobar2" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + cat >expected <<-EOF && + *foobar2 + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Try to steal another user's package as a Trusted User." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + cat >expected <<-EOF && + *foobar + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Try to disown another user's package as a regular user." ' + SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + test_must_fail \ + env SSH_ORIGINAL_COMMAND="disown foobar2" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + *foobar2 + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Try to disown another user's package as a Trusted User." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 +' + +test_expect_success "Adopt a package base and add co-maintainers." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="set-comaintainers foobar user3 user4" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 5|3|1 + 6|3|2 + EOF + echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Update package base co-maintainers." ' + SSH_ORIGINAL_COMMAND="set-comaintainers foobar user2 user3 user4" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 4|3|1 + 5|3|2 + 6|3|3 + EOF + echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Try to add co-maintainers to an orphan package base." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="set-comaintainers foobar2 user2 user3 user4" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 4|3|1 + 5|3|2 + 6|3|3 + EOF + echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Disown a package base and check (co-)maintainer list." ' + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + *foobar + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + cat >expected <<-EOF && + 5|3|1 + 6|3|2 + EOF + echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Force-disown a package base and check (co-)maintainer list." ' + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user3 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 >actual && + test_cmp expected actual && + cat >expected <<-EOF && + EOF + echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Check whether package requests are closed when disowning." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (1, 2, 3, "foobar", 4, "", ""); + INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (2, 3, 3, "foobar", 5, "", ""); + INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (3, 2, 2, "foobar2", 6, "", ""); + EOD + >sendmail.out && + SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat <<-EOD >expected && + Subject: [PRQ#1] Orphan Request for foobar Accepted + EOD + grep "^Subject.*PRQ" sendmail.out >sendmail.parts && + test_cmp sendmail.parts expected && + cat <<-EOD >expected && + 1|2||The user user disowned the package. + EOD + echo "SELECT ID, Status, ClosedUID, ClosureComment FROM PackageRequests WHERE ClosedTS > 0;" | sqlite3 aur.db >actual && + test_cmp actual expected +' + +test_expect_success "Flag a package base out-of-date." ' + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 1|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as flagger." ' + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as maintainer." ' + SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Unflag a package base as random user." ' + SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user3 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 1|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Flag using a comment which is too short." ' + SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + test_must_fail \ + env SSH_ORIGINAL_COMMAND="flag foobar xx" \ + AUR_USER=user2 AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 0|Because. + EOF + echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Vote for a package base." ' + SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 3|1 + EOF + echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual && + cat >expected <<-EOF && + 1 + EOF + echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Vote for a package base twice." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + 3|1 + EOF + echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual && + cat >expected <<-EOF && + 1 + EOF + echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Remove vote from a package base." ' + SSH_ORIGINAL_COMMAND="unvote foobar" AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual && + cat >expected <<-EOF && + 0 + EOF + echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_expect_success "Try to remove the vote again." ' + test_must_fail \ + env SSH_ORIGINAL_COMMAND="unvote foobar" \ + AUR_USER=user AUR_PRIVILEGED=0 \ + "$GIT_SERVE" 2>&1 && + cat >expected <<-EOF && + EOF + echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \ + sqlite3 aur.db >actual && + test_cmp expected actual && + cat >expected <<-EOF && + 0 + EOF + echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \ + sqlite3 aur.db >actual && + test_cmp expected actual +' + +test_done diff --git a/test/t1300-git-update.sh b/test/t1300-git-update.sh deleted file mode 100755 index 06d14984..00000000 --- a/test/t1300-git-update.sh +++ /dev/null @@ -1,498 +0,0 @@ -#!/bin/sh - -test_description='git-update tests' - -. ./setup.sh - -dump_package_info() { - for t in Packages Licenses PackageLicenses Groups PackageGroups \ - PackageDepends PackageRelations PackageSources \ - PackageNotifications; do - echo "SELECT * FROM $t;" | sqlite3 aur.db - done -} - -test_expect_success 'Test update hook on a fresh repository.' ' - old=0000000000000000000000000000000000000000 && - 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 - EOF - dump_package_info >actual && - 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 - dump_package_info >actual && - 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 - dump_package_info >actual && - 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 - dump_package_info >actual && - test_cmp expected actual -' - -test_expect_success 'Test restore mode on a non-existent repository.' ' - cat >expected <<-EOD && - error: restore: repository not found: foobar3 - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" restore >actual 2>&1 && - test_cmp expected actual -' - -test_expect_success 'Pushing to a branch other than master.' ' - old=0000000000000000000000000000000000000000 && - new=$(git -C aur.git rev-parse HEAD) && - cat >expected <<-EOD && - error: pushing to a branch other than master is restricted - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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^) && - cat >expected <<-EOD && - error: denying non-fast-forward (you should pull first) - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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^) && - cat >expected <<-EOD && - error: denying non-fast-forward (you should pull first) - EOD - test_must_fail \ - env AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 && - test_cmp expected actual -' - -test_expect_success 'Performing a non-fast-forward ref update as normal user with AUR_OVERWRITE=1.' ' - old=$(git -C aur.git rev-parse HEAD) && - new=$(git -C aur.git rev-parse HEAD^) && - cat >expected <<-EOD && - error: denying non-fast-forward (you should pull first) - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 AUR_OVERWRITE=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 && - test_cmp expected actual -' - -test_expect_success 'Performing a non-fast-forward ref update as Trusted User with AUR_OVERWRITE=1.' ' - 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 AUR_OVERWRITE=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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing .SRCINFO$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing .SRCINFO$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing PKGBUILD$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: the repository must not contain subdirectories$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing mandatory field: pkgver$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing mandatory field: pkgrel$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: invalid package name: !$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: invalid epoch: !$" actual -' - -test_expect_success 'Pushing .SRCINFO with too long URL.' ' - old=$(git -C aur.git rev-parse HEAD) && - url="http://$(printf "%7993s" x | sed "s/ /x/g")/" && - test_when_finished "git -C aur.git reset --hard $old" && - ( - cd aur.git && - sed "s#.*url.*#\\0\\nurl = $url#" .SRCINFO >.SRCINFO.new - mv .SRCINFO.new .SRCINFO - git commit -q -am "Change URL" - ) && - new=$(git -C aur.git rev-parse HEAD) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: url field too long: $url\$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing install file: install$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing changelog file: changelog$" actual -' - -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) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: missing source file: file$" actual -' - -test_expect_success 'Pushing .SRCINFO with too long source URL.' ' - old=$(git -C aur.git rev-parse HEAD) && - url="http://$(printf "%7993s" x | sed "s/ /x/g")/" && - test_when_finished "git -C aur.git reset --hard $old" && - ( - cd aur.git && - sed "s#.*depends.*#\\0\\nsource = $url#" .SRCINFO >.SRCINFO.new - mv .SRCINFO.new .SRCINFO - git commit -q -am "Add huge source URL" - ) && - new=$(git -C aur.git rev-parse HEAD) && - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - grep -q "^error: source entry too long: $url\$" actual -' - -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) && - cat >expected <<-EOD && - error: package is blacklisted: forbidden - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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) && - cat >expected <<-EOD && - warning: package is blacklisted: forbidden - EOD - AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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) && - cat >expected <<-EOD && - error: package already provided by [core]: official - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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) && - cat >expected <<-EOD && - warning: package already provided by [core]: official - EOD - AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -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) && - cat >expected <<-EOD && - error: cannot overwrite package: foobar - EOD - test_must_fail \ - env AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \ - "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && - test_cmp expected actual -' - -test_done diff --git a/test/t1300-git-update.t b/test/t1300-git-update.t new file mode 100755 index 00000000..06d14984 --- /dev/null +++ b/test/t1300-git-update.t @@ -0,0 +1,498 @@ +#!/bin/sh + +test_description='git-update tests' + +. ./setup.sh + +dump_package_info() { + for t in Packages Licenses PackageLicenses Groups PackageGroups \ + PackageDepends PackageRelations PackageSources \ + PackageNotifications; do + echo "SELECT * FROM $t;" | sqlite3 aur.db + done +} + +test_expect_success 'Test update hook on a fresh repository.' ' + old=0000000000000000000000000000000000000000 && + 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 + EOF + dump_package_info >actual && + 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 + dump_package_info >actual && + 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 + dump_package_info >actual && + 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 + dump_package_info >actual && + test_cmp expected actual +' + +test_expect_success 'Test restore mode on a non-existent repository.' ' + cat >expected <<-EOD && + error: restore: repository not found: foobar3 + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" restore >actual 2>&1 && + test_cmp expected actual +' + +test_expect_success 'Pushing to a branch other than master.' ' + old=0000000000000000000000000000000000000000 && + new=$(git -C aur.git rev-parse HEAD) && + cat >expected <<-EOD && + error: pushing to a branch other than master is restricted + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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^) && + cat >expected <<-EOD && + error: denying non-fast-forward (you should pull first) + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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^) && + cat >expected <<-EOD && + error: denying non-fast-forward (you should pull first) + EOD + test_must_fail \ + env AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 && + test_cmp expected actual +' + +test_expect_success 'Performing a non-fast-forward ref update as normal user with AUR_OVERWRITE=1.' ' + old=$(git -C aur.git rev-parse HEAD) && + new=$(git -C aur.git rev-parse HEAD^) && + cat >expected <<-EOD && + error: denying non-fast-forward (you should pull first) + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 AUR_OVERWRITE=1 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 && + test_cmp expected actual +' + +test_expect_success 'Performing a non-fast-forward ref update as Trusted User with AUR_OVERWRITE=1.' ' + 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 AUR_OVERWRITE=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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing .SRCINFO$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing .SRCINFO$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing PKGBUILD$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: the repository must not contain subdirectories$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing mandatory field: pkgver$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing mandatory field: pkgrel$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid package name: !$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: invalid epoch: !$" actual +' + +test_expect_success 'Pushing .SRCINFO with too long URL.' ' + old=$(git -C aur.git rev-parse HEAD) && + url="http://$(printf "%7993s" x | sed "s/ /x/g")/" && + test_when_finished "git -C aur.git reset --hard $old" && + ( + cd aur.git && + sed "s#.*url.*#\\0\\nurl = $url#" .SRCINFO >.SRCINFO.new + mv .SRCINFO.new .SRCINFO + git commit -q -am "Change URL" + ) && + new=$(git -C aur.git rev-parse HEAD) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: url field too long: $url\$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing install file: install$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing changelog file: changelog$" actual +' + +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) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: missing source file: file$" actual +' + +test_expect_success 'Pushing .SRCINFO with too long source URL.' ' + old=$(git -C aur.git rev-parse HEAD) && + url="http://$(printf "%7993s" x | sed "s/ /x/g")/" && + test_when_finished "git -C aur.git reset --hard $old" && + ( + cd aur.git && + sed "s#.*depends.*#\\0\\nsource = $url#" .SRCINFO >.SRCINFO.new + mv .SRCINFO.new .SRCINFO + git commit -q -am "Add huge source URL" + ) && + new=$(git -C aur.git rev-parse HEAD) && + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + grep -q "^error: source entry too long: $url\$" actual +' + +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) && + cat >expected <<-EOD && + error: package is blacklisted: forbidden + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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) && + cat >expected <<-EOD && + warning: package is blacklisted: forbidden + EOD + AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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) && + cat >expected <<-EOD && + error: package already provided by [core]: official + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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) && + cat >expected <<-EOD && + warning: package already provided by [core]: official + EOD + AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +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) && + cat >expected <<-EOD && + error: cannot overwrite package: foobar + EOD + test_must_fail \ + env AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \ + "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 && + test_cmp expected actual +' + +test_done diff --git a/test/t2100-mkpkglists.sh b/test/t2100-mkpkglists.sh deleted file mode 100755 index fc11d073..00000000 --- a/test/t2100-mkpkglists.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh - -test_description='mkpkglists tests' - -. ./setup.sh - -test_expect_success 'Test package list generation with no packages.' ' - echo "DELETE FROM Packages;" | sqlite3 aur.db && - echo "DELETE FROM PackageBases;" | sqlite3 aur.db && - "$MKPKGLISTS" && - test $(zcat packages.gz | wc -l) -eq 1 && - test $(zcat pkgbase.gz | wc -l) -eq 1 -' - -test_expect_success 'Test package list generation.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, 0, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (2, "foobar2", 2, 0, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (3, "foobar3", NULL, 0, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (4, "foobar4", 1, 0, 0, ""); - INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (1, 1, "pkg1"); - INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (2, 1, "pkg2"); - INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (3, 1, "pkg3"); - INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (4, 2, "pkg4"); - INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (5, 3, "pkg5"); - EOD - "$MKPKGLISTS" && - cat <<-EOD >expected && - foobar - foobar2 - foobar4 - EOD - gunzip pkgbase.gz && - sed "/^#/d" pkgbase >actual && - test_cmp actual expected && - cat <<-EOD >expected && - pkg1 - pkg2 - pkg3 - pkg4 - EOD - gunzip packages.gz && - sed "/^#/d" packages >actual && - test_cmp actual expected -' - -test_expect_success 'Test user list generation.' ' - "$MKPKGLISTS" && - cat <<-EOD >expected && - dev - tu - tu2 - tu3 - tu4 - user - user2 - user3 - user4 - EOD - gunzip users.gz && - sed "/^#/d" users >actual && - test_cmp actual expected -' - -test_done diff --git a/test/t2100-mkpkglists.t b/test/t2100-mkpkglists.t new file mode 100755 index 00000000..fc11d073 --- /dev/null +++ b/test/t2100-mkpkglists.t @@ -0,0 +1,65 @@ +#!/bin/sh + +test_description='mkpkglists tests' + +. ./setup.sh + +test_expect_success 'Test package list generation with no packages.' ' + echo "DELETE FROM Packages;" | sqlite3 aur.db && + echo "DELETE FROM PackageBases;" | sqlite3 aur.db && + "$MKPKGLISTS" && + test $(zcat packages.gz | wc -l) -eq 1 && + test $(zcat pkgbase.gz | wc -l) -eq 1 +' + +test_expect_success 'Test package list generation.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, 0, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (2, "foobar2", 2, 0, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (3, "foobar3", NULL, 0, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (4, "foobar4", 1, 0, 0, ""); + INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (1, 1, "pkg1"); + INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (2, 1, "pkg2"); + INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (3, 1, "pkg3"); + INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (4, 2, "pkg4"); + INSERT INTO Packages (ID, PackageBaseID, Name) VALUES (5, 3, "pkg5"); + EOD + "$MKPKGLISTS" && + cat <<-EOD >expected && + foobar + foobar2 + foobar4 + EOD + gunzip pkgbase.gz && + sed "/^#/d" pkgbase >actual && + test_cmp actual expected && + cat <<-EOD >expected && + pkg1 + pkg2 + pkg3 + pkg4 + EOD + gunzip packages.gz && + sed "/^#/d" packages >actual && + test_cmp actual expected +' + +test_expect_success 'Test user list generation.' ' + "$MKPKGLISTS" && + cat <<-EOD >expected && + dev + tu + tu2 + tu3 + tu4 + user + user2 + user3 + user4 + EOD + gunzip users.gz && + sed "/^#/d" users >actual && + test_cmp actual expected +' + +test_done diff --git a/test/t2200-tuvotereminder.sh b/test/t2200-tuvotereminder.sh deleted file mode 100755 index c82ce874..00000000 --- a/test/t2200-tuvotereminder.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -test_description='tuvotereminder tests' - -. ./setup.sh - -test_expect_success 'Test Trusted User vote reminders.' ' - now=$(date -d now +%s) && - tomorrow=$(date -d tomorrow +%s) && - threedays=$(date -d "3 days" +%s) && - cat <<-EOD | sqlite3 aur.db && - INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (1, "Lorem ipsum.", "user", 0, $now, 0.00, 2); - INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (2, "Lorem ipsum.", "user", 0, $tomorrow, 0.00, 2); - INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (3, "Lorem ipsum.", "user", 0, $tomorrow, 0.00, 2); - INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (4, "Lorem ipsum.", "user", 0, $threedays, 0.00, 2); - EOD - >sendmail.out && - "$TUVOTEREMINDER" && - grep -q "Proposal 2" sendmail.out && - grep -q "Proposal 3" sendmail.out && - test_must_fail grep -q "Proposal 1" sendmail.out && - test_must_fail grep -q "Proposal 4" sendmail.out -' - -test_expect_success 'Check that only TUs who did not vote receive reminders.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 2); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (2, 2); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (3, 2); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (4, 2); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 7); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (3, 7); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (2, 8); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (4, 8); - INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 9); - EOD - >sendmail.out && - "$TUVOTEREMINDER" && - cat <<-EOD >expected && - Subject: TU Vote Reminder: Proposal 2 - To: tu2@localhost - Subject: TU Vote Reminder: Proposal 2 - To: tu4@localhost - Subject: TU Vote Reminder: Proposal 3 - To: tu3@localhost - Subject: TU Vote Reminder: Proposal 3 - To: tu4@localhost - EOD - grep "^\(Subject\|To\)" sendmail.out >sendmail.parts && - test_cmp sendmail.parts expected -' - -test_done diff --git a/test/t2200-tuvotereminder.t b/test/t2200-tuvotereminder.t new file mode 100755 index 00000000..c82ce874 --- /dev/null +++ b/test/t2200-tuvotereminder.t @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='tuvotereminder tests' + +. ./setup.sh + +test_expect_success 'Test Trusted User vote reminders.' ' + now=$(date -d now +%s) && + tomorrow=$(date -d tomorrow +%s) && + threedays=$(date -d "3 days" +%s) && + cat <<-EOD | sqlite3 aur.db && + INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (1, "Lorem ipsum.", "user", 0, $now, 0.00, 2); + INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (2, "Lorem ipsum.", "user", 0, $tomorrow, 0.00, 2); + INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (3, "Lorem ipsum.", "user", 0, $tomorrow, 0.00, 2); + INSERT INTO TU_VoteInfo (ID, Agenda, User, Submitted, End, Quorum, SubmitterID) VALUES (4, "Lorem ipsum.", "user", 0, $threedays, 0.00, 2); + EOD + >sendmail.out && + "$TUVOTEREMINDER" && + grep -q "Proposal 2" sendmail.out && + grep -q "Proposal 3" sendmail.out && + test_must_fail grep -q "Proposal 1" sendmail.out && + test_must_fail grep -q "Proposal 4" sendmail.out +' + +test_expect_success 'Check that only TUs who did not vote receive reminders.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 2); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (2, 2); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (3, 2); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (4, 2); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 7); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (3, 7); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (2, 8); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (4, 8); + INSERT INTO TU_Votes (VoteID, UserID) VALUES (1, 9); + EOD + >sendmail.out && + "$TUVOTEREMINDER" && + cat <<-EOD >expected && + Subject: TU Vote Reminder: Proposal 2 + To: tu2@localhost + Subject: TU Vote Reminder: Proposal 2 + To: tu4@localhost + Subject: TU Vote Reminder: Proposal 3 + To: tu3@localhost + Subject: TU Vote Reminder: Proposal 3 + To: tu4@localhost + EOD + grep "^\(Subject\|To\)" sendmail.out >sendmail.parts && + test_cmp sendmail.parts expected +' + +test_done diff --git a/test/t2300-pkgmaint.sh b/test/t2300-pkgmaint.sh deleted file mode 100755 index 478df526..00000000 --- a/test/t2300-pkgmaint.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -test_description='pkgmaint tests' - -. ./setup.sh - -test_expect_success 'Test package base cleanup script.' ' - now=$(date -d now +%s) && - threedaysago=$(date -d "3 days ago" +%s) && - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, $now, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (2, "foobar2", 2, $threedaysago, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (3, "foobar3", NULL, $now, 0, ""); - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (4, "foobar4", NULL, $threedaysago, 0, ""); - EOD - "$PKGMAINT" && - cat <<-EOD >expected && - foobar - foobar2 - foobar3 - EOD - echo "SELECT Name FROM PackageBases;" | sqlite3 aur.db >actual && - test_cmp actual expected -' - -test_done diff --git a/test/t2300-pkgmaint.t b/test/t2300-pkgmaint.t new file mode 100755 index 00000000..478df526 --- /dev/null +++ b/test/t2300-pkgmaint.t @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='pkgmaint tests' + +. ./setup.sh + +test_expect_success 'Test package base cleanup script.' ' + now=$(date -d now +%s) && + threedaysago=$(date -d "3 days ago" +%s) && + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, $now, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (2, "foobar2", 2, $threedaysago, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (3, "foobar3", NULL, $now, 0, ""); + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (4, "foobar4", NULL, $threedaysago, 0, ""); + EOD + "$PKGMAINT" && + cat <<-EOD >expected && + foobar + foobar2 + foobar3 + EOD + echo "SELECT Name FROM PackageBases;" | sqlite3 aur.db >actual && + test_cmp actual expected +' + +test_done diff --git a/test/t2400-aurblup.sh b/test/t2400-aurblup.sh deleted file mode 100755 index 708281c6..00000000 --- a/test/t2400-aurblup.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -test_description='aurblup tests' - -. ./setup.sh - -test_expect_success 'Test official provider update script.' ' - mkdir -p remote/test/foobar-1.0-1 && - cat <<-EOD >remote/test/foobar-1.0-1/desc && - %FILENAME% - foobar-1.0-any.pkg.tar.xz - - %NAME% - foobar - - %VERSION% - 1.0-1 - - %ARCH% - any - EOD - mkdir -p remote/test/foobar2-1.0-1 && - cat <<-EOD >remote/test/foobar2-1.0-1/desc && - %FILENAME% - foobar2-1.0-any.pkg.tar.xz - - %NAME% - foobar2 - - %VERSION% - 1.0-1 - - %ARCH% - any - - %PROVIDES% - foobar3 - foobar4 - EOD - ( cd remote/test && bsdtar -czf ../test.db * ) && - mkdir sync && - "$AURBLUP" && - cat <<-EOD >expected && - foobar|test|foobar - foobar2|test|foobar2 - foobar2|test|foobar3 - foobar2|test|foobar4 - EOD - echo "SELECT Name, Repo, Provides FROM OfficialProviders ORDER BY Provides;" | sqlite3 aur.db >actual && - test_cmp actual expected -' - -test_done diff --git a/test/t2400-aurblup.t b/test/t2400-aurblup.t new file mode 100755 index 00000000..708281c6 --- /dev/null +++ b/test/t2400-aurblup.t @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='aurblup tests' + +. ./setup.sh + +test_expect_success 'Test official provider update script.' ' + mkdir -p remote/test/foobar-1.0-1 && + cat <<-EOD >remote/test/foobar-1.0-1/desc && + %FILENAME% + foobar-1.0-any.pkg.tar.xz + + %NAME% + foobar + + %VERSION% + 1.0-1 + + %ARCH% + any + EOD + mkdir -p remote/test/foobar2-1.0-1 && + cat <<-EOD >remote/test/foobar2-1.0-1/desc && + %FILENAME% + foobar2-1.0-any.pkg.tar.xz + + %NAME% + foobar2 + + %VERSION% + 1.0-1 + + %ARCH% + any + + %PROVIDES% + foobar3 + foobar4 + EOD + ( cd remote/test && bsdtar -czf ../test.db * ) && + mkdir sync && + "$AURBLUP" && + cat <<-EOD >expected && + foobar|test|foobar + foobar2|test|foobar2 + foobar2|test|foobar3 + foobar2|test|foobar4 + EOD + echo "SELECT Name, Repo, Provides FROM OfficialProviders ORDER BY Provides;" | sqlite3 aur.db >actual && + test_cmp actual expected +' + +test_done diff --git a/test/t2500-notify.sh b/test/t2500-notify.sh deleted file mode 100755 index 380e65b8..00000000 --- a/test/t2500-notify.sh +++ /dev/null @@ -1,404 +0,0 @@ -#!/bin/sh - -test_description='notify tests' - -. ./setup.sh - -test_expect_success 'Test out-of-date notifications.' ' - cat <<-EOD | sqlite3 aur.db && - /* Use package base IDs which can be distinguished from user IDs. */ - INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1001, "foobar", 1, 0, 0, "This is a test OOD comment."); - INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1002, "foobar2", 2, 0, 0, ""); - INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1003, "foobar3", NULL, 0, 0, ""); - INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1004, "foobar4", 1, 0, 0, ""); - INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 2, 1); - INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 4, 2); - INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 3, 1); - INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 5, 2); - INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1003, 4, 1); - EOD - >sendmail.out && - "$NOTIFY" flag 1 1001 && - cat <<-EOD >expected && - Subject: AUR Out-of-date Notification for foobar - To: tu@localhost - Subject: AUR Out-of-date Notification for foobar - To: user2@localhost - Subject: AUR Out-of-date Notification for foobar - To: user@localhost - EOD - grep "^\(Subject\|To\)" sendmail.out >sendmail.parts && - test_cmp sendmail.parts expected && - cat <<-EOD | sqlite3 aur.db - DELETE FROM PackageComaintainers; - EOD -' - -test_expect_success 'Test subject and body of reset key notifications.' ' - cat <<-EOD | sqlite3 aur.db && - UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1; - EOD - >sendmail.out && - "$NOTIFY" send-resetkey 1 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Password Reset - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - A password reset request was submitted for the account user associated - with your email address. If you wish to reset your password follow the - link [1] below, otherwise ignore this message and nothing will happen. - - [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012 - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of welcome notifications.' ' - cat <<-EOD | sqlite3 aur.db && - UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1; - EOD - >sendmail.out && - "$NOTIFY" welcome 1 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: Welcome to the Arch User Repository - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Welcome to the Arch User Repository! In order to set an initial - password for your new account, please click the link [1] below. If the - link does not work, try copying and pasting it into your browser. - - [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012 - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of comment notifications.' ' - cat <<-EOD | sqlite3 aur.db && - /* Use package comments IDs which can be distinguished from other IDs. */ - INSERT INTO PackageComments (ID, PackageBaseID, UsersID, Comments, RenderedComment) VALUES (2001, 1001, 1, "This is a test comment.", "This is a test comment."); - INSERT INTO PackageNotifications (PackageBaseID, UserID) VALUES (1001, 2); - UPDATE Users SET CommentNotify = 1 WHERE ID = 2; - EOD - >sendmail.out && - "$NOTIFY" comment 1 1001 2001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Comment for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] added the following comment to foobar [2]: - - This is a test comment. - - -- - If you no longer wish to receive notifications about this package, - please go to the package page [2] and select "Disable notifications". - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of update notifications.' ' - cat <<-EOD | sqlite3 aur.db && - UPDATE Users SET UpdateNotify = 1 WHERE ID = 2; - EOD - >sendmail.out && - "$NOTIFY" update 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Package Update: foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] pushed a new commit to foobar [2]. - - -- - If you no longer wish to receive notifications about this package, - please go to the package page [2] and select "Disable notifications". - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of out-of-date notifications.' ' - >sendmail.out && - "$NOTIFY" flag 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Out-of-date Notification for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Your package foobar [1] has been flagged out-of-date by user [2]: - - This is a test OOD comment. - - [1] https://aur.archlinux.org/pkgbase/foobar/ - [2] https://aur.archlinux.org/account/user/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of adopt notifications.' ' - >sendmail.out && - "$NOTIFY" adopt 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Ownership Notification for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - The package foobar [1] was adopted by user [2]. - - [1] https://aur.archlinux.org/pkgbase/foobar/ - [2] https://aur.archlinux.org/account/user/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of disown notifications.' ' - >sendmail.out && - "$NOTIFY" disown 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Ownership Notification for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - The package foobar [1] was disowned by user [2]. - - [1] https://aur.archlinux.org/pkgbase/foobar/ - [2] https://aur.archlinux.org/account/user/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of co-maintainer addition notifications.' ' - >sendmail.out && - "$NOTIFY" comaintainer-add 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Co-Maintainer Notification for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - You were added to the co-maintainer list of foobar [1]. - - [1] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of co-maintainer removal notifications.' ' - >sendmail.out && - "$NOTIFY" comaintainer-remove 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Co-Maintainer Notification for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - You were removed from the co-maintainer list of foobar [1]. - - [1] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of delete notifications.' ' - >sendmail.out && - "$NOTIFY" delete 1 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Package deleted: foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] deleted foobar [2]. - - You will no longer receive notifications about this package. - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of merge notifications.' ' - >sendmail.out && - "$NOTIFY" delete 1 1001 1002 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: AUR Package deleted: foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] merged foobar [2] into foobar2 [3]. - - -- - If you no longer wish receive notifications about the new package, - please go to [3] and click "Disable notifications". - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - [3] https://aur.archlinux.org/pkgbase/foobar2/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of request open notifications.' ' - cat <<-EOD | sqlite3 aur.db && - /* Use package request IDs which can be distinguished from other IDs. */ - INSERT INTO PackageRequests (ID, PackageBaseID, PackageBaseName, UsersID, ReqTypeID, Comments, ClosureComment) VALUES (3001, 1001, "foobar", 1, 1, "This is a request test comment.", ""); - EOD - >sendmail.out && - "$NOTIFY" request-open 1 3001 orphan 1001 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: [PRQ#3001] Orphan Request for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] filed an orphan request for foobar [2]: - - This is a request test comment. - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of request open notifications for merge requests.' ' - >sendmail.out && - "$NOTIFY" request-open 1 3001 merge 1001 foobar2 && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: [PRQ#3001] Merge Request for foobar - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - user [1] filed a request to merge foobar [2] into foobar2 [3]: - - This is a request test comment. - - [1] https://aur.archlinux.org/account/user/ - [2] https://aur.archlinux.org/pkgbase/foobar/ - [3] https://aur.archlinux.org/pkgbase/foobar2/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of request close notifications.' ' - >sendmail.out && - "$NOTIFY" request-close 1 3001 accepted && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: [PRQ#3001] Deletion Request for foobar Accepted - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Request #3001 has been accepted by user [1]. - - [1] https://aur.archlinux.org/account/user/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of request close notifications (auto-accept).' ' - >sendmail.out && - "$NOTIFY" request-close 0 3001 accepted && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: [PRQ#3001] Deletion Request for foobar Accepted - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Request #3001 has been accepted automatically by the Arch User - Repository package request system. - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of request close notifications with closure comment.' ' - cat <<-EOD | sqlite3 aur.db && - UPDATE PackageRequests SET ClosureComment = "This is a test closure comment." WHERE ID = 3001; - EOD - >sendmail.out && - "$NOTIFY" request-close 1 3001 accepted && - grep ^Subject: sendmail.out >actual && - cat <<-EOD >expected && - Subject: [PRQ#3001] Deletion Request for foobar Accepted - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Request #3001 has been accepted by user [1]: - - This is a test closure comment. - - [1] https://aur.archlinux.org/account/user/ - EOD - test_cmp actual expected -' - -test_expect_success 'Test subject and body of TU vote reminders.' ' - >sendmail.out && - "$NOTIFY" tu-vote-reminder 1 && - grep ^Subject: sendmail.out | head -1 >actual && - cat <<-EOD >expected && - Subject: TU Vote Reminder: Proposal 1 - EOD - test_cmp actual expected && - sed -n "/^\$/,\$p" sendmail.out | head -4 | base64 -d >actual && - echo >>actual && - cat <<-EOD >expected && - Please remember to cast your vote on proposal 1 [1]. The voting period - ends in less than 48 hours. - - [1] https://aur.archlinux.org/tu/?id=1 - EOD - test_cmp actual expected -' - -test_done diff --git a/test/t2500-notify.t b/test/t2500-notify.t new file mode 100755 index 00000000..380e65b8 --- /dev/null +++ b/test/t2500-notify.t @@ -0,0 +1,404 @@ +#!/bin/sh + +test_description='notify tests' + +. ./setup.sh + +test_expect_success 'Test out-of-date notifications.' ' + cat <<-EOD | sqlite3 aur.db && + /* Use package base IDs which can be distinguished from user IDs. */ + INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1001, "foobar", 1, 0, 0, "This is a test OOD comment."); + INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1002, "foobar2", 2, 0, 0, ""); + INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1003, "foobar3", NULL, 0, 0, ""); + INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1004, "foobar4", 1, 0, 0, ""); + INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 2, 1); + INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 4, 2); + INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 3, 1); + INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 5, 2); + INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1003, 4, 1); + EOD + >sendmail.out && + "$NOTIFY" flag 1 1001 && + cat <<-EOD >expected && + Subject: AUR Out-of-date Notification for foobar + To: tu@localhost + Subject: AUR Out-of-date Notification for foobar + To: user2@localhost + Subject: AUR Out-of-date Notification for foobar + To: user@localhost + EOD + grep "^\(Subject\|To\)" sendmail.out >sendmail.parts && + test_cmp sendmail.parts expected && + cat <<-EOD | sqlite3 aur.db + DELETE FROM PackageComaintainers; + EOD +' + +test_expect_success 'Test subject and body of reset key notifications.' ' + cat <<-EOD | sqlite3 aur.db && + UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1; + EOD + >sendmail.out && + "$NOTIFY" send-resetkey 1 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Password Reset + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + A password reset request was submitted for the account user associated + with your email address. If you wish to reset your password follow the + link [1] below, otherwise ignore this message and nothing will happen. + + [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012 + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of welcome notifications.' ' + cat <<-EOD | sqlite3 aur.db && + UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1; + EOD + >sendmail.out && + "$NOTIFY" welcome 1 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: Welcome to the Arch User Repository + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Welcome to the Arch User Repository! In order to set an initial + password for your new account, please click the link [1] below. If the + link does not work, try copying and pasting it into your browser. + + [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012 + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of comment notifications.' ' + cat <<-EOD | sqlite3 aur.db && + /* Use package comments IDs which can be distinguished from other IDs. */ + INSERT INTO PackageComments (ID, PackageBaseID, UsersID, Comments, RenderedComment) VALUES (2001, 1001, 1, "This is a test comment.", "This is a test comment."); + INSERT INTO PackageNotifications (PackageBaseID, UserID) VALUES (1001, 2); + UPDATE Users SET CommentNotify = 1 WHERE ID = 2; + EOD + >sendmail.out && + "$NOTIFY" comment 1 1001 2001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Comment for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] added the following comment to foobar [2]: + + This is a test comment. + + -- + If you no longer wish to receive notifications about this package, + please go to the package page [2] and select "Disable notifications". + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of update notifications.' ' + cat <<-EOD | sqlite3 aur.db && + UPDATE Users SET UpdateNotify = 1 WHERE ID = 2; + EOD + >sendmail.out && + "$NOTIFY" update 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Package Update: foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] pushed a new commit to foobar [2]. + + -- + If you no longer wish to receive notifications about this package, + please go to the package page [2] and select "Disable notifications". + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of out-of-date notifications.' ' + >sendmail.out && + "$NOTIFY" flag 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Out-of-date Notification for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Your package foobar [1] has been flagged out-of-date by user [2]: + + This is a test OOD comment. + + [1] https://aur.archlinux.org/pkgbase/foobar/ + [2] https://aur.archlinux.org/account/user/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of adopt notifications.' ' + >sendmail.out && + "$NOTIFY" adopt 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Ownership Notification for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + The package foobar [1] was adopted by user [2]. + + [1] https://aur.archlinux.org/pkgbase/foobar/ + [2] https://aur.archlinux.org/account/user/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of disown notifications.' ' + >sendmail.out && + "$NOTIFY" disown 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Ownership Notification for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + The package foobar [1] was disowned by user [2]. + + [1] https://aur.archlinux.org/pkgbase/foobar/ + [2] https://aur.archlinux.org/account/user/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of co-maintainer addition notifications.' ' + >sendmail.out && + "$NOTIFY" comaintainer-add 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Co-Maintainer Notification for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + You were added to the co-maintainer list of foobar [1]. + + [1] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of co-maintainer removal notifications.' ' + >sendmail.out && + "$NOTIFY" comaintainer-remove 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Co-Maintainer Notification for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + You were removed from the co-maintainer list of foobar [1]. + + [1] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of delete notifications.' ' + >sendmail.out && + "$NOTIFY" delete 1 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Package deleted: foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] deleted foobar [2]. + + You will no longer receive notifications about this package. + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of merge notifications.' ' + >sendmail.out && + "$NOTIFY" delete 1 1001 1002 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: AUR Package deleted: foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] merged foobar [2] into foobar2 [3]. + + -- + If you no longer wish receive notifications about the new package, + please go to [3] and click "Disable notifications". + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + [3] https://aur.archlinux.org/pkgbase/foobar2/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of request open notifications.' ' + cat <<-EOD | sqlite3 aur.db && + /* Use package request IDs which can be distinguished from other IDs. */ + INSERT INTO PackageRequests (ID, PackageBaseID, PackageBaseName, UsersID, ReqTypeID, Comments, ClosureComment) VALUES (3001, 1001, "foobar", 1, 1, "This is a request test comment.", ""); + EOD + >sendmail.out && + "$NOTIFY" request-open 1 3001 orphan 1001 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: [PRQ#3001] Orphan Request for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] filed an orphan request for foobar [2]: + + This is a request test comment. + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of request open notifications for merge requests.' ' + >sendmail.out && + "$NOTIFY" request-open 1 3001 merge 1001 foobar2 && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: [PRQ#3001] Merge Request for foobar + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + user [1] filed a request to merge foobar [2] into foobar2 [3]: + + This is a request test comment. + + [1] https://aur.archlinux.org/account/user/ + [2] https://aur.archlinux.org/pkgbase/foobar/ + [3] https://aur.archlinux.org/pkgbase/foobar2/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of request close notifications.' ' + >sendmail.out && + "$NOTIFY" request-close 1 3001 accepted && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: [PRQ#3001] Deletion Request for foobar Accepted + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Request #3001 has been accepted by user [1]. + + [1] https://aur.archlinux.org/account/user/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of request close notifications (auto-accept).' ' + >sendmail.out && + "$NOTIFY" request-close 0 3001 accepted && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: [PRQ#3001] Deletion Request for foobar Accepted + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Request #3001 has been accepted automatically by the Arch User + Repository package request system. + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of request close notifications with closure comment.' ' + cat <<-EOD | sqlite3 aur.db && + UPDATE PackageRequests SET ClosureComment = "This is a test closure comment." WHERE ID = 3001; + EOD + >sendmail.out && + "$NOTIFY" request-close 1 3001 accepted && + grep ^Subject: sendmail.out >actual && + cat <<-EOD >expected && + Subject: [PRQ#3001] Deletion Request for foobar Accepted + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Request #3001 has been accepted by user [1]: + + This is a test closure comment. + + [1] https://aur.archlinux.org/account/user/ + EOD + test_cmp actual expected +' + +test_expect_success 'Test subject and body of TU vote reminders.' ' + >sendmail.out && + "$NOTIFY" tu-vote-reminder 1 && + grep ^Subject: sendmail.out | head -1 >actual && + cat <<-EOD >expected && + Subject: TU Vote Reminder: Proposal 1 + EOD + test_cmp actual expected && + sed -n "/^\$/,\$p" sendmail.out | head -4 | base64 -d >actual && + echo >>actual && + cat <<-EOD >expected && + Please remember to cast your vote on proposal 1 [1]. The voting period + ends in less than 48 hours. + + [1] https://aur.archlinux.org/tu/?id=1 + EOD + test_cmp actual expected +' + +test_done diff --git a/test/t2600-rendercomment.sh b/test/t2600-rendercomment.sh deleted file mode 100755 index be408b80..00000000 --- a/test/t2600-rendercomment.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/bin/sh - -test_description='rendercomment tests' - -. ./setup.sh - -test_expect_success 'Test comment rendering.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, 0, 0, ""); - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (1, 1, "Hello world! - This is a comment.", ""); - EOD - "$RENDERCOMMENT" 1 && - cat <<-EOD >expected && -

Hello world! - This is a comment.

- EOD - cat <<-EOD | sqlite3 aur.db >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 1; - EOD - test_cmp actual expected -' - -test_expect_success 'Test Markdown conversion.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (2, 1, "*Hello* [world](https://www.archlinux.org/)!", ""); - EOD - "$RENDERCOMMENT" 2 && - cat <<-EOD >expected && -

Hello world!

- EOD - cat <<-EOD | sqlite3 aur.db >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 2; - EOD - test_cmp actual expected -' - -test_expect_success 'Test HTML sanitizing.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (3, 1, "", ""); - EOD - "$RENDERCOMMENT" 3 && - cat <<-EOD >expected && - <script>alert("XSS!");</script> - EOD - cat <<-EOD | sqlite3 aur.db >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 3; - EOD - test_cmp actual expected -' - -test_expect_success 'Test link conversion.' ' - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (4, 1, " - Visit https://www.archlinux.org/#_test_. - Visit *https://www.archlinux.org/*. - Visit . - Visit \`https://www.archlinux.org/\`. - Visit [Arch Linux](https://www.archlinux.org/). - Visit [Arch Linux][arch]. - [arch]: https://www.archlinux.org/ - ", ""); - EOD - "$RENDERCOMMENT" 4 && - cat <<-EOD >expected && -

Visit https://www.archlinux.org/#_test_. - Visit https://www.archlinux.org/. - Visit https://www.archlinux.org/. - Visit https://www.archlinux.org/. - Visit Arch Linux. - Visit Arch Linux.

- EOD - cat <<-EOD | sqlite3 aur.db >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 4; - EOD - test_cmp actual expected -' - -test_expect_success 'Test Git commit linkification.' ' - local oid=`git -C aur.git rev-parse --verify HEAD` - cat <<-EOD | sqlite3 aur.db && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (5, 1, " - $oid - ${oid:0:7} - x.$oid.x - ${oid}x - 0123456789abcdef - \`$oid\` - http://example.com/$oid - ", ""); - EOD - "$RENDERCOMMENT" 5 && - cat <<-EOD >expected && -

${oid:0:12} - ${oid:0:7} - x.${oid:0:12}.x - ${oid}x - 0123456789abcdef - $oid - http://example.com/$oid

- EOD - cat <<-EOD | sqlite3 aur.db >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 5; - EOD - test_cmp actual expected -' - -test_expect_success 'Test Flyspray issue linkification.' ' - sqlite3 aur.db <<-EOD && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (6, 1, " - FS#1234567. - *FS#1234* - FS# - XFS#1 - \`FS#1234\` - https://archlinux.org/?test=FS#1234 - ", ""); - EOD - "$RENDERCOMMENT" 6 && - cat <<-EOD >expected && -

FS#1234567. - FS#1234 - FS# - XFS#1 - FS#1234 - https://archlinux.org/?test=FS#1234

- EOD - sqlite3 aur.db <<-EOD >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 6; - EOD - test_cmp actual expected -' - -test_expect_success 'Test headings lowering.' ' - sqlite3 aur.db <<-EOD && - INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (7, 1, " - # One - ## Two - ### Three - #### Four - ##### Five - ###### Six - ", ""); - EOD - "$RENDERCOMMENT" 7 && - cat <<-EOD >expected && -
One
-
Two
-
Three
-
Four
-
Five
-
Six
- EOD - sqlite3 aur.db <<-EOD >actual && - SELECT RenderedComment FROM PackageComments WHERE ID = 7; - EOD - test_cmp actual expected -' - -test_done diff --git a/test/t2600-rendercomment.t b/test/t2600-rendercomment.t new file mode 100755 index 00000000..be408b80 --- /dev/null +++ b/test/t2600-rendercomment.t @@ -0,0 +1,160 @@ +#!/bin/sh + +test_description='rendercomment tests' + +. ./setup.sh + +test_expect_success 'Test comment rendering.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageBases (ID, Name, PackagerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1, "foobar", 1, 0, 0, ""); + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (1, 1, "Hello world! + This is a comment.", ""); + EOD + "$RENDERCOMMENT" 1 && + cat <<-EOD >expected && +

Hello world! + This is a comment.

+ EOD + cat <<-EOD | sqlite3 aur.db >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 1; + EOD + test_cmp actual expected +' + +test_expect_success 'Test Markdown conversion.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (2, 1, "*Hello* [world](https://www.archlinux.org/)!", ""); + EOD + "$RENDERCOMMENT" 2 && + cat <<-EOD >expected && +

Hello world!

+ EOD + cat <<-EOD | sqlite3 aur.db >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 2; + EOD + test_cmp actual expected +' + +test_expect_success 'Test HTML sanitizing.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (3, 1, "", ""); + EOD + "$RENDERCOMMENT" 3 && + cat <<-EOD >expected && + <script>alert("XSS!");</script> + EOD + cat <<-EOD | sqlite3 aur.db >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 3; + EOD + test_cmp actual expected +' + +test_expect_success 'Test link conversion.' ' + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (4, 1, " + Visit https://www.archlinux.org/#_test_. + Visit *https://www.archlinux.org/*. + Visit . + Visit \`https://www.archlinux.org/\`. + Visit [Arch Linux](https://www.archlinux.org/). + Visit [Arch Linux][arch]. + [arch]: https://www.archlinux.org/ + ", ""); + EOD + "$RENDERCOMMENT" 4 && + cat <<-EOD >expected && +

Visit https://www.archlinux.org/#_test_. + Visit https://www.archlinux.org/. + Visit https://www.archlinux.org/. + Visit https://www.archlinux.org/. + Visit Arch Linux. + Visit Arch Linux.

+ EOD + cat <<-EOD | sqlite3 aur.db >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 4; + EOD + test_cmp actual expected +' + +test_expect_success 'Test Git commit linkification.' ' + local oid=`git -C aur.git rev-parse --verify HEAD` + cat <<-EOD | sqlite3 aur.db && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (5, 1, " + $oid + ${oid:0:7} + x.$oid.x + ${oid}x + 0123456789abcdef + \`$oid\` + http://example.com/$oid + ", ""); + EOD + "$RENDERCOMMENT" 5 && + cat <<-EOD >expected && +

${oid:0:12} + ${oid:0:7} + x.${oid:0:12}.x + ${oid}x + 0123456789abcdef + $oid + http://example.com/$oid

+ EOD + cat <<-EOD | sqlite3 aur.db >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 5; + EOD + test_cmp actual expected +' + +test_expect_success 'Test Flyspray issue linkification.' ' + sqlite3 aur.db <<-EOD && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (6, 1, " + FS#1234567. + *FS#1234* + FS# + XFS#1 + \`FS#1234\` + https://archlinux.org/?test=FS#1234 + ", ""); + EOD + "$RENDERCOMMENT" 6 && + cat <<-EOD >expected && +

FS#1234567. + FS#1234 + FS# + XFS#1 + FS#1234 + https://archlinux.org/?test=FS#1234

+ EOD + sqlite3 aur.db <<-EOD >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 6; + EOD + test_cmp actual expected +' + +test_expect_success 'Test headings lowering.' ' + sqlite3 aur.db <<-EOD && + INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (7, 1, " + # One + ## Two + ### Three + #### Four + ##### Five + ###### Six + ", ""); + EOD + "$RENDERCOMMENT" 7 && + cat <<-EOD >expected && +
One
+
Two
+
Three
+
Four
+
Five
+
Six
+ EOD + sqlite3 aur.db <<-EOD >actual && + SELECT RenderedComment FROM PackageComments WHERE ID = 7; + EOD + test_cmp actual expected +' + +test_done diff --git a/test/t2700-usermaint.sh b/test/t2700-usermaint.sh deleted file mode 100755 index 4f625142..00000000 --- a/test/t2700-usermaint.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -test_description='usermaint tests' - -. ./setup.sh - -test_expect_success 'Test removal of login IP addresses.' ' - now=$(date -d now +%s) && - threedaysago=$(date -d "3 days ago" +%s) && - tendaysago=$(date -d "10 days ago" +%s) && - cat <<-EOD | sqlite3 aur.db && - UPDATE Users SET LastLogin = $threedaysago, LastLoginIPAddress = "1.2.3.4" WHERE ID = 1; - UPDATE Users SET LastLogin = $tendaysago, LastLoginIPAddress = "2.3.4.5" WHERE ID = 2; - UPDATE Users SET LastLogin = $now, LastLoginIPAddress = "3.4.5.6" WHERE ID = 3; - UPDATE Users SET LastLogin = 0, LastLoginIPAddress = "4.5.6.7" WHERE ID = 4; - UPDATE Users SET LastLogin = 0, LastLoginIPAddress = "5.6.7.8" WHERE ID = 5; - UPDATE Users SET LastLogin = $tendaysago, LastLoginIPAddress = "6.7.8.9" WHERE ID = 6; - EOD - "$USERMAINT" && - cat <<-EOD >expected && - 1.2.3.4 - 3.4.5.6 - EOD - echo "SELECT LastLoginIPAddress FROM Users WHERE LastLoginIPAddress IS NOT NULL;" | sqlite3 aur.db >actual && - test_cmp actual expected -' - -test_expect_success 'Test removal of SSH login IP addresses.' ' - now=$(date -d now +%s) && - threedaysago=$(date -d "3 days ago" +%s) && - tendaysago=$(date -d "10 days ago" +%s) && - cat <<-EOD | sqlite3 aur.db && - UPDATE Users SET LastSSHLogin = $now, LastSSHLoginIPAddress = "1.2.3.4" WHERE ID = 1; - UPDATE Users SET LastSSHLogin = $threedaysago, LastSSHLoginIPAddress = "2.3.4.5" WHERE ID = 2; - UPDATE Users SET LastSSHLogin = $tendaysago, LastSSHLoginIPAddress = "3.4.5.6" WHERE ID = 3; - UPDATE Users SET LastSSHLogin = 0, LastSSHLoginIPAddress = "4.5.6.7" WHERE ID = 4; - UPDATE Users SET LastSSHLogin = 0, LastSSHLoginIPAddress = "5.6.7.8" WHERE ID = 5; - UPDATE Users SET LastSSHLogin = $tendaysago, LastSSHLoginIPAddress = "6.7.8.9" WHERE ID = 6; - EOD - "$USERMAINT" && - cat <<-EOD >expected && - 1.2.3.4 - 2.3.4.5 - EOD - echo "SELECT LastSSHLoginIPAddress FROM Users WHERE LastSSHLoginIPAddress IS NOT NULL;" | sqlite3 aur.db >actual && - test_cmp actual expected -' - -test_done diff --git a/test/t2700-usermaint.t b/test/t2700-usermaint.t new file mode 100755 index 00000000..4f625142 --- /dev/null +++ b/test/t2700-usermaint.t @@ -0,0 +1,49 @@ +#!/bin/sh + +test_description='usermaint tests' + +. ./setup.sh + +test_expect_success 'Test removal of login IP addresses.' ' + now=$(date -d now +%s) && + threedaysago=$(date -d "3 days ago" +%s) && + tendaysago=$(date -d "10 days ago" +%s) && + cat <<-EOD | sqlite3 aur.db && + UPDATE Users SET LastLogin = $threedaysago, LastLoginIPAddress = "1.2.3.4" WHERE ID = 1; + UPDATE Users SET LastLogin = $tendaysago, LastLoginIPAddress = "2.3.4.5" WHERE ID = 2; + UPDATE Users SET LastLogin = $now, LastLoginIPAddress = "3.4.5.6" WHERE ID = 3; + UPDATE Users SET LastLogin = 0, LastLoginIPAddress = "4.5.6.7" WHERE ID = 4; + UPDATE Users SET LastLogin = 0, LastLoginIPAddress = "5.6.7.8" WHERE ID = 5; + UPDATE Users SET LastLogin = $tendaysago, LastLoginIPAddress = "6.7.8.9" WHERE ID = 6; + EOD + "$USERMAINT" && + cat <<-EOD >expected && + 1.2.3.4 + 3.4.5.6 + EOD + echo "SELECT LastLoginIPAddress FROM Users WHERE LastLoginIPAddress IS NOT NULL;" | sqlite3 aur.db >actual && + test_cmp actual expected +' + +test_expect_success 'Test removal of SSH login IP addresses.' ' + now=$(date -d now +%s) && + threedaysago=$(date -d "3 days ago" +%s) && + tendaysago=$(date -d "10 days ago" +%s) && + cat <<-EOD | sqlite3 aur.db && + UPDATE Users SET LastSSHLogin = $now, LastSSHLoginIPAddress = "1.2.3.4" WHERE ID = 1; + UPDATE Users SET LastSSHLogin = $threedaysago, LastSSHLoginIPAddress = "2.3.4.5" WHERE ID = 2; + UPDATE Users SET LastSSHLogin = $tendaysago, LastSSHLoginIPAddress = "3.4.5.6" WHERE ID = 3; + UPDATE Users SET LastSSHLogin = 0, LastSSHLoginIPAddress = "4.5.6.7" WHERE ID = 4; + UPDATE Users SET LastSSHLogin = 0, LastSSHLoginIPAddress = "5.6.7.8" WHERE ID = 5; + UPDATE Users SET LastSSHLogin = $tendaysago, LastSSHLoginIPAddress = "6.7.8.9" WHERE ID = 6; + EOD + "$USERMAINT" && + cat <<-EOD >expected && + 1.2.3.4 + 2.3.4.5 + EOD + echo "SELECT LastSSHLoginIPAddress FROM Users WHERE LastSSHLoginIPAddress IS NOT NULL;" | sqlite3 aur.db >actual && + test_cmp actual expected +' + +test_done -- cgit v1.2.3-24-g4f1b