Author: dkulp Date: Tue Sep 11 18:54:08 2012 New Revision: 1383542 URL: http://svn.apache.org/viewvc?rev=1383542&view=rev Log: Merged revisions 1383522 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1383522 | dkulp | 2012-09-11 14:38:53 -0400 (Tue, 11 Sep 2012) | 10 lines Merged revisions 1381674 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1381674 | dkulp | 2012-09-06 12:40:48 -0400 (Thu, 06 Sep 2012) | 2 lines Add a test for basic-auth to the proxy ........ ........ Added: cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyAuthConduitTest.java Added: cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyAuthConduitTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyAuthConduitTest.java?rev=1383542&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyAuthConduitTest.java (added) +++ cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyAuthConduitTest.java Tue Sep 11 18:54:08 2012 @@ -0,0 +1,111 @@ +/** + * 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.http; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; + +import org.jboss.netty.handler.codec.http.HttpRequest; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import org.littleshoot.proxy.DefaultHttpProxyServer; +import org.littleshoot.proxy.HttpFilter; +import org.littleshoot.proxy.HttpRequestFilter; +import org.littleshoot.proxy.ProxyAuthorizationHandler; + + +/** + * + */ +public class HTTPProxyAuthConduitTest extends HTTPConduitTest { + static final int PROXY_PORT = Integer.parseInt(allocatePort(HTTPProxyAuthConduitTest.class)); + static DefaultHttpProxyServer proxy; + static CountingFilter requestFilter = new CountingFilter(); + + static class CountingFilter implements HttpRequestFilter { + AtomicInteger count = new AtomicInteger(); + public void filter(HttpRequest httpRequest) { + count.incrementAndGet(); + } + + public void reset() { + count.set(0); + } + public int getCount() { + return count.get(); + } + } + + public HTTPProxyAuthConduitTest() { + } + + + @AfterClass + public static void stopProxy() { + proxy.stop(); + proxy = null; + } + + @BeforeClass + public static void startProxy() { + proxy = new DefaultHttpProxyServer(PROXY_PORT, requestFilter, new HashMap<String, HttpFilter>()); + proxy.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() { + public boolean authenticate(String userName, String password) { + return "password".equals(password) && "CXF".equals(userName); + } + }); + proxy.start(); + } + @Before + public void resetCount() { + requestFilter.reset(); + } + + public void configureProxy(Client client) { + HTTPConduit cond = (HTTPConduit)client.getConduit(); + HTTPClientPolicy pol = cond.getClient(); + if (pol == null) { + pol = new HTTPClientPolicy(); + cond.setClient(pol); + } + pol.setProxyServer("localhost"); + pol.setProxyServerPort(PROXY_PORT); + ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy(); + auth.setUserName("CXF"); + auth.setPassword("password"); + cond.setProxyAuthorization(auth); + } + + public void resetProxyCount() { + requestFilter.reset(); + } + public void assertProxyRequestCount(int i) { + assertEquals("Unexpected request count", i, requestFilter.getCount()); + } + +}
