mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Default use-relative-redirects to true
Spring Boot unconditionally set useRelativeRedirects on the Tomcat Context, defaulting it to false. That overrode Tomcat's own default and forced absolute Location headers on every sendRedirect. Keep server.tomcat.use-relative-redirects a simple boolean, but default it to true so that relative Location headers are used out of the box. The property can still be set to false to opt back into absolute redirects. Smoke tests that asserted a port-qualified absolute Location are updated to the relative form, and the proxy tip in the reference documentation is qualified since the context root redirect no longer carries a scheme. Signed-off-by: Tiziano Basile <tiz.basile@gmail.com> See gh-51173
This commit is contained in:
committed by
Andy Wilkinson
parent
a07c43466b
commit
f119e58767
+2
-2
@@ -113,7 +113,7 @@ class SampleOAuth2AuthorizationServerApplicationTests {
|
||||
void anonymousShouldRedirectToLogin() {
|
||||
RestTestClient.ResponseSpec response = nonFollowingRedirect().get().uri("/").exchange();
|
||||
response.expectStatus().isFound();
|
||||
response.expectHeader().location("http://localhost:" + this.port + "/login");
|
||||
response.expectHeader().location("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,7 +182,7 @@ class SampleOAuth2AuthorizationServerApplicationTests {
|
||||
.body(body)
|
||||
.exchange();
|
||||
response.expectStatus().isFound();
|
||||
response.expectHeader().location("http://localhost:" + this.port + "/login");
|
||||
response.expectHeader().location("/login");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class SampleOAuth2ClientApplicationTests {
|
||||
void everythingShouldRedirectToLogin() {
|
||||
RestTestClient.ResponseSpec response = nonFollowingRedirect().get().uri("/").exchange();
|
||||
response.expectStatus().isFound();
|
||||
response.expectHeader().location("http://localhost:" + this.port + "/login");
|
||||
response.expectHeader().location("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ class SampleSaml2RelyingPartyApplicationTests {
|
||||
void everythingShouldRedirectToLogin() {
|
||||
RestTestClient.ResponseSpec response = nonFollowingRedirect().get().uri("/").exchange();
|
||||
response.expectStatus().isFound();
|
||||
response.expectHeader().location("http://localhost:" + this.port + "/login");
|
||||
response.expectHeader().location("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-5
@@ -22,7 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.web.servlet.client.RestTestClient;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -38,9 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@AutoConfigureRestTestClient
|
||||
class SampleGroovyTemplateApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private RestTestClient restTestClient;
|
||||
|
||||
@@ -62,7 +58,7 @@ class SampleGroovyTemplateApplicationTests {
|
||||
.body(map)
|
||||
.exchange()
|
||||
.expectHeader()
|
||||
.value("Location", (location) -> assertThat(location).contains("localhost:" + this.port));
|
||||
.value("Location", (location) -> assertThat(location).matches("/\\d+(;jsessionid=[\\w.]+)?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ class SampleMethodSecurityApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/");
|
||||
assertThat(location.toString()).isEqualTo("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ class SampleWebSecureCustomApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/login");
|
||||
assertThat(location.toString()).isEqualTo("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ class SampleWebSecureCustomApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/");
|
||||
assertThat(location.toString()).isEqualTo("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ class SampleWebSecureJdbcApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/login");
|
||||
assertThat(location.toString()).isEqualTo("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ class SampleWebSecureJdbcApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/");
|
||||
assertThat(location.toString()).isEqualTo("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -78,7 +78,7 @@ class SampleWebSecureApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/login");
|
||||
assertThat(location.toString()).isEqualTo("/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,7 @@ class SampleWebSecureApplicationTests {
|
||||
assertThat(result.getStatus()).isEqualTo(HttpStatus.FOUND);
|
||||
URI location = result.getResponseHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/");
|
||||
assertThat(location.toString()).isEqualTo("/");
|
||||
}
|
||||
|
||||
@org.springframework.boot.test.context.TestConfiguration(proxyBeanMethods = false)
|
||||
|
||||
+1
-5
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.web.servlet.client.RestTestClient;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -43,9 +42,6 @@ class SampleWebUiApplicationTests {
|
||||
@Autowired
|
||||
private RestTestClient restTestClient;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
void testHome() {
|
||||
this.restTestClient.get().uri("/").exchangeSuccessfully().expectBody(String.class).value((body) -> {
|
||||
@@ -67,7 +63,7 @@ class SampleWebUiApplicationTests {
|
||||
.getResponseHeaders()
|
||||
.getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).contains("localhost:" + this.port);
|
||||
assertThat(location.toString()).matches("/\\d+(;jsessionid=[\\w.]+)?");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user