@Test public void testGetMissing() throws Exception { MockHttpServletResponse response = getAsServletResponse(BASEPATH + "?service=csw&version=2.0.2&request=GetRepositoryItem&id=foo"); assertEquals(404, response.getErrorCode()); }
throw new RuntimeException(e); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode());
@Test public void testPercentSymbolInUriDoesNotThrowExceptionAndReturnsError400() throws Exception { // GIVEN String uri = "http://example.com/page~foo=bar%~.html"; state.setCurrentURI(uri); MockHttpServletResponse response = new MockHttpServletResponse(); // WHEN filter.doFilter(request, response, new FilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { } }); // THEN assertThat("URL is malformed and we expect that error 400 Bad request is send back in response.", response.getErrorCode(), equalTo(400)); }
@Override public void handle(HttpExchange ex) throws IOException { URI uri = ex.getRequestURI(); ex.getRequestBody().close(); LOGGER.info("Cas proxy callback: " + uri.toString()); String query = uri.getQuery(); MockHttpServletRequest request = createRequest(GeoServerCasConstants.CAS_PROXY_RECEPTOR_PATTERN); MockHttpServletResponse response = new MockHttpServletResponse(); MockFilterChain chain = new MockFilterChain(); // CAS sends the callback twice, the first time without parameters if (query != null) { request.setQueryString(query); String[] kvps = query.split("&"); for (String kvp : kvps) { String[] tmp = kvp.split("="); request.setupAddParameter(tmp[0], tmp[1]); } } try { getProxy().doFilter(request, response, chain); } catch (ServletException e) { throw new RuntimeException(e); } assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); ex.sendResponseHeaders(200, 0); ex.getResponseBody().close(); } }
public void testPngIntegration() throws Exception { String layerId = getLayerId(MockData.BASIC_POLYGONS); MockHttpServletResponse sr = getAsServletResponse("gwc/service/wmts?request=GetTile&layer=" + layerId + "&format=image/png&tilematrixset=EPSG:4326&tilematrix=EPSG:4326:0&tilerow=0&tilecol=0"); assertEquals(200, sr.getErrorCode()); assertEquals("image/png", sr.getContentType()); }
@Test public void hasPercentSymbolInUrlDoesNotThrowExceptionAndReturnsError400() throws Exception { // GIVEN String url = "http://example.com/page.html?test=%"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI(StringUtils.substringBefore(url, "?")); request.setRequestURL(url); MockHttpServletResponse response = new MockHttpServletResponse(); // WHEN filter.doFilter(request, response, new FilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { } }); // THEN assertThat("URL is malformed and we expect that error 400 Bad request is send back in response.", response.getErrorCode(), equalTo(400)); }
public void testGetLayersList() throws Exception { final String url = "gwc/rest/layers.xml"; MockHttpServletResponse sr = getAsServletResponse(url); assertEquals(200, sr.getErrorCode()); assertTrue(sr.getContentType(), sr.getContentType().startsWith("text/xml")); Document dom = getAsDOM(url); // print(dom); ArrayList<String> tileLayerNames = Lists.newArrayList(GWC.get().getTileLayerNames()); Collections.sort(tileLayerNames); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(ImmutableMap.of("atom", "http://www.w3.org/2005/Atom"))); for (String name : tileLayerNames) { String xpath = "//layers/layer/name[text() = '" + name + "']"; assertXpathExists(xpath, dom); xpath = "//layers/layer/atom:link[@href = 'http://localhost/geoserver/gwc/rest/layers/" + ServletUtils.URLEncode(name) + ".xml']"; assertXpathExists(xpath, dom); } }
public void testDirectWMSIntegrationIfModifiedSinceSupport() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(path); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); String lastModifiedHeader = response.getHeader("Last-Modified"); assertNotNull(lastModifiedHeader); Date lastModified = DateUtil.parseDate(lastModifiedHeader); MockHttpServletRequest httpReq = createRequest(path); httpReq.setMethod("GET"); httpReq.setBodyContent(new byte[] {}); httpReq.setHeader("If-Modified-Since", lastModifiedHeader); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); // set the If-Modified-Since header to some point in the past of the last modified value Date past = new Date(lastModified.getTime() - 5000); String ifModifiedSince = DateUtil.formatDate(past); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); Date future = new Date(lastModified.getTime() + 5000); ifModifiedSince = DateUtil.formatDate(future); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); }
/** * If direct WMS integration is enabled, a GetMap requests that hits the regular WMS but matches * a gwc tile should return with the proper {@code geowebcache-tile-index} HTTP response header. */ public void testDirectWMSIntegration() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); String request; MockHttpServletResponse response; request = buildGetMap(true, layerName, "EPSG:4326", null); response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertNull(response.getHeader("geowebcache-tile-index")); request = request + "&tiled=true"; response = getAsServletResponse(request); assertEquals(200, response.getErrorCode()); assertEquals("image/png", response.getContentType()); }
public void testGetLayer() throws Exception { final String layerName = getLayerId(MockData.BASIC_POLYGONS); final String url = "gwc/rest/layers/" + layerName + ".xml"; final String id = getCatalog().getLayerByName(layerName).getId(); MockHttpServletResponse sr = getAsServletResponse(url); assertEquals(200, sr.getErrorCode()); assertTrue(sr.getContentType(), sr.getContentType().startsWith("text/xml")); Document dom = getAsDOM(url); print(dom); assertXpathExists("/GeoServerLayer", dom); assertXpathEvaluatesTo(id, "/GeoServerLayer/id", dom); assertXpathEvaluatesTo(layerName, "/GeoServerLayer/name", dom); assertXpathEvaluatesTo("true", "/GeoServerLayer/enabled", dom); assertXpathEvaluatesTo("image/png", "/GeoServerLayer/mimeFormats/string[1]", dom); assertXpathEvaluatesTo("image/jpeg", "/GeoServerLayer/mimeFormats/string[2]", dom); assertXpathEvaluatesTo("EPSG:900913", "/GeoServerLayer/gridSubsets/gridSubset[1]/gridSetName", dom); }
assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertTrue(response.wasRedirectSent()); String redirectURL = response.getHeader("Location"); chain = new MockFilterChain(); String ticket =loginUsingTicket(helper, request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertFalse(response.wasRedirectSent()); chain = new MockFilterChain(); ticket =loginUsingTicket(helper, request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertFalse(response.wasRedirectSent()); ctx = (SecurityContext) request.getSession(true).getAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertFalse(response.wasRedirectSent()); auth = ctx.getAuthentication(); chain = new MockFilterChain(); ticket =loginUsingTicket(helper, request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertTrue(response.wasRedirectSent()); redirectURL = response.getHeader("Location"); chain = new MockFilterChain(); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode());
MockFilterChain chain = new MockFilterChain(); loginUsingTicket(helper, request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertFalse(response.wasRedirectSent()); (GeoServerLogoutFilter) getSecurityManager().loadFilter(GeoServerSecurityFilterChain.FORM_LOGOUT_FILTER); logoutFilter.doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertTrue(response.wasRedirectSent()); String redirectUrl = response.getHeader("Location"); chain = new MockFilterChain(); String ticket = loginUsingTicket(helper, request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertFalse(response.wasRedirectSent()); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertTrue(response.wasRedirectSent()); redirectUrl = response.getHeader("Location");
request.setHeader(GeoServerCasAuthenticationEntryPoint.CAS_REDIRECT, "false"); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getErrorCode()); request.setupAddParameter("ticket", ticket); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); TestingAuthenticationCache cache = getCache(); Authentication casAuth = cache.get(casProxyFilterName, username); request.setHeader(GeoServerCasAuthenticationEntryPoint.CAS_REDIRECT, "false"); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); cache = getCache(); casAuth = cache.get(casProxyFilterName, username); request.setHeader(GeoServerCasAuthenticationEntryPoint.CAS_REDIRECT, "false"); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getErrorCode()); cache = getCache(); casAuth = cache.get(casProxyFilterName, ticket); chain = new MockFilterChain(); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); cache = getCache(); casAuth = cache.get(casProxyFilterName, username);
@Test public void testBasicContents() throws Exception { MockHttpServletResponse response = getAsServletResponse(root() + "capabilities"); assertEquals(200, response.getErrorCode()); JSONArray json = (JSONArray) json(response); // print(json); // check we have the right number of layers assertEquals(getCatalog().getFeatureTypes().size(), json.size()); // extract and check one JXPathContext context = JXPathContext.newContext(json); JSONObject primitive = (JSONObject) context.getValue(".[name = 'sf:PrimitiveGeoFeature']"); assertNotNull(primitive); assertEquals("urn:ogc:def:crs:EPSG:4326", primitive.get("crs")); assertEquals("xy", primitive.get("axisorder")); JSONArray bbox = (JSONArray) primitive.get("bbox"); assertEquals(-180.0, bbox.getDouble(0), 1E-7); assertEquals(-90.0, bbox.getDouble(1), 1E-7); assertEquals(180.0, bbox.getDouble(2), 1E-7); assertEquals(90.0, bbox.getDouble(3), 1E-7); } }
request.setHeader(GeoServerCasAuthenticationEntryPoint.CAS_REDIRECT, "false"); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getErrorCode()); request.setQueryString("ticket=ST-blabla&"+GeoServerCasAuthenticationEntryPoint.CAS_REDIRECT+"=false"); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getErrorCode()); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); TestingAuthenticationCache cache = getCache(); Authentication casAuth = cache.get(casProxyFilterName, username); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); TestingAuthenticationCache cache = getCache(); Authentication casAuth = cache.get(casProxyFilterName, username); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getErrorCode()); TestingAuthenticationCache cache = getCache(); Authentication casAuth = cache.get(casProxyFilterName, proxyTicket); chain = new MockFilterChain(); getProxy().doFilter(request, response, chain); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); cache = getCache(); casAuth = cache.get(casProxyFilterName, username);
@Test public void testDescribePrimitiveGeoFeature() throws Exception { MockHttpServletResponse response = getAsServletResponse(root() + "describe/sf:PrimitiveGeoFeature"); assertEquals(200, response.getErrorCode()); assertEquals(MediaType.APPLICATION_JSON.getName(), response.getContentType());