|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2024 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.
|
|
25 | 25 | import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
26 | 26 | import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
27 | 27 | import org.springframework.web.server.WebSession;
|
| 28 | +import reactor.core.publisher.Mono; |
28 | 29 |
|
29 | 30 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 31 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
31 | 32 | import static org.mockito.Mockito.mock;
|
| 33 | +import static org.mockito.Mockito.when; |
32 | 34 |
|
33 | 35 | /**
|
34 | 36 | * @author Rob Winch
|
@@ -201,5 +203,25 @@ public void removeAuthorizedClientWhenClient1Client2SavedAndClient1RemovedThenCl
|
201 | 203 | assertThat(loadedAuthorizedClient2).isNotNull();
|
202 | 204 | assertThat(loadedAuthorizedClient2).isSameAs(authorizedClient2);
|
203 | 205 | }
|
| 206 | + |
| 207 | + @Test |
| 208 | + public void saveAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() { |
| 209 | + MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class); |
| 210 | + when(mockedExchange.getSession()).thenReturn(Mono.empty()); |
| 211 | + OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration1, this.principalName1, |
| 212 | + mock(OAuth2AccessToken.class)); |
| 213 | + assertThatIllegalArgumentException().isThrownBy( |
| 214 | + () -> authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, mockedExchange).block()) |
| 215 | + .withMessage("session cannot be null"); |
| 216 | + } |
| 217 | + |
| 218 | + @Test |
| 219 | + public void removeAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() { |
| 220 | + MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class); |
| 221 | + when(mockedExchange.getSession()).thenReturn(Mono.empty()); |
| 222 | + assertThatIllegalArgumentException().isThrownBy( |
| 223 | + () -> authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, mockedExchange).block()) |
| 224 | + .withMessage("session cannot be null"); |
| 225 | + } |
204 | 226 |
|
205 | 227 | }
|
0 commit comments