use of io.helidon.security.SecurityClientBuilder in project helidon by oracle.
the class SecurityFilterTest method testAtnAbortWith.
@Test
void testAtnAbortWith() {
SecurityFeature feature = SecurityFeature.builder(security).build();
SecurityContext securityContext = security.createContext("testAbortWith");
SecurityFilter sf = new SecurityFilter(feature.featureConfig(), security, serverConfig, securityContext);
ContainerRequest request = mock(ContainerRequest.class);
SecurityFilter.FilterContext filterContext = new SecurityFilter.FilterContext();
filterContext.setJerseyRequest(request);
SecurityDefinition methodSecurity = mock(SecurityDefinition.class);
SecurityClientBuilder<AuthenticationResponse> clientBuilder = mock(SecurityClientBuilder.class);
when(clientBuilder.buildAndGet()).thenReturn(AuthenticationResponse.failed("Unit-test"));
sf.processAuthentication(filterContext, clientBuilder, methodSecurity, tracing.atnTracing());
assertThat(filterContext.isShouldFinish(), is(true));
verify(request).abortWith(argThat(response -> response.getStatus() == 401));
}
use of io.helidon.security.SecurityClientBuilder in project helidon by oracle.
the class SecurityFilterTest method testAtzAbortWith.
@Test
void testAtzAbortWith() {
SecurityFeature feature = SecurityFeature.builder(security).build();
SecurityContext securityContext = security.createContext("testAbortWith");
SecurityFilter sf = new SecurityFilter(feature.featureConfig(), security, serverConfig, securityContext);
ContainerRequest request = mock(ContainerRequest.class);
SecurityFilter.FilterContext filterContext = new SecurityFilter.FilterContext();
filterContext.setJerseyRequest(request);
SecurityClientBuilder<AuthorizationResponse> clientBuilder = mock(SecurityClientBuilder.class);
when(clientBuilder.buildAndGet()).thenReturn(AuthorizationResponse.builder().description("Unit-test").status(SecurityResponse.SecurityStatus.FAILURE).build());
sf.processAuthorization(filterContext, clientBuilder);
assertThat(filterContext.isShouldFinish(), is(true));
verify(request).abortWith(argThat(response -> response.getStatus() == 403));
}
Aggregations