Author: bago
Date: Wed Nov 15 02:31:40 2006
New Revision: 475183

URL: http://svn.apache.org/viewvc?view=rev&rev=475183
Log:
Updated openspf yaml tests to current trunk and fixed a couple of bugs in JSpf 
testsuite:
1) mocked dns server was case sensitive in search => changed to use lowercase 
hosts
2) mocked dns server did not support CNAMEs

Modified:
    james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml

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=475183&r1=475182&r2=475183
==============================================================================
--- 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 
Wed Nov 15 02:31:40 2006
@@ -41,6 +41,8 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
@@ -58,7 +60,6 @@
         this.test = test;
     }
 
-
     protected abstract String getFilename();
 
     protected List internalLoadTests(String filename) throws IOException {
@@ -250,6 +251,10 @@
         }
 
         public List getRecords(String hostname, int recordType) throws 
TimeoutException {
+            return getRecords(hostname, recordType, 6);
+        }
+
+        public List getRecords(String hostname, int recordType, int depth) 
throws TimeoutException {
             String type = getRecordTypeDescription(recordType);
 
             List res;
@@ -257,6 +262,9 @@
             // remove trailing dot before running the search.
             if (hostname.endsWith(".")) hostname = hostname.substring(0, 
hostname.length()-1);
             
+            // dns search lowercases:
+            hostname = hostname.toLowerCase(Locale.US);
+            
             if (zonedata.get(hostname) != null) {
                 List l = (List) zonedata.get(hostname);
                 Iterator i = l.iterator();
@@ -281,6 +289,9 @@
                                 res.add((String) hm.get(type));
                             }
                         }
+                        if (hm.get("CNAME") != null && depth > 0) {
+                            return getRecords((String) hm.get("CNAME"), 
recordType, depth - 1);
+                        }
                     } else if ("TIMEOUT".equals(o)) {
                         throw new TimeoutException();
                     } else {
@@ -316,18 +327,18 @@
     protected static class SPFYamlTestSuite {
         public String comment;
         public HashMap tests;
-        public HashMap zonedata;
+        private HashMap zonedata;
         public String getComment() {
             return comment;
         }
         
         public SPFYamlTestSuite(HashMap source, int i) {
-            this.comment = (String) source.get("description");
-            if (this.comment == null) {
-                this.comment = "Test #"+i; 
+            this.setComment((String) source.get("description"));
+            if (this.getComment() == null) {
+                this.setComment("Test #"+i); 
             }
-            this.tests = (HashMap) source.get("tests");
-            this.zonedata = (HashMap) source.get("zonedata");
+            this.setTests((HashMap) source.get("tests"));
+            this.setZonedata((HashMap) source.get("zonedata"));
         }
         
         public void setComment(String comment) {
@@ -343,7 +354,13 @@
             return zonedata;
         }
         public void setZonedata(HashMap zonedata) {
-            this.zonedata = zonedata;
+            this.zonedata = new HashMap();
+            Set keys = zonedata.keySet();
+            for (Iterator i = keys.iterator(); i.hasNext(); ) {
+                String hostname = (String) i.next();
+                String lowercase = hostname.toLowerCase(Locale.US);
+                this.zonedata.put(lowercase, zonedata.get(hostname));
+            }
         }
     }
 

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=475183&r1=475182&r2=475183
==============================================================================
--- 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 
Wed Nov 15 02:31:40 2006
@@ -52,11 +52,11 @@
     - TIMEOUT
   example.net:
     - SPF:  v=spf1 -all exp=exp.example.net
-  A.example.net:
+  a.example.net:
     - SPF:  v=spf1 -all exp=exp.example.net
   exp.example.net:
     - TXT:  '%{l}'
-  A12345678901234567890123456789012345678901234567890123456789012.example.com:
+  a12345678901234567890123456789012345678901234567890123456789012.example.com:
     - SPF:  v=spf1 -all
 ---
 description: Record lookup
@@ -108,6 +108,18 @@
     host: 1.2.3.4
     mailfrom: [EMAIL PROTECTED]
     result: temperror
+  cname-support:
+    description: CNAME RRs must be followed
+    helo: mail.example.net
+    host: 1.2.3.4
+    mailfrom: [EMAIL PROTECTED]
+    result: fail
+  cname-loop-detection:
+    description: CNAME loops must be detected
+    helo: mail.example.net
+    host: 1.2.3.4
+    mailfrom: [EMAIL PROTECTED]
+    result: none
 zonedata:
   both.example.net:
     - TXT:  v=spf1 -all
@@ -126,7 +138,10 @@
     - TIMEOUT
   alltimeout.example.net:
     - TIMEOUT
-
+  alias.example.net:
+    - CNAME: both.example.net
+  cname-loop.example.net:
+    - CNAME: cname-loop.example.net
 ---
 description: Selecting records
 tests:
@@ -322,7 +337,7 @@
       encoded for sending to a name server, so resolver must give error
       or empty result.  Empty result is analogous to 4.3/1, and so
       is preferred.
-    spec: 8.1/2, 5/10
+    spec: [8.1/2, 5/10]
     helo: mail.example.com
     host: 1.2.3.4
     mailfrom: [EMAIL PROTECTED]
@@ -336,7 +351,7 @@
       Long labels cannot be coded in a DNS query packet, so resolver must
       give error or empty result.  Empty result is analogous to 4.3/1,
       and so is preferred.
-    spec: 8.1/2, 5/10
+    spec: [8.1/2, 5/10]
     helo: "%%%%%%%%%%%%%%%%%%%%%%"
     host: 1.2.3.4
     mailfrom: [EMAIL PROTECTED]
@@ -366,10 +381,8 @@
     - SPF: v=spf1 a:mail.example...com -all
   t11.example.com:
     - SPF: v=spf1 a:%{H}.bar -all
-
 ---
-description: >-
-  ALL mechanism syntax
+description: ALL mechanism syntax
 tests:
   all-dot:
     description: |
@@ -428,10 +441,8 @@
     - SPF: v=spf1 ?all
   e5.example.com:
     - SPF: v=spf1 all -all
-
 ---
-description: >-
-  PTR mechanism syntax
+description: PTR mechanism syntax
 tests:
   ptr-cidr:
     description: |-
@@ -498,10 +509,8 @@
     - AAAA: CAFE:BABE::1
   e4.example.com:
     - SPF: v=spf1 ptr -all
-  
 ---
-description: >-
-  A mechanism syntax
+description: A mechanism syntax
 tests:
   a-cidr6:
     description: |
@@ -558,7 +567,7 @@
     result: permerror
   a-nxdomain:
     description: >-
-      If no ips are returned, A mechanism doesn't match, even with /0.
+      If no ips are returned, A mechanism does not match, even with /0.
     spec: 5.3/3
     helo: mail.example.com
     host: 1.2.3.4
@@ -705,10 +714,8 @@
     - A: 1.2.3.4
   e12.example.com:
     - SPF: v=spf1 a:example.-com
-
 ---
-description: >-
-  include semantics and syntax
+description: Include mechanism semantics and syntax
 tests:
   include-fail:
     description: >-
@@ -776,7 +783,6 @@
   ip7.example.com:
     - SPF: v=spf1 ip4:1.2.3.7 ?all
   ip8.example.com:
-    - SPF: v=spf1 a -all
     - TIMEOUT
   erehwon.example.com:
     - TXT: v=spfl am not an SPF record
@@ -794,10 +800,8 @@
     - SPF: v=spf1 include +all
   e7.example.com:
     - SPF: v=spf1 include:erehwon.example.com -all
-
 ---
-description: >-
-  MX mechanism syntax
+description: MX mechanism syntax
 tests:
   mx-cidr6:
     description: |
@@ -854,7 +858,7 @@
     result: permerror
   mx-nxdomain:
     description: >-
-      If no ips are returned, MX mechanism doesn't match, even with /0.
+      If no ips are returned, MX mechanism does not match, even with /0.
     spec: 5.4/3
     helo: mail.example.com
     host: 1.2.3.4
@@ -958,7 +962,7 @@
     spec: 5.4/3
     helo: mail.example.com
     host: 1.2.3.4
-    mailfrom: ''
+    mailfrom: ""
     result: neutral
   mx-implicit:
     description: >-
@@ -973,7 +977,7 @@
 zonedata:
   mail.example.com:
     - A: 1.2.3.4
-    - MX: [0, '']
+    - MX: [0, ""]
     - SPF: v=spf1 mx
   e1.example.com:
     - SPF: v=spf1 mx/0 -all
@@ -1020,10 +1024,8 @@
     - A: 1.2.3.4
   e12.example.com:
     - SPF: v=spf1 mx:example.-com
-
 ---
-description: >-
-  IP4 mechanism syntax
+description: IP4 mechanism syntax
 tests:
   cidr4-0:
     description: >-
@@ -1129,10 +1131,8 @@
     - SPF: v=spf1 ip4:1.2.3.4:8080
   e9.example.com:
     - SPF: v=spf1 ip4:1.2.3
-
 ---
-description: >-
-  IP6 mechanism syntax
+description: IP6 mechanism syntax
 comment: >-
   IP4 only implementations may skip tests where host is not IP4
 tests:
@@ -1229,11 +1229,11 @@
     - SPF: v=spf1 ip6:CAFE:BABE:8000::/33
   e6.example.com:
     - SPF: v=spf1 ip6::CAFE::BABE
-  
 ---
-description: >-
-  Semantics of exp and other modifiers.  Implementing exp= is optional.  If not
-  implemented, the test driver should not check the explanation field.
+description: Semantics of exp and other modifiers
+comment: >-
+  Implementing exp= is optional.  If not implemented, the test driver should
+  not check the explanation field.
 tests:
   redirect-none:
     description: >-
@@ -1295,7 +1295,7 @@
   dorky-sentinel:
     description: >-
       An implementation that uses a legal expansion as a sentinel.  We
-      can't check them all, but we can check this one.
+      cannot check them all, but we can check this one.
     comment: >-
       Spaces are allowed in local-part.
     spec: 8.1/6
@@ -1346,8 +1346,7 @@
   e10.example.com:
     - SPF: v=spf1 redirect=erehwon.example.com
 ---
-description: |
-  check macro expansion rules
+description: Macro expansion rules
 tests:
   trailing-dot-domain:
     spec: 8.1/16
@@ -1514,7 +1513,7 @@
     comment: >-
       Domain-spec must end in either a macro, or a valid toplabel.
       It is not correct to check syntax after macro expansion.
-    helo: JUMPIN' JUPITER
+    helo: "JUMPIN' JUPITER"
     host: 192.168.218.40
     mailfrom: [EMAIL PROTECTED]
     result: fail
@@ -1596,10 +1595,8 @@
     - SPF: v=spf1 -include:_spfh.%{d2} ip4:1.2.3.0/24 -all
   _spfh.example.com:
     - SPF: v=spf1 -a:%{h} +all
-
 ---
-description: >-
-  Processing limits
+description: Processing limits
 tests:
   redirect-loop:
     description: >-
@@ -1625,7 +1622,7 @@
     comment: >-
       The required result for this test was the subject of much
       controversy.  Many felt that the RFC *should* have specified
-      permerror, but the concensus was that it failed to actually do so.
+      permerror, but the consensus was that it failed to actually do so.
       The preferred result reflects evaluating the 10 allowed MX records in the
       order returned by the test data - or sorted via priority.
       If testing with live DNS, the MX order may be random, and a pass
@@ -1641,7 +1638,7 @@
       there MUST be a limit of no more than 10 PTR looked up and checked.
     comment: >-
       The result of this test cannot be permerror not only because the
-      RFC doesn't specify it, but because the sender has no control over
+      RFC does not specify it, but because the sender has no control over
       the PTR records of spammers.
       The preferred result reflects evaluating the 10 allowed PTR records in
       the order returned by the test data.
@@ -1667,7 +1664,7 @@
       SPF implementations MUST limit the number of mechanisms and modifiers 
       that do DNS lookups to at most 10 per SPF check.
     comment: >-
-      We don't check whether an implementation counts mechanisms before
+      We do not check whether an implementation counts mechanisms before
       or after evaluation.  The RFC is not clear on this.
     spec: 10.1/6
     helo: mail.example.com
@@ -1744,4 +1741,4 @@
   inc.example.com:
     - SPF: v=spf1 a a a a a a a a
   e9.example.com:
-    - SPF: v=spf1 a include:inc.example.com a ip4:1.2.3.4 -all
\ No newline at end of file
+    - SPF: v=spf1 a include:inc.example.com a ip4:1.2.3.4 -all



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

Reply via email to