james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r804286 - in /james/server/sandbox/active/smtp_refactor/smtpserver-function/src: main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java test/java/org/apache/james/smtpserver/SPFHandlerTest.java
Date Fri, 14 Aug 2009 16:35:38 GMT
Author: norman
Date: Fri Aug 14 16:35:38 2009
New Revision: 804286

URL: http://svn.apache.org/viewvc?rev=804286&view=rev
Log:
Fix SPFHandler + SPFHandlerTest

Modified:
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=804286&r1=804285&r2=804286&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
(original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
Fri Aug 14 16:35:38 2009
@@ -28,6 +28,7 @@
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.SPF1Utils;
+import org.apache.james.jspf.core.exceptions.SPFErrorConstants;
 import org.apache.james.jspf.executor.SPFResult;
 import org.apache.james.jspf.impl.DefaultSPF;
 import org.apache.james.jspf.impl.SPF;
@@ -167,53 +168,51 @@
         String heloEhlo = (String) session.getState().get(
                 SMTPSession.CURRENT_HELO_NAME);
 
-        // Not scan the message if relaying allowed
-        if (session.isRelayingAllowed() && !checkAuthNetworks) {
-            getLogger().info(
-                    "Ipaddress " + session.getRemoteIPAddress()
-                            + " is allowed to relay. Don't check it");
-            return;
-        }
-
         // We have no Sender or HELO/EHLO yet return false
         if (sender == null || heloEhlo == null) {
             getLogger().info("No Sender or HELO/EHLO present");
-            return;
-        }
-        
-        String ip = session.getRemoteIPAddress();
-
-        SPFResult result = spf
-                .checkSPF(ip, sender.toString(), heloEhlo);
-
-        String spfResult = result.getResult();
-
-        String explanation = "Blocked - see: "
-                + result.getExplanation();
-
-        // Store the header
-        session.getState().put(SPF_HEADER, result.getHeaderText());
-
-        getLogger().info(
-                "Result for " + ip + " - " + sender + " - " + heloEhlo
-                        + " = " + spfResult);
-
-        // Check if we should block!
-        /*
-        if ((spfResult.equals(SPF1Utils.FAIL_CONV))
-                || (spfResult.equals(SPF1Utils.SOFTFAIL_CONV) && blockSoftFail)
-                || (spfResult.equals(SPF1Utils.PERM_ERROR_CONV) && blockPermError))
{
-
-            if (spfResult.equals(SPF1Utils.PERM_ERROR_CONV)) {
-                explanation = "Block caused by an invalid SPF record";
+        } else {
+            // No checks for authorized cliends
+            if (session.isRelayingAllowed() && checkAuthNetworks == false) {
+                getLogger().info(
+                        "Ipaddress " + session.getRemoteIPAddress()
+                                + " is allowed to relay. Don't check it");
+            } else {
+
+                String ip = session.getRemoteIPAddress();
+
+                SPFResult result = spf
+                        .checkSPF(ip, sender.toString(), heloEhlo);
+
+                String spfResult = result.getResult();
+
+                String explanation = "Blocked - see: "
+                        + result.getExplanation();
+
+                // Store the header
+                session.getState().put(SPF_HEADER, result.getHeaderText());
+
+                getLogger().info(
+                        "Result for " + ip + " - " + sender + " - " + heloEhlo
+                                + " = " + spfResult);
+
+                // Check if we should block!
+                if ((spfResult.equals(SPFErrorConstants.FAIL_CONV))
+                        || (spfResult.equals(SPFErrorConstants.SOFTFAIL_CONV) &&
blockSoftFail)
+                        || (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV) &&
blockPermError)) {
+
+                    if (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV)) {
+                        explanation = "Block caused by an invalid SPF record";
+                    }
+                    session.getState().put(SPF_DETAIL, explanation);
+                    session.getState().put(SPF_BLOCKLISTED, "true");
+
+                } else if (spfResult.equals(SPFErrorConstants.TEMP_ERROR_CONV)) {
+                    session.getState().put(SPF_TEMPBLOCKLISTED, "true");
+                }
             }
-            session.getState().put(SPF_DETAIL, explanation);
-            session.getState().put(SPF_BLOCKLISTED, "true");
-
-        } else if (spfResult.equals(SPF1Utils.TEMP_ERROR_CONV)) {
-            session.getState().put(SPF_TEMPBLOCKLISTED, "true");
         }
-        */
+
 
     }
 
@@ -242,6 +241,7 @@
             }
         }
         return new HookResult(HookReturnCode.DECLINED);
+      
     }
 
 

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=804286&r1=804285&r2=804286&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 14 16:35:38 2009
@@ -28,14 +28,13 @@
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSService;
-import org.apache.james.jspf.core.DNSServiceEnabled;
 import org.apache.james.jspf.core.exceptions.TimeoutException;
 import org.apache.james.smtpserver.core.filter.fastfail.SPFHandler;
+import org.apache.james.smtpserver.hook.HookReturnCode;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
-import org.xbill.DNS.Type;
 
 import junit.framework.TestCase;
 
@@ -47,19 +46,12 @@
 
     private boolean relaying = false;
 
-    private Mail mockMail = null;
+    private String command = "MAIL";
 
     protected void setUp() throws Exception {
         super.setUp();
         setupMockedDnsService();
         setRelayingAllowed(false);
-        mockMail = new MockMail();
-    }
-
-    
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        ContainerUtil.dispose(mockMail);
     }
 
     /**
@@ -97,30 +89,30 @@
                 "Unimplemented mock service");
             }
 
-            public List getRecords(String host, int type) throws TimeoutException {
-                switch (type) {
-                    case Type.TXT:
-                    case Type.SPF:
+            public List getRecords(DNSRequest req) throws TimeoutException {
+                switch (req.getRecordType()) {
+                    case DNSRequest.TXT:
+                    case DNSRequest.SPF:
                         List l = new ArrayList();
-                        if (host.equals("spf1.james.apache.org")) {
+                        if (req.getHostname().equals("spf1.james.apache.org")) {
                             // pass
                             l.add("v=spf1 +all");
                             return l;
-                        } else if (host.equals("spf2.james.apache.org")) {
+                        } else if (req.getHostname().equals("spf2.james.apache.org")) {
                             // fail
                             l.add("v=spf1 -all");
                             return l;
-                        } else if (host.equals("spf3.james.apache.org")) {
+                        } else if (req.getHostname().equals("spf3.james.apache.org")) {
                             // softfail
                             l.add("v=spf1 ~all");
                             return l;
-                        } else if (host.equals("spf4.james.apache.org")) {
+                        } else if (req.getHostname().equals("spf4.james.apache.org")) {
                             // permerror
                             l.add("v=spf1 badcontent!");
                             return l;
-                        } else if (host.equals("spf5.james.apache.org")) {
+                        } else if (req.getHostname().equals("spf5.james.apache.org")) {
                             // temperror
-                            throw new TimeoutException("");
+                            throw new TimeoutException("TIMEOUT");
                         } else {
                             return null;
                         }
@@ -130,31 +122,44 @@
                 }
             }
 
-			public List getRecords(DNSRequest request) throws TimeoutException {
-				// TODO Auto-generated method stub
-				return null;
-			}
-
         };
     }
 
+    private void setCommand(String command) {
+        this.command = command;
+    }
+
     /**
      * Setup mocked smtpsession
      */
-    private void setupMockedSMTPSession(final String ip, final String helo,
-            final MailAddress sender) {
+    private void setupMockedSMTPSession(final String ip, final String helo) {
         mockedSMTPSession = new AbstractSMTPSession() {
             HashMap state = new HashMap();
 
             HashMap connectionState = new HashMap();
 
+            Mail mail = new FakeMail();
+
+            boolean stopHandler = false;
+
+            public void writeResponse(String respString) {
+                // Do nothing
+            }
+
+            public String getCommandName() {
+                return command;
+            }
+
+            public Mail getMail() {
+                return mail;
+            }
+
             public String getRemoteIPAddress() {
                 return ip;
             }
 
             public Map getState() {
                 state.put(SMTPSession.CURRENT_HELO_NAME, helo);
-                state.put(SMTPSession.SENDER, sender);
                 return state;
             }
 
@@ -162,13 +167,9 @@
                 return relaying;
             }
 
-            public boolean isAuthSupported() {
+            public boolean isAuthRequired() {
                 return false;
             }
-            
-            public String getUser() {
-            return null;
-            }
 
             public int getRcptCount() {
                 return 0;
@@ -178,24 +179,17 @@
                 return connectionState;
             }
 
-        };
-    }
-
-    private void runHandlers(SPFHandler spf, SMTPSession mockedSMTPSession, MailAddress rcpt)
{
-        MailAddress sender = (MailAddress) mockedSMTPSession.getState().get(SMTPSession.SENDER);
-
-        spf.doMail(mockedSMTPSession, sender);
-
-        spf.doRcpt(mockedSMTPSession, sender, rcpt);
+            public void resetConnectionState() {
+                connectionState.clear();
+            }
 
-        spf.onMessage(mockedSMTPSession, mockMail);
+        };
     }
 
     public void testSPFpass() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org",
-                new MailAddress("test@spf1.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf1.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
 
@@ -205,25 +199,14 @@
         
         spf.initialize();
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNull("Not reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNull("Not blocked so no details", 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));
-        assertEquals("header", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_HEADER), mockMail.getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("declined", HookReturnCode.DECLINED, spf.doRcpt(mockedSMTPSession, sender,
rcpt).getResult());
     }
 
     public void testSPFfail() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",
-                new MailAddress("test@spf2.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf2.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -232,23 +215,14 @@
         
         spf.initialize();
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        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));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("fail", HookReturnCode.DENY, spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult());
     }
 
     public void testSPFsoftFail() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
-                new MailAddress("test@spf3.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf3.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -256,26 +230,16 @@
         spf.setDNSService(mockedDnsService);
         
         spf.initialize();
-
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNull("not reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNull("no details ", 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));
-        assertEquals("header", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_HEADER), mockMail.getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
+        
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("softfail declined", HookReturnCode.DECLINED, spf.doRcpt(mockedSMTPSession,
sender, rcpt).getResult());
     }
 
     public void testSPFsoftFailRejectEnabled() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
-                new MailAddress("test@spf3.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf3.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+    	
+        setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -286,23 +250,15 @@
         
         spf.setBlockSoftFail(true);
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNotNull("reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNotNull("details ", 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));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("softfail reject", HookReturnCode.DENY, spf.doRcpt(mockedSMTPSession,
sender, rcpt).getResult());
     }
 
     public void testSPFpermError() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf4.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+    	
+        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -313,23 +269,16 @@
         
         spf.setBlockSoftFail(true);
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNotNull("reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNotNull("details ", 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));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("permerror reject", HookReturnCode.DENY, spf.doRcpt(mockedSMTPSession,
sender, rcpt).getResult());
     }
 
     public void testSPFtempError() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org",
-                new MailAddress("test@spf5.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf5.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+    	
+        setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org");
+        
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -338,23 +287,16 @@
 
         spf.initialize();
         
-        runHandlers(spf, mockedSMTPSession, mailAddress);
 
-        assertNull("no reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNull("no details ", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_DETAIL));
-        assertNotNull("tempError", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_TEMPBLOCKLISTED));
-        assertNotNull("Header should present", mockedSMTPSession.getState()
-                .get(SPFHandler.SPF_HEADER));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("temperror denysoft", HookReturnCode.DENYSOFT, spf.doRcpt(mockedSMTPSession,
sender, rcpt).getResult());
     }
 
     public void testSPFNoRecord() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org",
-                new MailAddress("test@spf6.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf6.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+    	
+        setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -363,66 +305,16 @@
 
         spf.initialize();
         
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNull("no reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNull("no details ", 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));
-        assertEquals("header", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_HEADER), mockMail.getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
-    }
-
-    public void testSPFpermErrorNotRejectPostmaster() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "postmaster@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"));
-        SPFHandler spf = new SPFHandler();
-
-        ContainerUtil.enableLogging(spf, new MockLogger());
-
-        spf.setDNSService(mockedDnsService);
-        
-        spf.initialize();
-        
-        spf.setBlockSoftFail(true);
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        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));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("declined", HookReturnCode.DECLINED, spf.doRcpt(mockedSMTPSession, sender,
rcpt).getResult());
     }
 
-    public void testSPFpermErrorNotRejectAbuse() throws Exception {
-        MailAddress mailAddress = new MailAddress("abuse@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"));
-        SPFHandler spf = new SPFHandler();
-
-        ContainerUtil.enableLogging(spf, new MockLogger());
-        
-        spf.initialize();
-
-        spf.setDNSService(mockedDnsService);
-        spf.setBlockSoftFail(true);
-
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-    }
     
     public void testSPFpermErrorRejectDisabled() throws Exception {
-        MailAddress mailAddress = new MailAddress(
-                                "test@localhost");
-        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
-                new MailAddress("test@spf4.james.apache.org"));
+    	MailAddress sender = new MailAddress("test@spf4.james.apache.org");
+    	MailAddress rcpt = new MailAddress("test@localhost");
+        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org");
         SPFHandler spf = new SPFHandler();
 
         ContainerUtil.enableLogging(spf, new MockLogger());
@@ -433,16 +325,9 @@
         
         spf.setBlockPermError(false);
 
-        runHandlers(spf, mockedSMTPSession, mailAddress);
-
-        assertNull("not reject", mockedSMTPSession.getState().get(
-                SPFHandler.SPF_BLOCKLISTED));
-        assertNull("details ", 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));
+        assertEquals("declined",HookReturnCode.DECLINED, spf.doMail(mockedSMTPSession, sender).getResult());
+        assertEquals("declined", HookReturnCode.DECLINED, spf.doRcpt(mockedSMTPSession, sender,
rcpt).getResult());
     }
+    
    
 }



---------------------------------------------------------------------
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