Use Cannonicalized serialization for the compare tests
authorgilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 16 May 2005 16:43:29 +0000 (16:43 +0000)
committergilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 16 May 2005 16:43:29 +0000 (16:43 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1485 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/xml/Parser.java
tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java

index 5c679b0..b10639b 100644 (file)
@@ -46,6 +46,9 @@ import javax.xml.transform.stream.StreamResult;
 import javax.xml.validation.Schema;
 
 import org.apache.log4j.Logger;
+import org.apache.xml.security.c14n.CanonicalizationException;
+import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.c14n.InvalidCanonicalizerException;
 import org.opensaml.SAMLException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -220,6 +223,32 @@ public class Parser {
     }
     
     /**
+     *  Serializes the XML representation of the SAML object to a stream
+     *
+     * @param  out                      Stream to use for output
+     * @exception  java.io.IOException  Raised if an I/O problem is detected
+     * @exception  SAMLException Raised if the object is incompletely defined 
+     */
+    public static String serializeC14N(Node root){
+       byte[] bs = null;
+        try
+        {
+            Canonicalizer c = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
+            bs = c.canonicalizeSubtree(root, "#default saml samlp ds xsd xsi code kind rw typens");
+        }
+        catch (InvalidCanonicalizerException e)
+        {
+            return null;
+        }
+        catch (CanonicalizationException e)
+        {
+            return null;
+        }
+        return new String(bs);
+    }
+
+    
+    /**
      * Version of loadDom where the file is specified as a resource name
      * 
      * @param configFilePath input resource
index d083c15..823725b 100755 (executable)
@@ -516,9 +516,9 @@ public class ArpTests extends TestCase {
 
                        InputStream inStream = new FileInputStream("data/arp.site.xml");
                        parser.parse(new InputSource(inStream));
-                       String directXML = Parser.serialize(parser.getDocument().getDocumentElement());
+                       String directXML = Parser.serializeC14N(parser.getDocument().getDocumentElement());
 
-                       String processedXML = Parser.serialize(siteArp.unmarshall());
+                       String processedXML = Parser.serializeC14N(siteArp.unmarshall());
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct site ARP.",
@@ -529,9 +529,9 @@ public class ArpTests extends TestCase {
 
                        inStream = new FileInputStream("data/arp.user.test.xml");
                        parser.parse(new InputSource(inStream));
-                       directXML = Parser.serialize(parser.getDocument().getDocumentElement());
+                       directXML = Parser.serializeC14N(parser.getDocument().getDocumentElement());
 
-                       processedXML = Parser.serialize(userArp.unmarshall());
+                       processedXML = Parser.serializeC14N(userArp.unmarshall());
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct user ARP.",
@@ -664,12 +664,12 @@ public class ArpTests extends TestCase {
 
                                InputStream inStream = new FileInputStream(arpExamples[i]);
                                parser.parse(new InputSource(inStream));
-                               String directXML = Parser.serialize(parser.getDocument().getDocumentElement());
+                               String directXML = Parser.serializeC14N(parser.getDocument().getDocumentElement());
 
                                Arp arp1 = new Arp();
                                arp1.marshall(parser.getDocument().getDocumentElement());
 
-                               String processedXML = Parser.serialize(arp1.unmarshall());
+                               String processedXML = Parser.serializeC14N(arp1.unmarshall());
 
                                assertTrue(
                                        "Round trip marshall/unmarshall failed for file (" + arpExamples[i] + ")",