cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1381673 - in /cxf/trunk/systests/transports: pom.xml src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java
Date Thu, 06 Sep 2012 16:40:43 GMT
Author: dkulp
Date: Thu Sep  6 16:40:43 2012
New Revision: 1381673

URL: http://svn.apache.org/viewvc?rev=1381673&view=rev
Log:
Add a test that tests the basic HTTP proxy stuff

Added:
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java
Modified:
    cxf/trunk/systests/transports/pom.xml
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java

Modified: cxf/trunk/systests/transports/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/pom.xml?rev=1381673&r1=1381672&r2=1381673&view=diff
==============================================================================
--- cxf/trunk/systests/transports/pom.xml (original)
+++ cxf/trunk/systests/transports/pom.xml Thu Sep  6 16:40:43 2012
@@ -286,7 +286,11 @@
             <artifactId>commons-httpclient</artifactId>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.littleshoot</groupId>
+            <artifactId>littleproxy</artifactId>
+            <version>0.4</version>
+        </dependency>
     </dependencies>
 
 </project>

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java?rev=1381673&r1=1381672&r2=1381673&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
Thu Sep  6 16:40:43 2012
@@ -282,6 +282,16 @@ public class HTTPConduitTest extends Abs
         return fac.getTrustManagers();
     }
 
+    //methods that a subclass can override to inject a Proxy into the flow
+    //and assert the proxy was appropriately called
+    public void configureProxy(Client c) {
+    }
+    public void resetProxyCount() {
+    }
+    public void assertProxyRequestCount(int i) {
+    }
+
+    
     private Greeter getMortimerGreeter() throws MalformedURLException {
         URL wsdl = getClass().getResource("resources/greeting.wsdl");
         assertNotNull("WSDL is null", wsdl);
@@ -292,6 +302,8 @@ public class HTTPConduitTest extends Abs
         Greeter mortimer = service.getPort(mortimerQ, Greeter.class);
         assertNotNull("Port is null", mortimer);
         updateAddressPort(mortimer, PORT0);
+        
+        configureProxy(ClientProxy.getClient(mortimer));
         return mortimer;
     }
 
@@ -303,6 +315,7 @@ public class HTTPConduitTest extends Abs
         String answer = mortimer.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Mortimer".equals(answer));
+        assertProxyRequestCount(1);
     }
 
     @Test
@@ -318,6 +331,7 @@ public class HTTPConduitTest extends Abs
         } finally {
             rootLogger.setLevel(oldLevel);
         }
+        assertProxyRequestCount(1);
     }
 
     /**
@@ -343,7 +357,8 @@ public class HTTPConduitTest extends Abs
 
         Greeter rethwel = service.getPort(rethwelQ, Greeter.class);
         assertNotNull("Port is null", rethwel);
-        updateAddressPort(rethwel, PORT5);
+        updateAddressPort(rethwel, PORT4);
+        configureProxy(ClientProxy.getClient(rethwel));
 
         String answer = null;
         try {
@@ -352,6 +367,7 @@ public class HTTPConduitTest extends Abs
         } catch (Exception e) {
             //e.printStackTrace();
         }
+        assertProxyRequestCount(1);
         
     }
     
@@ -393,10 +409,12 @@ public class HTTPConduitTest extends Abs
         Greeter rethwel = service.getPort(rethwelQ, Greeter.class);
         updateAddressPort(rethwel, PORT4);
         assertNotNull("Port is null", rethwel);
+        configureProxy(ClientProxy.getClient(rethwel));
         
         String answer = rethwel.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Mortimer".equals(answer));
+        assertProxyRequestCount(2);        
     }
     
     /**
@@ -426,6 +444,7 @@ public class HTTPConduitTest extends Abs
         Greeter hurlon = service.getPort(hurlonQ, Greeter.class);
         assertNotNull("Port is null", hurlon);
         updateAddressPort(hurlon, PORT6);
+        configureProxy(ClientProxy.getClient(hurlon));
         
         String answer = null;
         try {
@@ -436,7 +455,7 @@ public class HTTPConduitTest extends Abs
             // read from the StreamReader
             //e.printStackTrace();
         }
-        
+        assertProxyRequestCount(2);        
     }
     /**
      * This methods tests a basic https connection to Bethal.
@@ -459,6 +478,7 @@ public class HTTPConduitTest extends Abs
         assertNotNull("Service is null", service);
 
         Greeter bethal = service.getPort(bethalQ, Greeter.class);
+
         assertNotNull("Port is null", bethal);
         updateAddressPort(bethal, PORT2);
         verifyBethalClient(bethal);        
@@ -486,6 +506,7 @@ public class HTTPConduitTest extends Abs
     // we just verify the configurations are loaded successfully
     private void verifyBethalClient(Greeter bethal) {
         Client client = ClientProxy.getClient(bethal);
+
         HTTPConduit http = 
             (HTTPConduit) client.getConduit();
         
@@ -504,6 +525,9 @@ public class HTTPConduitTest extends Abs
                      "Betty", authPolicy.getUserName());
         assertEquals("Set the wrong pass word form the configuration",
                      "password", authPolicy.getPassword());
+
+        configureProxy(ClientProxy.getClient(bethal));
+        
         String answer = bethal.sayHi();
         answer = bethal.sayHi();
         answer = bethal.sayHi();
@@ -511,6 +535,10 @@ public class HTTPConduitTest extends Abs
         answer = bethal.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Bethal".equals(answer));
+        
+        //With HTTPS, it will just be a CONNECT to the proxy and all the 
+        //data is encrypted.  Thus, the proxy cannot distinquish the requests
+        assertProxyRequestCount(0);
     }
     
     /**
@@ -552,9 +580,11 @@ public class HTTPConduitTest extends Abs
         http.setTlsClientParameters(tlsClientParameters);
         http.setAuthorization(authPolicy);
         
+        configureProxy(client);
         String answer = bethal.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Bethal".equals(answer));
+        assertProxyRequestCount(0);
     }
     
 
@@ -585,7 +615,11 @@ public class HTTPConduitTest extends Abs
         
         http.setClient(httpClientPolicy);
         http.setTlsClientParameters(tlsClientParameters);
+        configureProxy(client);
         poltim.sayHi();
+        //client -> poltim is https and thus not recorded but then redirected to mortimer
+        //client -> mortimer is http and recoreded
+        assertProxyRequestCount(1);
     }
     
     class MyHttpsTrustDecider extends MessageTrustDecider {
@@ -681,9 +715,12 @@ public class HTTPConduitTest extends Abs
         // Our expected server should be OU=Bethal
         http.setTrustDecider(new MyHttpsTrustDecider("Bethal"));
         
+        configureProxy(client);
         String answer = bethal.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Bethal".equals(answer));
+        assertProxyRequestCount(0);
+        
         
         // Nobody will not equal OU=Bethal
         MyHttpsTrustDecider trustDecider =
@@ -697,6 +734,7 @@ public class HTTPConduitTest extends Abs
             //assertTrue("Trust Decider was not called", 
             //              0 > trustDecider.wasCalled());
         }
+        assertProxyRequestCount(0);
     }
 
     @Test
@@ -743,7 +781,9 @@ public class HTTPConduitTest extends Abs
         
         // We actually get our answer from Bethal at the end of the
         // redirects.
+        configureProxy(ClientProxy.getClient(tarpin));
         String answer = tarpin.sayHi();
+        assertProxyRequestCount(0);
         
         assertTrue("Trust Decider wasn't called correctly", 
                        3 == trustDecider.wasCalled());
@@ -759,6 +799,7 @@ public class HTTPConduitTest extends Abs
         } catch (Exception e) {
             //e.printStackTrace();
         }
+        assertProxyRequestCount(0);
         
         // Set back to unlimited.
         http.getClient().setMaxRetransmits(-1);
@@ -777,7 +818,7 @@ public class HTTPConduitTest extends Abs
             assertTrue("Trust Decider wasn't called correctly",
                      2 == trustDecider.wasCalled());
         }
-        
+        assertProxyRequestCount(0);
     }
 
     public class MyBasicAuthSupplier implements HttpAuthSupplier {

Added: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java?rev=1381673&view=auto
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java
(added)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java
Thu Sep  6 16:40:43 2012
@@ -0,0 +1,100 @@
+/**
+ * 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.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;
+
+
+/**
+ * 
+ */
+public class HTTPProxyConduitTest extends HTTPConduitTest {
+    static final int PROXY_PORT = Integer.parseInt(allocatePort(HTTPProxyConduitTest.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 HTTPProxyConduitTest() {
+    }
+
+    
+    @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.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);
+    }
+    
+    public void resetProxyCount() {
+        requestFilter.reset();
+    }
+    public void assertProxyRequestCount(int i) {
+        assertEquals("Unexpected request count", i, requestFilter.getCount());
+    }
+    
+}



Mime
View raw message