X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FTestMailManagement.java;h=119d4bc62216e93a626f7c03c4d150c497a70250;hb=d4289da087838c89a8b5866c8194f91d5d4a6836;hp=e915278d4c4aa0395c1b15f97a9ca40d83a9bc9a;hpb=5bd6a18184e2becd7f5776c09d893efca9a44c13;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/account/TestMailManagement.java b/tests/org/cacert/gigi/pages/account/TestMailManagement.java index e915278d..119d4bc6 100644 --- a/tests/org/cacert/gigi/pages/account/TestMailManagement.java +++ b/tests/org/cacert/gigi/pages/account/TestMailManagement.java @@ -12,7 +12,6 @@ import org.cacert.gigi.GigiApiException; import org.cacert.gigi.Language; import org.cacert.gigi.User; import org.cacert.gigi.testUtils.ManagedTest; -import org.cacert.gigi.testUtils.TestEmailReciever.TestMail; import org.junit.Test; public class TestMailManagement extends ManagedTest { @@ -28,19 +27,17 @@ public class TestMailManagement extends ManagedTest { @Test public void testMailAddInternal() throws InterruptedException, GigiApiException { - EmailAddress adrr = new EmailAddress("test@test.tld", u); - adrr.insert(Language.getInstance("en")); - TestMail testMail = getMailReciever().recieve(); - assertTrue(adrr.getAddress().equals(testMail.getTo())); - String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1); - adrr.verify(hash); + createVerifiedEmail(u); + } + + @Test + public void testMailAddInternalFaulty() { try { new EmailAddress("kurti ", u); + fail(); } catch (IllegalArgumentException e) { // Intended. - return; } - fail(); } @Test @@ -57,4 +54,52 @@ public class TestMailManagement extends ManagedTest { fail(); } + @Test + public void testMailAddWebFaulty() throws MalformedURLException, UnsupportedEncodingException, IOException { + String newMail = createUniqueName() + "uniexample.org"; + assertNotNull(executeBasicWebInteraction(cookie, path, + "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"), 1)); + EmailAddress[] addrs = u.getEmails(); + for (int i = 0; i < addrs.length; i++) { + if (addrs[i].getAddress().equals(newMail)) { + fail(); + } + } + } + + @Test + public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException, + InterruptedException, GigiApiException { + EmailAddress adrr = createVerifiedEmail(u); + assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId())); + assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress()); + } + + @Test + public void testMailSetDefaultWebUnverified() throws MalformedURLException, UnsupportedEncodingException, + IOException, InterruptedException, GigiApiException { + EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u); + adrr.insert(Language.getInstance("en")); + assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId())); + assertNotEquals(User.getById(u.getId()).getEmail(), adrr.getAddress()); + getMailReciever().clearMails(); + } + + @Test + public void testMailSetDefaultWebInvalidID() throws MalformedURLException, UnsupportedEncodingException, + IOException, InterruptedException, GigiApiException { + User u2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD)); + int id = -1; + EmailAddress[] emails = u2.getEmails(); + for (int i = 0; i < emails.length; i++) { + if (emails[i].getAddress().equals(u2.getEmail())) { + id = emails[i].getId(); + } + } + assertNotEquals(id, -1); + assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + id)); + assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail()); + getMailReciever().clearMails(); + } + }