use of com.webauthn4j.springframework.security.options.AttestationOptionsProvider in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsEndpointFilterTest method doFilter_with_unmatched_url_test.
@Test
public void doFilter_with_unmatched_url_test() throws IOException, ServletException {
AttestationOptionsProvider optionsProvider = mock(AttestationOptionsProvider.class);
AttestationOptionsEndpointFilter optionsEndpointFilter = new AttestationOptionsEndpointFilter(optionsProvider, objectConverter);
AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
optionsEndpointFilter.setTrustResolver(trustResolver);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/unmatched_url");
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain filterChain = new MockFilterChain();
optionsEndpointFilter.doFilter(request, response, filterChain);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
}
use of com.webauthn4j.springframework.security.options.AttestationOptionsProvider in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsEndpointFilterTest method writeErrorResponse_with_RuntimeException_test.
@Test
public void writeErrorResponse_with_RuntimeException_test() throws IOException {
AttestationOptionsProvider optionsProvider = mock(AttestationOptionsProvider.class);
AttestationOptionsEndpointFilter optionsEndpointFilter = new AttestationOptionsEndpointFilter(optionsProvider, objectConverter);
MockHttpServletResponse response = new MockHttpServletResponse();
RuntimeException exception = new RuntimeException();
optionsEndpointFilter.writeErrorResponse(response, exception);
assertThat(response.getContentAsString()).isEqualTo("{\"errorMessage\":\"The server encountered an internal error\"}");
}
use of com.webauthn4j.springframework.security.options.AttestationOptionsProvider in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsEndpointFilterTest method doFilter_test.
@Test
public void doFilter_test() throws IOException, ServletException {
AttestationOptionsProvider optionsProvider = mock(AttestationOptionsProvider.class);
AttestationOptions attestationOptions = new AttestationOptions(null, null, null, null, null, Collections.emptyList(), null, null, null);
when(optionsProvider.getAttestationOptions(any(), any())).thenReturn(attestationOptions);
AttestationOptionsEndpointFilter optionsEndpointFilter = new AttestationOptionsEndpointFilter(optionsProvider, objectConverter);
AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
optionsEndpointFilter.setTrustResolver(trustResolver);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI(AttestationOptionsEndpointFilter.FILTER_URL);
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain filterChain = new MockFilterChain();
optionsEndpointFilter.doFilter(request, response, filterChain);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
}
use of com.webauthn4j.springframework.security.options.AttestationOptionsProvider in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsEndpointFilterTest method writeErrorResponse_with_InsufficientAuthenticationException_test.
@Test
public void writeErrorResponse_with_InsufficientAuthenticationException_test() throws IOException {
AttestationOptionsProvider optionsProvider = mock(AttestationOptionsProvider.class);
AttestationOptionsEndpointFilter optionsEndpointFilter = new AttestationOptionsEndpointFilter(optionsProvider, objectConverter);
MockHttpServletResponse response = new MockHttpServletResponse();
InsufficientAuthenticationException exception = new InsufficientAuthenticationException(null);
optionsEndpointFilter.writeErrorResponse(response, exception);
assertThat(response.getContentAsString()).isEqualTo("{\"errorMessage\":\"Anonymous access is prohibited\"}");
}
use of com.webauthn4j.springframework.security.options.AttestationOptionsProvider in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsEndpointFilterTest method doFilter_with_error_test.
@Test
public void doFilter_with_error_test() throws IOException, ServletException {
AttestationOptionsProvider optionsProvider = mock(AttestationOptionsProvider.class);
doThrow(new RuntimeException()).when(optionsProvider).getAttestationOptions(any(), any());
AttestationOptionsEndpointFilter optionsEndpointFilter = new AttestationOptionsEndpointFilter(optionsProvider, objectConverter);
AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
optionsEndpointFilter.setTrustResolver(trustResolver);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI(AttestationOptionsEndpointFilter.FILTER_URL);
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain filterChain = new MockFilterChain();
optionsEndpointFilter.doFilter(request, response, filterChain);
assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.value());
}
Aggregations