X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FTestEmailReciever.java;h=849bf927f234165190080c0ddba955a44a52cc76;hb=af1651c1ebb7fe2633181653a2b66a11ca6926fd;hp=e0131a3b3265ad3adb1857448882d74759f9118d;hpb=097b9af9a0457d89560335a773948770293df06c;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/TestEmailReciever.java b/tests/org/cacert/gigi/testUtils/TestEmailReciever.java index e0131a3b..849bf927 100644 --- a/tests/org/cacert/gigi/testUtils/TestEmailReciever.java +++ b/tests/org/cacert/gigi/testUtils/TestEmailReciever.java @@ -17,37 +17,44 @@ public class TestEmailReciever implements Runnable { String message; String from; String replyto; - public TestMail(String to, String subject, String message, String from, - String replyto) { + + public TestMail(String to, String subject, String message, String from, String replyto) { this.to = to; this.subject = subject; this.message = message; this.from = from; this.replyto = replyto; } + public String getTo() { return to; } + public String getSubject() { return subject; } + public String getMessage() { return message; } + public String getFrom() { return from; } + public String getReplyto() { return replyto; } + public String extractLink() { - Pattern link = Pattern.compile("http://[^\\s]+(?=\\s)"); + Pattern link = Pattern.compile("https?://[^\\s]+(?=\\s)"); Matcher m = link.matcher(getMessage()); m.find(); return m.group(0); } } + private Socket s; private DataInputStream dis; private DataOutputStream dos; @@ -61,11 +68,13 @@ public class TestEmailReciever implements Runnable { dos = new DataOutputStream(s.getOutputStream()); new Thread(this).start(); } + LinkedBlockingQueue mails = new LinkedBlockingQueue(); public TestMail recieve() throws InterruptedException { return mails.poll(5, TimeUnit.SECONDS); } + @Override public void run() { try { @@ -81,11 +90,9 @@ public class TestEmailReciever implements Runnable { } else if (type.equals("challengeAddrBox")) { String email = dis.readUTF(); if (approveRegex.matcher(email).matches()) { - System.out.println("approving mbox: " + email); dos.writeUTF("OK"); } else { - System.out.println("rejecting mbox: " + email); - dos.writeUTF("FAIL"); + dos.writeUTF(error); } dos.flush(); } else if (type.equals("ping")) { @@ -94,11 +101,21 @@ public class TestEmailReciever implements Runnable { } } } catch (IOException e) { - e.printStackTrace(); + if (!closed) { + e.printStackTrace(); + } } } + + String error = "FAIL"; + + public void setEmailCheckError(String error) { + this.error = error; + } + Pattern approveRegex = Pattern.compile(".*"); + public void setApproveRegex(Pattern approveRegex) { this.approveRegex = approveRegex; } @@ -106,9 +123,22 @@ public class TestEmailReciever implements Runnable { public void clearMails() { mails.clear(); } + public void reset() { clearMails(); + error = "FAIL"; approveRegex = Pattern.compile(".*"); } + boolean closed = false; + + public void destroy() { + try { + closed = true; + s.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }