From 284c78f737f0dd32f6950b5730ec7c6a0ace98a2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 17 Apr 2025 17:48:23 -0700 Subject: [PATCH] Fixup tests that rely on TestRestTemplate redirects See gh-43431 --- .../oauth2/client/SampleOAuth2ClientApplicationTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java index e8ab5308e93..452ad31bc60 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java @@ -21,6 +21,7 @@ import java.net.URI; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.http.client.ClientHttpRequestFactorySettings.Redirects; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; @@ -42,7 +43,8 @@ class SampleOAuth2ClientApplicationTests { @Test void everythingShouldRedirectToLogin() { - ResponseEntity entity = this.restTemplate.getForEntity("/", String.class); + ResponseEntity entity = this.restTemplate.withRedirects(Redirects.DONT_FOLLOW) + .getForEntity("/", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/login")); }