Search in sources :

Example 1 with AttestationOptionsProvider

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());
}
Also used : AuthenticationTrustResolverImpl(org.springframework.security.authentication.AuthenticationTrustResolverImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AttestationOptionsProvider(com.webauthn4j.springframework.security.options.AttestationOptionsProvider) AuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 2 with AttestationOptionsProvider

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\"}");
}
Also used : AttestationOptionsProvider(com.webauthn4j.springframework.security.options.AttestationOptionsProvider) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with AttestationOptionsProvider

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());
}
Also used : AuthenticationTrustResolverImpl(org.springframework.security.authentication.AuthenticationTrustResolverImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AttestationOptionsProvider(com.webauthn4j.springframework.security.options.AttestationOptionsProvider) AttestationOptions(com.webauthn4j.springframework.security.options.AttestationOptions) AuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with AttestationOptionsProvider

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\"}");
}
Also used : AttestationOptionsProvider(com.webauthn4j.springframework.security.options.AttestationOptionsProvider) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 5 with AttestationOptionsProvider

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());
}
Also used : AuthenticationTrustResolverImpl(org.springframework.security.authentication.AuthenticationTrustResolverImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AttestationOptionsProvider(com.webauthn4j.springframework.security.options.AttestationOptionsProvider) AuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

AttestationOptionsProvider (com.webauthn4j.springframework.security.options.AttestationOptionsProvider)5 Test (org.junit.Test)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 MockFilterChain (org.springframework.mock.web.MockFilterChain)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 AuthenticationTrustResolver (org.springframework.security.authentication.AuthenticationTrustResolver)3 AuthenticationTrustResolverImpl (org.springframework.security.authentication.AuthenticationTrustResolverImpl)3 AttestationOptions (com.webauthn4j.springframework.security.options.AttestationOptions)1 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)1