james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r802017 [3/3] - in /james/server/sandbox/active/smtp_refactor/smtpserver-function/src: main/java/org/apache/james/smtpserver/core/ main/java/org/apache/james/smtpserver/core/filter/ main/java/org/apache/james/smtpserver/core/filter/fastfail...
Date Fri, 07 Aug 2009 14:11:33 GMT
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -30,8 +30,6 @@
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.exceptions.TimeoutException;
 import org.apache.james.smtpserver.core.filter.fastfail.SPFHandler;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.Mail;
@@ -198,21 +196,10 @@
         };
     }
 
-    private void runHandlers(SPFHandler spf, SMTPSession mockedSMTPSession) {
-
-        setCommand("MAIL");
-        spf.onCommand(mockedSMTPSession);
-
-        setCommand("RCPT");
-        spf.onCommand(mockedSMTPSession);
-
-        spf.onMessage(mockedSMTPSession);
-    }
-
     public void testSPFpass() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org",
-                new MailAddress("test@spf1.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+    	MailAddress sender = new MailAddress("test@spf1.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org",sender,rcpt);
         SPFHandler spf = new SPFHandler();
 
 
@@ -222,7 +209,9 @@
         
         spf.initialize();
 
-        runHandlers(spf, mockedSMTPSession);
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
 
         assertNull("Not reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
@@ -235,13 +224,13 @@
         assertEquals("header", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
                 .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
-        assertFalse(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFfail() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",
-                new MailAddress("test@spf2.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+    	MailAddress sender = new MailAddress("test@spf2.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+    	
+    	setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",sender,rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -250,8 +239,10 @@
         
         spf.initialize();
 
-        runHandlers(spf, mockedSMTPSession);
-
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNotNull("reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNotNull("blocked", mockedSMTPSession.getState().get(
@@ -260,13 +251,12 @@
                 SPFHandler.SPF_TEMPBLOCKLISTED));
         assertNotNull("Header should present", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertTrue(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFsoftFail() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
-                new MailAddress("test@spf3.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+    	MailAddress sender = new MailAddress("test@spf3.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org", sender, rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -275,8 +265,10 @@
         
         spf.initialize();
 
-        runHandlers(spf, mockedSMTPSession);
-
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNull("not reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNull("no details ", mockedSMTPSession.getState().get(
@@ -288,13 +280,12 @@
         assertEquals("header", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
                 .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
-        assertFalse(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFsoftFailRejectEnabled() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
-                new MailAddress("test@spf3.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+    	MailAddress sender = new MailAddress("test@spf3.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",sender,rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -305,11 +296,10 @@
         
         spf.setBlockSoftFail(true);
 
-        setCommand("MAIL");
-        spf.onCommand(mockedSMTPSession);
-
-        setCommand("RCPT");
-        spf.onCommand(mockedSMTPSession);
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
 
         assertNotNull("reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
@@ -319,13 +309,12 @@
                 SPFHandler.SPF_TEMPBLOCKLISTED));
         assertNotNull("Header should present", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertTrue(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFpermError() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+        MailAddress sender = new MailAddress("test@spf4.james.apache.org");
+        MailAddress rcpt = new MailAddress("test@localhost");
+    	setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org", sender,rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -335,9 +324,11 @@
         spf.initialize();
         
         spf.setBlockSoftFail(true);
-
-        runHandlers(spf, mockedSMTPSession);
-
+        
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNotNull("reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNotNull("details ", mockedSMTPSession.getState().get(
@@ -346,13 +337,12 @@
                 SPFHandler.SPF_TEMPBLOCKLISTED));
         assertNotNull("Header should present", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertTrue(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFtempError() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org",
-                new MailAddress("test@spf5.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+    	MailAddress sender = new MailAddress("test@spf5.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org",sender, rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -360,9 +350,11 @@
         spf.setDNSService(mockedDnsService);
 
         spf.initialize();
-        
-        runHandlers(spf, mockedSMTPSession);
 
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNull("no reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNull("no details ", mockedSMTPSession.getState().get(
@@ -371,13 +363,12 @@
                 SPFHandler.SPF_TEMPBLOCKLISTED));
         assertNotNull("Header should present", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertTrue(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFNoRecord() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org",
-                new MailAddress("test@spf6.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+        MailAddress sender = new MailAddress("test@spf6.james.apache.org");
+        MailAddress rcpt = new MailAddress("test@localhost");
+    	setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org", sender, rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -386,8 +377,11 @@
 
         spf.initialize();
         
-        runHandlers(spf, mockedSMTPSession);
 
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNull("no reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNull("no details ", mockedSMTPSession.getState().get(
@@ -399,13 +393,12 @@
         assertEquals("header", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
                 .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
-        assertFalse(mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFpermErrorNotRejectPostmaster() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"), new MailAddress(
-                        "postmaster@localhost"));
+    	MailAddress sender =  new MailAddress("test@spf4.james.apache.org");
+    	MailAddress rcpt = new MailAddress("postmaster@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",sender,rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -416,20 +409,22 @@
         
         spf.setBlockSoftFail(true);
 
-        runHandlers(spf, mockedSMTPSession);
-
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNotNull("not removed this state", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNotNull("not removed this state", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_DETAIL));
         assertNotNull("not removed this state", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertFalse("not rejected", mockedSMTPSession.getStopHandlerProcessing());
     }
 
     public void testSPFpermErrorNotRejectAbuse() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"), new MailAddress("abuse@localhost"));
+        MailAddress sender =  new MailAddress("test@spf4.james.apache.org");
+        MailAddress rcpt = new MailAddress("abuse@localhost");
+    	setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org", sender, rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -439,15 +434,16 @@
         spf.setDNSService(mockedDnsService);
         spf.setBlockSoftFail(true);
 
-        runHandlers(spf, mockedSMTPSession);
-
-        assertFalse("not rejected",mockedSMTPSession.getStopHandlerProcessing());
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
     }
     
     public void testSPFpermErrorRejectDisabled() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"), new MailAddress(
-                        "test@localhost"));
+        MailAddress sender = new MailAddress("test@spf4.james.apache.org");
+        MailAddress rcpt = new MailAddress("test@localhost");
+    	setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org", sender, rcpt);
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -458,8 +454,10 @@
         
         spf.setBlockPermError(false);
 
-        runHandlers(spf, mockedSMTPSession);
-
+        spf.onMail(mockedSMTPSession,sender);
+        spf.onRcpt(mockedSMTPSession, rcpt);
+        spf.onData(mockedSMTPSession,mockedSMTPSession.getMail());
+        
         assertNull("not reject", mockedSMTPSession.getState().get(
                 SPFHandler.SPF_BLOCKLISTED));
         assertNull("details ", mockedSMTPSession.getState().get(
@@ -468,35 +466,7 @@
                 SPFHandler.SPF_TEMPBLOCKLISTED));
         assertNotNull("Header should present", mockedSMTPSession.getState()
                 .get(SPFHandler.SPF_HEADER));
-        assertFalse(mockedSMTPSession.getStopHandlerProcessing());
     }
     
-    public void testSPFfailAddJunkScore() throws Exception {
-        setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",
-                new MailAddress("test@spf2.james.apache.org"), new MailAddress(
-                        "test@localhost"));
-        mockedSMTPSession.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-        
-        SPFHandler spf = new SPFHandler();
-
-        ContainerUtil.enableLogging(spf, new MockLogger());
-        spf.setAction("junkScore");
-        spf.setScore(20);
-        spf.setDNSService(mockedDnsService);     
-        
-        spf.initialize();
-
-        runHandlers(spf, mockedSMTPSession);
-
-        assertNotNull("reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNotNull("blocked", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_DETAIL));
-        assertNull("No tempError", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_TEMPBLOCKLISTED));
-        assertNotNull("Header should present", mockedSMTPSession.getState()
-                .get(SPFHandler.SPF_HEADER));
-        assertFalse("Not stopped", mockedSMTPSession.getStopHandlerProcessing());
-        assertEquals("Score added",((JunkScore) mockedSMTPSession.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("SPFCheck"),
20.0, 0d);
-    }
+   
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -51,7 +51,7 @@
         response = null;
     }
 
-    private SMTPSession setupMockedSMTPSession(final Mail mail) {
+    private SMTPSession setupMockedSMTPSession() {
         mockedSMTPSession = new AbstractSMTPSession() {
 
             private HashMap state = new HashMap();
@@ -62,12 +62,6 @@
 
             private boolean relayingAllowed;
 
-            public void abortMessage() {
-            }
-
-            public Mail getMail() {
-                return mail;
-            }
 
             public String getRemoteHost() {
                 return host;
@@ -124,7 +118,7 @@
         MockSpamd spamd = new MockSpamd(port);
         new Thread(spamd).start();
 
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage("test")));
+        SMTPSession session = setupMockedSMTPSession();
 
         SpamAssassinHandler handler = new SpamAssassinHandler();
 
@@ -132,12 +126,12 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
 
-        assertNull("Email was not rejected", getResponse());
-        assertEquals("email was not spam", session.getMail().getAttribute(
+        Mail mail = setupMockedMail(setupMockedMimeMessage("test"));
+        assertNull("Email was not rejected", handler.onData(session,mail));
+        assertEquals("email was not spam", mail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "NO");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
 
     }
@@ -147,7 +141,7 @@
         int port = Util.getNonPrivilegedPort();
         new Thread(new MockSpamd(port)).start();
 
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage(MockSpamd.GTUBE)));
+        SMTPSession session = setupMockedSMTPSession();
 
         SpamAssassinHandler handler = new SpamAssassinHandler();
 
@@ -155,12 +149,13 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(2000.0);
-        handler.onMessage(session);
+        
 
-        assertNull("Email was not rejected", getResponse());
-        assertEquals("email was spam", session.getMail().getAttribute(
+        Mail mail = setupMockedMail(setupMockedMimeMessage(MockSpamd.GTUBE));
+        assertNull("Email was not rejected", handler.onData(session,mail));
+        assertEquals("email was spam", mail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
     }
 
@@ -169,7 +164,7 @@
         int port = Util.getNonPrivilegedPort();
         new Thread(new MockSpamd(port)).start();
 
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage(MockSpamd.GTUBE)));
+        SMTPSession session = setupMockedSMTPSession();
 
         SpamAssassinHandler handler = new SpamAssassinHandler();
 
@@ -177,12 +172,11 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
-
-        assertNotNull("Email was rejected", getResponse());
-        assertEquals("email was spam", session.getMail().getAttribute(
+        Mail mail = setupMockedMail(setupMockedMimeMessage(MockSpamd.GTUBE));
+        assertNotNull("Email was rejected", handler.onData(session, mail));
+        assertEquals("email was spam", mail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
     }
 

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -53,13 +53,13 @@
 
         // no tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(0));
+        handler.onRcpt(setupMockedSession(0),null);
         assertTrue("No tarpit",
                 (System.currentTimeMillis() - startTime) < tarpitTime - tarpitTolerance);
 
         // tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(3));
+        handler.onRcpt(setupMockedSession(0),null);
         assertTrue("tarpit",
                 (System.currentTimeMillis() - startTime) >= tarpitTime - tarpitTolerance);
     }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -42,12 +42,10 @@
 import org.apache.james.api.dnsservice.AbstractDNSServer;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.smtpserver.core.filter.fastfail.URIRBLHandler;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.mailet.base.test.FakeMimeMessage;
-import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMimeMessage;
 
 public class URIRBLHandlerTest extends TestCase {
     private static final String BAD_DOMAIN1 = "bad.domain.de";
@@ -56,14 +54,7 @@
     private static final String URISERVER = "multi.surbl.org.";
     private SMTPSession mockedSMTPSession;
 
-    private String response = null;
-    
-    public void setUp() {
-        // reset reponse
-        response = null;
-    }
-
-    private SMTPSession setupMockedSMTPSession(final Mail mail) {
+    private SMTPSession setupMockedSMTPSession() {
         mockedSMTPSession = new AbstractSMTPSession() {
 
             private HashMap state = new HashMap();
@@ -75,13 +66,7 @@
             private boolean relayingAllowed;
 
             private boolean processing;
-            
-            public void abortMessage() {
-            }
 
-            public Mail getMail() {
-                return mail;
-            }
 
             public String getRemoteHost() {
                 return host;
@@ -104,9 +89,6 @@
                 this.relayingAllowed = relayingAllowed;
             }
 
-            public void writeResponse(String respString) {
-                response = respString;
-            }
             
             public void setStopHandlerProcessing(boolean processing) {
                 this.processing = processing;
@@ -121,9 +103,6 @@
 
     }
 
-    private String getResponse() {
-        return response;
-    }
 
     private Mail setupMockedMail(MimeMessage message) {
         FakeMail mail = new FakeMail();
@@ -198,17 +177,16 @@
         ArrayList servers = new ArrayList();
         servers.add(URISERVER);
         
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage("http://"
+ GOOD_DOMAIN + "/")));
+        SMTPSession session = setupMockedSMTPSession();
 
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        String response = handler.onData(session,setupMockedMail(setupMockedMimeMessage("http://"
+ GOOD_DOMAIN + "/")));
 
-        assertFalse("Not Stop handler processing", session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
     }
     
     public void testBlocked() throws IOException, MessagingException {
@@ -216,17 +194,16 @@
         ArrayList servers = new ArrayList();
         servers.add(URISERVER);
         
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage("http://"
+ BAD_DOMAIN1 + "/")));
+        SMTPSession session = setupMockedSMTPSession();
 
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        String response = handler.onData(session,setupMockedMail(setupMockedMimeMessage("http://"
+ BAD_DOMAIN1 + "/")));
 
-        assertTrue("Stop handler processing", session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
+        assertNotNull("Email was rejected", response);
     }
     
     public void testBlockedMultiPart() throws IOException, MessagingException {
@@ -234,38 +211,15 @@
         ArrayList servers = new ArrayList();
         servers.add(URISERVER);
         
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessageMP("http://"
+ BAD_DOMAIN1 + "/" + " " +"http://" + GOOD_DOMAIN + "/")));
+        SMTPSession session = setupMockedSMTPSession();
 
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        String response = handler.onData(session,setupMockedMail(setupMockedMimeMessageMP("http://"
+ BAD_DOMAIN1 + "/" + " " +"http://" + GOOD_DOMAIN + "/")));
 
-        assertTrue("Stop handler processing", session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
-    }
-    
-    public void testAddJunkScore() throws IOException, MessagingException {
-        
-        ArrayList servers = new ArrayList();
-        servers.add(URISERVER);
-        
-        SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage("http://"
+ BAD_DOMAIN1 + "/")));
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-        
-        URIRBLHandler handler = new URIRBLHandler();
-
-        ContainerUtil.enableLogging(handler, new MockLogger());
-        handler.setDnsServer(setupMockedDnsServer());
-        handler.setUriRblServer(servers);
-        handler.setAction("junkScore");
-        handler.setScore(20);
-        handler.onMessage(session);
-
-        assertFalse("Not stop handler processing", session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
-        assertEquals("JunkScore added", ((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("UriRBLCheck"),
20.0, 0d);
+        assertNotNull("Email was rejected", response);
     }
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -47,14 +47,9 @@
     private final static String INVALID_USER = "invalid";
     private final static String USER1 = "user1";
     private final static String USER2 = "user2";
-    private String response = null;
     private MockServiceManager serviceMan;
-    
-    public void setUp() {
-        response = null;
-    }
-    
-    private SMTPSession setupMockedSMTPSession(final SMTPHandlerConfigurationData conf, final
MailAddress rcpt, final boolean relayingAllowed, final boolean authRequired, final String
username) {
+
+    private SMTPSession setupMockedSMTPSession(final SMTPHandlerConfigurationData conf, final
boolean relayingAllowed, final boolean authRequired, final String username) {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
             boolean stop = false;
@@ -76,13 +71,11 @@
             }
         
             public Map getState() {
-                state.put(SMTPSession.CURRENT_RECIPIENT,rcpt);
-
                 return state;
             }
         
             public void writeResponse(String resp) {
-                response = resp;
+            	// nothing todo
             }
         
             public void setStopHandlerProcessing(boolean stop) {
@@ -180,46 +173,43 @@
     public void testRejectInvalidUser() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER
+ "@localhost"),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(INVALID_USER + "@localhost"));
     
-        assertTrue("Rejected",session.getStopHandlerProcessing());
         assertNotNull("Rejected",response);
     }
     
     public void testNotRejectInvalidUserAuth() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER
+ "@localhost"),false,true,"authedUser");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,true,"authedUser");
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(INVALID_USER + "@localhost"));
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
     }
     
     public void testNotRejectInvalidUserRelay() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER
+ "@localhost"),true,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),true,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(INVALID_USER + "@localhost"));
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
     }
     
     public void testNotRejectValidUser() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(VALID_USER
+ "@localhost"),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(VALID_USER + "@localhost"));
     
         assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
@@ -229,14 +219,13 @@
         String recipient = "recip@domain";
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidRecipients(recipient);
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(recipient));
         
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
     }
     
@@ -246,14 +235,12 @@
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidDomains(domain);
-        handler.onCommand(session);
-        
+        String response = handler.onRcpt(session,new MailAddress(recipient));
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
     }
     
@@ -263,14 +250,12 @@
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidRegex("reci.*");
-        handler.onCommand(session);
-        
+        String response = handler.onRcpt(session,new MailAddress(recipient));        
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
         assertNull("Not rejected",response);
     }
     
@@ -290,27 +275,25 @@
     }
     
     public void testHasAddressMapping() throws Exception {
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(USER1
+ "@localhost"),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
     
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
         ContainerUtil.enableLogging(handler,new MockLogger());
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(USER1 + "@localhost"));
       
     
         assertNull("No reject",response);
-        assertFalse("Not stop processing",session.getStopHandlerProcessing());
     }
     
     public void testHasErrorMapping() throws Exception {
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(USER2
+ "@localhost"),false,false,null);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),false,false,null);
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
         ContainerUtil.enableLogging(handler,new MockLogger());
-        handler.onCommand(session);
+        String response = handler.onRcpt(session,new MailAddress(USER2 + "@localhost"));
      
        assertNull("Valid Error mapping",session.getState().get("VALID_USER"));
        assertNotNull("Error mapping",response);
-       assertTrue("Stop processing",session.getStopHandlerProcessing());
     }
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
Fri Aug  7 14:11:31 2009
@@ -40,7 +40,6 @@
 import junit.framework.TestCase;
 
 public class ValidRcptMXTest extends TestCase {
-    private String response = null;
 
     private final static String INVALID_HOST = "invalid.host.de";
 
@@ -49,23 +48,20 @@
     private final static String LOOPBACK = "127.0.0.1";
 
     protected void setUp() throws Exception {
-        response = null;
-
         super.setUp();
     }
 
-    private SMTPSession setupMockedSMTPSession(final MailAddress rcpt) {
+    private SMTPSession setupMockedSMTPSession() {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
             boolean stopProcessing = false;
 
             public Map getState() {
-                state.put(SMTPSession.CURRENT_RECIPIENT, rcpt);
                 return state;
             }
 
             public void writeResponse(String resp) {
-                response = resp;
+                // do nothing
             }
             
             public String getRemoteIPAddress() {
@@ -117,31 +113,23 @@
 
         handler.setDNSServer(dns);
         handler.setBannedNetworks(bNetworks, dns);
-        handler.onCommand(setupMockedSMTPSession(new MailAddress("test@" + INVALID_HOST)));
+        String response =  handler.onRcpt(setupMockedSMTPSession(),new MailAddress("test@"
+ INVALID_HOST));
 
         assertNotNull("Reject", response);
     }
     
-
-    public void testAddJunkScoreLoopbackMX() throws ParseException {
+    public void testNotRejectValidMX() throws ParseException {
         Collection bNetworks = new ArrayList();
-        bNetworks.add("127.0.0.1");
-        
-        SMTPSession session = setupMockedSMTPSession(new MailAddress("test@" + INVALID_HOST));
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
         
         DNSService dns = setupMockedDNSServer();
         ValidRcptMX handler = new ValidRcptMX();
-        handler.setScore(20);
-        handler.setAction("junkScore");
 
         ContainerUtil.enableLogging(handler, new MockLogger());
 
         handler.setDNSServer(dns);
         handler.setBannedNetworks(bNetworks, dns);
-        handler.onCommand(session);
+        String response =  handler.onRcpt(setupMockedSMTPSession(),new MailAddress("test@"
+ INVALID_HOST));
 
         assertNull("Not Reject", response);
-        assertEquals("JunkScore added",((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("ValidRcptMXCheck"),20.0,
0d);
     }
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
Fri Aug  7 14:11:31 2009
@@ -30,20 +30,13 @@
 import org.apache.james.api.dnsservice.AbstractDNSServer;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.smtpserver.core.filter.fastfail.ValidSenderDomainHandler;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.mailet.MailAddress;
 
 import junit.framework.TestCase;
 
 public class ValidSenderDomainHandlerTest extends TestCase {
-    
-    private String response = null;
 
-    public void setUp() {
-        response = null;
-    }
     
     private DNSService setupDNSServer() {
         DNSService dns = new AbstractDNSServer(){
@@ -60,15 +53,12 @@
         return dns;
     }
     
-    private SMTPSession setupMockedSession(final MailAddress sender) {
+    private SMTPSession setupMockedSession() {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
             boolean processing = false;
             
             public Map getState() {
-
-                state.put(SMTPSession.SENDER, sender);
-
                 return state;
             }
             
@@ -77,7 +67,6 @@
             }
             
             public void writeResponse(String resp) {
-                response = resp;
             }
             
             public void setStopHandlerProcessing(boolean processing) {
@@ -92,42 +81,23 @@
         return session;
     }
     
-    private String getResponse() {
-        return response;
-    }
-    
     // Test for JAMES-580
     public void testNullSenderNotReject() {
         ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
         ContainerUtil.enableLogging(handler, new MockLogger());
         
         handler.setDnsServer(setupDNSServer());
-        handler.onCommand(setupMockedSession(null));
-        
-        assertNull("Not blocked cause its a nullsender",getResponse());
-    }
-    
-    public void testInvalidSenderDomainAddJunkScore() throws ParseException {
-        ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
-        SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
-        ContainerUtil.enableLogging(handler, new MockLogger());
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-        handler.setAction("JunkScore");
-        handler.setScore(20);
-        handler.setDnsServer(setupDNSServer());
-        handler.onCommand(session);
+        String response = handler.onMail(setupMockedSession(),null);
         
-        assertNull("Not blocked cause we use JunkScore",getResponse());
-        assertEquals("JunkScore is stored",((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("ValidSenderDomainCheck"),20.0,0d);
+        assertNull("Not blocked cause its a nullsender",response);
     }
-    
+   
     public void testInvalidSenderDomainReject() throws ParseException {
         ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
-        SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
+        SMTPSession session = setupMockedSession();
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupDNSServer());
-        handler.onCommand(session);
-        
-        assertNotNull("Blocked cause we use reject action",getResponse());
+        String response = handler.onMail(setupMockedSession(),new MailAddress("invalid@invalid"));
       
+        assertNotNull("Blocked cause we use reject action",response);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message