]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/LoginTest.java
Merge branch 'libs/jetty/upstream' into libs/jetty/local
[gigi.git] / tests / org / cacert / gigi / LoginTest.java
1 package org.cacert.gigi;
2
3 import java.io.IOException;
4 import static org.junit.Assert.*;
5 import java.io.OutputStream;
6 import java.net.HttpURLConnection;
7 import java.net.URL;
8 import java.net.URLEncoder;
9
10 import org.cacert.gigi.testUtils.ManagedTest;
11 import org.junit.Test;
12
13 public class LoginTest extends ManagedTest {
14         public static final String secureReference = "/account/certs/email";
15         @Test
16         public void testLoginUnverified() throws IOException {
17                 long uniq = System.currentTimeMillis();
18                 String email = "system" + uniq + "@testmail.org";
19                 String pw = "1'aAaA";
20                 registerUser("an", "bn", email, pw);
21                 waitForMail();
22                 assertFalse(isLoggedin(login(email, pw)));
23         }
24         @Test
25         public void testLoginVerified() throws IOException {
26                 long uniq = System.currentTimeMillis();
27                 String email = "system2" + uniq + "@testmail.org";
28                 String pw = "1'aAaA";
29                 createVerifiedUser("an", "bn", email, pw);
30                 assertTrue(isLoggedin(login(email, pw)));
31         }
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;
37         }
38
39 }