1 package org.cacert.gigi;
3 import java.io.IOException;
4 import static org.junit.Assert.*;
5 import java.io.OutputStream;
6 import java.net.HttpURLConnection;
8 import java.net.URLEncoder;
10 import org.cacert.gigi.testUtils.ManagedTest;
11 import org.junit.Test;
13 public class LoginTest extends ManagedTest {
14 public static final String secureReference = "/account/certs/email";
17 public void testLoginUnverified() throws IOException {
18 long uniq = System.currentTimeMillis();
19 String email = "system" + uniq + "@testmail.org";
21 registerUser("an", "bn", email, pw);
23 assertFalse(isLoggedin(login(email, pw)));
27 public void testLoginVerified() throws IOException {
28 long uniq = System.currentTimeMillis();
29 String email = "system2" + uniq + "@testmail.org";
31 createVerifiedUser("an", "bn", email, pw);
32 assertTrue(isLoggedin(login(email, pw)));
35 public boolean isLoggedin(String cookie) throws IOException {
36 URL u = new URL("https://" + getServerName() + secureReference);
37 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
38 huc.addRequestProperty("Cookie", cookie);
39 return huc.getResponseCode() == 200;