|
@@ -21,6 +21,7 @@ import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.http.ResponseCookie;
|
|
import org.springframework.security.web.server.header.ContentTypeOptionsHttpHeadersWriter;
|
|
import org.springframework.security.web.server.header.ContentTypeOptionsHttpHeadersWriter;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.TestPropertySource;
|
|
import org.springframework.test.context.TestPropertySource;
|
|
@@ -33,6 +34,7 @@ import java.nio.charset.Charset;
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
import java.util.Base64;
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
+import static org.springframework.security.test.web.reactive.server.SecurityExchangeMutators.withUser;
|
|
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
|
|
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -70,10 +72,10 @@ public class HelloWebfluxFnApplicationITests {
|
|
this.rest
|
|
this.rest
|
|
.filter(robsCredentials())
|
|
.filter(robsCredentials())
|
|
.get()
|
|
.get()
|
|
- .uri("/users")
|
|
|
|
|
|
+ .uri("/principal")
|
|
.exchange()
|
|
.exchange()
|
|
.expectStatus().isOk()
|
|
.expectStatus().isOk()
|
|
- .expectBody().json("[{\"id\":null,\"username\":\"rob\",\"password\":\"rob\",\"firstname\":\"Rob\",\"lastname\":\"Winch\"},{\"id\":null,\"username\":\"admin\",\"password\":\"admin\",\"firstname\":\"Admin\",\"lastname\":\"User\"}]");
|
|
|
|
|
|
+ .expectBody().json("{\"username\":\"rob\"}");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -81,7 +83,7 @@ public class HelloWebfluxFnApplicationITests {
|
|
this.rest
|
|
this.rest
|
|
.filter(invalidPassword())
|
|
.filter(invalidPassword())
|
|
.get()
|
|
.get()
|
|
- .uri("/users")
|
|
|
|
|
|
+ .uri("/principal")
|
|
.exchange()
|
|
.exchange()
|
|
.expectStatus().isUnauthorized()
|
|
.expectStatus().isUnauthorized()
|
|
.expectBody().isEmpty();
|
|
.expectBody().isEmpty();
|
|
@@ -141,17 +143,17 @@ public class HelloWebfluxFnApplicationITests {
|
|
@Test
|
|
@Test
|
|
public void sessionWorks() throws Exception {
|
|
public void sessionWorks() throws Exception {
|
|
ExchangeResult result = this.rest
|
|
ExchangeResult result = this.rest
|
|
- .filter(robsCredentials())
|
|
|
|
- .get()
|
|
|
|
- .uri("/users")
|
|
|
|
- .exchange()
|
|
|
|
- .returnResult(String.class);
|
|
|
|
|
|
+ .filter(robsCredentials())
|
|
|
|
+ .get()
|
|
|
|
+ .uri("/principal")
|
|
|
|
+ .exchange()
|
|
|
|
+ .returnResult(String.class);
|
|
|
|
|
|
String session = result.getResponseHeaders().getFirst("Set-Cookie");
|
|
String session = result.getResponseHeaders().getFirst("Set-Cookie");
|
|
|
|
|
|
this.rest
|
|
this.rest
|
|
.get()
|
|
.get()
|
|
- .uri("/users")
|
|
|
|
|
|
+ .uri("/principal")
|
|
.header("Cookie", session)
|
|
.header("Cookie", session)
|
|
.exchange()
|
|
.exchange()
|
|
.expectStatus().isOk();
|
|
.expectStatus().isOk();
|
|
@@ -171,14 +173,14 @@ public class HelloWebfluxFnApplicationITests {
|
|
@Test
|
|
@Test
|
|
public void headers() throws Exception {
|
|
public void headers() throws Exception {
|
|
this.rest
|
|
this.rest
|
|
- .filter(robsCredentials())
|
|
|
|
- .get()
|
|
|
|
- .uri("/principal")
|
|
|
|
- .exchange()
|
|
|
|
- .expectHeader().valueEquals(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0, must-revalidate")
|
|
|
|
- .expectHeader().valueEquals(HttpHeaders.EXPIRES, "0")
|
|
|
|
- .expectHeader().valueEquals(HttpHeaders.PRAGMA, "no-cache")
|
|
|
|
- .expectHeader().valueEquals(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS, ContentTypeOptionsHttpHeadersWriter.NOSNIFF);
|
|
|
|
|
|
+ .filter(robsCredentials())
|
|
|
|
+ .get()
|
|
|
|
+ .uri("/principal")
|
|
|
|
+ .exchange()
|
|
|
|
+ .expectHeader().valueEquals(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0, must-revalidate")
|
|
|
|
+ .expectHeader().valueEquals(HttpHeaders.EXPIRES, "0")
|
|
|
|
+ .expectHeader().valueEquals(HttpHeaders.PRAGMA, "no-cache")
|
|
|
|
+ .expectHeader().valueEquals(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS, ContentTypeOptionsHttpHeadersWriter.NOSNIFF);
|
|
}
|
|
}
|
|
|
|
|
|
private ExchangeFilterFunction robsCredentials() {
|
|
private ExchangeFilterFunction robsCredentials() {
|