X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FTestMailManagement.java;h=bf73cd38c9c2cd8ef63e729b964977ce46eb0147;hp=6659a1e115cbacb5467aca7c3cbe8e75267ee8b0;hb=d23d7a6fa9dc38c6193fea70017e0bff11257be5;hpb=a1a980dd0cc65f33a6189eb81a164fe79abb647c diff --git a/tests/org/cacert/gigi/pages/account/TestMailManagement.java b/tests/org/cacert/gigi/pages/account/TestMailManagement.java index 6659a1e1..bf73cd38 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.dbObjects.EmailAddress; import org.cacert.gigi.dbObjects.ObjectCache; import org.cacert.gigi.dbObjects.User; -import org.cacert.gigi.localisation.Language; import org.cacert.gigi.pages.account.mail.MailOverview; import org.cacert.gigi.testUtils.ClientTest; import org.junit.Test; @@ -22,6 +21,7 @@ public class TestMailManagement extends ClientTest { private String path = MailOverview.DEFAULT_PATH; public TestMailManagement() throws IOException { + clearCaches(); // and reset rate limits cookie = login(u.getEmail(), TEST_PASSWORD); assertTrue(isLoggedin(cookie)); } @@ -32,9 +32,9 @@ public class TestMailManagement extends ClientTest { } @Test - public void testMailAddInternalFaulty() { + public void testMailAddInternalFaulty() throws GigiApiException { try { - new EmailAddress(u, "kurti "); + new EmailAddress(u, "kurti ", Locale.ENGLISH); fail(); } catch (IllegalArgumentException e) { // Intended. @@ -44,42 +44,61 @@ public class TestMailManagement extends ClientTest { @Test public void testMailAddWeb() throws MalformedURLException, UnsupportedEncodingException, IOException { String newMail = createUniqueName() + "uni@example.org"; - assertNull(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)) { - return; - } - } - fail(); + assertNull(addMail(newMail)); + assertTrue(existsEmail(newMail)); } @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)); + assertNotNull(addMail(newMail)); + assertFalse(existsEmail(newMail)); + } + + @Test + public void testMailAddWebMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException { + String u = createUniqueName(); + String newMail = u + "uni@eXample.org"; + assertNull(addMail(newMail)); + assertTrue(existsEmail(newMail.toLowerCase())); + + String newMail2 = u + "uni@eXamPlE.org"; + assertNotNull(addMail(newMail2)); + assertTrue(existsEmail(newMail2.toLowerCase())); + + String newMail3 = u + "-buni@eXamPlE.org"; + assertNull(addMail(newMail3)); + assertTrue(existsEmail(newMail.toLowerCase())); + assertTrue(existsEmail(newMail3.toLowerCase())); + } + + private String addMail(String newMail) throws IOException, MalformedURLException, UnsupportedEncodingException { + return executeBasicWebInteraction(cookie, path, "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"), 1); + } + + private boolean existsEmail(String newMail) { EmailAddress[] addrs = u.getEmails(); for (int i = 0; i < addrs.length; i++) { if (addrs[i].getAddress().equals(newMail)) { - fail(); + return true; } } + return false; } @Test public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException { - EmailAddress adrr = createVerifiedEmail(u); - assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId())); + EmailAddress addr = createVerifiedEmail(u); + assertNull(executeBasicWebInteraction(cookie, path, "default=" + addr.getId())); ObjectCache.clearAllCaches(); - assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress()); + assertEquals(User.getById(u.getId()).getEmail(), addr.getAddress()); } @Test public void testMailSetDefaultWebUnverified() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException { - EmailAddress adrr = new EmailAddress(u, createUniqueName() + "test@test.tld"); - adrr.insert(Language.getInstance(Locale.ENGLISH)); - assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId())); - assertNotEquals(User.getById(u.getId()).getEmail(), adrr.getAddress()); + EmailAddress addr = new EmailAddress(u, createUniqueName() + "test@test.tld", Locale.ENGLISH); + assertNotNull(executeBasicWebInteraction(cookie, path, "default=" + addr.getId())); + assertNotEquals(User.getById(u.getId()).getEmail(), addr.getAddress()); getMailReciever().clearMails(); } @@ -94,7 +113,7 @@ public class TestMailManagement extends ClientTest { } } assertNotEquals(id, -1); - assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + id)); + assertNotNull(executeBasicWebInteraction(cookie, path, "default=" + id)); assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail()); getMailReciever().clearMails(); } @@ -102,7 +121,7 @@ public class TestMailManagement extends ClientTest { @Test public void testMailDeleteWeb() throws InterruptedException, GigiApiException, MalformedURLException, UnsupportedEncodingException, IOException { EmailAddress addr = createVerifiedEmail(u); - assertNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + addr.getId(), 0)); + assertNull(executeBasicWebInteraction(cookie, path, "delete=" + addr.getId(), 0)); User u = User.getById(this.u.getId()); EmailAddress[] addresses = u.getEmails(); for (int i = 0; i < addresses.length; i++) { @@ -115,7 +134,8 @@ public class TestMailManagement extends ClientTest { EmailAddress[] addr = new EmailAddress[] { createVerifiedEmail(u), createVerifiedEmail(u) }; - assertNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + addr[0].getId() + "&delid[]=" + addr[1].getId(), 0)); + assertNull(executeBasicWebInteraction(cookie, path, "delete=" + addr[0].getId(), 0)); + assertNull(executeBasicWebInteraction(cookie, path, "delete=" + addr[1].getId(), 0)); User u = User.getById(this.u.getId()); EmailAddress[] addresses = u.getEmails(); for (int i = 0; i < addresses.length; i++) { @@ -128,14 +148,14 @@ public class TestMailManagement extends ClientTest { public void testMailDeleteWebFaulty() throws MalformedURLException, UnsupportedEncodingException, IOException { User u2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@test.tld", TEST_PASSWORD)); EmailAddress em = u2.getEmails()[0]; - assertNotNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + em.getId(), 0)); + assertNotNull(executeBasicWebInteraction(cookie, path, "delete=" + em.getId(), 0)); u2 = User.getById(u2.getId()); assertNotEquals(u2.getEmails().length, 0); } @Test public void testMailDeleteWebPrimary() throws MalformedURLException, UnsupportedEncodingException, IOException { - assertNotNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + u.getEmails()[0].getId(), 0)); + assertNotNull(executeBasicWebInteraction(cookie, path, "delete=" + u.getEmails()[0].getId(), 0)); assertNotEquals(u.getEmails().length, 0); } }