|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.server.authentication;
|
18 | 18 |
|
19 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
20 |
| -import static org.mockito.ArgumentMatchers.any; |
21 |
| -import static org.mockito.Mockito.when; |
22 |
| - |
23 | 19 | import org.junit.Before;
|
24 | 20 | import org.junit.Test;
|
25 | 21 | import org.junit.runner.RunWith;
|
26 | 22 | import org.mockito.Mock;
|
27 | 23 | import org.mockito.junit.MockitoJUnitRunner;
|
28 | 24 | import org.springframework.security.core.Authentication;
|
29 | 25 | import org.springframework.security.web.server.WebFilterExchange;
|
30 |
| - |
| 26 | +import reactor.core.publisher.Mono; |
31 | 27 | import reactor.test.publisher.PublisherProbe;
|
32 | 28 |
|
| 29 | +import java.time.Duration; |
| 30 | +import java.util.concurrent.CountDownLatch; |
| 31 | +import java.util.concurrent.TimeUnit; |
| 32 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 33 | + |
| 34 | +import static org.assertj.core.api.Assertions.assertThat; |
| 35 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 36 | +import static org.mockito.ArgumentMatchers.any; |
| 37 | +import static org.mockito.Mockito.when; |
| 38 | + |
33 | 39 | /**
|
34 | 40 | * @author Rob Winch
|
35 | 41 | * @since 5.1
|
@@ -88,4 +94,26 @@ public void onAuthenticationSuccessWhenMultipleThenExecuted() {
|
88 | 94 | this.delegate1Result.assertWasSubscribed();
|
89 | 95 | this.delegate2Result.assertWasSubscribed();
|
90 | 96 | }
|
| 97 | + |
| 98 | + @Test |
| 99 | + public void onAuthenticationSuccessSequential() throws Exception { |
| 100 | + AtomicBoolean slowDone = new AtomicBoolean(); |
| 101 | + CountDownLatch latch = new CountDownLatch(1); |
| 102 | + ServerAuthenticationSuccessHandler slow = (exchange, authentication) -> |
| 103 | + Mono.delay(Duration.ofMillis(100)) |
| 104 | + .doOnSuccess(__ -> slowDone.set(true)) |
| 105 | + .then(); |
| 106 | + ServerAuthenticationSuccessHandler second = (exchange, authentication) -> |
| 107 | + Mono.fromRunnable(() -> { |
| 108 | + latch.countDown(); |
| 109 | + assertThat(slowDone.get()) |
| 110 | + .describedAs("ServerAuthenticationSuccessHandler should be executed sequentially") |
| 111 | + .isTrue(); |
| 112 | + }); |
| 113 | + DelegatingServerAuthenticationSuccessHandler handler = new DelegatingServerAuthenticationSuccessHandler(slow, second); |
| 114 | + |
| 115 | + handler.onAuthenticationSuccess(this.exchange, this.authentication).block(); |
| 116 | + |
| 117 | + assertThat(latch.await(3, TimeUnit.SECONDS)).isTrue(); |
| 118 | + } |
91 | 119 | }
|
0 commit comments