1 package org.cacert.gigi;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.HttpURLConnection;
8 import java.security.GeneralSecurityException;
9 import java.security.KeyPair;
10 import java.security.PrivateKey;
11 import java.security.cert.X509Certificate;
12 import java.sql.SQLException;
14 import org.cacert.gigi.Certificate.CSRType;
15 import org.cacert.gigi.testUtils.ManagedTest;
16 import org.junit.Test;
18 public class TestSeparateSessionScope extends ManagedTest {
21 public void testSeparateScope() throws IOException, GeneralSecurityException, SQLException, InterruptedException {
22 String mail = "thisgo" + createUniqueName() + "@example.com";
23 int user = createAssuranceUser("test", "tugo", mail, TEST_PASSWORD);
24 String cookie = login(mail, TEST_PASSWORD);
25 KeyPair kp = generateKeypair();
26 String csr = generatePEMCSR(kp, "CN=felix@dogcraft.de");
27 Certificate c = new Certificate(user, "/CN=testmail@example.com", "sha256", csr, CSRType.CSR, CertificateProfile.getById(1));
28 final PrivateKey pk = kp.getPrivate();
29 c.issue().waitFor(60000);
30 final X509Certificate ce = c.cert();
31 String scookie = login(pk, ce);
33 assertTrue(isLoggedin(cookie));
34 assertFalse(isLoggedin(scookie));
36 URL u = new URL("https://" + getServerName().replaceAll("^www", "secure") + SECURE_REFERENCE);
37 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
38 authenticateClientCert(pk, ce, huc);
39 huc.setRequestProperty("Cookie", scookie);
40 assertEquals(200, huc.getResponseCode());
42 HttpURLConnection huc2 = (HttpURLConnection) u.openConnection();
43 authenticateClientCert(pk, ce, huc2);
44 huc2.setRequestProperty("Cookie", cookie);
45 assertEquals(302, huc2.getResponseCode());