Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jzheaux committed Feb 27, 2025
1 parent 85f0f3f commit e569c7a
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.converter.GenericHttpMessageConverter;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
Expand Down Expand Up @@ -74,6 +75,8 @@ class WebAuthnRegistrationFilterTests {
@Mock
private FilterChain chain;

private MockHttpServletRequest request = new MockHttpServletRequest();

private MockHttpServletResponse response = new MockHttpServletResponse();

private static final String REGISTRATION_REQUEST_BODY = """
Expand Down Expand Up @@ -101,32 +104,26 @@ class WebAuthnRegistrationFilterTests {

private WebAuthnRegistrationFilter filter;

private MockHttpServletRequest request;

@BeforeEach
void setup() {
this.filter = new WebAuthnRegistrationFilter(this.userCredentials, this.operations);
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.chain = mock(FilterChain.class);
}

@Test
void doFilterWhenCustomRequestRegisterCredentialMatcherThenUses() throws Exception {
RequestMatcher requestMatcher = mock(RequestMatcher.class);
this.filter.setRegisterCredentialMatcher(requestMatcher);
FilterChain mock = mock(FilterChain.class);
this.filter.doFilter(this.request, this.response, mock);
this.filter.doFilter(this.request, this.response, new MockFilterChain());
verify(requestMatcher).matches(any());
}

@Test
void doFilterWhenCustomRequestRemoveCredentialMatcherThenUses() throws Exception {
RequestMatcher requestMatcher = mock(RequestMatcher.class);
given(requestMatcher.matcher(any())).willReturn(RequestMatcher.MatchResult.notMatch());
this.filter.setRemoveCredentialMatcher(requestMatcher);
FilterChain mock = mock(FilterChain.class);
this.filter.doFilter(this.request, this.response, mock);
verify(requestMatcher).matches(any());
this.filter.doFilter(this.request, this.response, new MockFilterChain());
verify(requestMatcher).matcher(any());
}

@Test
Expand Down

0 comments on commit e569c7a

Please sign in to comment.