vdkoogh 2003/12/30 01:42:27
Modified: src_unitTests/org/apache/xml/security/test ModuleTest.java
Added:
src_unitTests/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI
AttributeAncestorOrSelfTest.java
src_unitTests/org/apache/xml/security/test/c14n/implementations
C14NInteropTest.java
Removed: src_unitTests/org/apache/xml/security/test/c14n/implementations
C14NInterop.java
Log:
Renamed some Tests to have Test in the classname.
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.1
xml-security/src_unitTests/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/AttributeAncestorOrSelfTest.java
Index: AttributeAncestorOrSelfTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xml.security.test.external.org.apache.xalan.XPathAPI;
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.XMLUtils;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* This test is to ensure that the owner element of an Attribute is on the
* ancestor-or-self axis.
*
* @author $Author: vdkoogh $
*/
public class AttributeAncestorOrSelfTest extends TestCase {
/** [EMAIL PROTECTED] org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(
AttributeAncestorOrSelfTest.class.getName());
/** Field xercesVerStr */
static String xercesVerStr = XMLUtils.getXercesVersion();
/** Field xalanVerStr */
static String xalanVerStr = XMLUtils.getXalanVersion();
/**
* Method suite
*
*
*/
public static Test suite() {
return new TestSuite(AttributeAncestorOrSelfTest.class);
}
/**
* Constructor AttributeAncestorOrSelf
*
* @param Name_
*/
public AttributeAncestorOrSelfTest(String Name_) {
super(Name_);
}
/**
* Method main
*
* @param args
*/
public static void main(String[] args) {
String[] testCaseName = { "-noloading",
AttributeAncestorOrSelfTest.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
/**
* Process input args and execute the XPath.
*
* @param xmlString
* @param ctxNodeStr
* @param evalStr
*
* @throws Exception
*/
static private boolean isAncestorOf(
String xmlString, String ctxNodeStr, String evalStr)
throws Exception {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setValidating(false);
dfactory.setNamespaceAware(true);
DocumentBuilder db = dfactory.newDocumentBuilder();
Document document =
db.parse(new ByteArrayInputStream(_nodeSetInput1.getBytes()));
Element nscontext = document.createElementNS(null, "nscontext");
nscontext.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds",
"http://www.w3.org/2000/09/xmldsig#");
Node ctxNode = XPathAPI.selectSingleNode(document, ctxNodeStr,
nscontext);
XObject include = XPathAPI.eval(ctxNode, evalStr, nscontext);
return include.bool();
}
//J-
static final String _nodeSetInput1 =
"<?xml version=\"1.0\"?>\n"
+ "<ds:Signature xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>" + "\n"
+ "<ds:Object Id='id1'>" + "\n"
+ "<!-- the comment -->and text"
+ "</ds:Object>" + "\n"
+ "</ds:Signature>";
//J+
/**
* Method test01
*
* @throws Exception
*/
public static void test01() throws Exception {
String ctxNodeStr = "/ds:Signature/ds:Object";
String evalStr = "ancestor-or-self::ds:Signature";
assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " + xalanVerStr,
isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
}
/**
* Method test02
*
* @throws Exception
*/
public static void test02() throws Exception {
String ctxNodeStr = "/ds:Signature/ds:Object/text()";
String evalStr = "ancestor-or-self::ds:Signature";
assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " + xalanVerStr,
isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
}
/**
* Method test03
*
* @throws Exception
*/
public static void test03() throws Exception {
String ctxNodeStr = "/ds:Signature/ds:Object/@Id";
String evalStr = "ancestor-or-self::ds:Object";
assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " + xalanVerStr,
isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
}
static {
org.apache.xml.security.Init.init();
}
}
1.7 +1 -1
xml-security/src_unitTests/org/apache/xml/security/test/ModuleTest.java
Index: ModuleTest.java
===================================================================
RCS file:
/home/cvs/xml-security/src_unitTests/org/apache/xml/security/test/ModuleTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ModuleTest.java 29 Apr 2003 21:36:58 -0000 1.6
+++ ModuleTest.java 30 Dec 2003 09:42:27 -0000 1.7
@@ -31,7 +31,7 @@
suite.addTest(org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315Test.suite());
suite.addTest(org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.suite());
suite.addTest(org.apache.xml.security.test.external.org.apache.xalan.XPathAPI.XalanBug1425Test.suite());
-
suite.addTest(org.apache.xml.security.test.external.org.apache.xalan.XPathAPI.AttributeAncestorOrSelf.suite());
+
suite.addTest(org.apache.xml.security.test.external.org.apache.xalan.XPathAPI.AttributeAncestorOrSelfTest.suite());
suite.addTest(org.apache.xml.security.test.signature.XMLSignatureInputTest.suite());
suite.addTest(org.apache.xml.security.test.transforms.implementations.TransformBase64DecodeTest.suite());
suite.addTest(org.apache.xml.security.test.utils.resolver.ResourceResolverSpiTest.suite());
1.1
xml-security/src_unitTests/org/apache/xml/security/test/c14n/implementations/C14NInteropTest.java
Index: C14NInteropTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xml.security.test.c14n.implementations;
import java.io.File;
import java.util.Iterator;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
import
org.apache.xml.security.c14n.implementations.Canonicalizer20010315OmitComments;
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.test.interop.InteropTest;
import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.transforms.params.XPath2FilterContainer;
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Unit test for [EMAIL PROTECTED]
org.apache.xml.security.c14n.implementations.Canonicalizer20010315WithXPath}
*
* @author Christian Geuer-Pollmann
*/
public class C14NInteropTest extends InteropTest {
/** [EMAIL PROTECTED] org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(C14NInteropTest.class.getName());
/**
* Method suite
*
*
*/
public static Test suite() {
return new TestSuite(C14NInteropTest.class);
}
/**
* Constructor Canonicalizer20010315WithXPathTest
*
* @param Name_
*/
public C14NInteropTest(String Name_) {
super(Name_);
}
/**
* Method main
*
* @param args
*/
public static void main_(String[] args) {
String[] testCaseName = { "-noloading", C14NInteropTest.class.getName()
};
org.apache.xml.security.Init.init();
junit.textui.TestRunner.main(testCaseName);
}
/**
* Method test_Y1
*
* @throws Exception
*/
public void test_Y1() throws Exception {
boolean success = t("data/interop/c14n/Y1", "exc-signature.xml");
assertTrue(success);
}
/**
* Method test_Y2
*
* @throws Exception
*/
public void test_Y2() throws Exception {
boolean success = t("data/interop/c14n/Y2", "signature-joseph-exc.xml");
assertTrue(success);
}
/**
* Method test_Y3
*
* @throws Exception
*/
public void test_Y3() throws Exception {
boolean success = t("data/interop/c14n/Y3", "signature.xml");
assertTrue(success);
}
/**
* Method test_Y4
*
* @throws Exception
*/
public void test_Y4() throws Exception {
boolean success = t("data/interop/c14n/Y4", "signature.xml");
assertTrue(success);
}
/**
* Method _test_Y4_stripped
*
* @throws Exception
*/
public void test_Y4_stripped() throws Exception {
// boolean success = t("data/interop/c14n/Y4", "signatureStripped.xml");
boolean success = t("data/interop/c14n/Y4", "signature.xml");
assertTrue(success);
}
/**
* Method t
*
* @param directory
* @param file
*
* @throws Exception
*/
public boolean t(String directory, String file) throws Exception
{
String basedir = System.getProperty("basedir");
if(basedir != null && !"".equals(basedir)) {
directory = basedir + "/" + directory;
}
File f = new File(directory + "/" + file);
javax.xml.parsers.DocumentBuilderFactory dbf =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse(f);
long start = System.currentTimeMillis();
XMLUtils.circumventBug2650(doc);
long end = System.currentTimeMillis();
log.debug("fixSubtree took " + (int) (end - start));
Element sigElement =
(Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS,
Constants._TAG_SIGNATURE).item(0);
XMLSignature signature = new XMLSignature(sigElement,
f.toURL().toString());
boolean verify =
signature.checkSignatureValue(signature.getKeyInfo().getPublicKey());
int failures = 0;
if (!verify) {
for (int i = 0; i < signature.getSignedInfo().getLength(); i++) {
boolean refVerify =
signature.getSignedInfo().getVerificationResult(i);
if (refVerify) {
log.debug("Reference " + i + " was OK");
} else {
log.debug("Reference " + i + " failed");
failures++;
/*
XMLSignatureInput result =
signature.getSignedInfo()
.getReferencedContentAfterTransformsItem(i);
JavaUtils.writeBytesToFilename("data/temp" + "/c14n-" + i
+ "-apache.txt", result
.getBytes());
*/
}
}
}
return verify;
}
/**
* Method main
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
org.apache.xml.security.Init.init();
javax.xml.parsers.DocumentBuilderFactory dbf =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
String nsA = "http://www.a.com/";
String nsB = "http://www.b.com/";
// String nsC = "http://www.c.com/";
Element A_A = doc.createElementNS(nsA, "A:A");
Element A_B = doc.createElementNS(nsA, "A:B");
Element A_C = doc.createElementNS(null, "C");
// Element A_C = doc.createElementNS(nsC, "A:C");
// Element A_D = doc.createElementNS(nsC, "A:D");
// Element A_E = doc.createElementNS(nsC, "A:E");
A_A.setAttributeNS(Constants.NamespaceSpecNS, "xmlns",
"google://jsdfl/");
A_A.setAttributeNS(Constants.XML_LANG_SPACE_SpecNS, "xml:lang", "de");
A_A.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:A", nsA);
A_A.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:B", nsB);
A_A.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:C",
"http://c.com/");
A_B.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:D",
"http://c.com/");
A_B.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:E",
"http://c.com/");
A_C.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", "");
doc.appendChild(A_A);
A_A.appendChild(A_B);
A_B.appendChild(A_C);
log.debug("Created document");
Canonicalizer20010315OmitComments c = new
Canonicalizer20010315OmitComments();
System.out.println(new String(c.engineCanonicalizeSubTree(doc)));
XMLSignature sig = new XMLSignature(doc, "",
XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
A_A.appendChild(sig.getElement());
Transforms transforms = new Transforms(doc);
XPath2FilterContainer xf2_1 =
XPath2FilterContainer.newInstanceIntersect(doc, "//self::node()[local-name() =
'B']");
transforms.addTransform(Transforms.TRANSFORM_XPATH2FILTER,
xf2_1.getElement());
XPath2FilterContainer xf2_2 =
XPath2FilterContainer.newInstanceSubtract(doc,
"//namespace::*[local-name()='B']");
transforms.addTransform(Transforms.TRANSFORM_XPATH2FILTER,
xf2_2.getElement());
log.info("Created signature object");
sig.addDocument("", transforms);
log.info("Reference added");
sig.sign(sig.createSecretKey("secret".getBytes()));
log.info("Signing finished");
XMLSignatureInput s =
sig.getSignedInfo().getReferencedContentAfterTransformsItem(0);
Set nodes = s.getNodeSet();
Iterator it = nodes.iterator();
while (it.hasNext()) {
Node n = (Node) it.next();
if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
Element e = ((Attr)n).getOwnerElement();
System.out.println("<" + e.getTagName() + " " + n + " />");
} else if (n.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("<" + ((Element)n).getTagName() + " />");
}
}
log.info("finished");
System.out.println("###########################");
System.out.println(new String(s.getBytes()));
}
}