|
1 | 1 | /* |
2 | | - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package org.springframework.security.oauth2.client.userinfo; |
18 | 17 |
|
19 | 18 | import java.time.Duration; |
|
50 | 49 | import org.springframework.web.reactive.function.client.WebClient; |
51 | 50 |
|
52 | 51 | import static org.assertj.core.api.Assertions.assertThat; |
| 52 | +import static org.assertj.core.api.Assertions.assertThatCode; |
53 | 53 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
54 | 54 | import static org.mockito.ArgumentMatchers.any; |
55 | 55 | import static org.mockito.Mockito.mock; |
@@ -152,6 +152,24 @@ public void loadUserWhenUserInfoSuccessResponseThenReturnUser() { |
152 | 152 | assertThat(userAuthority.getAttributes()).isEqualTo(user.getAttributes()); |
153 | 153 | } |
154 | 154 |
|
| 155 | + // gh-9336 |
| 156 | + @Test |
| 157 | + public void loadUserWhenUserInfo201CreatedResponseThenReturnUser() { |
| 158 | + // @formatter:off |
| 159 | + String userInfoResponse = "{\n" |
| 160 | + + " \"id\": \"user1\",\n" |
| 161 | + + " \"first-name\": \"first\",\n" |
| 162 | + + " \"last-name\": \"last\",\n" |
| 163 | + + " \"middle-name\": \"middle\",\n" |
| 164 | + + " \"address\": \"address\",\n" |
| 165 | + + " \"email\": \"user1@example.com\"\n" |
| 166 | + + "}\n"; |
| 167 | + // @formatter:on |
| 168 | + this.server.enqueue(new MockResponse().setResponseCode(201) |
| 169 | + .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(userInfoResponse)); |
| 170 | + assertThatCode(() -> this.userService.loadUser(oauth2UserRequest()).block()).doesNotThrowAnyException(); |
| 171 | + } |
| 172 | + |
155 | 173 | // gh-5500 |
156 | 174 | @Test |
157 | 175 | public void loadUserWhenAuthenticationMethodHeaderSuccessResponseThenHttpMethodGet() throws Exception { |
|
0 commit comments