mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-20 06:29:16 +00:00
Add nullability annotations to tests in smoke-test/spring-boot-smoke-test-web-security-method
See gh-47263
This commit is contained in:
@@ -28,3 +28,7 @@ dependencies {
|
||||
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
|
||||
testImplementation(project(":starter:spring-boot-starter-test"))
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
||||
+8
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package smoketest.security.method;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -74,7 +75,9 @@ class SampleMethodSecurityApplicationTests {
|
||||
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST,
|
||||
new HttpEntity<>(form, headers), String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
|
||||
URI location = entity.getHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
assertThat(location.toString()).endsWith(this.port + "/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +92,10 @@ class SampleMethodSecurityApplicationTests {
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
String cookie = entity.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET,
|
||||
new HttpEntity<>(headers), String.class);
|
||||
URI location = entity.getHeaders().getLocation();
|
||||
assertThat(location).isNotNull();
|
||||
ResponseEntity<String> page = this.restTemplate.exchange(location, HttpMethod.GET, new HttpEntity<>(headers),
|
||||
String.class);
|
||||
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||
assertThat(page.getBody()).contains("Access denied");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user