|
@@ -28,6 +28,7 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
|
|
|
import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
|
|
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
|
|
+import org.springframework.web.reactive.function.client.WebClientResponseException;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
|
@@ -116,6 +117,23 @@ public class WebClientReactiveClientCredentialsTokenResponseClientTests {
|
|
|
assertThat(response.getAccessToken().getScopes()).isEqualTo(registration.getScopes());
|
|
|
}
|
|
|
|
|
|
+ @Test(expected = WebClientResponseException.class)
|
|
|
+ // gh-6089
|
|
|
+ public void getTokenResponseWhenInvalidResponse() throws WebClientResponseException {
|
|
|
+ ClientRegistration registration = this.clientRegistration.build();
|
|
|
+ enqueueUnexpectedResponse();
|
|
|
+
|
|
|
+ OAuth2ClientCredentialsGrantRequest request = new OAuth2ClientCredentialsGrantRequest(registration);
|
|
|
+
|
|
|
+ OAuth2AccessTokenResponse response = this.client.getTokenResponse(request).block();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void enqueueUnexpectedResponse(){
|
|
|
+ MockResponse response = new MockResponse()
|
|
|
+ .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ .setResponseCode(301);
|
|
|
+ this.server.enqueue(response);
|
|
|
+ }
|
|
|
|
|
|
private void enqueueJson(String body) {
|
|
|
MockResponse response = new MockResponse()
|