You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2013/04/22 13:20:30 UTC

svn commit: r1470456 - in /cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j: DOMToStaxRoundTripTest.java StaxRoundTripTest.java StaxToDOMRoundTripTest.java

Author: coheigea
Date: Mon Apr 22 11:20:30 2013
New Revision: 1470456

URL: http://svn.apache.org/r1470456
Log:
Adding some tests

Modified:
    cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/DOMToStaxRoundTripTest.java
    cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxRoundTripTest.java
    cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxToDOMRoundTripTest.java

Modified: cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/DOMToStaxRoundTripTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/DOMToStaxRoundTripTest.java?rev=1470456&r1=1470455&r2=1470456&view=diff
==============================================================================
--- cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/DOMToStaxRoundTripTest.java (original)
+++ cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/DOMToStaxRoundTripTest.java Mon Apr 22 11:20:30 2013
@@ -348,6 +348,51 @@ public class DOMToStaxRoundTripTest exte
     }
     
     @Test
+    public void testSignatureTimestampWrongNamespace() throws Exception {
+        // Create + configure service
+        Service service = createService();
+        
+        WSSSecurityProperties inProperties = new WSSSecurityProperties();
+        inProperties.setCallbackHandler(new TestPwdCallback());
+        Properties cryptoProperties = 
+            CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
+        inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
+        WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
+        service.getInInterceptors().add(inhandler);
+        
+        // Create + configure client
+        Echo echo = createClientProxy();
+        
+        Client client = ClientProxy.getClient(echo);
+        client.getInInterceptors().add(new LoggingInInterceptor());
+        client.getOutInterceptors().add(new LoggingOutInterceptor());
+        
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put(
+            WSHandlerConstants.ACTION, 
+            WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE
+        );
+        properties.put(
+            WSHandlerConstants.SIGNATURE_PARTS, 
+            "{}{" + WSSConstants.NS_WSSE10 + "}Timestamp;"
+            + "{}{" + WSSConstants.NS_SOAP11 + "}Body;"
+        );
+        properties.put(WSHandlerConstants.PW_CALLBACK_REF, new TestPwdCallback());
+        properties.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
+        properties.put(WSHandlerConstants.USER, "myalias");
+        
+        WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
+        client.getOutInterceptors().add(ohandler);
+
+        try {
+            echo.echo("test");
+            fail("Failure expected on a wrong namespace");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            // expected
+        }
+    }
+    
+    @Test
     public void testSignaturePKI() throws Exception {
         // Create + configure service
         Service service = createService();

Modified: cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxRoundTripTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxRoundTripTest.java?rev=1470456&r1=1470455&r2=1470456&view=diff
==============================================================================
--- cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxRoundTripTest.java (original)
+++ cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxRoundTripTest.java Mon Apr 22 11:20:30 2013
@@ -409,110 +409,6 @@ public class StaxRoundTripTest extends A
         assertEquals("test", echo.echo("test"));
     }
     
-   /*
-    * TODO
-    @Test
-    public void testOverrideCustomAction() throws Exception {
-        SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");
-
-        WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
-        PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
-
-        SoapMessage msg = new SoapMessage(new MessageImpl());
-        Exchange ex = new ExchangeImpl();
-        ex.setInMessage(msg);
-
-        msg.setContent(SOAPMessage.class, saaj);
-        
-        CountingUsernameTokenAction action = new CountingUsernameTokenAction();
-        Map<Object, Object> customActions = new HashMap<Object, Object>(1);
-        customActions.put(WSConstants.UT, action);
-                
-        msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
-        msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
-        msg.put(WSHandlerConstants.USER, "username");
-        msg.put("password", "myAliasPassword");
-        msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
-        msg.put(WSS4JOutInterceptor.WSS4J_ACTION_MAP, customActions);
-        handler.handleMessage(msg);
-
-        SOAPPart doc = saaj.getSOAPPart();
-        assertValid("//wsse:Security", doc);
-        assertValid("//wsse:Security/wsse:UsernameToken", doc);
-        assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
-        // Test to see that the plaintext password is used in the header
-        assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
-        assertEquals(1, action.getExecutions());
-        
-        try {
-            customActions.put(WSConstants.UT, new Object());
-            handler.handleMessage(msg);
-        } catch (SoapFault e) {
-            assertEquals("An invalid action configuration was defined.", e.getMessage());
-        }
-        
-        try {
-            customActions.put(new Object(), CountingUsernameTokenAction.class);
-            handler.handleMessage(msg);
-        } catch (SoapFault e) {
-            assertEquals("An invalid action configuration was defined.", e.getMessage());
-        }
-    }
-    
-    
-    @Test
-    public void testAddCustomAction() throws Exception {
-        SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");
-
-        WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
-        PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
-
-        SoapMessage msg = new SoapMessage(new MessageImpl());
-        Exchange ex = new ExchangeImpl();
-        ex.setInMessage(msg);
-
-        msg.setContent(SOAPMessage.class, saaj);
-        
-        CountingUsernameTokenAction action = new CountingUsernameTokenAction();
-        Map<Object, Object> customActions = new HashMap<Object, Object>(1);
-        customActions.put(12345, action);
-                
-        msg.put(WSHandlerConstants.ACTION, "12345");
-        msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
-        msg.put(WSHandlerConstants.USER, "username");
-        msg.put("password", "myAliasPassword");
-        msg.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
-        msg.put(WSS4JOutInterceptor.WSS4J_ACTION_MAP, customActions);
-        handler.handleMessage(msg);
-
-        SOAPPart doc = saaj.getSOAPPart();
-        assertValid("//wsse:Security", doc);
-        assertValid("//wsse:Security/wsse:UsernameToken", doc);
-        assertValid("//wsse:Security/wsse:UsernameToken/wsse:Username[text()='username']", doc);
-        // Test to see that the plaintext password is used in the header
-        assertValid("//wsse:Security/wsse:UsernameToken/wsse:Password[text()='myAliasPassword']", doc);
-        assertEquals(1, action.getExecutions());
-    }
-    
-    private static class CountingUsernameTokenAction extends UsernameTokenAction {
-
-        private int executions;
-        
-        @Override
-        public void execute(WSHandler handler, int actionToDo, Document doc,
-                RequestData reqData) throws WSSecurityException {
-            
-            this.executions++;
-            reqData.setPwType(WSConstants.PW_TEXT);
-            super.execute(handler, actionToDo, doc, reqData);
-        }
-
-        public int getExecutions() {
-            return this.executions;
-        }
-    }
-    */
-    
     private Service createService() {
         // Create the Service
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

Modified: cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxToDOMRoundTripTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxToDOMRoundTripTest.java?rev=1470456&r1=1470455&r2=1470456&view=diff
==============================================================================
--- cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxToDOMRoundTripTest.java (original)
+++ cxf/branches/wss4j2.0-port/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/StaxToDOMRoundTripTest.java Mon Apr 22 11:20:30 2013
@@ -358,7 +358,7 @@ public class StaxToDOMRoundTripTest exte
             new XMLSecurityConstants.Action[]{WSSConstants.SIGNATURE, WSSConstants.TIMESTAMP}
         );
         properties.addSignaturePart(
-            new SecurePart(new QName(WSSConstants.NS_WSSE10, "Timestamp"), SecurePart.Modifier.Element)
+            new SecurePart(new QName(WSSConstants.NS_WSU10, "Timestamp"), SecurePart.Modifier.Element)
         );
         properties.addSignaturePart(
             new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element)
@@ -375,6 +375,57 @@ public class StaxToDOMRoundTripTest exte
         assertEquals("test", echo.echo("test"));
     }
     
+    // TODO
+    @Test
+    @org.junit.Ignore
+    public void testSignatureTimestampWrongNamespace() throws Exception {
+        // Create + configure service
+        Service service = createService();
+        
+        Map<String, Object> inProperties = new HashMap<String, Object>();
+        inProperties.put(
+            WSHandlerConstants.ACTION, 
+            WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.TIMESTAMP
+        );
+        inProperties.put(WSHandlerConstants.PW_CALLBACK_REF, new TestPwdCallback());
+        inProperties.put(WSHandlerConstants.SIG_VER_PROP_FILE, "insecurity.properties");
+        WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
+        service.getInInterceptors().add(inInterceptor);
+        
+        // Create + configure client
+        Echo echo = createClientProxy();
+        
+        Client client = ClientProxy.getClient(echo);
+        client.getInInterceptors().add(new LoggingInInterceptor());
+        client.getOutInterceptors().add(new LoggingOutInterceptor());
+        
+        WSSSecurityProperties properties = new WSSSecurityProperties();
+        properties.setOutAction(
+            new XMLSecurityConstants.Action[]{WSSConstants.SIGNATURE, WSSConstants.TIMESTAMP}
+        );
+        properties.addSignaturePart(
+            new SecurePart(new QName(WSSConstants.NS_WSSE10, "Timestamp"), SecurePart.Modifier.Element)
+        );
+        properties.addSignaturePart(
+            new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element)
+        );
+        properties.setSignatureUser("myalias");
+        
+        Properties cryptoProperties = 
+            CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
+        properties.setSignatureCryptoProperties(cryptoProperties);
+        properties.setCallbackHandler(new TestPwdCallback());
+        WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
+        client.getOutInterceptors().add(ohandler);
+
+        try {
+            echo.echo("test");
+            fail("Failure expected on a wrong namespace");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            ex.printStackTrace();
+        }
+    }
+    
     @Test
     public void testSignaturePKI() throws Exception {
         // Create + configure service