|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 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.
|
|
37 | 37 | import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
38 | 38 | import org.springframework.security.oauth2.core.oidc.user.TestOidcUsers;
|
39 | 39 | import org.springframework.security.oauth2.core.user.TestOAuth2Users;
|
| 40 | +import org.springframework.security.web.server.ServerRedirectStrategy; |
40 | 41 | import org.springframework.security.web.server.WebFilterExchange;
|
41 | 42 | import org.springframework.web.server.ServerWebExchange;
|
42 | 43 | import org.springframework.web.server.WebFilterChain;
|
43 | 44 |
|
44 | 45 | import static org.assertj.core.api.Assertions.assertThat;
|
45 | 46 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
| 47 | +import static org.mockito.ArgumentMatchers.any; |
46 | 48 | import static org.mockito.BDDMockito.given;
|
47 | 49 | import static org.mockito.Mockito.mock;
|
| 50 | +import static org.mockito.Mockito.times; |
| 51 | +import static org.mockito.Mockito.verify; |
48 | 52 |
|
49 | 53 | /**
|
50 | 54 | * Tests for {@link OidcClientInitiatedServerLogoutSuccessHandler}
|
@@ -219,6 +223,27 @@ public void logoutWhenCustomRedirectUriResolverSetThenRedirects() {
|
219 | 223 | assertThat(redirectedUrl(this.exchange)).isEqualTo("https://test.com");
|
220 | 224 | }
|
221 | 225 |
|
| 226 | + @Test |
| 227 | + public void setRedirectStrategyWhenGivenNullThenThrowsException() { |
| 228 | + assertThatIllegalArgumentException().isThrownBy(() -> this.handler.setRedirectStrategy(null)); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + public void logoutWhenCustomRedirectStrategySetThenCustomRedirectStrategyUse() { |
| 233 | + ServerRedirectStrategy redirectStrategy = mock(ServerRedirectStrategy.class); |
| 234 | + given(redirectStrategy.sendRedirect(any(), any())).willReturn(Mono.empty()); |
| 235 | + OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), |
| 236 | + AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId()); |
| 237 | + WebFilterExchange filterExchange = new WebFilterExchange(this.exchange, this.chain); |
| 238 | + given(this.exchange.getRequest()) |
| 239 | + .willReturn(MockServerHttpRequest.get("/").queryParam("location", "https://test.com").build()); |
| 240 | + this.handler.setRedirectStrategy(redirectStrategy); |
| 241 | + |
| 242 | + this.handler.onLogoutSuccess(filterExchange, token).block(); |
| 243 | + |
| 244 | + verify(redirectStrategy, times(1)).sendRedirect(any(), any()); |
| 245 | + } |
| 246 | + |
222 | 247 | private String redirectedUrl(ServerWebExchange exchange) {
|
223 | 248 | return exchange.getResponse().getHeaders().getFirst("Location");
|
224 | 249 | }
|
|
0 commit comments