X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FLoginTest.java;h=ed1c932af6e9c4676e64c74c6c50debe42bacd9e;hp=3097062365111722586fc401c94dbc8926ec7343;hb=f4fa4314692900e57a074d9f65a558e136dadb44;hpb=53d9194f480a4351e6b80551fc2aa537e7d5b039 diff --git a/tests/org/cacert/gigi/LoginTest.java b/tests/org/cacert/gigi/LoginTest.java index 30970623..ed1c932a 100644 --- a/tests/org/cacert/gigi/LoginTest.java +++ b/tests/org/cacert/gigi/LoginTest.java @@ -4,8 +4,19 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; 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; +import java.security.cert.X509Certificate; +import org.cacert.gigi.dbObjects.Certificate; +import org.cacert.gigi.dbObjects.Certificate.CSRType; +import org.cacert.gigi.dbObjects.Digest; +import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.testUtils.IOUtils; import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; @@ -27,6 +38,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() + SECURE_REFERENCE, huc.getHeaderField("Location")); + } + @Test public void testLoginWrongPassword() throws IOException { String email = createUniqueName() + "@testmail.org"; @@ -58,4 +86,23 @@ public class LoginTest extends ManagedTest { assertThat(readURL, containsString("Password")); } + @Test + public void testLoginCertificate() throws IOException, GeneralSecurityException, GigiApiException, InterruptedException { + String email = createUniqueName() + "@testmail.org"; + int user = createVerifiedUser("an", "bn", email, TEST_PASSWORD); + KeyPair kp = generateKeypair(); + String csr = generatePEMCSR(kp, "CN=hans"); + User u = User.getById(user); + Certificate c = new Certificate(u, u, Certificate.buildDN("CN", "hans"), Digest.SHA256, csr, CSRType.CSR, getClientProfile()); + final PrivateKey pk = kp.getPrivate(); + await(c.issue(null, "2y", u)); + final X509Certificate ce = c.cert(); + c.setLoginEnabled(true); + String cookie = login(pk, ce); + URL u2 = new URL("https://" + getSecureServerName() + SECURE_REFERENCE); + HttpURLConnection huc = (HttpURLConnection) u2.openConnection(); + huc.addRequestProperty("Cookie", cookie); + authenticateClientCert(pk, ce, huc); + assertEquals(200, huc.getResponseCode()); + } }