Signed-off-by: Lukas Fleischer <lfleisc...@archlinux.org>
---
 git-interface/test/setup.sh       |   4 +
 git-interface/test/t0002-serve.sh | 207 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+)

diff --git a/git-interface/test/setup.sh b/git-interface/test/setup.sh
index 7f3d45a..f9c1616 100644
--- a/git-interface/test/setup.sh
+++ b/git-interface/test/setup.sh
@@ -86,6 +86,10 @@ sed \
 
 echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(1, 'user', '!', 'user@localhost', 1);" | sqlite3 aur.db
 echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(2, 'tu', '!', 'tu@localhost', 2);" | sqlite3 aur.db
+echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(3, 'dev', '!', 'dev@localhost', 3);" | sqlite3 aur.db
+echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(4, 'user2', '!', 'user2@localhost', 1);" | sqlite3 aur.db
+echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(5, 'user3', '!', 'user3@localhost', 1);" | sqlite3 aur.db
+echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES 
(6, 'user4', '!', 'user4@localhost', 1);" | sqlite3 aur.db
 
 echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (1, 
'$AUTH_FINGERPRINT_USER', '$AUTH_KEYTYPE_USER $AUTH_KEYTEXT_USER');" | sqlite3 
aur.db
 echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (2, 
'$AUTH_FINGERPRINT_TU', '$AUTH_KEYTYPE_TU $AUTH_KEYTEXT_TU');" | sqlite3 aur.db
diff --git a/git-interface/test/t0002-serve.sh 
b/git-interface/test/t0002-serve.sh
index ce8340e..2f1926e 100755
--- a/git-interface/test/t0002-serve.sh
+++ b/git-interface/test/t0002-serve.sh
@@ -110,4 +110,211 @@ test_expect_success "Try to restore an existing package 
base." '
        test_must_fail "$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." '
+       SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
+       test_must_fail "$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 &&
+       SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
+       test_must_fail "$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 &&
+       SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
+       test_must_fail "$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." '
+       SSH_ORIGINAL_COMMAND="set-comaintainers foobar2 user2 user3 user4" \
+       AUR_USER=user AUR_PRIVILEGED=0 \
+       test_must_fail "$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_done
-- 
2.9.3

Reply via email to