Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C5FACCAB0 for ; Fri, 25 May 2012 16:14:32 +0000 (UTC) Received: (qmail 5853 invoked by uid 500); 25 May 2012 16:14:32 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 5804 invoked by uid 500); 25 May 2012 16:14:32 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 5793 invoked by uid 99); 25 May 2012 16:14:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2012 16:14:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2012 16:14:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 59E562388847; Fri, 25 May 2012 16:14:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1342711 - in /cxf/trunk/systests/ws-security/src/test: java/org/apache/cxf/systest/ws/common/ java/org/apache/cxf/systest/ws/fault/ java/org/apache/cxf/systest/ws/fault/server/ resources/ resources/org/apache/cxf/systest/ws/fault/ resource... Date: Fri, 25 May 2012 16:14:02 -0000 To: commits@cxf.apache.org From: coheigea@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120525161403.59E562388847@eris.apache.org> Author: coheigea Date: Fri May 25 16:14:02 2012 New Revision: 1342711 URL: http://svn.apache.org/viewvc?rev=1342711&view=rev Log: Added some system tests to test signing and encrypting SOAP (1.1 + 1.2) faults Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/DoubleItPortTypeImpl.java - copied, changed from r1342710, cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/Server.java - copied, changed from r1342710, cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/client.xml cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java cxf/trunk/systests/ws-security/src/test/resources/DoubleItLogical.wsdl Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java?rev=1342711&r1=1342710&r2=1342711&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java (original) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java Fri May 25 16:14:02 2012 @@ -21,6 +21,7 @@ package org.apache.cxf.systest.ws.common import javax.jws.WebService; import org.apache.cxf.feature.Features; +import org.example.contract.doubleit.DoubleItFault; import org.example.contract.doubleit.DoubleItPortType; @WebService(targetNamespace = "http://www.example.org/contract/DoubleIt", @@ -29,7 +30,7 @@ import org.example.contract.doubleit.Dou @Features(features = "org.apache.cxf.feature.LoggingFeature") public class DoubleItImpl implements DoubleItPortType { - public int doubleIt(int numberToDouble) { + public int doubleIt(int numberToDouble) throws DoubleItFault { return numberToDouble * 2; } Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java?rev=1342711&r1=1342710&r2=1342711&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java (original) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java Fri May 25 16:14:02 2012 @@ -25,6 +25,7 @@ import javax.jws.WebService; import javax.xml.ws.WebServiceContext; import org.apache.cxf.feature.Features; +import org.example.contract.doubleit.DoubleItFault; import org.example.contract.doubleit.DoubleItPortType; import org.junit.Assert; @@ -37,7 +38,7 @@ public class DoubleItPortTypeImpl implem @Resource WebServiceContext wsContext; - public int doubleIt(int numberToDouble) { + public int doubleIt(int numberToDouble) throws DoubleItFault { Principal pr = wsContext.getUserPrincipal(); Assert.assertNotNull("Principal must not be null", pr); Copied: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/DoubleItPortTypeImpl.java (from r1342710, cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java) URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/DoubleItPortTypeImpl.java?p2=cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/DoubleItPortTypeImpl.java&p1=cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java&r1=1342710&r2=1342711&rev=1342711&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItPortTypeImpl.java (original) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/DoubleItPortTypeImpl.java Fri May 25 16:14:02 2012 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cxf.systest.ws.common; +package org.apache.cxf.systest.ws.fault; import java.security.Principal; @@ -25,8 +25,8 @@ import javax.jws.WebService; import javax.xml.ws.WebServiceContext; import org.apache.cxf.feature.Features; +import org.example.contract.doubleit.DoubleItFault; import org.example.contract.doubleit.DoubleItPortType; -import org.junit.Assert; @WebService(targetNamespace = "http://www.example.org/contract/DoubleIt", serviceName = "DoubleItService", @@ -37,13 +37,18 @@ public class DoubleItPortTypeImpl implem @Resource WebServiceContext wsContext; - public int doubleIt(int numberToDouble) { - Principal pr = wsContext.getUserPrincipal(); + public int doubleIt(int numberToDouble) throws DoubleItFault { - Assert.assertNotNull("Principal must not be null", pr); - Assert.assertNotNull("Principal.getName() must not return null", pr.getName()); + Principal pr = wsContext.getUserPrincipal(); + if ("alice".equals(pr.getName())) { + return numberToDouble * 2; + } - return numberToDouble * 2; + org.example.schema.doubleit.DoubleItFault internalFault = + new org.example.schema.doubleit.DoubleItFault(); + internalFault.setMajor((short)124); + internalFault.setMinor((short)1256); + throw new DoubleItFault("This is a fault", internalFault); } } Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java?rev=1342711&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java (added) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java Fri May 25 16:14:02 2012 @@ -0,0 +1,130 @@ +/** + * 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.cxf.systest.ws.fault; + +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.systest.ws.fault.server.Server; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.example.contract.doubleit.DoubleItPortType; +import org.junit.BeforeClass; + +/** + * A set of tests for (signing and encrypting) SOAP Faults. + */ +public class FaultTest extends AbstractBusClientServerTestBase { + static final String PORT = allocatePort(Server.class); + + private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt"; + private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService"); + + @BeforeClass + public static void startServers() throws Exception { + assertTrue( + "Server failed to launch", + // run the server in the same process + // set this to false to fork + launchServer(Server.class, true) + ); + } + + @org.junit.AfterClass + public static void cleanup() throws Exception { + SecurityTestUtil.cleanup(); + stopAllServers(); + } + + @org.junit.Test + public void testSoap11() throws Exception { + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = FaultTest.class.getResource("client/client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItSoap11Port"); + DoubleItPortType utPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(utPort, PORT); + + // Make a successful invocation + ((BindingProvider)utPort).getRequestContext().put("ws-security.username", "alice"); + utPort.doubleIt(25); + + // Now make an invocation using another username + ((BindingProvider)utPort).getRequestContext().put("ws-security.username", "bob"); + ((BindingProvider)utPort).getRequestContext().put("ws-security.password", "password"); + try { + utPort.doubleIt(25); + fail("Expected failure on bob"); + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("This is a fault")); + } + + bus.shutdown(true); + } + + @org.junit.Test + public void testSoap12() throws Exception { + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = FaultTest.class.getResource("client/client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItSoap12Port"); + DoubleItPortType utPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(utPort, PORT); + + // Make a successful invocation + ((BindingProvider)utPort).getRequestContext().put("ws-security.username", "alice"); + utPort.doubleIt(25); + + // Now make an invocation using another username + ((BindingProvider)utPort).getRequestContext().put("ws-security.username", "bob"); + ((BindingProvider)utPort).getRequestContext().put("ws-security.password", "password"); + try { + utPort.doubleIt(25); + fail("Expected failure on bob"); + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("This is a fault")); + } + + bus.shutdown(true); + } + + +} Copied: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/Server.java (from r1342710, cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java) URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/Server.java?p2=cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/Server.java&p1=cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java&r1=1342710&r2=1342711&rev=1342711&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/common/DoubleItImpl.java (original) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/server/Server.java Fri May 25 16:14:02 2012 @@ -16,21 +16,32 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cxf.systest.ws.common; -import javax.jws.WebService; +package org.apache.cxf.systest.ws.fault.server; -import org.apache.cxf.feature.Features; -import org.example.contract.doubleit.DoubleItPortType; +import java.net.URL; -@WebService(targetNamespace = "http://www.example.org/contract/DoubleIt", - serviceName = "DoubleItService", - endpointInterface = "org.example.contract.doubleit.DoubleItPortType") -@Features(features = "org.apache.cxf.feature.LoggingFeature") -public class DoubleItImpl implements DoubleItPortType { - - public int doubleIt(int numberToDouble) { - return numberToDouble * 2; +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; + +public class Server extends AbstractBusTestServerBase { + + public Server() { + + } + + protected void run() { + URL busFile = Server.class.getResource("server.xml"); + Bus busLocal = new SpringBusFactory().createBus(busFile); + BusFactory.setDefaultBus(busLocal); + setBus(busLocal); + + try { + new Server(); + } catch (Exception e) { + e.printStackTrace(); + } } - } Modified: cxf/trunk/systests/ws-security/src/test/resources/DoubleItLogical.wsdl URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/DoubleItLogical.wsdl?rev=1342711&r1=1342710&r2=1342711&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/DoubleItLogical.wsdl (original) +++ cxf/trunk/systests/ws-security/src/test/resources/DoubleItLogical.wsdl Fri May 25 16:14:02 2012 @@ -43,6 +43,14 @@ + + + + + + + + @@ -55,10 +63,14 @@ + + + + Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl?rev=1342711&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl Fri May 25 16:14:02 2012 @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/client.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/client.xml?rev=1342711&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/client.xml (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/client/client.xml Fri May 25 16:14:02 2012 @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml?rev=1342711&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml Fri May 25 16:14:02 2012 @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +