]> WPIA git - gigi.git/commitdiff
add: test redirect after login
authorFelix Dörre <felix@dogcraft.de>
Thu, 15 Sep 2016 18:34:49 +0000 (20:34 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 15 Sep 2016 18:34:49 +0000 (20:34 +0200)
Change-Id: I3caf0a1641a1673e13d68a5c8b9ec4885729811b

tests/org/cacert/gigi/LoginTest.java

index c0ff71a4a65a6b0ba4c9aa2588edd305304ec2f0..86e3d7b7e53314a10e9b51c4513400bc4666a304 100644 (file)
@@ -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";