cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r1208938 - in /cxf/trunk/systests/jaxrs/src/test: java/org/apache/cxf/systest/jaxrs/cors/ resources/jaxrs_cors/WEB-INF/
Date Thu, 01 Dec 2011 02:56:25 GMT
Author: bimargulies
Date: Thu Dec  1 02:56:24 2011
New Revision: 1208938

URL: http://svn.apache.org/viewvc?rev=1208938&view=rev
Log:
CXF-3943: test non-* Origin restriction.

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
  (with props)
Modified:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/BasicCrossOriginTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CorsServer.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/BasicCrossOriginTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/BasicCrossOriginTest.java?rev=1208938&r1=1208937&r2=1208938&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/BasicCrossOriginTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/BasicCrossOriginTest.java
Thu Dec  1 02:56:24 2011
@@ -19,7 +19,11 @@
 
 package org.apache.cxf.systest.jaxrs.cors;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.cors.CorsHeaderConstants;
 import org.apache.cxf.systest.jaxrs.AbstractSpringServer;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -30,24 +34,32 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
 
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
 public class BasicCrossOriginTest extends AbstractBusClientServerTestBase {
     public static final String PORT = SpringServer.PORT;
+    private WebClient configClient;
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", 
-                   launchServer(SpringServer.class, true));
+        assertTrue("server did not launch correctly", launchServer(SpringServer.class, true));
+    }
+
+    @Before
+    public void before() {
+        List<Object> providers = new ArrayList<Object>();
+        providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());
+        configClient = WebClient.create("http://localhost:" + PORT + "/config", providers);
     }
-    
+
     @Test
     public void testSimpleGet() throws Exception {
         String origin = "http://localhost:" + PORT;
         HttpClient httpclient = new DefaultHttpClient();
-        HttpGet httpget = new HttpGet(origin + "/simpleGet/HelloThere");
+        HttpGet httpget = new HttpGet(origin + "/test/simpleGet/HelloThere");
         httpget.addHeader("Origin", origin);
         HttpResponse response = httpclient.execute(httpget);
         HttpEntity entity = response.getEntity();
@@ -59,11 +71,36 @@ public class BasicCrossOriginTest extend
         assertEquals(1, aaoHeaders.length);
         assertEquals("*", aaoHeaders[0].getValue());
     }
-    
+
+    @Test
+    public void specificOriginSimpleGet() throws Exception {
+        String origin = "http://localhost:" + PORT;
+
+        String confResult = configClient.accept("text/plain").replacePath("/setOriginList")
+            .type("application/json")
+            .post(new String[] {
+                origin
+            }, String.class);
+        assertEquals("ok", confResult);
+
+        HttpClient httpclient = new DefaultHttpClient();
+        HttpGet httpget = new HttpGet(origin + "/test/simpleGet/HelloThere");
+        httpget.addHeader("Origin", origin);
+        HttpResponse response = httpclient.execute(httpget);
+        HttpEntity entity = response.getEntity();
+        String e = IOUtils.toString(entity.getContent(), "utf-8");
+
+        assertEquals("HelloThere", e);
+        Header[] aaoHeaders = response.getHeaders(CorsHeaderConstants.HEADER_AC_ALLOW_ORIGIN);
+        assertNotNull(aaoHeaders);
+        assertEquals(1, aaoHeaders.length);
+        assertEquals(origin, aaoHeaders[0].getValue());
+    }
+
     @Ignore
     public static class SpringServer extends AbstractSpringServer {
         public static final String PORT = AbstractSpringServer.PORT;
-        
+
         public SpringServer() {
             super("/jaxrs_cors");
         }

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java?rev=1208938&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
Thu Dec  1 02:56:24 2011
@@ -0,0 +1,60 @@
+/**
+ * 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.jaxrs.cors;
+
+import java.util.Arrays;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.cxf.jaxrs.cors.CrossOriginInputFilter;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+/**
+ * 
+ */
+public class ConfigServer implements ApplicationContextAware {
+    private ApplicationContext appContext;
+
+    @POST
+    @Consumes("application/json")
+    @Path("/setOriginList")
+    @Produces("text/plain")
+    public String setOriginList(String[] origins) {
+        CrossOriginInputFilter inputFilter = appContext
+            .getBean("cors-input", org.apache.cxf.jaxrs.cors.CrossOriginInputFilter.class);
+        if (origins == null || origins.length == 0) {
+            inputFilter.setAllowAllOrigins(true);
+        } else {
+            inputFilter.setAllowAllOrigins(false);
+            inputFilter.setAllowedOrigins(Arrays.asList(origins));
+        }
+        return "ok";
+    }
+
+    public void setApplicationContext(ApplicationContext context) throws BeansException {
+        appContext = context;
+    }
+
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/ConfigServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CorsServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CorsServer.java?rev=1208938&r1=1208937&r2=1208938&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CorsServer.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CorsServer.java
Thu Dec  1 02:56:24 2011
@@ -35,4 +35,6 @@ public class CorsServer {
     public String simpleGet(@PathParam("echo") String echo) {
         return echo;
     }
+    
+
 }

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml?rev=1208938&r1=1208937&r2=1208938&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml Thu Dec  1 02:56:24
2011
@@ -27,18 +27,29 @@ http://cxf.apache.org/core 
 	<bean id="cors-output" class="org.apache.cxf.jaxrs.cors.CrossOriginOutputFilter">
 	</bean>
 
-	<jaxrs:server id="cors-service" address="/">
+	<jaxrs:server id="cors-service" address="/test">
 		<jaxrs:serviceBeans>
 			<ref bean="cors-server" />
 		</jaxrs:serviceBeans>
 		<jaxrs:providers>
 			<ref bean="cors-input" />
 			<ref bean="cors-output" />
-		</jaxrs:providers>
+		</jaxrs:providers><!-- 
 		<jaxrs:features>
 			<cxf:logging />
 		</jaxrs:features>
+		-->
 	</jaxrs:server>
+	<jaxrs:server id="config-service" address="/config">
+		<jaxrs:serviceBeans>
+			<ref bean="config-server" />
+		</jaxrs:serviceBeans>
+		<jaxrs:providers>
+			<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
+		</jaxrs:providers> 
+	</jaxrs:server>
+
+	<bean id="config-server" class="org.apache.cxf.systest.jaxrs.cors.ConfigServer"/>
 	<bean id="cors-server" scope="prototype"
 		class="org.apache.cxf.systest.jaxrs.cors.CorsServer" />
 </beans>



Mime
View raw message