From 485345c765f3c66751d4aad8d5c935e3cbf58cf1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Thu, 15 Sep 2016 20:34:49 +0200 Subject: [PATCH] add: test redirect after login Change-Id: I3caf0a1641a1673e13d68a5c8b9ec4885729811b --- tests/org/cacert/gigi/LoginTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/org/cacert/gigi/LoginTest.java b/tests/org/cacert/gigi/LoginTest.java index c0ff71a4..86e3d7b7 100644 --- a/tests/org/cacert/gigi/LoginTest.java +++ b/tests/org/cacert/gigi/LoginTest.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.net.URLEncoder; import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.PrivateKey; @@ -38,6 +39,23 @@ public class LoginTest extends ManagedTest { assertTrue(isLoggedin(login(email, TEST_PASSWORD))); } + @Test + public void testLoginRedirectBack() throws IOException { + String email = createUniqueName() + "@testmail.org"; + createVerifiedUser("an", "bn", email, TEST_PASSWORD); + + URL u0 = new URL("https://" + getServerName() + SECURE_REFERENCE); + HttpURLConnection huc0 = (HttpURLConnection) u0.openConnection(); + String headerField = stripCookie(huc0.getHeaderField("Set-Cookie")); + + HttpURLConnection huc = post(headerField, "/login", "username=" + URLEncoder.encode(email, "UTF-8") + "&password=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8"), 0); + + headerField = huc.getHeaderField("Set-Cookie"); + assertNotNull(headerField); + assertEquals(302, huc.getResponseCode()); + assertEquals("https://" + getServerName().replaceFirst(":443$", "") + SECURE_REFERENCE, huc.getHeaderField("Location")); + } + @Test public void testLoginWrongPassword() throws IOException { String email = createUniqueName() + "@testmail.org"; -- 2.39.2