|
From: <pe...@us...> - 2004-01-13 23:38:02
|
Update of /cvsroot/neuclear/neuclear-xmlsig/src/test/org/neuclear/xml/xmlsec
In directory sc8-pr-cvs1:/tmp/cvs-serv25308/src/test/org/neuclear/xml/xmlsec
Modified Files:
SimpleXMLSigTest.java
Added Files:
RefTest.java XMLSignerTest.java
Log Message:
Refactoring parts of the core of XMLSignature. There shouldnt be any real API changes.
--- NEW FILE: RefTest.java ---
package org.neuclear.xml.xmlsec;
import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.neuclear.commons.crypto.CryptoException;
import org.neuclear.xml.XMLException;
import java.io.File;
import java.net.MalformedURLException;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: RefTest.java,v 1.1 2004/01/13 23:37:59 pelle Exp $
$Log: RefTest.java,v $
Revision 1.1 2004/01/13 23:37:59 pelle
Refactoring parts of the core of XMLSignature. There shouldnt be any real API changes.
*/
/**
* User: pelleb
* Date: Jan 13, 2004
* Time: 9:49:09 PM
*/
public class RefTest extends TestCase {
public RefTest(String string) {
super(string);
}
public void testExternalReference() throws XMLException, CryptoException, MalformedURLException {
File rfile=new File("src/testdata/homegrown/signature-enveloped-rsa.xml");
final String uri = rfile.toURL().toExternalForm();
Reference ref=new Reference(uri);
assertNotNull(ref);
assertNotNull(ref.getDigest());
assertEquals(uri,ref.getUri());
System.out.println(ref.asXML());
}
public void testEnvelopedReference() throws DocumentException, XMLException, CryptoException {
Document doc=DocumentHelper.parseText("<test id=\"one\">hello</test>");
Reference ref=new Reference(doc.getRootElement(),Reference.XMLSIGTYPE_ENVELOPED);
assertNotNull(ref);
assertNotNull(ref.getDigest());
assertEquals("#one",ref.getUri());
System.out.println(ref.asXML());
}
}
--- NEW FILE: XMLSignerTest.java ---
package org.neuclear.xml.xmlsec;
import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
import org.neuclear.commons.crypto.signers.InvalidPassphraseException;
import org.neuclear.commons.crypto.signers.NonExistingSignerException;
import org.neuclear.commons.crypto.signers.TestCaseSigner;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: XMLSignerTest.java,v 1.1 2004/01/13 23:37:59 pelle Exp $
$Log: XMLSignerTest.java,v $
Revision 1.1 2004/01/13 23:37:59 pelle
Refactoring parts of the core of XMLSignature. There shouldnt be any real API changes.
*/
/**
* User: pelleb
* Date: Jan 13, 2004
* Time: 8:50:32 PM
*/
public class XMLSignerTest extends TestCase{
public XMLSignerTest(String string) throws InvalidPassphraseException {
super(string);
signer=new TestCaseSigner();
}
public void testSign() throws DocumentException, XMLSecurityException, NonExistingSignerException, UserCancellationException {
Document doc=DocumentHelper.parseText("<hello>test</hello>");
XMLSignature sig=new QuickEmbeddedSignature("neu://bob@test",signer,doc.getRootElement());
assertTrue(sig.verifySignature());
}
private final TestCaseSigner signer;
}
Index: SimpleXMLSigTest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/test/org/neuclear/xml/xmlsec/SimpleXMLSigTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** SimpleXMLSigTest.java 21 Nov 2003 04:44:31 -0000 1.5
--- SimpleXMLSigTest.java 13 Jan 2004 23:37:59 -0000 1.6
***************
*** 22,25 ****
--- 22,28 ----
* $Id$
* $Log$
+ * Revision 1.6 2004/01/13 23:37:59 pelle
+ * Refactoring parts of the core of XMLSignature. There shouldnt be any real API changes.
+ *
* Revision 1.5 2003/11/21 04:44:31 pelle
* EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
***************
*** 153,157 ****
public final void testQuickRSASignXML() throws DocumentException, XMLException, CryptoException {
Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement("http://testsigs", doc.getRootElement(), signer);
final File outputFile = new File("target/testdata/homegrown/signature-enveloped-rsa-quick.xml");
XMLTools.writeFile(outputFile, doc);
--- 156,160 ----
public final void testQuickRSASignXML() throws DocumentException, XMLException, CryptoException {
Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement( doc.getRootElement(), signer);
final File outputFile = new File("target/testdata/homegrown/signature-enveloped-rsa-quick.xml");
XMLTools.writeFile(outputFile, doc);
***************
*** 165,169 ****
assertTrue("Test if public key is really DSA", dsaSigner.getPublic() instanceof DSAPublicKey);
Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement("http://testDSAsigs", doc.getRootElement(), dsaSigner);
final File outputFile = new File("target/testdata/homegrown/signature-enveloped-dsa-quick.xml");
--- 168,172 ----
assertTrue("Test if public key is really DSA", dsaSigner.getPublic() instanceof DSAPublicKey);
Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement( doc.getRootElement(), dsaSigner);
final File outputFile = new File("target/testdata/homegrown/signature-enveloped-dsa-quick.xml");
***************
*** 178,182 ****
final Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement("http://testsigs", doc.getRootElement(), signer);
assertTrue("Test if Signature is valid", XMLSecTools.verifySignature(doc.getRootElement(), signer.getPublic()));
doc.getRootElement().addElement("BadElement");
--- 181,185 ----
final Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement( doc.getRootElement(), signer);
assertTrue("Test if Signature is valid", XMLSecTools.verifySignature(doc.getRootElement(), signer.getPublic()));
doc.getRootElement().addElement("BadElement");
***************
*** 189,193 ****
final Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement("http://testDSAsigs", doc.getRootElement(), dsaSigner);
assertTrue("Test if DSA Signature is valid", XMLSecTools.verifySignature(doc.getRootElement(), dsaSigner.getPublic()));
doc.getRootElement().addElement("BadElement");
--- 192,196 ----
final Document doc = DocumentHelper.parseText(TESTXML);
! XMLSecTools.signElement(doc.getRootElement(), dsaSigner);
assertTrue("Test if DSA Signature is valid", XMLSecTools.verifySignature(doc.getRootElement(), dsaSigner.getPublic()));
doc.getRootElement().addElement("BadElement");
|