Prefer existing Context in ReactorContextTestExecutionListener
Issue gh-4718
This commit is contained in:
parent
9363e2ba41
commit
be593b95a8
|
@ -77,7 +77,7 @@ public class ReactorContextTestExecutionListener
|
|||
return context;
|
||||
}
|
||||
Context toMerge = ReactiveSecurityContextHolder.withAuthentication(authentication);
|
||||
return context.putAll(toMerge);
|
||||
return toMerge.putAll(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -92,6 +92,25 @@ public class ReactorContextTestExecutionListenerTests {
|
|||
assertAuthentication(expectedAuthentication);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeTestMethodWhenExistingAuthenticationThenReactorContextHasOriginalAuthentication() throws Exception {
|
||||
TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
||||
TestingAuthenticationToken contextHolder = new TestingAuthenticationToken("contextHolder", "password", "ROLE_USER");
|
||||
TestSecurityContextHolder.setContext(new SecurityContextImpl(contextHolder));
|
||||
|
||||
this.listener.beforeTestMethod(this.testContext);
|
||||
|
||||
Mono<Authentication> authentication = Mono.just("any")
|
||||
.flatMap(s -> ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(expectedAuthentication));
|
||||
|
||||
StepVerifier.create(authentication)
|
||||
.expectNext(expectedAuthentication)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterTestMethodWhenSecurityContextEmptyThenNoError() throws Exception {
|
||||
this.listener.beforeTestMethod(this.testContext);
|
||||
|
|
Loading…
Reference in New Issue