Author: coheigea
Date: Fri Nov 22 10:59:04 2013
New Revision: 1544485

URL: http://svn.apache.org/r1544485
Log:
Adding some negative tests (@Ignore'd for now) for WS-SecurityPolicy streaming 
SwA

Modified:
    
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/parts/StaxPartsTest.java
    
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/parts/stax-server.xml

Modified: 
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/parts/StaxPartsTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/parts/StaxPartsTest.java?rev=1544485&r1=1544484&r2=1544485&view=diff
==============================================================================
--- 
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/parts/StaxPartsTest.java
 (original)
+++ 
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/parts/StaxPartsTest.java
 Fri Nov 22 10:59:04 2013
@@ -22,13 +22,17 @@ package org.apache.cxf.systest.ws.parts;
 import java.net.URL;
 
 import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Service;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.ws.security.SecurityConstants;
 import org.example.contract.doubleit.DoubleItPortType;
+import org.example.contract.doubleit.DoubleItSwaPortType;
+import org.example.schema.doubleit.DoubleIt3;
 import org.junit.BeforeClass;
 
 /**
@@ -464,5 +468,140 @@ public class StaxPartsTest extends Abstr
         bus.shutdown(true);
     }
 
+    // TODO - re-enable once we move off WSS4J 2.0-beta
+    @org.junit.Test
+    @org.junit.Ignore
+    public void testSignedAttachments() throws Exception {
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = PartsTest.class.getResource("client.xml");
+
+        Bus bus = bf.createBus(busFile.toString());
+        SpringBusFactory.setDefaultBus(bus);
+        SpringBusFactory.setThreadDefaultBus(bus);
+
+        URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
+        Service service = Service.create(wsdl, SERVICE_QNAME);
+       
+        // Successful invocation
+        QName portQName = new QName(NAMESPACE, 
"DoubleItSignedAttachmentsPort");
+        DoubleItSwaPortType port = service.getPort(portQName, 
DoubleItSwaPortType.class);
+        updateAddressPort(port, PORT);
+        
+        // DOM
+        DoubleIt3 doubleIt = new DoubleIt3();
+        doubleIt.setNumberToDouble(25);
+        port.doubleIt3(doubleIt, "12345".getBytes());
+        
+        // Streaming
+        enableStreaming(port);
+        doubleIt = new DoubleIt3();
+        doubleIt.setNumberToDouble(25);
+        port.doubleIt3(doubleIt, "12345".getBytes());
+        
+        // This should fail, as the service requires that the Attachments must 
be signed
+        portQName = new QName(NAMESPACE, "DoubleItSignedAttachmentsPort2");
+        port = service.getPort(portQName, DoubleItSwaPortType.class);
+        updateAddressPort(port, PORT);
+        
+        // DOM
+        try {
+            doubleIt = new DoubleIt3();
+            doubleIt.setNumberToDouble(25);
+            port.doubleIt3(doubleIt, "12345".getBytes());
+            fail("Failure expected on an attachment which isn't signed");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            String error = "SignedParts";
+            assertTrue(ex.getMessage().contains(error));
+        }
+        
+        // Streaming
+        try {
+            enableStreaming(port);
+            doubleIt = new DoubleIt3();
+            doubleIt.setNumberToDouble(25);
+            port.doubleIt3(doubleIt, "12345".getBytes());
+            fail("Failure expected on an attachment which isn't signed");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            // String error = "SignedParts";
+            // assertTrue(ex.getMessage().contains(error));
+        }
+        
+        ((java.io.Closeable)port).close();
+        bus.shutdown(true);
+    }
+    
+    // TODO - re-enable once we move off WSS4J 2.0-beta
+    @org.junit.Test
+    @org.junit.Ignore
+    public void testEncryptedAttachments() throws Exception {
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = PartsTest.class.getResource("client.xml");
+
+        Bus bus = bf.createBus(busFile.toString());
+        SpringBusFactory.setDefaultBus(bus);
+        SpringBusFactory.setThreadDefaultBus(bus);
+
+        URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
+        Service service = Service.create(wsdl, SERVICE_QNAME);
+       
+        // Successful invocation
+        QName portQName = new QName(NAMESPACE, 
"DoubleItEncryptedAttachmentsPort");
+        DoubleItSwaPortType port = service.getPort(portQName, 
DoubleItSwaPortType.class);
+        updateAddressPort(port, PORT);
+        
+        // DOM
+        DoubleIt3 doubleIt = new DoubleIt3();
+        doubleIt.setNumberToDouble(25);
+        port.doubleIt3(doubleIt, "12345".getBytes());
+        
+        // Streaming
+        enableStreaming(port);
+        doubleIt = new DoubleIt3();
+        doubleIt.setNumberToDouble(25);
+        port.doubleIt3(doubleIt, "12345".getBytes());
+        
+        // This should fail, as the service requires that the Attachments must 
be encrypted
+        portQName = new QName(NAMESPACE, "DoubleItEncryptedAttachmentsPort2");
+        port = service.getPort(portQName, DoubleItSwaPortType.class);
+        updateAddressPort(port, PORT);
+        
+        // DOM
+        try {
+            doubleIt = new DoubleIt3();
+            doubleIt.setNumberToDouble(25);
+            port.doubleIt3(doubleIt, "12345".getBytes());
+            fail("Failure expected on an attachment which isn't encrypted");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            String error = "EncryptedParts";
+            assertTrue(ex.getMessage().contains(error));
+        }
+        
+        // Streaming
+        try {
+            enableStreaming(port);
+            doubleIt = new DoubleIt3();
+            doubleIt.setNumberToDouble(25);
+            port.doubleIt3(doubleIt, "12345".getBytes());
+            fail("Failure expected on an attachment which isn't encrypted");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            // String error = "SignedParts";
+            // assertTrue(ex.getMessage().contains(error));
+        }
+        
+        ((java.io.Closeable)port).close();
+        bus.shutdown(true);
+    }
+    
+    static void enableStreaming(DoubleItSwaPortType port) {
+        ((BindingProvider)port).getRequestContext().put(
+            SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
+        );
+        ((BindingProvider)port).getResponseContext().put(
+            SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
+        );
+    }
+  
     
 }

Modified: 
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/parts/stax-server.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/parts/stax-server.xml?rev=1544485&r1=1544484&r2=1544485&view=diff
==============================================================================
--- 
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/parts/stax-server.xml
 (original)
+++ 
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/parts/stax-server.xml
 Fri Nov 22 10:59:04 2013
@@ -256,4 +256,81 @@
             </p:policies>
         </jaxws:features>
     </jaxws:endpoint>
+    
+    <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"; 
id="SignedAttachments" 
+         
address="http://localhost:${testutil.ports.StaxServer}/DoubleItSignedAttachments";
 
+         serviceName="s:DoubleItService" 
endpointName="s:DoubleItSignedAttachmentsPort" 
+         implementor="org.apache.cxf.systest.ws.parts.DoubleIt3Impl" 
+         wsdlLocation="org/apache/cxf/systest/ws/parts/DoubleItParts.wsdl">
+        <jaxws:properties>
+            <entry key="ws-security.callback-handler" 
value="org.apache.cxf.systest.ws.common.UTPasswordCallback"/>
+            <entry key="ws-security.signature.properties" 
value="bob.properties"/>
+            <entry key="ws-security.encryption.username" 
value="useReqSigCert"/>
+            <entry key="ws-security.subject.cert.constraints" 
value=".*O=apache.org.*"/>
+            <entry key="ws-security.enable.streaming" value="true"/>
+        </jaxws:properties>
+        <jaxws:features>
+            <p:policies>
+                <wsp:PolicyReference 
xmlns:wsp="http://www.w3.org/ns/ws-policy"; 
+                     
URI="classpath:/org/apache/cxf/systest/ws/parts/signed-attachments-policy.xml"/>
+            </p:policies>
+        </jaxws:features>
+    </jaxws:endpoint>
+    <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"; 
id="SignedAttachments2" 
+         
address="http://localhost:${testutil.ports.StaxServer}/DoubleItSignedAttachments2";
 
+         serviceName="s:DoubleItService" 
endpointName="s:DoubleItSignedAttachmentsPort2" 
+         implementor="org.apache.cxf.systest.ws.parts.DoubleIt3Impl" 
+         wsdlLocation="org/apache/cxf/systest/ws/parts/DoubleItParts.wsdl">
+        <jaxws:properties>
+            <entry key="ws-security.callback-handler" 
value="org.apache.cxf.systest.ws.common.UTPasswordCallback"/>
+            <entry key="ws-security.signature.properties" 
value="bob.properties"/>
+            <entry key="ws-security.encryption.username" 
value="useReqSigCert"/>
+            <entry key="ws-security.subject.cert.constraints" 
value=".*O=apache.org.*"/>
+            <entry key="ws-security.enable.streaming" value="true"/>
+        </jaxws:properties>
+        <jaxws:features>
+            <p:policies>
+                <wsp:PolicyReference 
xmlns:wsp="http://www.w3.org/ns/ws-policy"; 
+                     
URI="classpath:/org/apache/cxf/systest/ws/parts/signed-attachments-policy.xml"/>
+            </p:policies>
+        </jaxws:features>
+    </jaxws:endpoint>
+    <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"; 
id="EncryptedAttachments" 
+         
address="http://localhost:${testutil.ports.StaxServer}/DoubleItEncryptedAttachments";
 
+         serviceName="s:DoubleItService" 
endpointName="s:DoubleItEncryptedAttachmentsPort" 
+         implementor="org.apache.cxf.systest.ws.parts.DoubleIt3Impl" 
+         wsdlLocation="org/apache/cxf/systest/ws/parts/DoubleItParts.wsdl">
+        <jaxws:properties>
+            <entry key="ws-security.callback-handler" 
value="org.apache.cxf.systest.ws.common.UTPasswordCallback"/>
+            <entry key="ws-security.signature.properties" 
value="bob.properties"/>
+            <entry key="ws-security.encryption.username" 
value="useReqSigCert"/>
+            <entry key="ws-security.subject.cert.constraints" 
value=".*O=apache.org.*"/>
+            <entry key="ws-security.enable.streaming" value="true"/>
+        </jaxws:properties>
+        <jaxws:features>
+            <p:policies>
+                <wsp:PolicyReference 
xmlns:wsp="http://www.w3.org/ns/ws-policy"; 
+                     
URI="classpath:/org/apache/cxf/systest/ws/parts/encrypted-attachments-policy.xml"/>
+            </p:policies>
+        </jaxws:features>
+    </jaxws:endpoint>
+    <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"; 
id="EncryptedAttachments2" 
+         
address="http://localhost:${testutil.ports.StaxServer}/DoubleItEncryptedAttachments2";
 
+         serviceName="s:DoubleItService" 
endpointName="s:DoubleItEncryptedAttachmentsPort2" 
+         implementor="org.apache.cxf.systest.ws.parts.DoubleIt3Impl" 
+         wsdlLocation="org/apache/cxf/systest/ws/parts/DoubleItParts.wsdl">
+        <jaxws:properties>
+            <entry key="ws-security.callback-handler" 
value="org.apache.cxf.systest.ws.common.UTPasswordCallback"/>
+            <entry key="ws-security.signature.properties" 
value="bob.properties"/>
+            <entry key="ws-security.encryption.username" 
value="useReqSigCert"/>
+            <entry key="ws-security.subject.cert.constraints" 
value=".*O=apache.org.*"/>
+            <entry key="ws-security.enable.streaming" value="true"/>
+        </jaxws:properties>
+        <jaxws:features>
+            <p:policies>
+                <wsp:PolicyReference 
xmlns:wsp="http://www.w3.org/ns/ws-policy"; 
+                     
URI="classpath:/org/apache/cxf/systest/ws/parts/encrypted-attachments-policy.xml"/>
+            </p:policies>
+        </jaxws:features>
+    </jaxws:endpoint>
 </beans>


Reply via email to