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";
16 public void testLoginUnverified() throws IOException {
17 long uniq = System.currentTimeMillis();
18 String email = "system" + uniq + "@testmail.org";
20 registerUser("an", "bn", email, pw);
22 assertFalse(isLoggedin(login(email, pw)));
25 public void testLoginVerified() throws IOException {
26 long uniq = System.currentTimeMillis();
27 String email = "system2" + uniq + "@testmail.org";
29 createVerifiedUser("an", "bn", email, pw);
30 assertTrue(isLoggedin(login(email, pw)));
32 public boolean isLoggedin(String cookie) throws IOException {
33 URL u = new URL("https://" + getServerName() + secureReference);
34 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
35 huc.addRequestProperty("Cookie", cookie);
36 return huc.getResponseCode() == 200;