Polish gh-14977
This commit is contained in:
parent
1695d03b72
commit
e34621ec2c
|
@ -94,7 +94,6 @@ public final class WebSessionServerOAuth2AuthorizedClientRepository implements S
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Map<String, OAuth2AuthorizedClient> getAuthorizedClients(WebSession session) {
|
private Map<String, OAuth2AuthorizedClient> getAuthorizedClients(WebSession session) {
|
||||||
Assert.notNull(session, "session cannot be null");
|
Assert.notNull(session, "session cannot be null");
|
||||||
Map<String, OAuth2AuthorizedClient> authorizedClients = session.getAttribute(this.sessionAttributeName);
|
Map<String, OAuth2AuthorizedClient> authorizedClients = session.getAttribute(this.sessionAttributeName);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.security.oauth2.client.web.server;
|
package org.springframework.security.oauth2.client.web.server;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||||
import org.springframework.mock.web.server.MockServerWebExchange;
|
import org.springframework.mock.web.server.MockServerWebExchange;
|
||||||
|
@ -24,13 +25,13 @@ import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||||
import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
||||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebSession;
|
import org.springframework.web.server.WebSession;
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
@ -206,22 +207,26 @@ public class WebSessionServerOAuth2AuthorizedClientRepositoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void saveAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
public void saveAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
||||||
MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class);
|
ServerWebExchange exchange = mock(ServerWebExchange.class);
|
||||||
when(mockedExchange.getSession()).thenReturn(Mono.empty());
|
given(exchange.getSession()).willReturn(Mono.empty());
|
||||||
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration1, this.principalName1,
|
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration1, this.principalName1,
|
||||||
mock(OAuth2AccessToken.class));
|
mock(OAuth2AccessToken.class));
|
||||||
assertThatIllegalArgumentException().isThrownBy(
|
// @formatter:off
|
||||||
() -> authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, mockedExchange).block())
|
assertThatIllegalArgumentException()
|
||||||
|
.isThrownBy(() -> this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, exchange).block())
|
||||||
.withMessage("session cannot be null");
|
.withMessage("session cannot be null");
|
||||||
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
public void removeAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
||||||
MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class);
|
ServerWebExchange exchange = mock(ServerWebExchange.class);
|
||||||
when(mockedExchange.getSession()).thenReturn(Mono.empty());
|
given(exchange.getSession()).willReturn(Mono.empty());
|
||||||
assertThatIllegalArgumentException().isThrownBy(
|
// @formatter:off
|
||||||
() -> authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, mockedExchange).block())
|
assertThatIllegalArgumentException()
|
||||||
|
.isThrownBy(() -> this.authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, exchange).block())
|
||||||
.withMessage("session cannot be null");
|
.withMessage("session cannot be null");
|
||||||
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue