Author: norman
Date: Mon Aug 21 10:34:25 2006
New Revision: 433297

URL: http://svn.apache.org/viewvc?rev=433297&view=rev
Log:
Fix a bug in which the Exception in PTRMechanism was not catched correctly. See 
JSPF-23

Modified:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
    
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1TestMockDNSService.java
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/test.txt

Modified: 
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL: 
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?rev=433297&r1=433296&r2=433297&view=diff
==============================================================================
--- 
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java 
(original)
+++ 
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java 
Mon Aug 21 10:34:25 2006
@@ -43,47 +43,51 @@
             + SPF1Parser.DOMAIN_SPEC_REGEX + ")?";
 
     /**
-     * @see 
org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPF1Data)
+     * @see 
org.apache.james.jspf.core.Mechanism#run(org.apache.james.jspf.core.SPF1Data)
      */
     public boolean run(SPF1Data spfData) throws PermErrorException,
-            TempErrorException, NoneException {
+            TempErrorException {
         String compareDomain;
         IPAddr compareIP;
         ArrayList validatedHosts = new ArrayList();
 
-        // update currentDepth
-        spfData.setCurrentDepth(spfData.getCurrentDepth() + 1);
+        try { 
+            // update currentDepth
+            spfData.setCurrentDepth(spfData.getCurrentDepth() + 1);
 
-        // Get the right host.
-        String host = expandHost(spfData);
+            // Get the right host.
+            String host = expandHost(spfData);
 
         
-        // Get PTR Records for the ipAddress which is provided by SPF1Data
-        List domainList = spfData.getDnsProbe().getPTRRecords(
-                spfData.getIpAddress());
-        for (int i = 0; i < domainList.size(); i++) {
-
-            // Get a record for this
-            List aList = spfData.getDnsProbe().getARecords(
-                    (String) domainList.get(i), 32);
-            for (int j = 0; j < aList.size(); j++) {
-                compareIP = (IPAddr) aList.get(j);
-                if (compareIP.toString().equals(spfData.getIpAddress())) {
-                    validatedHosts.add(domainList.get(i));
+            // Get PTR Records for the ipAddress which is provided by SPF1Data
+            List domainList = spfData.getDnsProbe().getPTRRecords(
+                    spfData.getIpAddress());
+            for (int i = 0; i < domainList.size(); i++) {
+
+                // Get a record for this
+                List aList = spfData.getDnsProbe().getARecords(
+                        (String) domainList.get(i), 32);
+                for (int j = 0; j < aList.size(); j++) {
+                    compareIP = (IPAddr) aList.get(j);
+                    if (compareIP.toString().equals(spfData.getIpAddress())) {
+                        validatedHosts.add(domainList.get(i));
+                    }
                 }
             }
-        }
 
-        // Check if we match one of this ptr!
-        for (int j = 0; j < validatedHosts.size(); j++) {
-            compareDomain = (String) validatedHosts.get(j);
-            if (compareDomain.equals(host)
-                    || compareDomain.endsWith("." + host)) {
-                return true;
+            // Check if we match one of this ptr!
+            for (int j = 0; j < validatedHosts.size(); j++) {
+                compareDomain = (String) validatedHosts.get(j);
+                if (compareDomain.equals(host)
+                        || compareDomain.endsWith("." + host)) {
+                    return true;
+                }
             }
+        } catch (NoneException e) {
+            // No PTR record found    
+            return false;    
         }
         
-
         return false;
 
     }

Modified: 
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1TestMockDNSService.java
URL: 
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1TestMockDNSService.java?rev=433297&r1=433296&r2=433297&view=diff
==============================================================================
--- 
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1TestMockDNSService.java
 (original)
+++ 
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1TestMockDNSService.java
 Mon Aug 21 10:34:25 2006
@@ -81,6 +81,8 @@
                 return "v=spf1 +a:myipv6a.record -all";
             if ("spf22-test.foo.bar".equals(hostname))
                 throw new TempErrorException("DNS Server returns temperror");  
        
+            if ("spf23-test.foo.bar".equals(hostname))
+                return "v=spf1 ptr -all";
         }
         throw new IllegalStateException("Mock data not available");
     }
@@ -117,6 +119,8 @@
 
     public List getPTRRecords(String ipAddress) throws PermErrorException,
             NoneException, TempErrorException {
+        if (ipAddress.equals("10.0.0.1")) 
+            throw new NoneException("No PTR rrecord");
         throw new IllegalStateException("Mock data not available");
     }
 

Modified: james/jspf/trunk/src/test/resources/org/apache/james/jspf/test.txt
URL: 
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/resources/org/apache/james/jspf/test.txt?rev=433297&r1=433296&r2=433297&view=diff
==============================================================================
--- james/jspf/trunk/src/test/resources/org/apache/james/jspf/test.txt 
(original)
+++ james/jspf/trunk/src/test/resources/org/apache/james/jspf/test.txt Mon Aug 
21 10:34:25 2006
@@ -155,3 +155,11 @@
 smtp-comment    /.*/ 
 header-comment  /.*/ spfquery:
 received-spf    /.*/ Received-SPF:
+
+spfquery -ip=10.0.0.1 -sender=spf23-test.foo.bar -helo=spf23-test.foo.bar
+result          /.*/ fail
+smtp-comment    /.*/ 
+header-comment  /.*/ spfquery:
+received-spf    /.*/ Received-SPF:
+explanation     /.*/ 
http://www.openspf.org/why.html?sender=spf23-test.foo.bar&ip=10.0.0.1
+



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to