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 2018/03/26 11:08:50 UTC

svn commit: r1827752 - in /webservices/wss4j/trunk/ws-security-dom/src/test: java/org/apache/wss4j/dom/message/ resources/org/ resources/org/apache/ resources/org/apache/wss4j/ resources/org/apache/wss4j/dom/ resources/org/apache/wss4j/dom/message/

Author: coheigea
Date: Mon Mar 26 11:08:49 2018
New Revision: 1827752

URL: http://svn.apache.org/viewvc?rev=1827752&view=rev
Log:
Adding a test for WSS-626

Added:
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePrefixListTest.java
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/
    webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml

Added: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePrefixListTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePrefixListTest.java?rev=1827752&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePrefixListTest.java (added)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePrefixListTest.java Mon Mar 26 11:08:49 2018
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wss4j.dom.message;
+
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.wss4j.common.crypto.Crypto;
+import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.common.util.Loader;
+import org.apache.wss4j.common.util.XMLUtils;
+import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.dom.common.SecurityTestUtil;
+import org.apache.wss4j.dom.engine.WSSConfig;
+import org.apache.wss4j.dom.engine.WSSecurityEngine;
+import org.apache.wss4j.dom.engine.WSSecurityEngineResult;
+import org.apache.wss4j.dom.handler.WSHandlerResult;
+import org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+
+/**
+ * A test-case for WSS-626 - "Duplicates in the PrefixList".
+ */
+public class SignaturePrefixListTest extends org.junit.Assert {
+    private static final org.slf4j.Logger LOG =
+        org.slf4j.LoggerFactory.getLogger(SignaturePrefixListTest.class);
+
+    private WSSecurityEngine secEngine = new WSSecurityEngine();
+    private Crypto crypto;
+
+    @org.junit.AfterClass
+    public static void cleanup() throws Exception {
+        SecurityTestUtil.cleanup();
+    }
+
+    public SignaturePrefixListTest() throws Exception {
+        WSSConfig.init();
+        crypto = CryptoFactory.getInstance();
+    }
+
+    @Test
+    public void testDuplicatePrefixListValues() throws Exception {
+        Document doc = null;
+        try (InputStream inputStream =
+            Loader.getResource("org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml").openStream()) {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setNamespaceAware(true);
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            doc = builder.parse(inputStream);
+        }
+
+        WSSecHeader secHeader = new WSSecHeader(doc);
+        secHeader.insertSecurityHeader();
+
+        WSSecSignature builder = new WSSecSignature(secHeader);
+        builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
+        Document signedDoc = builder.build(crypto);
+
+        if (LOG.isDebugEnabled()) {
+            String outputString =
+                XMLUtils.prettyDocumentToString(signedDoc);
+            LOG.debug(outputString);
+            // System.out.println(outputString);
+        }
+        WSHandlerResult results = verify(signedDoc);
+
+        WSSecurityEngineResult actionResult =
+            results.getActionResults().get(WSConstants.SIGN).get(0);
+        assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
+        assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
+        REFERENCE_TYPE referenceType =
+            (REFERENCE_TYPE)actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE);
+        assertTrue(referenceType == REFERENCE_TYPE.ISSUER_SERIAL);
+    }
+
+    private WSHandlerResult verify(Document doc) throws Exception {
+        return secEngine.processSecurityHeader(doc, null, null, crypto);
+    }
+
+}
\ No newline at end of file

Added: webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml?rev=1827752&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml (added)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/resources/org/apache/wss4j/dom/message/SignaturePrefixListMessage.xml Mon Mar 26 11:08:49 2018
@@ -0,0 +1,39 @@
+<?xml version='1.0' encoding='utf-8'?>
+<S12:Envelope xmlns:S12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns5="http://www.w3.org/1999/xlink" xmlns:ebbp="http://docs.oasis-open.org/ebxml-bp/ebbp-signals-2.0" xmlns:eb="http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+	<S12:Header>
+		<eb:Messaging S12:mustUnderstand="true">
+			<eb:UserMessage>
+				<eb:MessageInfo>
+					<eb:Timestamp>2018-03-26T11:30:29.769+02:00</eb:Timestamp>
+					<eb:MessageId>MID-1522056240506@ponton.xp</eb:MessageId>
+				</eb:MessageInfo>
+				<eb:PartyInfo>
+					<eb:From>
+						<eb:PartyId type="AS4-Name">pontonxp</eb:PartyId>
+						<eb:Role>http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/defaultRole</eb:Role>
+					</eb:From>
+					<eb:To>
+						<eb:PartyId type="AS4-Name">domibus_plain</eb:PartyId>
+						<eb:Role>http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/defaultRole</eb:Role>
+					</eb:To>
+				</eb:PartyInfo>
+				<eb:CollaborationInfo>
+					<eb:AgreementRef>http://domibus.eu/agreement/plain</eb:AgreementRef>
+					<eb:Service type="http://docs.oasis-open.org/ebxml-msg/as4/200902/service">sendMessageService</eb:Service>
+					<eb:Action>http://docs.oasis-open.org/ebxml-msg/as4/200902/action</eb:Action>
+					<eb:ConversationId>MID-1522056240506@ponton.xp</eb:ConversationId>
+				</eb:CollaborationInfo>
+				<eb:PayloadInfo>
+					<eb:PartInfo href="cid:payload-1522056629904">
+						<eb:Schema location="http://www.efet.org/schemas/V3R2/EFET-BCN-V3R2.xsd" version="3.20"/>
+						<eb:Description xml:lang="en">Payload</eb:Description>
+						<eb:PartProperties>
+							<eb:Property name="MimeType">text/xml</eb:Property>
+						</eb:PartProperties>
+					</eb:PartInfo>
+				</eb:PayloadInfo>
+			</eb:UserMessage>
+		</eb:Messaging>
+	</S12:Header>
+	<S12:Body/>
+</S12:Envelope>
\ No newline at end of file