]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/LoginTest.java
Merge "Suggestions to enhance the SQL call pattern."
[gigi.git] / tests / org / cacert / gigi / LoginTest.java
index 940664fa79052cf1ea60d055b0d8dfef196cf0f7..cb575caf78190d3fb97bf33e0326beb242af57b6 100644 (file)
@@ -1,7 +1,12 @@
 package org.cacert.gigi;
 
-import java.io.IOException;
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URLConnection;
+
+import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
 
@@ -9,19 +14,48 @@ public class LoginTest extends ManagedTest {
 
     @Test
     public void testLoginUnverified() throws IOException {
-        long uniq = System.currentTimeMillis();
-        String email = "system" + uniq + "@testmail.org";
+        String email = createUniqueName() + "@testmail.org";
         registerUser("an", "bn", email, TEST_PASSWORD);
-        waitForMail();
+        getMailReciever().receive();
         assertFalse(isLoggedin(login(email, TEST_PASSWORD)));
     }
 
     @Test
     public void testLoginVerified() throws IOException {
-        long uniq = System.currentTimeMillis();
-        String email = "system2" + uniq + "@testmail.org";
+        String email = createUniqueName() + "@testmail.org";
         createVerifiedUser("an", "bn", email, TEST_PASSWORD);
         assertTrue(isLoggedin(login(email, TEST_PASSWORD)));
     }
 
+    @Test
+    public void testLoginWrongPassword() throws IOException {
+        String email = createUniqueName() + "@testmail.org";
+        createVerifiedUser("an", "bn", email, TEST_PASSWORD);
+        assertFalse(isLoggedin(login(email, TEST_PASSWORD + "b")));
+    }
+
+    @Test
+    public void testLogoutVerified() throws IOException {
+        String email = createUniqueName() + "@testmail.org";
+        createVerifiedUser("an", "bn", email, TEST_PASSWORD);
+        String cookie = login(email, TEST_PASSWORD);
+        assertTrue(isLoggedin(cookie));
+        logout(cookie);
+        assertFalse(isLoggedin(cookie));
+    }
+
+    private void logout(String cookie) throws IOException {
+        get(cookie, "/logout").getHeaderField("Location");
+    }
+
+    @Test
+    public void testLoginMethodDisplay() throws IOException {
+        String email = createUniqueName() + "@testmail.org";
+        createVerifiedUser("an", "bn", email, TEST_PASSWORD);
+        String l = login(email, TEST_PASSWORD);
+        URLConnection c = get(l, "");
+        String readURL = IOUtils.readURL(c);
+        assertThat(readURL, containsString("Password"));
+    }
+
 }