You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2014/09/25 11:41:18 UTC
svn commit: r1627495 -
/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java
Author: coheigea
Date: Thu Sep 25 09:41:18 2014
New Revision: 1627495
URL: http://svn.apache.org/r1627495
Log:
Adding some more crypto provider tests
Modified:
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java?rev=1627495&r1=1627494&r2=1627495&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/CryptoProviderTest.java Thu Sep 25 09:41:18 2014
@@ -34,7 +34,10 @@ import org.apache.xml.security.utils.Bas
import org.w3c.dom.Document;
import javax.security.auth.callback.CallbackHandler;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
@@ -91,6 +94,60 @@ public class CryptoProviderTest extends
}
/**
+ * Like before but substitute in an "EMAILADDRESS" instead of the OID
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testSignatureEmailAddress() throws Exception {
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecSignature sign = new WSSecSignature();
+ sign.setUserInfo("wss86", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
+ WSSecHeader secHeader = new WSSecHeader();
+ secHeader.insertSecurityHeader(doc);
+ Document signedDoc = sign.build(doc, crypto, secHeader);
+
+ String outputString = XMLUtils.PrettyDocumentToString(signedDoc);
+ outputString =
+ outputString.replace("1.2.840.113549.1.9.1=#16125765726e6572406578616d706c652e636f6d",
+ "EMAILADDRESS=Werner@example.com");
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ InputStream is = new ByteArrayInputStream(outputString.getBytes());
+ Document parsedDoc = dbf.newDocumentBuilder().parse(is);
+ verify(parsedDoc);
+ }
+
+ /**
+ * Like before but substitute in an "E" instead of the OID
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testSignatureOtherEmailAddress() throws Exception {
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecSignature sign = new WSSecSignature();
+ sign.setUserInfo("wss86", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
+ WSSecHeader secHeader = new WSSecHeader();
+ secHeader.insertSecurityHeader(doc);
+ Document signedDoc = sign.build(doc, crypto, secHeader);
+
+ String outputString = XMLUtils.PrettyDocumentToString(signedDoc);
+ outputString =
+ outputString.replace("1.2.840.113549.1.9.1=#16125765726e6572406578616d706c652e636f6d",
+ "E=Werner@example.com");
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ InputStream is = new ByteArrayInputStream(outputString.getBytes());
+ Document parsedDoc = dbf.newDocumentBuilder().parse(is);
+ verify(parsedDoc);
+ }
+
+ /**
* Test loading a certificate using BouncyCastle, and using it to encrypt a message, but
* decrypt the message using the Java Keystore provider
*/