From ac1b135cb9728e98c45b0ddaf802acea93955202 Mon Sep 17 00:00:00 2001 From: wiiitek Date: Fri, 15 Apr 2022 20:00:55 +0200 Subject: [PATCH 1/6] additional tests for springdoc to document behaviour behind the proxy --- .../ui/app31/SpringDocBehindProxyTest.java | 77 +++++++++++++++++++ ...ndProxyWithCustomSpringAndUIPathsTest.java | 73 ++++++++++++++++++ ...ocBehindProxyWithCustomUIPathPathTest.java | 73 ++++++++++++++++++ .../src/test/resources/results/app31 | 24 ++++++ 4 files changed, 247 insertions(+) create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java create mode 100644 springdoc-openapi-ui/src/test/resources/results/app31 diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java new file mode 100644 index 000000000..ac05779a5 --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java @@ -0,0 +1,77 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MvcResult; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@TestPropertySource(properties = {"server.forward-headers-strategy=framework"}) +public class SpringDocBehindProxyTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldServeSwaggerUIAtDefaultPath() throws Exception { + mockMvc.perform(get("/swagger-ui/index.html")) + .andExpect(status().isOk()); + } + + @Test + public void shouldReturnCorrectInitializerJS() throws Exception { + MvcResult mvcResult = mockMvc.perform(get("/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()).andReturn(); + String actualContent = mvcResult.getResponse().getContentAsString(); + + assertTrue(actualContent.contains("window.ui")); + assertTrue(actualContent.contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",")); + } + + @Test + public void shouldCalculateOauthRedirectBehindProxy() throws Exception { + mockMvc.perform(get("/v3/api-docs/swagger-config") + .header("X-Forwarded-Proto", "https") + .header("X-Forwarded-Host", "proxy-host") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()) + .andExpect(jsonPath("oauth2RedirectUrl", equalTo("https://proxy-host/path/prefix/swagger-ui/oauth2-redirect.html"))); + } + + @Test + public void shouldCalculateUrlsBehindProxy() throws Exception { + mockMvc.perform(get("/v3/api-docs/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()) + .andExpect(jsonPath("configUrl", equalTo("/path/prefix/v3/api-docs/swagger-config"))) + .andExpect(jsonPath("url", equalTo("/path/prefix/v3/api-docs"))); + } +} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java new file mode 100644 index 000000000..45371e8dd --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java @@ -0,0 +1,73 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MvcResult; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework", + "springdoc.api-docs.path=/docs/v3/openapi", + "springdoc.swagger-ui.path=/documentation/swagger.html" +}) +public class SpringDocBehindProxyWithCustomSpringAndUIPathsTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + private static final String EXTERNAL_SWAGGER_CONFIG_URL = "/path/prefix/docs/v3/openapi/swagger-config"; + private static final String EXTERNAL_OPENAPI_JSON_URL = "/path/prefix/docs/v3/openapi"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldServeOpenapiJsonUnderCustomPath() throws Exception { + mockMvc.perform(get("/docs/v3/openapi") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()); + } + + @Test + public void shouldCalculateUrlsBehindProxy() throws Exception { + mockMvc.perform(get("/docs/v3/openapi/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()) + .andExpect(jsonPath("configUrl", equalTo(EXTERNAL_SWAGGER_CONFIG_URL))) + .andExpect(jsonPath("url", equalTo(EXTERNAL_OPENAPI_JSON_URL))); + } + + @Test + public void shouldReturnCorrectInitializerJS() throws Exception { + MvcResult mvcResult = mockMvc.perform(get("/documentation/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()).andReturn(); + String actualContent = mvcResult.getResponse().getContentAsString(); + + assertTrue(actualContent.contains("window.ui")); + assertTrue(actualContent.contains("\"configUrl\" : \"" + EXTERNAL_SWAGGER_CONFIG_URL +"\",")); + } +} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java new file mode 100644 index 000000000..1af6f8656 --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java @@ -0,0 +1,73 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MvcResult; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework", + "springdoc.swagger-ui.path=/documentation/swagger.html" +}) +public class SpringDocBehindProxyWithCustomUIPathPathTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + private static final String EXTERNAL_SWAGGER_CONFIG_URL = "/path/prefix/v3/api-docs/swagger-config"; + private static final String EXTERNAL_OPENAPI_JSON_URL = "/path/prefix/v3/api-docs"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldRedirectSwaggerUIFromCustomPath() throws Exception { + mockMvc.perform(get("/documentation/swagger.html") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isFound()) + .andExpect(header().string("Location", "/path/prefix/documentation/swagger-ui/index.html")); + } + + @Test + public void shouldCalculateUrlsBehindProxy() throws Exception { + mockMvc.perform(get("/v3/api-docs/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()) + .andExpect(jsonPath("configUrl", equalTo(EXTERNAL_SWAGGER_CONFIG_URL))) + .andExpect(jsonPath("url", equalTo(EXTERNAL_OPENAPI_JSON_URL))); + } + + @Test + public void shouldReturnCorrectInitializerJS() throws Exception { + MvcResult mvcResult = mockMvc.perform(get("/documentation/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .andExpect(status().isOk()).andReturn(); + String actualContent = mvcResult.getResponse().getContentAsString(); + + assertTrue(actualContent.contains("window.ui")); + assertTrue(actualContent.contains("\"configUrl\" : \"" + EXTERNAL_SWAGGER_CONFIG_URL + "\",")); + } +} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/resources/results/app31 b/springdoc-openapi-ui/src/test/resources/results/app31 new file mode 100644 index 000000000..490a902cc --- /dev/null +++ b/springdoc-openapi-ui/src/test/resources/results/app31 @@ -0,0 +1,24 @@ +window.onload = function() { + // + + // the following lines will be replaced by docker/configurator, when it runs in a docker-container + window.ui = SwaggerUIBundle({ + url: "https://petstore.swagger.io/v2/swagger.json", + dom_id: '#swagger-ui', + deepLinking: true, + presets: [ + SwaggerUIBundle.presets.apis, + SwaggerUIStandalonePreset + ], + plugins: [ + SwaggerUIBundle.plugins.DownloadUrl + ], + layout: "StandaloneLayout" , + + "configUrl" : "/path/prefix/v3/api-docs/swagger-config", + "validatorUrl" : "" + + }); + + // +}; From 582f3d284bfffdf7bf318f4c530adc2bb15a0355 Mon Sep 17 00:00:00 2001 From: wiiitek Date: Wed, 27 Apr 2022 23:28:02 +0200 Subject: [PATCH 2/6] wip: tests for webflux-ui --- .../ui/app31/SpringDocApp31Test.java | 43 ++++++++++ .../ui/app31/SpringDocBehindProxyTest.java | 85 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java create mode 100644 springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java new file mode 100644 index 000000000..443b770f9 --- /dev/null +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java @@ -0,0 +1,43 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; + +@TestPropertySource(properties = { + "springdoc.swagger-ui.path=/api/", + "springdoc.swagger-ui.show-extensions=true", + "springdoc.swagger-ui.query-config-enabled=true", +}) +public class SpringDocApp31Test extends AbstractSpringDocTest { + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void test_query_config() { + webTestClient.get().uri("/api/").exchange() + .expectStatus().isFound() + .expectHeader().location("/api/webjars/swagger-ui/index.html?showExtensions=true&configUrl=/v3/api-docs/swagger-config"); + } +} diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java new file mode 100644 index 000000000..272cd266b --- /dev/null +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java @@ -0,0 +1,85 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@TestPropertySource(properties = { "server.forward-headers-strategy=framework" }) +public class SpringDocBehindProxyTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldServeSwaggerUIAtDefaultPath() { + webTestClient.get().uri("/webjars/swagger-ui/index.html").exchange() + .expectStatus().isOk(); + } + + @Test + public void shouldReturnCorrectInitializerJS() throws Exception { + webTestClient + .get().uri("/webjars/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk() + .expectBody(String.class) + .consumeWith(response -> { + String actualContent = response.getResponseBody(); + assertNotNull(actualContent); + assertTrue(actualContent.contains("window.ui")); + assertTrue(actualContent.contains("\"configUrl\" : \"/v3/api-docs/swagger-config\",")); + // TODO: what should be returned + //assertTrue(actualContent.contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",")); + } + ); + } + + @Test + public void shouldCalculateOauthRedirectBehindProxy() throws Exception { + webTestClient + .get().uri("/v3/api-docs/swagger-config") + .header("X-Forwarded-Proto", "https") + .header("X-Forwarded-Host", "proxy-host") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk().expectBody() + .jsonPath("$.oauth2RedirectUrl").isEqualTo("https://proxy-host/path/prefix/swagger-ui/oauth2-redirect.html"); + } + + @Test + public void shouldCalculateUrlsBehindProxy() throws Exception { + webTestClient + .get().uri("/v3/api-docs/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk().expectBody() + .jsonPath("$.configUrl").isEqualTo("/path/prefix/v3/api-docs/swagger-config") + .jsonPath("$.url").isEqualTo("/path/prefix/v3/api-docs"); + } +} From ef7cc817f19e2e7c8ef8efaaeeba4b6371fc4e51 Mon Sep 17 00:00:00 2001 From: wiiitek Date: Wed, 4 May 2022 17:06:36 +0200 Subject: [PATCH 3/6] simplify unit tests for springdoc ui behind a proxy --- .../ui/app31/SpringDocApp31Test.java | 47 ----------------- .../ui/app31/SpringDocBehindProxyTest.java | 39 +++++++++------ ...ngDocBehindProxyWithCustomUIPathTest.java} | 50 ++++++++++--------- ...ProxyWithCustomUIPathWithApiDocsTest.java} | 48 +++++++++--------- .../ui/app31/SpringDocApp31Test.java | 43 ---------------- .../ui/app31/SpringDocBehindProxyTest.java | 24 ++++----- 6 files changed, 86 insertions(+), 165 deletions(-) delete mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java rename springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/{SpringDocBehindProxyWithCustomUIPathPathTest.java => SpringDocBehindProxyWithCustomUIPathTest.java} (62%) rename springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/{SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java => SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java} (61%) delete mode 100644 springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java deleted file mode 100644 index 954d88c28..000000000 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * * Copyright 2019-2020 the original author or authors. - * * - * * Licensed 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 - * * - * * https://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 test.org.springdoc.ui.app31; - -import org.junit.jupiter.api.Test; -import test.org.springdoc.ui.AbstractSpringDocTest; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.test.context.TestPropertySource; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@TestPropertySource(properties = { - "springdoc.swagger-ui.path=/api/", - "springdoc.swagger-ui.show-extensions=true", - "springdoc.swagger-ui.query-config-enabled=true", -}) -public class SpringDocApp31Test extends AbstractSpringDocTest { - - @SpringBootApplication - static class SpringDocTestApp {} - - @Test - public void test_query_config() throws Exception { - mockMvc.perform(get("/api/")) - .andExpect(status().isFound()) - .andExpect(header().string("Location", "/api/swagger-ui/index.html?showExtensions=true&configUrl=/v3/api-docs/swagger-config")); - } -} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java index ac05779a5..d70d2eaf4 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java @@ -19,19 +19,21 @@ package test.org.springdoc.ui.app31; import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.web.servlet.MvcResult; -import test.org.springdoc.ui.AbstractSpringDocTest; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@TestPropertySource(properties = {"server.forward-headers-strategy=framework"}) +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework" +}) public class SpringDocBehindProxyTest extends AbstractSpringDocTest { private static final String X_FORWARD_PREFIX = "/path/prefix"; @@ -47,13 +49,12 @@ public void shouldServeSwaggerUIAtDefaultPath() throws Exception { @Test public void shouldReturnCorrectInitializerJS() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/swagger-ui/swagger-initializer.js") + mockMvc.perform(get("/swagger-ui/swagger-initializer.js") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) - .andExpect(status().isOk()).andReturn(); - String actualContent = mvcResult.getResponse().getContentAsString(); - - assertTrue(actualContent.contains("window.ui")); - assertTrue(actualContent.contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",")); + .andExpect(status().isOk()) + .andExpect(content().string( + containsString("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",") + )); } @Test @@ -63,15 +64,21 @@ public void shouldCalculateOauthRedirectBehindProxy() throws Exception { .header("X-Forwarded-Host", "proxy-host") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isOk()) - .andExpect(jsonPath("oauth2RedirectUrl", equalTo("https://proxy-host/path/prefix/swagger-ui/oauth2-redirect.html"))); + .andExpect(jsonPath("oauth2RedirectUrl", + equalTo("https://proxy-host/path/prefix/swagger-ui/oauth2-redirect.html") + )); } @Test public void shouldCalculateUrlsBehindProxy() throws Exception { mockMvc.perform(get("/v3/api-docs/swagger-config") - .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isOk()) - .andExpect(jsonPath("configUrl", equalTo("/path/prefix/v3/api-docs/swagger-config"))) - .andExpect(jsonPath("url", equalTo("/path/prefix/v3/api-docs"))); + .andExpect(jsonPath("url", + equalTo("/path/prefix/v3/api-docs") + )) + .andExpect(jsonPath("configUrl", + equalTo("/path/prefix/v3/api-docs/swagger-config") + )); } -} \ No newline at end of file +} diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java similarity index 62% rename from springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java rename to springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java index 1af6f8656..1034a9c99 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathPathTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java @@ -19,55 +19,59 @@ package test.org.springdoc.ui.app31; import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.web.servlet.MvcResult; -import test.org.springdoc.ui.AbstractSpringDocTest; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @TestPropertySource(properties = { "server.forward-headers-strategy=framework", - "springdoc.swagger-ui.path=/documentation/swagger.html" + "springdoc.swagger-ui.path=/foo/documentation/swagger.html" }) -public class SpringDocBehindProxyWithCustomUIPathPathTest extends AbstractSpringDocTest { +public class SpringDocBehindProxyWithCustomUIPathTest extends AbstractSpringDocTest { private static final String X_FORWARD_PREFIX = "/path/prefix"; - private static final String EXTERNAL_SWAGGER_CONFIG_URL = "/path/prefix/v3/api-docs/swagger-config"; - private static final String EXTERNAL_OPENAPI_JSON_URL = "/path/prefix/v3/api-docs"; - @SpringBootApplication static class SpringDocTestApp {} @Test public void shouldRedirectSwaggerUIFromCustomPath() throws Exception { - mockMvc.perform(get("/documentation/swagger.html") + mockMvc.perform(get("/foo/documentation/swagger.html") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isFound()) - .andExpect(header().string("Location", "/path/prefix/documentation/swagger-ui/index.html")); + .andExpect(header().string("Location", "/path/prefix/foo/documentation/swagger-ui/index.html")); } @Test - public void shouldCalculateUrlsBehindProxy() throws Exception { - mockMvc.perform(get("/v3/api-docs/swagger-config") + public void shouldReturnCorrectInitializerJS() throws Exception { + mockMvc.perform(get("/foo/documentation/swagger-ui/swagger-initializer.js") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isOk()) - .andExpect(jsonPath("configUrl", equalTo(EXTERNAL_SWAGGER_CONFIG_URL))) - .andExpect(jsonPath("url", equalTo(EXTERNAL_OPENAPI_JSON_URL))); + .andExpect(content().string( + containsString("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",") + )); } @Test - public void shouldReturnCorrectInitializerJS() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/documentation/swagger-ui/swagger-initializer.js") + public void shouldCalculateUrlsBehindProxy() throws Exception { + mockMvc.perform(get("/v3/api-docs/swagger-config") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) - .andExpect(status().isOk()).andReturn(); - String actualContent = mvcResult.getResponse().getContentAsString(); - - assertTrue(actualContent.contains("window.ui")); - assertTrue(actualContent.contains("\"configUrl\" : \"" + EXTERNAL_SWAGGER_CONFIG_URL + "\",")); + .andExpect(status().isOk()) + .andExpect(jsonPath("url", + equalTo("/path/prefix/v3/api-docs") + )) + .andExpect(jsonPath("configUrl", + equalTo("/path/prefix/v3/api-docs/swagger-config") + )); } -} \ No newline at end of file + +} diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java similarity index 61% rename from springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java rename to springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java index 45371e8dd..14c56468d 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomSpringAndUIPathsTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java @@ -19,55 +19,57 @@ package test.org.springdoc.ui.app31; import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.web.servlet.MvcResult; -import test.org.springdoc.ui.AbstractSpringDocTest; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @TestPropertySource(properties = { "server.forward-headers-strategy=framework", - "springdoc.api-docs.path=/docs/v3/openapi", - "springdoc.swagger-ui.path=/documentation/swagger.html" + "springdoc.swagger-ui.path=/foo/documentation/swagger.html", + "springdoc.api-docs.path=/bar/openapi/v3" }) -public class SpringDocBehindProxyWithCustomSpringAndUIPathsTest extends AbstractSpringDocTest { +public class SpringDocBehindProxyWithCustomUIPathWithApiDocsTest extends AbstractSpringDocTest { private static final String X_FORWARD_PREFIX = "/path/prefix"; - private static final String EXTERNAL_SWAGGER_CONFIG_URL = "/path/prefix/docs/v3/openapi/swagger-config"; - private static final String EXTERNAL_OPENAPI_JSON_URL = "/path/prefix/docs/v3/openapi"; - @SpringBootApplication static class SpringDocTestApp {} @Test public void shouldServeOpenapiJsonUnderCustomPath() throws Exception { - mockMvc.perform(get("/docs/v3/openapi") + mockMvc.perform(get("/bar/openapi/v3") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isOk()); } @Test - public void shouldCalculateUrlsBehindProxy() throws Exception { - mockMvc.perform(get("/docs/v3/openapi/swagger-config") + public void shouldReturnCorrectInitializerJS() throws Exception { + mockMvc.perform(get("/foo/documentation/swagger-ui/swagger-initializer.js") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) .andExpect(status().isOk()) - .andExpect(jsonPath("configUrl", equalTo(EXTERNAL_SWAGGER_CONFIG_URL))) - .andExpect(jsonPath("url", equalTo(EXTERNAL_OPENAPI_JSON_URL))); + .andExpect(content().string( + containsString("\"configUrl\" : \"/path/prefix/bar/openapi/v3/swagger-config\",") + )); } @Test - public void shouldReturnCorrectInitializerJS() throws Exception { - MvcResult mvcResult = mockMvc.perform(get("/documentation/swagger-ui/swagger-initializer.js") + public void shouldCalculateUrlsBehindProxy() throws Exception { + mockMvc.perform(get("/bar/openapi/v3/swagger-config") .header("X-Forwarded-Prefix", X_FORWARD_PREFIX)) - .andExpect(status().isOk()).andReturn(); - String actualContent = mvcResult.getResponse().getContentAsString(); - - assertTrue(actualContent.contains("window.ui")); - assertTrue(actualContent.contains("\"configUrl\" : \"" + EXTERNAL_SWAGGER_CONFIG_URL +"\",")); + .andExpect(status().isOk()) + .andExpect(jsonPath("url", + equalTo("/path/prefix/bar/openapi/v3") + )) + .andExpect(jsonPath("configUrl", + equalTo("/path/prefix/bar/openapi/v3/swagger-config") + )); } -} \ No newline at end of file +} diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java deleted file mode 100644 index 443b770f9..000000000 --- a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * * Copyright 2019-2020 the original author or authors. - * * - * * Licensed 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 - * * - * * https://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 test.org.springdoc.ui.app31; - -import org.junit.jupiter.api.Test; -import test.org.springdoc.ui.AbstractSpringDocTest; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource(properties = { - "springdoc.swagger-ui.path=/api/", - "springdoc.swagger-ui.show-extensions=true", - "springdoc.swagger-ui.query-config-enabled=true", -}) -public class SpringDocApp31Test extends AbstractSpringDocTest { - - @SpringBootApplication - static class SpringDocTestApp {} - - @Test - public void test_query_config() { - webTestClient.get().uri("/api/").exchange() - .expectStatus().isFound() - .expectHeader().location("/api/webjars/swagger-ui/index.html?showExtensions=true&configUrl=/v3/api-docs/swagger-config"); - } -} diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java index 272cd266b..a044bc911 100644 --- a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java @@ -24,10 +24,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.test.context.TestPropertySource; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -@TestPropertySource(properties = { "server.forward-headers-strategy=framework" }) +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework" +}) public class SpringDocBehindProxyTest extends AbstractSpringDocTest { private static final String X_FORWARD_PREFIX = "/path/prefix"; @@ -49,14 +50,9 @@ public void shouldReturnCorrectInitializerJS() throws Exception { .exchange() .expectStatus().isOk() .expectBody(String.class) - .consumeWith(response -> { - String actualContent = response.getResponseBody(); - assertNotNull(actualContent); - assertTrue(actualContent.contains("window.ui")); - assertTrue(actualContent.contains("\"configUrl\" : \"/v3/api-docs/swagger-config\",")); - // TODO: what should be returned - //assertTrue(actualContent.contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",")); - } + .consumeWith(response -> + assertThat(response.getResponseBody()) + .contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",") ); } @@ -79,7 +75,9 @@ public void shouldCalculateUrlsBehindProxy() throws Exception { .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) .exchange() .expectStatus().isOk().expectBody() - .jsonPath("$.configUrl").isEqualTo("/path/prefix/v3/api-docs/swagger-config") - .jsonPath("$.url").isEqualTo("/path/prefix/v3/api-docs"); + .jsonPath("$.url") + .isEqualTo("/path/prefix/v3/api-docs") + .jsonPath("$.configUrl") + .isEqualTo("/path/prefix/v3/api-docs/swagger-config"); } } From 0d1b3ab4a357a9efb05b21984db8bf8ae5026de1 Mon Sep 17 00:00:00 2001 From: wiiitek Date: Wed, 4 May 2022 17:49:50 +0200 Subject: [PATCH 4/6] update tests for webflux springdoc UI --- ...ingDocBehindProxyWithCustomUIPathTest.java | 77 ++++++++++++++++++ ...dProxyWithCustomUIPathWithApiDocsTest.java | 78 +++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java create mode 100644 springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java new file mode 100644 index 000000000..dce9ffeea --- /dev/null +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java @@ -0,0 +1,77 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework", + "springdoc.swagger-ui.path=/foo/documentation/swagger.html" +}) +public class SpringDocBehindProxyWithCustomUIPathTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldRedirectSwaggerUIFromCustomPath() { + webTestClient + .get().uri("/foo/documentation/swagger.html") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isFound() + .expectHeader().location("/path/prefix/foo/documentation/swagger-ui/index.html"); + } + + @Test + public void shouldReturnCorrectInitializerJS() { + webTestClient + .get().uri("/foo/documentation/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk() + .expectBody(String.class) + .consumeWith(response -> + assertThat(response.getResponseBody()) + .contains("\"configUrl\" : \\\"/path/prefix/v3/api-docs/swagger-config\\\",") + ); + } + + @Test + public void shouldCalculateUrlsBehindProxy() throws Exception { + webTestClient + .get().uri("/v3/api-docs/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk() + .expectBody() + .jsonPath("$.url") + .isEqualTo("/path/prefix/v3/api-docs") + .jsonPath("$.configUrl") + .isEqualTo("/path/prefix/v3/api-docs/swagger-config"); + } +} diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java new file mode 100644 index 000000000..2ca47c497 --- /dev/null +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java @@ -0,0 +1,78 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +@TestPropertySource(properties = { + "server.forward-headers-strategy=framework", + "springdoc.swagger-ui.path=/foo/documentation/swagger.html", + "springdoc.api-docs.path=/bar/openapi/v3" +}) +public class SpringDocBehindProxyWithCustomUIPathWithApiDocsTest extends AbstractSpringDocTest { + + private static final String X_FORWARD_PREFIX = "/path/prefix"; + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void shouldRedirectSwaggerUIFromCustomPath() { + webTestClient + .get().uri("/foo/documentation/swagger.html") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isFound() + .expectHeader().location("/path/prefix/foo/documentation/swagger-ui/index.html"); + } + + @Test + public void shouldReturnCorrectInitializerJS() { + webTestClient + .get().uri("/foo/documentation/swagger-ui/swagger-initializer.js") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk() + .expectBody(String.class) + .consumeWith(response -> + assertThat(response.getResponseBody()) + .contains("\"configUrl\" : \\\"/path/prefix/v3/api-docs/swagger-config\\\",") + ); + } + + @Test + public void shouldCalculateUrlsBehindProxy() { + webTestClient + .get().uri("/bar/openapi/v3/swagger-config") + .header("X-Forwarded-Prefix", X_FORWARD_PREFIX) + .exchange() + .expectStatus().isOk() + .expectBody() + .jsonPath("$.url") + .isEqualTo("/path/prefix/bar/openapi/v3") + .jsonPath("$.configUrl") + .isEqualTo("/path/prefix/bar/openapi/v3/swagger-config"); + } +} From e236c22704f747729088605c65f8d2bac89636e8 Mon Sep 17 00:00:00 2001 From: wiiitek Date: Wed, 4 May 2022 17:59:21 +0200 Subject: [PATCH 5/6] rename for tests to be in new tests folder --- .../ui/app31/SpringDocApp31Test.java | 47 +++++++++++++++++++ .../SpringDocBehindProxyTest.java | 2 +- ...ingDocBehindProxyWithCustomUIPathTest.java | 2 +- ...dProxyWithCustomUIPathWithApiDocsTest.java | 2 +- .../SpringDocBehindProxyTest.java | 2 +- ...ingDocBehindProxyWithCustomUIPathTest.java | 2 +- ...dProxyWithCustomUIPathWithApiDocsTest.java | 2 +- 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java rename springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyTest.java (98%) rename springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyWithCustomUIPathTest.java (98%) rename springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java (98%) rename springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyTest.java (98%) rename springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyWithCustomUIPathTest.java (98%) rename springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/{app31 => app32}/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java (98%) diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java new file mode 100644 index 000000000..954d88c28 --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocApp31Test.java @@ -0,0 +1,47 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed 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 + * * + * * https://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 test.org.springdoc.ui.app31; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@TestPropertySource(properties = { + "springdoc.swagger-ui.path=/api/", + "springdoc.swagger-ui.show-extensions=true", + "springdoc.swagger-ui.query-config-enabled=true", +}) +public class SpringDocApp31Test extends AbstractSpringDocTest { + + @SpringBootApplication + static class SpringDocTestApp {} + + @Test + public void test_query_config() throws Exception { + mockMvc.perform(get("/api/")) + .andExpect(status().isFound()) + .andExpect(header().string("Location", "/api/swagger-ui/index.html?showExtensions=true&configUrl=/v3/api-docs/swagger-config")); + } +} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java similarity index 98% rename from springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java rename to springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java index d70d2eaf4..9149c7252 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java similarity index 98% rename from springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java rename to springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java index 1034a9c99..6371e6dfa 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java similarity index 98% rename from springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java rename to springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java index 14c56468d..bbb11ba75 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java similarity index 98% rename from springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java rename to springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java index a044bc911..b1bd6f172 100644 --- a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyTest.java +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java similarity index 98% rename from springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java rename to springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java index dce9ffeea..3cda29a88 100644 --- a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathTest.java +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; diff --git a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java similarity index 98% rename from springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java rename to springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java index 2ca47c497..156d4fef5 100644 --- a/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app31/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java +++ b/springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java @@ -16,7 +16,7 @@ * */ -package test.org.springdoc.ui.app31; +package test.org.springdoc.ui.app32; import org.junit.jupiter.api.Test; import test.org.springdoc.ui.AbstractSpringDocTest; From e78a1100a830e7a3134cb2cbfd2b3627fdc4576a Mon Sep 17 00:00:00 2001 From: wiiitek Date: Wed, 4 May 2022 18:34:14 +0200 Subject: [PATCH 6/6] remove not needed result file --- .../src/test/resources/results/app31 | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 springdoc-openapi-ui/src/test/resources/results/app31 diff --git a/springdoc-openapi-ui/src/test/resources/results/app31 b/springdoc-openapi-ui/src/test/resources/results/app31 deleted file mode 100644 index 490a902cc..000000000 --- a/springdoc-openapi-ui/src/test/resources/results/app31 +++ /dev/null @@ -1,24 +0,0 @@ -window.onload = function() { - // - - // the following lines will be replaced by docker/configurator, when it runs in a docker-container - window.ui = SwaggerUIBundle({ - url: "https://petstore.swagger.io/v2/swagger.json", - dom_id: '#swagger-ui', - deepLinking: true, - presets: [ - SwaggerUIBundle.presets.apis, - SwaggerUIStandalonePreset - ], - plugins: [ - SwaggerUIBundle.plugins.DownloadUrl - ], - layout: "StandaloneLayout" , - - "configUrl" : "/path/prefix/v3/api-docs/swagger-config", - "validatorUrl" : "" - - }); - - // -};