1+ /*
2+ *
3+ * * Copyright 2019-2020 the original author or authors.
4+ * *
5+ * * Licensed under the Apache License, Version 2.0 (the "License");
6+ * * you may not use this file except in compliance with the License.
7+ * * You may obtain a copy of the License at
8+ * *
9+ * * https://www.apache.org/licenses/LICENSE-2.0
10+ * *
11+ * * Unless required by applicable law or agreed to in writing, software
12+ * * distributed under the License is distributed on an "AS IS" BASIS,
13+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * * See the License for the specific language governing permissions and
15+ * * limitations under the License.
16+ *
17+ */
18+
19+ package test .org .springdoc .ui .app5 ;
20+
21+ import org .junit .jupiter .api .Test ;
22+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
23+ import org .springframework .test .context .TestPropertySource ;
24+ import test .org .springdoc .ui .AbstractSpringDocTest ;
25+
26+ import static org .hamcrest .CoreMatchers .equalTo ;
27+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
28+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
29+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
30+
31+ @ TestPropertySource (properties = {"server.forward-headers-strategy=framework" , "springdoc.cache.disabled=true" })
32+ public class SpringDocOauthRedirectUrlRecalculateTest extends AbstractSpringDocTest {
33+
34+ @ Test
35+ public void oauth2_redirect_url_recalculation () throws Exception {
36+ mockMvc .perform (get ("/v3/api-docs/swagger-config" ).header ("X-Forwarded-Proto" , "https" ).header ("X-Forwarded-Host" , "host1" ))
37+ .andExpect (status ().isOk ())
38+ .andExpect (jsonPath ("oauth2RedirectUrl" , equalTo ("https://host1/swagger-ui/oauth2-redirect.html" )));
39+
40+ mockMvc .perform (get ("/v3/api-docs/swagger-config" ).header ("X-Forwarded-Proto" , "http" ).header ("X-Forwarded-Host" , "host2:8080" ))
41+ .andExpect (status ().isOk ())
42+ .andExpect (jsonPath ("oauth2RedirectUrl" , equalTo ("http://host2:8080/swagger-ui/oauth2-redirect.html" )));
43+ }
44+
45+ @ SpringBootApplication
46+ static class SpringDocTestApp {
47+ }
48+
49+ }
0 commit comments