|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.server.authentication.logout;
|
18 | 18 |
|
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
19 | 20 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
20 | 21 | import static org.mockito.Mockito.*;
|
21 | 22 |
|
|
28 | 29 | import org.springframework.security.core.Authentication;
|
29 | 30 | import org.springframework.security.web.server.WebFilterExchange;
|
30 | 31 |
|
| 32 | +import reactor.core.publisher.Mono; |
31 | 33 | import reactor.test.publisher.PublisherProbe;
|
32 | 34 |
|
| 35 | +import java.time.Duration; |
33 | 36 | import java.util.List;
|
| 37 | +import java.util.concurrent.CountDownLatch; |
| 38 | +import java.util.concurrent.TimeUnit; |
| 39 | +import java.util.concurrent.atomic.AtomicBoolean; |
34 | 40 |
|
35 | 41 | /**
|
36 | 42 | * @author Eric Deandrea
|
@@ -98,4 +104,26 @@ public void logoutWhenMultipleThenExecuted() {
|
98 | 104 | this.delegate1Result.assertWasSubscribed();
|
99 | 105 | this.delegate2Result.assertWasSubscribed();
|
100 | 106 | }
|
| 107 | + |
| 108 | + @Test |
| 109 | + public void logoutSequential() throws Exception { |
| 110 | + AtomicBoolean slowDone = new AtomicBoolean(); |
| 111 | + CountDownLatch latch = new CountDownLatch(1); |
| 112 | + ServerLogoutHandler slow = (exchange, authentication) -> |
| 113 | + Mono.delay(Duration.ofMillis(100)) |
| 114 | + .doOnSuccess(__ -> slowDone.set(true)) |
| 115 | + .then(); |
| 116 | + ServerLogoutHandler second = (exchange, authentication) -> |
| 117 | + Mono.fromRunnable(() -> { |
| 118 | + latch.countDown(); |
| 119 | + assertThat(slowDone.get()) |
| 120 | + .describedAs("ServerLogoutHandler should be executed sequentially") |
| 121 | + .isTrue(); |
| 122 | + }); |
| 123 | + DelegatingServerLogoutHandler handler = new DelegatingServerLogoutHandler(slow, second); |
| 124 | + |
| 125 | + handler.logout(this.exchange, this.authentication).block(); |
| 126 | + |
| 127 | + assertThat(latch.await(3, TimeUnit.SECONDS)).isTrue(); |
| 128 | + } |
101 | 129 | }
|
0 commit comments