Spring Boot 3.0 - Ticket number for RestTemplate redirection issue added.
@@ -11,6 +11,10 @@ import org.springframework.http.ResponseEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+// Tests worked with Spring Boot 2.7.5 with random port configuration
+// Not working after migration to Spring Boot 3.0
+// Revert change when ticket https://github.com/spring-projects/spring-boot/issues/33451
+// is resolved.
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class HerokuWebSecurityConfigTest {
@@ -22,7 +26,7 @@ public class HerokuWebSecurityConfigTest {
private RestTemplateBuilder builder;
@Test
- void shouldRedirectWhenProtoProvided() throws InterruptedException {
+ void shouldRedirectWhenProtoProvided() {
var restTemplate = builder
.defaultHeader("x-forwarded-proto", "value")
.build();
@@ -31,12 +35,13 @@ public class HerokuWebSecurityConfigTest {
assertEquals(HttpStatus.FOUND, result.getStatusCode());
assertEquals("https", result.getHeaders().getLocation().getScheme());
}
+
@Test
void shouldNotRedirectWhenProtoNotProvided() {
var restTemplate = builder
.build();
var rootAddress = "http://localhost:" + port + "/";
- ResponseEntity entity = restTemplate.getForEntity(rootAddress, String.class);
+ ResponseEntity<String> entity = restTemplate.getForEntity(rootAddress, String.class);
assertTrue(entity.getStatusCode().is2xxSuccessful());
}
}
