|
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.
|
|
17 | 17 | package org.springframework.security.oauth2.client.web.server;
|
18 | 18 |
|
19 | 19 | import org.junit.jupiter.api.Test;
|
| 20 | +import reactor.core.publisher.Mono; |
20 | 21 |
|
21 | 22 | import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
22 | 23 | import org.springframework.mock.web.server.MockServerWebExchange;
|
23 | 24 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
24 | 25 | import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
25 | 26 | import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
26 | 27 | import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
| 28 | +import org.springframework.web.server.ServerWebExchange; |
27 | 29 | import org.springframework.web.server.WebSession;
|
28 | 30 |
|
29 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 32 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
| 33 | +import static org.mockito.BDDMockito.given; |
31 | 34 | import static org.mockito.Mockito.mock;
|
32 | 35 |
|
33 | 36 | /**
|
@@ -202,4 +205,28 @@ public void removeAuthorizedClientWhenClient1Client2SavedAndClient1RemovedThenCl
|
202 | 205 | assertThat(loadedAuthorizedClient2).isSameAs(authorizedClient2);
|
203 | 206 | }
|
204 | 207 |
|
| 208 | + @Test |
| 209 | + public void saveAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() { |
| 210 | + ServerWebExchange exchange = mock(ServerWebExchange.class); |
| 211 | + given(exchange.getSession()).willReturn(Mono.empty()); |
| 212 | + OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration1, this.principalName1, |
| 213 | + mock(OAuth2AccessToken.class)); |
| 214 | + // @formatter:off |
| 215 | + assertThatIllegalArgumentException() |
| 216 | + .isThrownBy(() -> this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, exchange).block()) |
| 217 | + .withMessage("session cannot be null"); |
| 218 | + // @formatter:on |
| 219 | + } |
| 220 | + |
| 221 | + @Test |
| 222 | + public void removeAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() { |
| 223 | + ServerWebExchange exchange = mock(ServerWebExchange.class); |
| 224 | + given(exchange.getSession()).willReturn(Mono.empty()); |
| 225 | + // @formatter:off |
| 226 | + assertThatIllegalArgumentException() |
| 227 | + .isThrownBy(() -> this.authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, exchange).block()) |
| 228 | + .withMessage("session cannot be null"); |
| 229 | + // @formatter:on |
| 230 | + } |
| 231 | + |
205 | 232 | }
|
0 commit comments