mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Make RedirectServer*Tests less specific
Issue: gh-4816
This commit is contained in:
parent
3c7fb977fe
commit
060d8689fe
@ -29,6 +29,8 @@ import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.server.ServerRedirectStrategy;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.publisher.PublisherProbe;
|
||||
import reactor.test.publisher.TestPublisher;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
@ -62,10 +64,12 @@ public class RedirectServerAuthenticationEntryPointTests {
|
||||
|
||||
@Test
|
||||
public void commenceWhenNoSubscribersThenNoActions() {
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
this.entryPoint.commence(this.exchange,
|
||||
this.exception);
|
||||
|
||||
verifyZeroInteractions(this.exchange);
|
||||
assertThat(this.exchange.getResponse().getHeaders().getLocation()).isNull();
|
||||
assertThat(this.exchange.getSession().block().isStarted()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -81,12 +85,14 @@ public class RedirectServerAuthenticationEntryPointTests {
|
||||
|
||||
@Test
|
||||
public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() {
|
||||
Mono<Void> result = Mono.empty();
|
||||
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(result);
|
||||
PublisherProbe<Void> redirectResult = PublisherProbe.empty();
|
||||
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono());
|
||||
this.entryPoint.setServerRedirectStrategy(this.serverRedirectStrategy);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
assertThat(this.entryPoint.commence(this.exchange, this.exception)).isEqualTo(result);
|
||||
this.entryPoint.commence(this.exchange, this.exception).block();
|
||||
|
||||
redirectResult.assertWasSubscribed();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
@ -29,6 +29,7 @@ import org.springframework.security.web.server.WebFilterExchange;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.publisher.PublisherProbe;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@ -67,10 +68,13 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
||||
|
||||
@Test
|
||||
public void successWhenNoSubscribersThenNoActions() {
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||
this.chain), this.authentication);
|
||||
|
||||
verifyZeroInteractions(this.exchange);
|
||||
assertThat(this.exchange.getResponse().getHeaders().getLocation()).isNull();
|
||||
assertThat(this.exchange.getSession().block().isStarted()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,13 +91,14 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
||||
|
||||
@Test
|
||||
public void successWhenCustomLocationThenCustomLocationUsed() {
|
||||
Mono<Void> result = Mono.empty();
|
||||
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(result);
|
||||
PublisherProbe<Void> redirectResult = PublisherProbe.empty();
|
||||
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono());
|
||||
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
assertThat(this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||
this.chain), this.authentication)).isEqualTo(result);
|
||||
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||
this.chain), this.authentication).block();
|
||||
redirectResult.assertWasSubscribed();
|
||||
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user