use of reactor.util.context.Context in project spring-security by spring-projects.
the class CurrentSecurityContextArgumentResolverTests method metaAnnotationWhenDefaultSecurityContextThenInjectSecurityContext.
@Test
public void metaAnnotationWhenDefaultSecurityContextThenInjectSecurityContext() {
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentCustomSecurityContext").build().arg(Mono.class, SecurityContext.class);
Authentication auth = buildAuthenticationWithPrincipal("current_custom_security_context");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
SecurityContext securityContext = (SecurityContext) argument.subscriberContext(context).cast(Mono.class).block().block();
assertThat(securityContext.getAuthentication()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
}
use of reactor.util.context.Context in project spring-security by spring-projects.
the class CurrentSecurityContextArgumentResolverTests method resolveArgumentWithAuthenticationOptional1.
@Test
public void resolveArgumentWithAuthenticationOptional1() {
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthPropOptional").build().arg(Mono.class, Object.class);
Authentication auth = buildAuthenticationWithPrincipal("auth_optional");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<Object> obj = (Mono<Object>) argument.subscriberContext(context).block();
assertThat(obj.block()).isEqualTo("auth_optional");
ReactiveSecurityContextHolder.clearContext();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onRejectedExecutionWithoutDataSignalDelegatesToErrorLocal.
@Test
public void onRejectedExecutionWithoutDataSignalDelegatesToErrorLocal() {
BiFunction<Throwable, Object, Throwable> localHook = (e, v) -> new IllegalStateException("boom_" + v, e);
Context c = Context.of(Hooks.KEY_ON_OPERATOR_ERROR, localHook);
IllegalArgumentException failure = new IllegalArgumentException("foo");
final Throwable throwable = Operators.onRejectedExecution(failure, null, null, null, c);
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("boom_null").hasNoSuppressedExceptions();
assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class).hasMessage("Scheduler unavailable").hasCause(failure);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method discardQueueWithClearStopsOnQueuePollingError.
@Test
public void discardQueueWithClearStopsOnQueuePollingError() {
AtomicInteger discardedCount = new AtomicInteger();
@SuppressWarnings("unchecked") Queue<Integer> q = Mockito.mock(Queue.class);
Mockito.when(q.poll()).thenReturn(1, 2).thenThrow(new IllegalStateException("poll boom")).thenReturn(4, 5).thenReturn(null);
Context hookContext = Operators.discardLocalAdapter(Integer.class, i -> discardedCount.incrementAndGet()).apply(Context.empty());
Operators.onDiscardQueueWithClear(q, hookContext, null);
assertThat(discardedCount).as("discarding stops").hasValue(2);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onErrorDroppedLocal.
@Test
public void onErrorDroppedLocal() {
AtomicReference<Throwable> hookState = new AtomicReference<>();
Consumer<Throwable> localHook = hookState::set;
Context c = Context.of(Hooks.KEY_ON_ERROR_DROPPED, localHook);
Operators.onErrorDropped(new IllegalArgumentException("boom"), c);
assertThat(hookState.get()).isInstanceOf(IllegalArgumentException.class).hasMessage("boom");
}
Aggregations