summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2017-01-25 18:27:06 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2017-01-25 18:42:34 +0100
commit33095b3292bdb2fa5561bf257c86004eeddcfae9 (patch)
treea15f2ce4bad1cdd98b35c9ae32053db1d62bd3ec
parent0e34dd6542afecc0890f77fbcb497fb5d8690d5b (diff)
downloadaur-33095b3292bdb2fa5561bf257c86004eeddcfae9.tar.gz
aur-33095b3292bdb2fa5561bf257c86004eeddcfae9.tar.xz
t1200: Test IP address log and bans
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rw-r--r--test/setup.sh8
-rwxr-xr-xtest/t1200-git-serve.sh21
2 files changed, 29 insertions, 0 deletions
diff --git a/test/setup.sh b/test/setup.sh
index 26873e8d..2959a4e6 100644
--- a/test/setup.sh
+++ b/test/setup.sh
@@ -98,6 +98,12 @@ AUTH_KEYTYPE_MISSING=sha-rsa
AUTH_KEYTEXT_MISSING=AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UTpssBunuTBCT3KFtv+yb+cN0VmI2C9O9U7wHlkEZWxNBK8is6tnDHXBxRuvRk0LHILkTidLLFX22ZF0+TFgSz7uuEvGZVNpa2Fn2+vKJJYMvZEvb/f8VHF5/Jddt21VOyu23royTN/duiT7WIZdCtEmq5C9Y43NPfsB8FbUc+FVSYT2Lq7g1/bzvFF+CZxwCrGjC3qC7p3pshICfFR8bbWgRN33ClxIQ7MvkcDtfNu38dLotJqdfEa7NdQgba5/S586f1A4OWKc/mQJFyTaGhRBxw/cBSjqonvO0442VYLHFxlrTHoUunKyOJ8+BJfKgjWmfENC9ESY3mL/IEn5
AUTH_FINGERPRINT_MISSING=SHA256:uB0B+30r2WA1TDMUmFcaEBjosjnFGzn33XFhiyvTL9w
+# Setup fake SSH environment.
+SSH_CLIENT='1.2.3.4 1234 22'
+SSH_CONNECTION='1.2.3.4 1234 4.3.2.1 22'
+SSH_TTY=/dev/pts/0
+export SSH_CLIENT SSH_CONNECTION SSH_TTY
+
# Initialize the test database.
rm -f aur.db
sed \
@@ -122,6 +128,8 @@ echo "INSERT INTO Users (ID, UserName, Passwd, Email, AccountTypeID) VALUES (9,
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
+echo "INSERT INTO Bans (IPAddress, BanTS) VALUES ('1.3.3.7', 0);" | sqlite3 aur.db
+
echo "INSERT INTO PackageBlacklist (Name) VALUES ('forbidden');" | sqlite3 aur.db
echo "INSERT INTO OfficialProviders (Name, Repo, Provides) VALUES ('official', 'core', 'official');" | sqlite3 aur.db
diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh
index f986b625..07383aff 100755
--- a/test/t1200-git-serve.sh
+++ b/test/t1200-git-serve.sh
@@ -31,6 +31,27 @@ test_expect_success 'Test maintenance mode.' '
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" &&
+ SSH_ORIGINAL_COMMAND=help test_must_fail "$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 &&