upd: enforce that test cases receive all mails explicitly
authorFelix Dörre <felix@dogcraft.de>
Sat, 28 Oct 2017 06:44:39 +0000 (08:44 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 31 Oct 2017 17:34:16 +0000 (18:34 +0100)
Change-Id: I7a9335f13b125d473f6f12bd05d3f2da6d535785

24 files changed:
src/club/wpia/gigi/ping/PingerDaemon.java
tests/club/wpia/gigi/LoginTest.java
tests/club/wpia/gigi/TestUser.java
tests/club/wpia/gigi/api/TestFindAgent.java
tests/club/wpia/gigi/dbObjects/TestVerificationMail.java
tests/club/wpia/gigi/pages/TestVerify.java
tests/club/wpia/gigi/pages/account/TestMailManagement.java
tests/club/wpia/gigi/pages/account/TestPasswordResetExternal.java
tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java
tests/club/wpia/gigi/pages/admin/TestSEAdminPageCertSearch.java
tests/club/wpia/gigi/pages/admin/TestSEAdminPageDetails.java
tests/club/wpia/gigi/pages/main/KeyCompromiseTest.java
tests/club/wpia/gigi/pages/main/KeyCompromiseTestMessage.java
tests/club/wpia/gigi/pages/main/RegisterPageTest.java
tests/club/wpia/gigi/pages/wot/TestVerification.java
tests/club/wpia/gigi/ping/TestDNS.java
tests/club/wpia/gigi/ping/TestHTTP.java
tests/club/wpia/gigi/ping/TestSSL.java
tests/club/wpia/gigi/template/TestTemplateMail.java
tests/club/wpia/gigi/testUtils/BusinessTest.java
tests/club/wpia/gigi/testUtils/ConfiguredTest.java
tests/club/wpia/gigi/testUtils/MailReceiver.java
tests/club/wpia/gigi/testUtils/ManagedTest.java
tests/club/wpia/gigi/testUtils/TestEmailReceiver.java

index 51cc985..d6016c6 100644 (file)
@@ -12,7 +12,6 @@ import club.wpia.gigi.database.GigiResultSet;
 import club.wpia.gigi.dbObjects.Domain;
 import club.wpia.gigi.dbObjects.DomainPingConfiguration;
 import club.wpia.gigi.dbObjects.DomainPingType;
-import club.wpia.gigi.util.RandomToken;
 
 public class PingerDaemon extends Thread {
 
@@ -91,11 +90,6 @@ public class PingerDaemon extends Thread {
         String config = conf.getInfo();
         DomainPinger dp = pingers.get(type);
         if (dp != null) {
-            if (dp instanceof EmailPinger) {
-                String token = null;
-                token = RandomToken.generateToken(16);
-                config = config + ":" + token;
-            }
             Domain target = conf.getTarget();
             System.err.println("Executing " + dp + " on " + target + " (" + System.currentTimeMillis() + ")");
             try {
index ab2780c..551d88d 100644 (file)
@@ -28,7 +28,7 @@ public class LoginTest extends ManagedTest {
     public void testLoginUnverified() throws IOException {
         String email = createUniqueName() + "@testmail.org";
         registerUser("an", "bn", email, TEST_PASSWORD);
-        getMailReceiver().receive();
+        getMailReceiver().receive(email);
         assertFalse(isLoggedin(login(email, TEST_PASSWORD)));
     }
 
index 7ad3f49..a2206ee 100644 (file)
@@ -10,8 +10,6 @@ import java.util.Locale;
 import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
-import club.wpia.gigi.dbObjects.Verification;
-import club.wpia.gigi.dbObjects.Verification.VerificationType;
 import club.wpia.gigi.dbObjects.Country;
 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
 import club.wpia.gigi.dbObjects.Domain;
@@ -20,6 +18,8 @@ import club.wpia.gigi.dbObjects.Name;
 import club.wpia.gigi.dbObjects.NamePart;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
 import club.wpia.gigi.dbObjects.User;
+import club.wpia.gigi.dbObjects.Verification;
+import club.wpia.gigi.dbObjects.Verification.VerificationType;
 import club.wpia.gigi.testUtils.BusinessTest;
 import club.wpia.gigi.util.DayDate;
 import club.wpia.gigi.util.Notary;
@@ -90,9 +90,9 @@ public class TestUser extends BusinessTest {
         User u = User.getById(id);
 
         new EmailAddress(u, uq + "b@email.org", Locale.ENGLISH);
-        getMailReceiver().receive().verify();
+        getMailReceiver().receive(uq + "b@email.org").verify();
         new EmailAddress(u, uq + "c@email.org", Locale.ENGLISH);
-        getMailReceiver().receive();// no-verify
+        getMailReceiver().receive(uq + "c@email.org");// no-verify
         assertEquals(3, u.getEmails().length);
 
         assertTrue(u.isValidEmail(uq + "a@email.org"));
index b1bec53..753eb77 100644 (file)
@@ -15,14 +15,13 @@ import org.json.JSONTokener;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
-import club.wpia.gigi.api.FindAgent;
 import club.wpia.gigi.dbObjects.Certificate;
+import club.wpia.gigi.dbObjects.Certificate.CSRType;
+import club.wpia.gigi.dbObjects.Certificate.SANType;
 import club.wpia.gigi.dbObjects.CertificateProfile;
 import club.wpia.gigi.dbObjects.Digest;
 import club.wpia.gigi.dbObjects.Group;
 import club.wpia.gigi.dbObjects.User;
-import club.wpia.gigi.dbObjects.Certificate.CSRType;
-import club.wpia.gigi.dbObjects.Certificate.SANType;
 import club.wpia.gigi.pages.account.FindAgentAccess;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.RestrictedApiTest;
@@ -73,10 +72,9 @@ public class TestFindAgent extends RestrictedApiTest {
         grant((userUFirst ? us2 : u), Group.LOCATE_AGENT);
         v = doApi(FindAgent.PATH_MAIL, "from=" + id + "&to=" + u2 + "&subject=the-subject&body=body");
         assertEquals(v.getResponseMessage(), 200, v.getResponseCode());
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive(us2.getEmail());
         assertEquals("body", mail.getMessage());
         assertThat(mail.getSubject(), containsString("the-subject"));
-        assertEquals(us2.getEmail(), mail.getTo());
     }
 
     @Test
index 43efda4..f9e43c7 100644 (file)
@@ -9,13 +9,9 @@ import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.database.GigiPreparedStatement;
-import club.wpia.gigi.dbObjects.Country;
-import club.wpia.gigi.dbObjects.Name;
-import club.wpia.gigi.dbObjects.NamePart;
-import club.wpia.gigi.dbObjects.User;
-import club.wpia.gigi.dbObjects.Verification.VerificationType;
 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
+import club.wpia.gigi.dbObjects.Verification.VerificationType;
 import club.wpia.gigi.testUtils.BusinessTest;
 import club.wpia.gigi.util.DayDate;
 import club.wpia.gigi.util.Notary;
@@ -83,7 +79,7 @@ public class TestVerificationMail extends BusinessTest {
 
         // verify preferred name only
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
 
@@ -91,7 +87,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
         assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
@@ -100,7 +96,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
         assertThat(message, containsString("James Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
@@ -110,7 +106,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
 
@@ -118,7 +114,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
         assertThat(message, containsString("James Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
@@ -129,7 +125,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 60 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
@@ -140,7 +136,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 70 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
@@ -151,7 +147,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 80 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
@@ -162,7 +158,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 90 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 70 Verification Points."));
@@ -173,7 +169,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 100 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 80 Verification Points."));
@@ -184,7 +180,7 @@ public class TestVerificationMail extends BusinessTest {
         newAgent();
 
         enterVerification(firstName, secondName, thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 110 Verification Points."));
         assertThat(message, containsString("James Doe: with 10 to total 90 Verification Points."));
@@ -206,24 +202,24 @@ public class TestVerificationMail extends BusinessTest {
         // verify preferred name only 5 times
         newAgent();
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(firstName);
 
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
         assertThat(message, containsString(requiresMoreTotal(50)));
@@ -231,7 +227,7 @@ public class TestVerificationMail extends BusinessTest {
         // verify preferred name second name
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
         assertThat(message, containsString(requiresMoreTotal(40)));
@@ -239,19 +235,19 @@ public class TestVerificationMail extends BusinessTest {
         // verify preferred name second name 4 more times
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
 
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
         assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
@@ -259,14 +255,14 @@ public class TestVerificationMail extends BusinessTest {
         // get more than 100 VP in total
         newAgent();
         enterVerification(secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
 
         // verify third name
         newAgent();
         enterVerification(thirdName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
 
@@ -300,7 +296,7 @@ public class TestVerificationMail extends BusinessTest {
 
         // add second Verification result first name 50 VP
         enterVerification(15, firstName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
         assertThat(message, containsString(requiresMoreTotal(50)));
@@ -326,10 +322,14 @@ public class TestVerificationMail extends BusinessTest {
 
         // add second Verification result first name 100 VP, second name 50 VP
         enterVerification(15, firstName, secondName);
-        message = getMailReceiver().receive().getMessage();
+        message = applicantMail();
         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
         assertThat(message, containsString("John Doe: with 15 to total 100 Verification Points."));
         assertThat(message, containsString("James Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
         assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
     }
+
+    private String applicantMail() {
+        return getMailReceiver().receive(applicant.getEmail()).getMessage();
+    }
 }
index d1b799b..34723f9 100644 (file)
@@ -19,7 +19,7 @@ public class TestVerify extends ClientBusinessTest {
     @Test
     public void testVerify() throws GigiApiException {
         EmailAddress ea = new EmailAddress(u, "test@example.com", Locale.ENGLISH);
-        TestMail tm = getMailReceiver().receive();
+        TestMail tm = getMailReceiver().receive(ea.getAddress());
         Pattern p = Pattern.compile(".*hash=(.*)");
         Matcher m = p.matcher(tm.extractLink());
         assertTrue(m.matches());
index 84ad60d..1a42d20 100644 (file)
@@ -47,6 +47,7 @@ public class TestMailManagement extends ClientTest {
         String newMail = createUniqueName() + "uni@example.org";
         assertNull(addMail(newMail));
         assertTrue(existsEmail(newMail));
+        getMailReceiver().receive(newMail);
     }
 
     @Test
@@ -62,6 +63,7 @@ public class TestMailManagement extends ClientTest {
         String newMail = u + "uni@eXample.org";
         assertNull(addMail(newMail));
         assertTrue(existsEmail(newMail.toLowerCase()));
+        getMailReceiver().receive(newMail.toLowerCase());
 
         String newMail2 = u + "uni@eXamPlE.org";
         assertNotNull(addMail(newMail2));
@@ -71,6 +73,7 @@ public class TestMailManagement extends ClientTest {
         assertNull(addMail(newMail3));
         assertTrue(existsEmail(newMail.toLowerCase()));
         assertTrue(existsEmail(newMail3.toLowerCase()));
+        getMailReceiver().receive(newMail3.toLowerCase());
     }
 
     private String addMail(String newMail) throws IOException, MalformedURLException, UnsupportedEncodingException {
@@ -100,7 +103,7 @@ public class TestMailManagement extends ClientTest {
         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());
-        getMailReceiver().clearMails();
+        getMailReceiver().receive(addr.getAddress());
     }
 
     @Test
@@ -116,7 +119,7 @@ public class TestMailManagement extends ClientTest {
         assertNotEquals(id, -1);
         assertNotNull(executeBasicWebInteraction(cookie, path, "default=" + id));
         assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail());
-        getMailReceiver().clearMails();
+        getMailReceiver().assertEmpty();
     }
 
     @Test
index 35c482d..1efc5f7 100644 (file)
@@ -35,10 +35,9 @@ public class TestPasswordResetExternal extends ClientTest {
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         assertNull(error);
 
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive(this.u.getEmail());
         assertThat(mail.getSubject(), containsString("Verification"));
-        mail = getMailReceiver().receive();
-        assertEquals(mail.getTo(), this.u.getEmail());
+        mail = getMailReceiver().receive(this.u.getEmail());
         String link = mail.extractLink();
         String npw = TEST_PASSWORD + "'";
         System.out.println(link);
index 8a439a3..9bcaa82 100644 (file)
@@ -27,15 +27,17 @@ public class TestSEAdminNotificationMail extends ClientTest {
 
     private int targetID;
 
+    private String targetEmail;
+
     public TestSEAdminNotificationMail() throws IOException, GigiApiException {
         grant(u, Group.SUPPORTER);
         cookie = login(email, TEST_PASSWORD);
         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
 
-        String email = createUniqueName() + "@example.com";
+        targetEmail = createUniqueName() + "@example.com";
         String fname = "Först";
         String lname = "Secönd";
-        targetID = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
+        targetID = createVerifiedUser(fname, lname, targetEmail, TEST_PASSWORD);
     }
 
     @Test
@@ -44,22 +46,19 @@ public class TestSEAdminNotificationMail extends ClientTest {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0);
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("The DoB was changed"));
         assertThat(message, containsString("supporter " + u.getPreferredName().toString() + " triggered:"));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("The DoB in your account was changed to 2000-02-01."));
     }
 
     @Test
     public void testPasswordReset() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "aword=SecretWord&resetPass", 0);
-        TestMail tm;
-        String targetMail = ServerConstants.getSupportMailAddress();
-        do {
-            tm = getMailReceiver().receive();
-        } while ( !tm.getTo().equals(targetMail));
+        getMailReceiver().receive(targetEmail);
+        TestMail tm = getMailReceiver().receive(ServerConstants.getSupportMailAddress());
         assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
     }
 
@@ -72,10 +71,10 @@ public class TestSEAdminNotificationMail extends ClientTest {
         Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
     }
 
@@ -88,10 +87,10 @@ public class TestSEAdminNotificationMail extends ClientTest {
         Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
     }
 
@@ -105,13 +104,13 @@ public class TestSEAdminNotificationMail extends ClientTest {
         User target = User.getById(targetID);
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
         // mail to board
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(ServerConstants.getBoardMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted for '" + target.getPreferredName().toString() + "'."));
     }
 
@@ -125,13 +124,13 @@ public class TestSEAdminNotificationMail extends ClientTest {
         User target = User.getById(targetID);
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
         // mail to board
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(ServerConstants.getBoardMailAddress()).getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + target.getPreferredName().toString() + "'."));
     }
 
@@ -141,10 +140,10 @@ public class TestSEAdminNotificationMail extends ClientTest {
         User user = User.getById(targetID);
 
         // mail to support
-        String message = getMailReceiver().receive().getMessage();
+        String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
         assertThat(message, containsString("All certificates in the account " + user.getPreferredName().toString()));
         // mail to user
-        message = getMailReceiver().receive().getMessage();
+        message = getMailReceiver().receive(targetEmail).getMessage();
         assertThat(message, containsString("All certificates in your account have been revoked."));
     }
 }
index dd7d197..e61f559 100644 (file)
@@ -39,7 +39,7 @@ public class TestSEAdminPageCertSearch extends ClientTest {
         cookie = login(email, TEST_PASSWORD);
         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
 
-        certMail = uniq + "_certOwner@example.com";
+        certMail = uniq + "_certowner@example.com";
         int id = createVerifiedUser("fn", "ln", certMail, TEST_PASSWORD);
         User u1 = User.getById(id);
         KeyPair kp = generateKeypair();
@@ -73,22 +73,11 @@ public class TestSEAdminPageCertSearch extends ClientTest {
     public void testRevoke() throws IOException {
         URLConnection conn = post(Certificates.SUPPORT_PATH + "/" + c.getSerial(), "action=revoke");
         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + Certificates.SUPPORT_PATH + "/" + c.getSerial(), conn.getHeaderField("Location"));
-        boolean hadSupport = false;
-        boolean hadUser = false;
         for (int i = 0; i < 2; i++) {
-            TestMail tm = getMailReceiver().receive();
-            if (tm.getTo().equals(ServerConstants.getSupportMailAddress())) {
-                hadSupport = true;
-            } else if (tm.getTo().equals(certMail)) {
-                hadUser = true;
-            } else {
-                throw new Error("Unknown mail:" + tm.getTo());
-            }
+            TestMail tm = getMailReceiver().receive(i == 0 ? ServerConstants.getSupportMailAddress() : certMail);
             assertThat(tm.getMessage(), CoreMatchers.containsString(certMail));
             assertThat(tm.getMessage(), CoreMatchers.containsString(c.getSerial()));
         }
-        assertTrue(hadSupport);
-        assertTrue(hadUser);
         assertEquals(CertificateStatus.REVOKED, c.getStatus());
     }
 
index 909dd03..72930b3 100644 (file)
@@ -56,7 +56,7 @@ public class TestSEAdminPageDetails extends ClientTest {
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
         String email2 = createUniqueName() + "@example.com";
         EmailAddress ea = new EmailAddress(User.getById(id), email2, Locale.ENGLISH);
-        getMailReceiver().receive().verify();
+        getMailReceiver().receive(email2).verify();
         // Refresh email Object
         ObjectCache.clearAllCaches();
         ea = EmailAddress.getById(ea.getId());
@@ -108,6 +108,10 @@ public class TestSEAdminPageDetails extends ClientTest {
         assertEquals(3, logCountAdmin(id));
         assertEquals(3, logCountUser(clientCookie));
 
+        // discarding all 6 mails
+        for (int i = 0; i < 6; i++) {
+            getMailReceiver().receive(null);
+        }
     }
 
     @Test
index af9cbb6..46ffe0d 100644 (file)
@@ -187,6 +187,7 @@ public class KeyCompromiseTest extends ClientTest {
         if (error == null) {
             assertThat(result, hasNoError());
             assertRevoked(result);
+            getMailReceiver().receive(u.getEmail());
         } else if ("error".equals(error)) {
             assertThat(result, hasError());
             assertNotEquals(CertificateStatus.REVOKED, cert.getStatus());
index 06a5ba5..7dfb415 100644 (file)
@@ -92,7 +92,7 @@ public class KeyCompromiseTestMessage extends ClientTest {
         String data = IOUtils.readURL(rc);
         assertThat(data, hasError());
         assertThat(data, CoreMatchers.containsString(HTMLEncoder.encodeHTML("message may not contain '---'")));
-        assertNull(getMailReceiver().poll());
+        assertNull(getMailReceiver().poll(null));
         assertEquals(CertificateStatus.ISSUED, cert.getStatus());
     }
 
@@ -108,7 +108,7 @@ public class KeyCompromiseTestMessage extends ClientTest {
     private TestMail reportCompromiseAndCheck(String params) throws IOException, UnsupportedEncodingException, CertificateEncodingException, GeneralSecurityException {
         HttpURLConnection huc = reportCompromise(params);
         assertThat(IOUtils.readURL(huc), hasNoError());
-        TestMail rc = getMailReceiver().receive();
+        TestMail rc = getMailReceiver().receive(email);
         assertEquals(u.getEmail(), rc.getTo());
         assertThat(rc.getMessage(), CoreMatchers.containsString(cert.getSerial()));
         assertEquals(CertificateStatus.REVOKED, cert.getStatus());
index aee9ad5..d9de3a9 100644 (file)
@@ -45,14 +45,14 @@ public class RegisterPageTest extends ManagedTest {
     public void testSuccess() throws IOException, InterruptedException {
         long uniq = System.currentTimeMillis();
         registerUser("ab", "b", "correct" + uniq + "@email.de", TEST_PASSWORD);
-        assertSuccessfullRegMail();
+        assertSuccessfullRegMail("correct" + uniq + "@email.de");
 
         String defaultSignup = "fname=" + URLEncoder.encode("ab", "UTF-8") + "&lname=" + URLEncoder.encode("b", "UTF-8") + "&pword1=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&pword2=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&day=1&month=1&year=1910&tos_agree=1&mname=mn&suffix=sf&email=";
 
         String query = defaultSignup + URLEncoder.encode("correct3_" + uniq + "@email.de", "UTF-8") + "&general=1&country=1&regional=1&radius=1&name-type=western";
         String data = fetchStartErrorMessage(runRegister(query));
         assertNull(data);
-        assertSuccessfullRegMail();
+        assertSuccessfullRegMail("correct3_" + uniq + "@email.de");
 
         getMailReceiver().setEmailCheckError("400 Greylisted");
         getMailReceiver().setApproveRegex(Pattern.compile("a"));
@@ -60,12 +60,12 @@ public class RegisterPageTest extends ManagedTest {
         data = fetchStartErrorMessage(runRegister(query));
         assertNotNull(data);
 
-        assertNull(getMailReceiver().poll());
+        assertNull(getMailReceiver().poll(null));
 
     }
 
-    private void assertSuccessfullRegMail() {
-        String link = getMailReceiver().receive().extractLink();
+    private void assertSuccessfullRegMail(String mail) {
+        String link = getMailReceiver().receive(mail).extractLink();
         assertTrue(link, link.startsWith("https://"));
     }
 
@@ -188,6 +188,7 @@ public class RegisterPageTest extends ManagedTest {
     public void testDoubleMail() throws IOException {
         long uniq = System.currentTimeMillis();
         registerUser("RegisterTest", "User", "testmail" + uniq + "@example.com", TEST_PASSWORD);
+        getMailReceiver().receive("testmail" + uniq + "@example.com");
         try {
             registerUser("RegisterTest", "User", "testmail" + uniq + "@example.com", TEST_PASSWORD);
             throw new Error("Registering a user with the same email needs to fail.");
@@ -225,6 +226,7 @@ public class RegisterPageTest extends ManagedTest {
         assertNull(data);
         User u = User.getByEmail(email);
         assertEquals("DE", u.getResidenceCountry().getCode());
+        getMailReceiver().receive(email);
     }
 
     @Test
@@ -239,5 +241,6 @@ public class RegisterPageTest extends ManagedTest {
         assertNull(data);
         User u = User.getByEmail(email);
         assertEquals(null, u.getResidenceCountry());
+        getMailReceiver().receive(email);
     }
 }
index eaff941..5b61f23 100644 (file)
@@ -101,6 +101,7 @@ public class TestVerification extends ManagedTest {
         String body = executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
         assertThat(body, containsString("10"));
         assertThat(body, containsString(applicantM));
+        getMailReceiver().receive(applicantM);
     }
 
     @Test
@@ -165,6 +166,7 @@ public class TestVerification extends ManagedTest {
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         if (succeed) {
             assertNull(error);
+            getMailReceiver().receive(applicantM);
         } else {
             assertTrue(error, !error.startsWith("</div>"));
             assertThat(error, containsString("changed his personal details"));
@@ -186,11 +188,13 @@ public class TestVerification extends ManagedTest {
         c.add(Calendar.HOUR_OF_DAY, 12);
 
         executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
     }
 
     @Test
     public void testVerifyFormPastInRange() throws IOException {
         executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
     }
 
     @Test
@@ -202,6 +206,7 @@ public class TestVerification extends ManagedTest {
         c.add(Calendar.DAY_OF_MONTH, 1);
 
         executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
     }
 
     @Test
@@ -236,7 +241,8 @@ public class TestVerification extends ManagedTest {
     @Test
     public void testVerifyListingValid() throws IOException, GigiApiException {
         String uniqueLoc = createUniqueName();
-        execute("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
 
         String cookie = login(applicantM, TEST_PASSWORD);
         URLConnection url = get(cookie, Points.PATH);
@@ -250,6 +256,8 @@ public class TestVerification extends ManagedTest {
     public void testAgentListingValid() throws IOException, GigiApiException {
         String uniqueLoc = createUniqueName();
         executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
+
         String cookie = login(agentM, TEST_PASSWORD);
         URLConnection url = get(cookie, Points.PATH);
         String resp = IOUtils.readURL(url);
@@ -317,6 +325,7 @@ public class TestVerification extends ManagedTest {
         // enter second entry
         String uniqueLoc = createUniqueName();
         executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        getMailReceiver().receive(applicantM);
 
         // enter third entry on the same day
         URLConnection uc = get(cookie, VerifyPage.PATH);
@@ -333,7 +342,7 @@ public class TestVerification extends ManagedTest {
 
     @Test
     public void testRANotificationSet() throws IOException, GigiApiException {
-        getMailReceiver().clearMails();
+        getMailReceiver().assertEmpty();
 
         User users[] = User.findByEmail(agentM);
         assertTrue("user RA Agent not found", users != null && users.length > 0);
@@ -348,18 +357,15 @@ public class TestVerification extends ManagedTest {
         // enter verification
         String uniqueLoc = createUniqueName();
         executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
-        TestMail tm;
-
-        do {
-            tm = getMailReceiver().receive();
-        } while ( !tm.getTo().equals(targetMail));
+        getMailReceiver().receive(applicantM);
+        TestMail tm = getMailReceiver().receive(targetMail);
         assertThat(tm.getMessage(), containsString("You entered a verification for the account with email address " + applicantM));
 
     }
 
     @Test
     public void testRANotificationNotSet() throws IOException, GigiApiException {
-        getMailReceiver().clearMails();
+        getMailReceiver().assertEmpty();
 
         User users[] = User.findByEmail(agentM);
         assertTrue("user RA Agent not found", users != null && users.length > 0);
@@ -375,7 +381,7 @@ public class TestVerification extends ManagedTest {
 
         TestMail tm;
 
-        tm = getMailReceiver().receive();
+        tm = getMailReceiver().receive(applicantM);
         assertThat(tm.getMessage(), not(containsString("You entered a verification for the account with email address " + applicantM)));
 
     }
index 4285e8b..f970cb2 100644 (file)
@@ -75,7 +75,7 @@ public class TestDNS extends PingTest {
                 "&adddomain&csrf=" + csrf;
         String p2 = sendDomainForm(content);
 
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive("postmaster@" + test);
         if (emailVariant == 0) {
             mail.verify();
         }
index 8dc041f..ae29f97 100644 (file)
@@ -76,7 +76,7 @@ public class TestHTTP extends PingTest {
                 "&adddomain&csrf=" + csrf;
         String p2 = sendDomainForm(content);
 
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive("postmaster@" + test);
         if (emailVariant == 0) {
             mail.verify();
         }
@@ -175,7 +175,7 @@ public class TestHTTP extends PingTest {
         }
         waitForPings(2);
 
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive("postmaster@" + test);
         mail.verify();
 
         String newcontent = IOUtils.readURL(get(p2));
index 9b93c77..e4c5de0 100644 (file)
@@ -45,11 +45,11 @@ import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.database.DatabaseConnection;
 import club.wpia.gigi.database.DatabaseConnection.Link;
 import club.wpia.gigi.dbObjects.Certificate;
+import club.wpia.gigi.dbObjects.Certificate.CSRType;
 import club.wpia.gigi.dbObjects.CertificateProfile;
 import club.wpia.gigi.dbObjects.Digest;
 import club.wpia.gigi.dbObjects.Job;
 import club.wpia.gigi.dbObjects.User;
-import club.wpia.gigi.dbObjects.Certificate.CSRType;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.PingTest;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -206,7 +206,7 @@ public class TestSSL extends PingTest {
         boolean secondsSucceeds = sslVariant != 0;
         // assertTrue(secondsSucceeds ^ accept2);
 
-        TestMail mail = getMailReceiver().receive();
+        TestMail mail = getMailReceiver().receive("postmaster@" + test);
         if (emailVariant == 0) {
             mail.verify();
         }
index c660714..940c157 100644 (file)
@@ -30,7 +30,7 @@ public class TestTemplateMail extends BusinessTest {
     public void testSimple() throws IOException {
         vars.put("var", "val");
         testExecuteMail(vars, "Subject: subj\n\n<?=$var?>l");
-        TestMail tm = getMailReceiver().receive();
+        TestMail tm = getMailReceiver().receive(TEST_MAIL);
         assertEquals(MailTemplate.SUBJECT_TAG + "subj", tm.getSubject());
         assertThat(tm.getMessage(), startsWith("vall"));
     }
@@ -40,7 +40,7 @@ public class TestTemplateMail extends BusinessTest {
         vars.put("var", "val\">");
         vars.put("var2", "sl\">");
         testExecuteMail(vars, "Subject: a<?=$var?>b\n\n<?=$var2?>l");
-        TestMail tm = getMailReceiver().receive();
+        TestMail tm = getMailReceiver().receive(TEST_MAIL);
         assertEquals(MailTemplate.SUBJECT_TAG + "aval\">b", tm.getSubject());
         assertThat(tm.getMessage(), startsWith("sl\">l"));
 
@@ -49,7 +49,7 @@ public class TestTemplateMail extends BusinessTest {
     @Test
     public void testTranslate() throws IOException {
         testExecuteMail(vars, "Subject: a<?=_a<?>b\n\nc<?=_b\"?>l");
-        TestMail tm = getMailReceiver().receive();
+        TestMail tm = getMailReceiver().receive(TEST_MAIL);
         assertEquals(MailTemplate.SUBJECT_TAG + "aa<b", tm.getSubject());
         assertThat(tm.getMessage(), startsWith("cb\"l"));
 
index 727310d..28da80f 100644 (file)
@@ -70,12 +70,12 @@ public abstract class BusinessTest extends ConfiguredTest {
         }
 
         @Override
-        public void clearMails() {
+        public void assertEmpty() {
             mails.clear();
         }
 
         @Override
-        public TestMail receive() {
+        public TestMail receive(String to) {
             TestMail poll;
             try {
                 poll = mails.poll(30, TimeUnit.SECONDS);
@@ -85,6 +85,9 @@ public abstract class BusinessTest extends ConfiguredTest {
             if (poll == null) {
                 throw new AssertionError("Mail receiving timed out");
             }
+            if (to != null) {
+                assertEquals(to, poll.getTo());
+            }
             return poll;
         }
 
@@ -99,7 +102,7 @@ public abstract class BusinessTest extends ConfiguredTest {
         }
 
         @Override
-        public TestMail poll() {
+        public TestMail poll(String to) {
             throw new Error("Currently unimplemented");
         }
 
index 4dd091e..ead6ffd 100644 (file)
@@ -249,7 +249,7 @@ public abstract class ConfiguredTest {
     public void verify(Domain d) {
         try {
             d.addPing(DomainPingType.EMAIL, "admin");
-            TestMail testMail = getMailReceiver().receive();
+            TestMail testMail = getMailReceiver().receive("admin@" + d.getSuffix());
             testMail.verify();
             assertTrue(d.isVerified());
         } catch (GigiApiException e) {
index 4d1bc10..139c554 100644 (file)
@@ -6,14 +6,14 @@ import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
 
 public interface MailReceiver {
 
-    void clearMails();
+    void assertEmpty();
 
-    TestMail receive();
+    TestMail receive(String to);
 
     void setApproveRegex(Pattern compiled);
 
     void setEmailCheckError(String string);
 
-    TestMail poll();
+    TestMail poll(String to);
 
 }
index 3eeda2c..a2eb449 100644 (file)
@@ -291,7 +291,7 @@ public class ManagedTest extends ConfiguredTest {
     public static int createVerifiedUser(String firstName, String lastName, String email, String password) {
         registerUser(firstName, lastName, email, password);
         try {
-            ter.receive().verify();
+            ter.receive(email).verify();
 
             try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `users` WHERE `email`=?")) {
                 ps.setString(1, email);
@@ -496,11 +496,10 @@ public class ManagedTest extends ConfiguredTest {
 
     public EmailAddress createVerifiedEmail(User u, String email) throws InterruptedException, GigiApiException {
         EmailAddress addr = new EmailAddress(u, email, Locale.ENGLISH);
-        TestMail testMail = getMailReceiver().receive();
-        assertEquals(addr.getAddress(), testMail.getTo());
+        TestMail testMail = getMailReceiver().receive(addr.getAddress());
         String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
         addr.verify(hash);
-        getMailReceiver().clearMails();
+        getMailReceiver().assertEmpty();
         return addr;
     }
 
index 01dbe78..9bba9b3 100644 (file)
@@ -1,5 +1,7 @@
 package club.wpia.gigi.testUtils;
 
+import static org.junit.Assert.*;
+
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -83,6 +85,10 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
             uc.getInputStream().close();
         }
 
+        @Override
+        public String toString() {
+            return "TestMail: " + subject + " for " + to;
+        }
     }
 
     private Socket s;
@@ -130,7 +136,7 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
      * @see #poll()
      */
     @Override
-    public TestMail receive() {
+    public TestMail receive(String to) {
         TestMail poll;
 
         try {
@@ -142,6 +148,9 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
         if (poll == null) {
             throw new AssertionError("Mail receiving timed out");
         }
+        if (to != null) {
+            assertEquals(to, poll.getTo());
+        }
 
         return poll;
     }
@@ -154,8 +163,12 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
      *         has been sent.
      * @see #receive()
      */
-    public TestMail poll() {
-        return mails.poll();
+    public TestMail poll(String to) {
+        TestMail tm = mails.poll();
+        if (tm != null && to != null) {
+            assertEquals(to, tm.getTo());
+        }
+        return tm;
     }
 
     @Override
@@ -226,19 +239,21 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
      * Removes all queued mails.
      */
     @Override
-    public void clearMails() {
+    public void assertEmpty() {
+        int originalSize = mails.size();
         mails.clear();
+        assertEquals("test case should consume all produced emails", 0, originalSize);
     }
 
     /**
      * Resets this class to its initial state
      * 
-     * @see #clearMails()
+     * @see #assertEmpty()
      * @see #setApproveRegex(Pattern)
      * @see #setEmailCheckError(String)
      */
     public void reset() {
-        clearMails();
+        assertEmpty();
         error = "FAIL";
         approveRegex = Pattern.compile(".*");
     }