X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FLoginTest.java;h=f02f0ad04239a7fd66279c7a23b07f6396fe4ee0;hb=e545cb295b12e3ecb0d777b2f2b6a601c9b27387;hp=940664fa79052cf1ea60d055b0d8dfef196cf0f7;hpb=943d8e7ed0ea5a9d56e7e694a3cbd849c52bad16;p=gigi.git diff --git a/tests/org/cacert/gigi/LoginTest.java b/tests/org/cacert/gigi/LoginTest.java index 940664fa..f02f0ad0 100644 --- a/tests/org/cacert/gigi/LoginTest.java +++ b/tests/org/cacert/gigi/LoginTest.java @@ -1,7 +1,10 @@ package org.cacert.gigi; -import java.io.IOException; import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.URL; + import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; @@ -9,19 +12,38 @@ 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 { + cookie(new URL("https://" + getServerName() + "/logout").openConnection(), cookie).getHeaderField("Location"); + } + }