|
| 1 | +/* |
| 2 | + * Copyright (C) 2026 B3Partners B.V. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + */ |
| 6 | +package org.tailormap.api.controller; |
| 7 | + |
| 8 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 9 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
| 10 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 11 | +import static org.tailormap.api.TestRequestProcessor.setServletPath; |
| 12 | + |
| 13 | +import org.junit.jupiter.api.BeforeAll; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.api.TestInstance; |
| 16 | +import org.junit.jupiter.api.parallel.Execution; |
| 17 | +import org.junit.jupiter.api.parallel.ExecutionMode; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.beans.factory.annotation.Value; |
| 20 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 21 | +import org.springframework.http.MediaType; |
| 22 | +import org.springframework.test.context.TestPropertySource; |
| 23 | +import org.springframework.test.web.servlet.MockMvc; |
| 24 | +import org.springframework.test.web.servlet.setup.MockMvcBuilders; |
| 25 | +import org.springframework.web.context.WebApplicationContext; |
| 26 | +import org.tailormap.api.annotation.PostgresIntegrationTest; |
| 27 | + |
| 28 | +@PostgresIntegrationTest |
| 29 | +@AutoConfigureMockMvc |
| 30 | +@Execution(ExecutionMode.CONCURRENT) |
| 31 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 32 | +@TestPropertySource( |
| 33 | + properties = { |
| 34 | + // Use the default proxy configuration, which denies layer patterns, |
| 35 | + // to test the default configuration of the GeoServiceProxyController |
| 36 | + "tailormap-api.proxy.passthrough.hostnames=", |
| 37 | + "tailormap-api.proxy.passthrough.layerpatterns=" |
| 38 | + }) |
| 39 | +class GeoServiceProxyControllerDefaultProxyConfigIntegrationTest { |
| 40 | + private final String begroeidterreindeelUrl = |
| 41 | + "/app/default/layer/lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel/proxy/wms"; |
| 42 | + |
| 43 | + @Autowired |
| 44 | + private WebApplicationContext context; |
| 45 | + |
| 46 | + private MockMvc mockMvc; |
| 47 | + |
| 48 | + @Value("${tailormap-api.base-path}") |
| 49 | + private String apiBasePath; |
| 50 | + |
| 51 | + @BeforeAll |
| 52 | + void initialize() { |
| 53 | + mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void post_request() throws Exception { |
| 58 | + final String path = apiBasePath + begroeidterreindeelUrl; |
| 59 | + mockMvc.perform(post(path) |
| 60 | + .param("REQUEST", "GetMap") |
| 61 | + .param("SERVICE", "WMS") |
| 62 | + .param("VERSION", "1.3.0") |
| 63 | + .param("FORMAT", "image/png") |
| 64 | + .param("STYLES", "") |
| 65 | + .param("TRANSPARENT", "TRUE") |
| 66 | + .param("LAYERS", "postgis:begroeidterreindeel") |
| 67 | + .param("WIDTH", "2775") |
| 68 | + .param("HEIGHT", "1002") |
| 69 | + .param("CRS", "EPSG:28992") |
| 70 | + .param("BBOX", "130574.85495843932,457818.25613033347,133951.6192003861,459037.5418133715") |
| 71 | + .contentType(MediaType.APPLICATION_FORM_URLENCODED) |
| 72 | + .with(setServletPath(path))) |
| 73 | + .andExpect(status().isOk()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void get_request() throws Exception { |
| 78 | + final String path = apiBasePath + begroeidterreindeelUrl; |
| 79 | + mockMvc.perform(get(path) |
| 80 | + .param("REQUEST", "GetMap") |
| 81 | + .param("SERVICE", "WMS") |
| 82 | + .param("VERSION", "1.3.0") |
| 83 | + .param("FORMAT", "image/png") |
| 84 | + .param("STYLES", "") |
| 85 | + .param("TRANSPARENT", "TRUE") |
| 86 | + .param("LAYERS", "postgis:begroeidterreindeel") |
| 87 | + .param("WIDTH", "2775") |
| 88 | + .param("HEIGHT", "1002") |
| 89 | + .param("CRS", "EPSG:28992") |
| 90 | + .param("BBOX", "130574.85495843932,457818.25613033347,133951.6192003861,459037.5418133715") |
| 91 | + .with(setServletPath(path))) |
| 92 | + .andExpect(status().isOk()); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void disallow_invalid_layer_name_param() throws Exception { |
| 97 | + final String path = apiBasePath + begroeidterreindeelUrl; |
| 98 | + mockMvc.perform(post(path) |
| 99 | + .param("REQUEST", "GetMap") |
| 100 | + .param("SERVICE", "WMS") |
| 101 | + .param("LAYERS", "postgis:invalid_layer_name") |
| 102 | + .contentType(MediaType.APPLICATION_FORM_URLENCODED) |
| 103 | + .with(setServletPath(path))) |
| 104 | + .andExpect(status().isBadRequest()); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + void disallow_two_layer_names_param() throws Exception { |
| 109 | + final String path = apiBasePath + begroeidterreindeelUrl; |
| 110 | + mockMvc.perform(post(path) |
| 111 | + .param("REQUEST", "GetMap") |
| 112 | + .param("SERVICE", "WMS") |
| 113 | + .param("LAYERS", "postgis:invalid_layer_name,postgis:begroeidterreindeel") |
| 114 | + .contentType(MediaType.APPLICATION_FORM_URLENCODED) |
| 115 | + .with(setServletPath(path))) |
| 116 | + .andExpect(status().isBadRequest()); |
| 117 | + } |
| 118 | +} |
0 commit comments