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.dbObjects.Certificate;
15 import org.cacert.gigi.dbObjects.CertificateProfile;
16 import org.cacert.gigi.dbObjects.Certificate.CSRType;
17 import org.cacert.gigi.testUtils.ManagedTest;
18 import org.junit.Test;
20 public class TestSeparateSessionScope extends ManagedTest {
23 public void testSeparateScope() throws IOException, GeneralSecurityException, SQLException, InterruptedException, GigiApiException {
24 String mail = "thisgo" + createUniqueName() + "@example.com";
25 int user = createAssuranceUser("test", "tugo", mail, TEST_PASSWORD);
26 String cookie = login(mail, TEST_PASSWORD);
27 KeyPair kp = generateKeypair();
28 String csr = generatePEMCSR(kp, "CN=felix@dogcraft.de");
29 Certificate c = new Certificate(user, "/CN=testmail@example.com", "sha256", csr, CSRType.CSR, CertificateProfile.getById(1));
30 final PrivateKey pk = kp.getPrivate();
31 c.issue(null, "2y").waitFor(60000);
32 final X509Certificate ce = c.cert();
33 String scookie = login(pk, ce);
35 assertTrue(isLoggedin(cookie));
36 assertFalse(isLoggedin(scookie));
38 URL u = new URL("https://" + getServerName().replaceAll("^www", "secure") + SECURE_REFERENCE);
39 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
40 authenticateClientCert(pk, ce, huc);
41 huc.setRequestProperty("Cookie", scookie);
42 assertEquals(200, huc.getResponseCode());
44 HttpURLConnection huc2 = (HttpURLConnection) u.openConnection();
45 authenticateClientCert(pk, ce, huc2);
46 huc2.setRequestProperty("Cookie", cookie);
47 assertEquals(302, huc2.getResponseCode());