|
32 | 32 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange;
|
33 | 33 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
|
34 | 34 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse;
|
| 35 | +import org.springframework.web.reactive.function.client.WebClient; |
35 | 36 |
|
36 | 37 | import java.time.Instant;
|
37 | 38 |
|
38 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
39 | 40 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 41 | +import static org.mockito.Mockito.*; |
40 | 42 |
|
41 | 43 | /**
|
42 | 44 | * @author Rob Winch
|
@@ -259,4 +261,31 @@ private MockResponse jsonResponse(String json) {
|
259 | 261 | .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
260 | 262 | .setBody(json);
|
261 | 263 | }
|
| 264 | + |
| 265 | + @Test(expected=IllegalArgumentException.class) |
| 266 | + public void setWebClientNullThenIllegalArgumentException(){ |
| 267 | + tokenResponseClient.setWebClient(null); |
| 268 | + } |
| 269 | + |
| 270 | + @Test |
| 271 | + public void setCustomWebClientThenCustomWebClientIsUsed() { |
| 272 | + WebClient customClient = mock(WebClient.class); |
| 273 | + when(customClient.post()).thenReturn(WebClient.builder().build().post()); |
| 274 | + |
| 275 | + tokenResponseClient.setWebClient(customClient); |
| 276 | + |
| 277 | + String accessTokenSuccessResponse = "{\n" + |
| 278 | + " \"access_token\": \"access-token-1234\",\n" + |
| 279 | + " \"token_type\": \"bearer\",\n" + |
| 280 | + " \"expires_in\": \"3600\",\n" + |
| 281 | + " \"scope\": \"openid profile\"\n" + |
| 282 | + "}\n"; |
| 283 | + this.server.enqueue(jsonResponse(accessTokenSuccessResponse)); |
| 284 | + |
| 285 | + this.clientRegistration.scope("openid", "profile", "email", "address"); |
| 286 | + |
| 287 | + OAuth2AccessTokenResponse response = this.tokenResponseClient.getTokenResponse(authorizationCodeGrantRequest()).block(); |
| 288 | + |
| 289 | + verify(customClient, atLeastOnce()).post(); |
| 290 | + } |
262 | 291 | }
|
0 commit comments