]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/LoginTest.java
[EMPTY] Formatting with configured formatter.
[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
16         @Test
17         public void testLoginUnverified() throws IOException {
18                 long uniq = System.currentTimeMillis();
19                 String email = "system" + uniq + "@testmail.org";
20                 String pw = "1'aAaA";
21                 registerUser("an", "bn", email, pw);
22                 waitForMail();
23                 assertFalse(isLoggedin(login(email, pw)));
24         }
25
26         @Test
27         public void testLoginVerified() throws IOException {
28                 long uniq = System.currentTimeMillis();
29                 String email = "system2" + uniq + "@testmail.org";
30                 String pw = "1'aAaA";
31                 createVerifiedUser("an", "bn", email, pw);
32                 assertTrue(isLoggedin(login(email, pw)));
33         }
34
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;
40         }
41
42 }