Use Credentials object instead of 2 attributes for Basic Authentication

This commit changes the usage of two separate attributes (username and
password) into one: a single `Credentials` object.
Additionally, the attributes key under which the credentials are stored
is changed to be specific to Basic Authentication, in order to allow for
other sorts of authentication later.

Issue: SPR-15764
This commit is contained in:
Arjen Poutsma
2017-07-27 16:08:29 +02:00
parent 26de6268aa
commit 1d86c9c3d1
2 changed files with 94 additions and 33 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.http.HttpStatus;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials;
/**
* @author Arjen Poutsma
@@ -84,7 +85,7 @@ public class ExchangeFilterFunctionsTests {
}
@Test
public void basicAuthentication() throws Exception {
public void basicAuthenticationUsernamePassword() throws Exception {
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
ClientResponse response = mock(ClientResponse.class);
@@ -100,11 +101,17 @@ public class ExchangeFilterFunctionsTests {
assertEquals(response, result);
}
@Test(expected = IllegalArgumentException.class)
public void basicAuthenticationInvalidCharacters() throws Exception {
ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9");
}
@Test
public void basicAuthenticationAttributes() throws Exception {
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com"))
.attribute(ExchangeFilterFunctions.USERNAME_ATTRIBUTE, "foo")
.attribute(ExchangeFilterFunctions.PASSWORD_ATTRIBUTE, "bar").build();
.attributes(basicAuthenticationCredentials("foo", "bar"))
.build();
ClientResponse response = mock(ClientResponse.class);
ExchangeFunction exchange = r -> {