Commit 8f316c0e authored by Stefano Costa's avatar Stefano Costa
Browse files

[GEOS-7295] Authkey community module breaks OpenLayers preview

parent 9f704aa0
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.security;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
......@@ -35,6 +35,8 @@ import org.geoserver.wms.WMSInfo;
import org.junit.Test;
import org.w3c.dom.Document;
import com.mockrunner.mock.web.MockHttpServletResponse;
public class AuthencationKeyOWSTest extends GeoServerSystemTestSupport {
private static String adminKey;
......@@ -261,4 +263,24 @@ public class AuthencationKeyOWSTest extends GeoServerSystemTestSupport {
String url = engine.evaluate("//wfs:FeatureCollection/@xsi:schemaLocation", doc);
assertTrue(url.contains("&authkey=" + citeKey));
}
/*
* Tests that URLs in the OpenLayers Map are correctly generated (see: GEOS-7295)
*/
@Test
public void testOpenLayersMapOutput() throws Exception {
MockHttpServletResponse response = getAsServletResponse("cite/wms?service=WMS&"
+ "version=1.1.0&"
+ "request=GetMap&"
+ "bbox=-2.0,2.0,-1.0,6.0&"
+ "layers=" + MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart() + "&"
+ "width=300&"
+ "height=300&"
+ "srs=EPSG:4326&"
+ "format=application/openlayers"
+ "&authkey=" + citeKey);
byte[] responseContent = getBinary(response);
String htmlDoc = new String(responseContent, "UTF-8");
assertTrue(htmlDoc.indexOf("http://localhost:8080/geoserver/cite/wms?authkey=" + citeKey) > 0);
}
}
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -166,6 +166,13 @@ public class OpenLayersMapOutputFormat implements GetMapOutputFormat {
map.put("maxResolution", new Double(getMaxResolution(mapContent.getRenderingArea())));
String baseUrl = ResponseUtils.buildURL(request.getBaseUrl(), "/", null, URLType.RESOURCE);
String queryString = null;
// remove query string from baseUrl
if (baseUrl.indexOf("?") > 0) {
int idx = baseUrl.indexOf("?");
queryString = baseUrl.substring(idx); // include question mark
baseUrl = baseUrl.substring(0, idx); // leave out question mark
}
map.put("baseUrl", canonicUrl(baseUrl));
// TODO: replace service path with call to buildURL since it does this
......@@ -177,6 +184,10 @@ public class OpenLayersMapOutputFormat implements GetMapOutputFormat {
if (LocalWorkspace.get() != null) {
servicePath = LocalWorkspace.get().getName() + "/" + servicePath;
}
// append query string to servicePath
if (queryString != null) {
servicePath += queryString;
}
map.put("servicePath", servicePath);
map.put("parameters", getLayerParameter(request.getRawKvp()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment