Skip to content

Commit b97cb76

Browse files
committed
tests review
1 parent d5be3b9 commit b97cb76

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import test.org.springdoc.ui.AbstractSpringDocTest;
2323

2424
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.context.annotation.Import;
2526
import org.springframework.test.context.TestPropertySource;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
2829

2930
@TestPropertySource(properties = {
3031
"server.forward-headers-strategy=framework"
3132
})
33+
@Import(SpringDocConfig.class)
3234
public class SpringDocBehindProxyTest extends AbstractSpringDocTest {
3335

3436
private static final String X_FORWARD_PREFIX = "/path/prefix";
@@ -65,7 +67,7 @@ public void shouldCalculateOauthRedirectBehindProxy() throws Exception {
6567
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
6668
.exchange()
6769
.expectStatus().isOk().expectBody()
68-
.jsonPath("$.oauth2RedirectUrl").isEqualTo("https://proxy-host/path/prefix/swagger-ui/oauth2-redirect.html");
70+
.jsonPath("$.oauth2RedirectUrl").isEqualTo("https://proxy-host/path/prefix/webjars/swagger-ui/oauth2-redirect.html");
6971
}
7072

7173
@Test

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import test.org.springdoc.ui.AbstractSpringDocTest;
2323

2424
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.context.annotation.Import;
2526
import org.springframework.test.context.TestPropertySource;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
@@ -30,6 +31,7 @@
3031
"server.forward-headers-strategy=framework",
3132
"springdoc.swagger-ui.path=/foo/documentation/swagger.html"
3233
})
34+
@Import(SpringDocConfig.class)
3335
public class SpringDocBehindProxyWithCustomUIPathTest extends AbstractSpringDocTest {
3436

3537
private static final String X_FORWARD_PREFIX = "/path/prefix";
@@ -44,20 +46,20 @@ public void shouldRedirectSwaggerUIFromCustomPath() {
4446
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
4547
.exchange()
4648
.expectStatus().isFound()
47-
.expectHeader().location("/path/prefix/foo/documentation/swagger-ui/index.html");
49+
.expectHeader().location("/path/prefix/foo/documentation/webjars/swagger-ui/index.html");
4850
}
4951

5052
@Test
5153
public void shouldReturnCorrectInitializerJS() {
5254
webTestClient
53-
.get().uri("/foo/documentation/swagger-ui/swagger-initializer.js")
55+
.get().uri("/foo/documentation/webjars/swagger-ui/swagger-initializer.js")
5456
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
5557
.exchange()
5658
.expectStatus().isOk()
5759
.expectBody(String.class)
5860
.consumeWith(response ->
5961
assertThat(response.getResponseBody())
60-
.contains("\"configUrl\" : \\\"/path/prefix/v3/api-docs/swagger-config\\\",")
62+
.contains("\"configUrl\" : \"/path/prefix/v3/api-docs/swagger-config\",")
6163
);
6264
}
6365

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app32/SpringDocBehindProxyWithCustomUIPathWithApiDocsTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import test.org.springdoc.ui.AbstractSpringDocTest;
2323

2424
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.context.annotation.Import;
2526
import org.springframework.test.context.TestPropertySource;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
@@ -31,6 +32,7 @@
3132
"springdoc.swagger-ui.path=/foo/documentation/swagger.html",
3233
"springdoc.api-docs.path=/bar/openapi/v3"
3334
})
35+
@Import(SpringDocConfig.class)
3436
public class SpringDocBehindProxyWithCustomUIPathWithApiDocsTest extends AbstractSpringDocTest {
3537

3638
private static final String X_FORWARD_PREFIX = "/path/prefix";
@@ -45,20 +47,20 @@ public void shouldRedirectSwaggerUIFromCustomPath() {
4547
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
4648
.exchange()
4749
.expectStatus().isFound()
48-
.expectHeader().location("/path/prefix/foo/documentation/swagger-ui/index.html");
50+
.expectHeader().location("/path/prefix/foo/documentation/webjars/swagger-ui/index.html");
4951
}
5052

5153
@Test
5254
public void shouldReturnCorrectInitializerJS() {
5355
webTestClient
54-
.get().uri("/foo/documentation/swagger-ui/swagger-initializer.js")
56+
.get().uri("/foo/documentation/webjars/swagger-ui/swagger-initializer.js")
5557
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
5658
.exchange()
5759
.expectStatus().isOk()
5860
.expectBody(String.class)
5961
.consumeWith(response ->
6062
assertThat(response.getResponseBody())
61-
.contains("\"configUrl\" : \\\"/path/prefix/v3/api-docs/swagger-config\\\",")
63+
.contains("\"configUrl\" : \"/path/prefix/bar/openapi/v3/swagger-config\",")
6264
);
6365
}
6466

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.ui.app32;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.server.adapter.ForwardedHeaderTransformer;
6+
7+
@Configuration
8+
public class SpringDocConfig {
9+
10+
@Bean
11+
ForwardedHeaderTransformer forwardedHeaderTransformer() {
12+
return new ForwardedHeaderTransformer();
13+
}
14+
}

0 commit comments

Comments
 (0)