james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r452402 - in /james/jspf/trunk/src: main/java/org/apache/james/jspf/ main/java/org/apache/james/jspf/core/ main/java/org/apache/james/jspf/parser/ main/java/org/apache/james/jspf/terms/ test/java/org/apache/james/jspf/ test/java/org/apache/...
Date Tue, 03 Oct 2006 10:29:28 GMT
Author: bago
Date: Tue Oct  3 03:29:25 2006
New Revision: 452402

URL: http://svn.apache.org/viewvc?view=rev&rev=452402
Log:
Updated rfc4408.yml tests from new.openspf.org (we still pass them)
Introduced an SPFChecker interface to be used for recursive call as a dependency.
Made it possible for SPF to receive an external SPFParser (so we can reuse it)
Optimized tests to reuse a single SPFParser between tests (it is stateless)
Fixed SPF to avoid settingup the FallbackPolicy if not enabled.
Removed few catch(Exception e) in favor of specific exception catches
Changed ipAddr method to avoid throwing NumberFormatException and wrap it in a PermErrorException.
Changed include/redirect to not create a new SPF object but to use the spfProbe (SPFChecker)
service embedded in spf1data.

Added:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java   (with props)
Modified:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/IPAddr.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/SPF1Parser.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
    james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
    james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java Tue Oct  3 03:29:25 2006
@@ -27,6 +27,7 @@
 import org.apache.james.jspf.core.SPF1Constants;
 import org.apache.james.jspf.core.SPF1Data;
 import org.apache.james.jspf.core.SPF1Record;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -44,7 +45,7 @@
  * 
  */
 
-public class SPF {
+public class SPF implements SPFChecker {
 
     private DNSService dnsProbe;
 
@@ -57,7 +58,7 @@
     private boolean useBestGuess = false;
 
     private FallbackPolicy fallBack;
-
+    
     private boolean useTrustedForwarder = false;
     
     /**
@@ -83,11 +84,22 @@
      * @param logger the logger to use
      */
     public SPF(DNSService dnsProbe, Logger logger) {
+        this(dnsProbe, new SPF1Parser(logger), logger);
+    }
+    
+    
+    /**
+     * Uses passed services
+     * 
+     * @param dnsProbe the dns provider
+     * @param parser the parser to use
+     * @param logger the logger to use
+     */
+    public SPF(DNSService dnsProbe, SPF1Parser parser, Logger logger) {
         super();
         this.dnsProbe = dnsProbe;
-        this.parser = new SPF1Parser(logger);
+        this.parser = parser;
         this.log = logger;
-        this.fallBack =  new FallbackPolicy(logger);
     }
 
     /**
@@ -109,7 +121,7 @@
 
         try {
             // Setup the data
-            spfData = new SPF1Data(mailFrom, hostName, ipAddress, dnsProbe);
+            spfData = new SPF1Data(mailFrom, hostName, ipAddress, dnsProbe, this);
             SPFInternalResult res = checkSPF(spfData);
             resultChar = res.getResultChar();
             result = SPF1Utils.resultToName(resultChar);
@@ -142,26 +154,12 @@
     }
 
     /**
-     * Run check for SPF with the given values.
-     * 
-     * @param spfData
-     *             The SPF1Data which should be used to run the check
-     * @return result 
-     *             The SPFInternalResult 
-     * @throws PermErrorException
-     *             Get thrown if an error was detected
-     * @throws NoneException
-     *             Get thrown if no Record was found
-     * @throws TempErrorException
-     *             Get thrown if a DNS problem was detected
-     * @throws NeutralException  
-     *             Get thrown if the result should be neutral
+     * @see org.apache.james.jspf.SPFChecker#checkSPF(org.apache.james.jspf.core.SPF1Data)
      */
     public SPFInternalResult checkSPF(SPF1Data spfData) throws PermErrorException,
             NoneException, TempErrorException, NeutralException {
         SPF1Record spfRecord = null;
-        String result = SPF1Constants.NEUTRAL;
-        String explanation = null;
+        spfData.setCurrentResult(SPF1Constants.NEUTRAL);
         
         // Initial checks (spec 4.3)
         if (spfData.getCurrentDomain() != null) {
@@ -174,7 +172,7 @@
         }
 
         // Get the raw dns txt entry which contains a spf entry
-        String spfDnsEntry = getSpfRecord(dnsProbe,spfData.getCurrentDomain(),
+        String spfDnsEntry = getSpfRecord(spfData.getDnsProbe(),spfData.getCurrentDomain(),
                 SPF1Constants.SPF_VERSION);
 
         // No SPF-Record found
@@ -183,7 +181,7 @@
                 // We should use bestguess
                 spfDnsEntry = SPF1Utils.BEST_GUESS_RECORD;
                 
-            } else if (fallBack.getFallBackEntry(spfData.getCurrentDomain()) != null){
+            } else if (fallBack != null && fallBack.getFallBackEntry(spfData.getCurrentDomain())
!= null){
                 // We should use fallback
                 spfRecord = fallBack.getFallBackEntry(spfData.getCurrentDomain());
                 log.debug("Set FallBack SPF-Record:" +spfRecord.toString());
@@ -194,21 +192,18 @@
 
         // check if the spfRecord was set before
         if (spfRecord == null) {
-            // logging
-            log.debug("Start parsing SPF-Record:" + spfDnsEntry);
-
             spfRecord = parser.parse(spfDnsEntry);
         }
 
         String qualifier = null;
         boolean hasCommand = false;
         Iterator com = null;
-        
+
         // trustedForwarder support is enabled
         if (useTrustedForwarder) {
             com = new TrustedForwarderPolicy(spfRecord.getDirectives(),log).getUpdatedDirectives().iterator();
         } else {
-            // get all commands
+        // get all commands
             com = spfRecord.getDirectives().iterator();
         }
         while (com.hasNext()) {
@@ -236,12 +231,11 @@
 
             if (qualifier != null) {
                 if (qualifier.equals("")) {
-                    result = SPF1Constants.PASS;
+                    spfData.setCurrentResult(SPF1Constants.PASS);
                 } else {
-                    result = qualifier;
+                    spfData.setCurrentResult(qualifier);
                 }
 
-                spfData.setCurrentResult(result);
                 spfData.setMatch(true);
 
                 // If we have a match we should break the while loop
@@ -275,19 +269,17 @@
             }
 
             if (qualifier != null) {
-                result = qualifier;
-
-                spfData.setCurrentResult(result);
+                spfData.setCurrentResult(qualifier);
                 spfData.setMatch(true);
             }
         }
 
         // If no match was found set the result to neutral
         if (!spfData.isMatch() && (hasCommand == true)) {
-            result = SPF1Constants.NEUTRAL;
+            spfData.setCurrentResult(SPF1Constants.NEUTRAL);
         } 
         
-        if (result.equals(SPF1Constants.FAIL)) {  
+        if (SPF1Constants.FAIL.equals(spfData.getCurrentResult())) {  
             if (spfData.getExplanation()==null || spfData.getExplanation().equals("")) {
                 if(defaultExplanation == null) {
                     try {
@@ -306,10 +298,9 @@
                     }
                 }
             }
-            explanation = spfData.getExplanation();
         }
         
-        return new SPFInternalResult(result, explanation);
+        return new SPFInternalResult(spfData.getCurrentResult(), spfData.getExplanation());
     }
 
     /**
@@ -414,6 +405,14 @@
      */
     public FallbackPolicy getFallbackPolicy() {
         return fallBack;
+    }
+    
+    
+    /**
+     * Initialize fallback policy and enable its usage.
+     */
+    public void initializeFallbackPolicy() {
+        this.fallBack =  new FallbackPolicy(this.log);
     }
     
     /**

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/IPAddr.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/IPAddr.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/IPAddr.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/IPAddr.java Tue Oct  3 03:29:25
2006
@@ -95,7 +95,7 @@
             try {
                 getAddress((String) data);
                 return true;
-            } catch (Exception e) {
+            } catch (PermErrorException e) {
                 return false;
             }
         } else {
@@ -186,19 +186,23 @@
     private void stringToInternal(String netAddress) throws PermErrorException {
         netAddress = stripDot(netAddress);
 
-        byte[] bytes = Inet6Util.createByteArrayFromIPAddressString(netAddress);
-
-        if (bytes.length == 4) {
-            for (int i = 0; i < bytes.length; i++) {
-                address[i] = bytes[i];
-            }
-        } else if (bytes.length == 16) {
-            setIP6Defaults();
-            for (int i = 0; i < bytes.length / 2; i++) {
-                address[i] = unsigned(bytes[i * 2]) * 256
-                        + unsigned(bytes[i * 2 + 1]);
+        try {
+            byte[] bytes = Inet6Util.createByteArrayFromIPAddressString(netAddress);
+    
+            if (bytes.length == 4) {
+                for (int i = 0; i < bytes.length; i++) {
+                    address[i] = bytes[i];
+                }
+            } else if (bytes.length == 16) {
+                setIP6Defaults();
+                for (int i = 0; i < bytes.length / 2; i++) {
+                    address[i] = unsigned(bytes[i * 2]) * 256
+                            + unsigned(bytes[i * 2 + 1]);
+                }
+            } else {
+                throw new PermErrorException("Not a valid address: " + netAddress);
             }
-        } else {
+        } catch (NumberFormatException e) {
             throw new PermErrorException("Not a valid address: " + netAddress);
         }
     }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java Tue Oct  3 03:29:25
2006
@@ -38,7 +38,9 @@
 
 public class SPF1Data implements MacroData {
 
-    private DNSService dnsProbe = null;
+    private DNSService dnsProbe;
+
+    private SPFChecker spfProbe;
 
     private String ipAddress = ""; // also used for (i)<sending-host>
 
@@ -92,12 +94,13 @@
      *             Get thrown if no valid emailaddress get passed
      */
     public SPF1Data(String mailFrom, String heloDomain, String clientIP,
-            DNSService dnsProbe) throws PermErrorException, NoneException {
+            DNSService dnsProbe, SPFChecker spfProbe) throws PermErrorException, NoneException
{
         super();
         this.mailFrom = mailFrom.trim();
         this.hostName = heloDomain.trim();
         this.ipAddress = IPAddr.getProperIpAddress(clientIP.trim());
         this.dnsProbe = dnsProbe;
+        this.spfProbe = spfProbe;
 
         try {
             // get the in Address
@@ -408,6 +411,15 @@
      */
     public boolean ignoreExplanation() {
         return ignoreExplanation;
+    }
+
+    /**
+     * Return the SPF checker to be used in recursive lookups
+     * 
+     * @return the spf checker
+     */
+    public SPFChecker getSpfProbe() {
+        return spfProbe;
     }
 
 }

Added: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java?view=auto&rev=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java (added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java Tue Oct  3 03:29:25
2006
@@ -0,0 +1,53 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jspf.core;
+
+import org.apache.james.jspf.SPFInternalResult;
+import org.apache.james.jspf.exceptions.NeutralException;
+import org.apache.james.jspf.exceptions.NoneException;
+import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.exceptions.TempErrorException;
+
+/**
+ * Interface for the SPFChecker service.
+ */
+public interface SPFChecker {
+
+    /**
+     * Run check for SPF with the given values.
+     * 
+     * @param spfData
+     *             The SPF1Data which should be used to run the check
+     * @return result 
+     *             The SPFInternalResult 
+     * @throws PermErrorException
+     *             Get thrown if an error was detected
+     * @throws NoneException
+     *             Get thrown if no Record was found
+     * @throws TempErrorException
+     *             Get thrown if a DNS problem was detected
+     * @throws NeutralException  
+     *             Get thrown if the result should be neutral
+     */
+    public SPFInternalResult checkSPF(SPF1Data spfData)
+            throws PermErrorException, NoneException, TempErrorException,
+            NeutralException;
+
+}
\ No newline at end of file

Propchange: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPFChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/SPF1Parser.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/SPF1Parser.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/SPF1Parser.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/SPF1Parser.java Tue Oct  3
03:29:25 2006
@@ -339,14 +339,14 @@
         if (log.isDebugEnabled()) {
             log.debug("Parsing catch group positions: Modifiers["
                     + TERM_STEP_REGEX_MODIFIER_POS + "] Qualifier["
-                    + TERM_STEP_REGEX_QUALIFIER_POS + " Mechanism["
+                    + TERM_STEP_REGEX_QUALIFIER_POS + "] Mechanism["
                     + TERM_STEP_REGEX_MECHANISM_POS + "]");
             for (int k = 0; k < matchResultPositions.size(); k++) {
                 log
                         .debug(k
                                 + ") "
                                 + (matchResultPositions.get(k) != null ? ((TermDef) matchResultPositions
-                                        .get(k)).getPattern()
+                                        .get(k)).getPattern().pattern()
                                         : null));
             }
         }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java Tue Oct  3
03:29:25 2006
@@ -94,8 +94,9 @@
                 }
 
             }
+        // PermError / TempError
         } catch (Exception e) {
-            e.printStackTrace();
+            log.debug("No valid ipAddress: ",e);
             throw new PermErrorException("No valid ipAddress: "
                     + spfData.getIpAddress());
         }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java Tue Oct
 3 03:29:25 2006
@@ -53,16 +53,13 @@
         spfData.setCurrentDepth(spfData.getCurrentDepth() + 1);
 
         String host = expandHost(spfData);
-        try {
-            host = new MacroExpand(spfData, log).expandDomain(host);
-        } catch (Exception e) {
-            throw new PermErrorException(e.getMessage());
-        }
+
+        // throws a PermErrorException that we can pass through
+        host = new MacroExpand(spfData, log).expandDomain(host);
 
         try {
             aRecords = spfData.getDnsProbe().getRecords(host,DNSService.A);
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (DNSService.TimeoutException e) {
             return false;
         }
        
@@ -72,6 +69,13 @@
 
         // No match found
         return false;
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "exists:"+getDomain();
     }
 
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java Tue Oct
 3 03:29:25 2006
@@ -67,12 +67,8 @@
         if (host == null) {
             host = spfData.getCurrentDomain();
         } else {
-            try {
-                host = new MacroExpand(spfData, log).expandDomain(host);
-
-            } catch (Exception e) {
-                throw new PermErrorException(e.getMessage());
-            }
+            // throws a PermErrorException that we cat pass through
+            host = new MacroExpand(spfData, log).expandDomain(host);
         }
         return host;
     }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java Tue Oct
 3 03:29:25 2006
@@ -20,7 +20,6 @@
 
 package org.apache.james.jspf.terms;
 
-import org.apache.james.jspf.SPF;
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.LogEnabled;
 import org.apache.james.jspf.core.Logger;
@@ -68,38 +67,46 @@
         // update currentDepth
         spfData.setCurrentDepth(spfData.getCurrentDepth() + 1);      
         
-        try {
-            host = new MacroExpand(spfData, log).expandDomain(host);
-        } catch (PermErrorException e) {
-            throw new PermErrorException("Error in include modifier: " + host);
-        }
-            
-        spfData.setCurrentDomain(host);
-        
-        // On includes we should not use the explanation of the included domain
-        spfData.setIgnoreExplanation(true);
+        // throws a PermErrorException that we can pass through
+        host = new MacroExpand(spfData, log).expandDomain(host);
+
+        String prevRes = spfData.getCurrentResult();
+        String prevHost = spfData.getCurrentDomain();
         
-        String res = null;
         try {
-             res = new SPF(spfData.getDnsProbe(),log).checkSPF(spfData).getResultChar();
-          
-        } catch (NoneException e) {
-            throw new PermErrorException("included checkSPF returned NoneException");
-        } catch (NeutralException e) {
-            throw new PermErrorException("included checkSPF returned NeutralException");
-        }
-        
-        // Reset the ignore
-        spfData.setIgnoreExplanation(false);
-        
-        if (res == null) {
-            throw new TempErrorException("included checkSPF returned null");
-        } else if (res.equals(SPF1Constants.PASS)) {
-            return true;
-        } else if (res.equals(SPF1Constants.FAIL) || res.equals(SPF1Constants.SOFTFAIL) ||
res.equals(SPF1Constants.NEUTRAL)) {
-            return false;
-        } else {
-            throw new TempErrorException("included checkSPF returned an Illegal result");
+    
+            spfData.setCurrentDomain(host);
+            
+            // On includes we should not use the explanation of the included domain
+            spfData.setIgnoreExplanation(true);
+            
+    
+            
+            String res = null;
+            try {
+                 res = spfData.getSpfProbe().checkSPF(spfData).getResultChar();
+              
+            } catch (NoneException e) {
+                throw new PermErrorException("included checkSPF returned NoneException");
+            } catch (NeutralException e) {
+                throw new PermErrorException("included checkSPF returned NeutralException");
+            }
+            
+            // Reset the ignore
+            spfData.setIgnoreExplanation(false);
+            
+            if (res == null) {
+                throw new TempErrorException("included checkSPF returned null");
+            } else if (res.equals(SPF1Constants.PASS)) {
+                return true;
+            } else if (res.equals(SPF1Constants.FAIL) || res.equals(SPF1Constants.SOFTFAIL)
|| res.equals(SPF1Constants.NEUTRAL)) {
+                return false;
+            } else {
+                throw new TempErrorException("included checkSPF returned an Illegal result");
+            }
+        } finally {
+            spfData.setCurrentDomain(prevHost);
+            spfData.setCurrentResult(prevRes);
         }
             
     }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java Tue Oct
 3 03:29:25 2006
@@ -20,7 +20,6 @@
 
 package org.apache.james.jspf.terms;
 
-import org.apache.james.jspf.SPF;
 import org.apache.james.jspf.core.LogEnabled;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPF1Data;
@@ -67,20 +66,14 @@
             // update currentDepth
             spfData.setCurrentDepth(spfData.getCurrentDepth() + 1);
 
-            try {
-                host = new MacroExpand(spfData, log).expandDomain(host);
-            } catch (Exception e) {
-                throw new PermErrorException("Error in redirect modifier: "
-                        + host);
-            }
+            // throws a PermErrorException that we can pass through
+            host = new MacroExpand(spfData, log).expandDomain(host);
 
             spfData.setCurrentDomain(host);
 
             String res = null;
             try {
-                res = new SPF(spfData.getDnsProbe(),log).checkSPF(spfData).getResultChar();
-                
-
+                res = spfData.getSpfProbe().checkSPF(spfData).getResultChar();
             } catch (NoneException e) {
                 // no spf record assigned to the redirect domain
                 throw new PermErrorException(

Modified: james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java (original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java Tue Oct  3
03:29:25 2006
@@ -20,6 +20,7 @@
 package org.apache.james.jspf;
 
 import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.parser.SPF1Parser;
 import org.jvyaml.Constructor;
 import org.jvyaml.DefaultYAMLFactory;
 import org.jvyaml.YAMLFactory;
@@ -40,6 +41,8 @@
 
     SPFYamlTestSuite data;
     String test;
+    protected SPF spf;
+    protected static SPF1Parser parser;
 
     protected AbstractYamlTest(SPFYamlTestSuite def, String test) {
         super(def.getComment()+" #"+test);
@@ -112,8 +115,12 @@
         
         System.out.println("testing "+next+": "+currentTest.get("description"));
     
-        SPF spf = new SPF(new LoggingDNSService(getDNSService()), new ConsoleLogger());
-        
+        if (parser == null) {
+            parser = new SPF1Parser(new ConsoleLogger());
+            System.err.println("--------------------------------------------");
+        }
+        spf = new SPF(new LoggingDNSService(getDNSService()), parser, new ConsoleLogger());
+
         String ip = null;
         String sender = null;
         String helo = null;

Modified: james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java (original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java Tue Oct  3
03:29:25 2006
@@ -30,7 +30,7 @@
      * Test method for 'org.apache.james.jspf.core.SPF1Data.getMacroIpAddress()'
      */
     public void testGetMacroIpAddress() throws PermErrorException, NoneException {
-        SPF1Data d = new SPF1Data("mailfrom@fromdomain.com","helodomain.com","2001:DB8::CB01",
null);
+        SPF1Data d = new SPF1Data("mailfrom@fromdomain.com","helodomain.com","2001:DB8::CB01",
null, null);
         assertEquals("2.0.0.1.0.D.B.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.C.B.0.1",d.getMacroIpAddress());
     }
 

Modified: james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml?view=diff&rev=452402&r1=452401&r2=452402
==============================================================================
--- james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml (original)
+++ james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml Tue Oct  3
03:29:25 2006
@@ -1092,7 +1092,6 @@
       p	= the validated domain name of <ip>
     comment: >-
       If a subdomain of the <domain> is present, it SHOULD be used.  
-      Need preferred, acceptable explanations to test this.
     helo: msgbas2x.cos.example.com
     host: CAFE:BABE::3
     mailfrom: test@e6.example.com
@@ -1104,11 +1103,20 @@
       p	= the validated domain name of <ip>
     comment: >-
       If a subdomain of the <domain> is present, it SHOULD be used.  
-      Need preferred, acceptable explanations to test this.
     helo: msgbas2x.cos.example.com
     host: 192.168.218.42
     mailfrom: test@e7.example.com
-    result: [ pass, neutral ]
+    result: [ pass, softfail ]
+  upper-macro:
+    spec: 8.1/26
+    description: >-
+      Uppercased macros expand exactly as their lowercased equivalents, 
+      and are then URL escaped.
+    helo: msgbas2x.cos.example.com
+    host: 192.168.218.42
+    mailfrom: jack&jill=up@e8.example.com
+    result: fail
+    explanation: http://example.com/why.html?l=jack%26jill%3Dup
 zonedata:
   example.com.d.spf.example.com:
     - SPF: v=spf1 redirect=a.spf.example.com
@@ -1164,11 +1172,15 @@
   mx.e7.example.com:
     - A: 192.168.218.42
   mx.e7.example.com.should.example.com:
-    - A: 192.168.218.42
+    - A: 127.0.0.2
   mx.example.com.ok.example.com:
-    - A: 192.168.218.42
+    - A: 127.0.0.2
   e7.example.com:
-    - SPF: v=spf1 exists:%{p}.should.example.com ?exists:%{p}.ok.example.com -all
+    - SPF: v=spf1 exists:%{p}.should.example.com ~exists:%{p}.ok.example.com
+  e8.example.com:
+    - SPF: v=spf1 -all exp=msg8.%{D2}
+  msg8.example.com:
+    - TXT: "http://example.com/why.html?l=%{L}"
 
 ---
 description: >-



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