Skip to content

Commit e569c7a

Browse files
committed
Fix Tests
Issue gh-16517
1 parent 85f0f3f commit e569c7a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

web/src/test/java/org/springframework/security/web/webauthn/registration/WebAuthnRegistrationFilterTests.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.converter.GenericHttpMessageConverter;
30+
import org.springframework.mock.web.MockFilterChain;
3031
import org.springframework.mock.web.MockHttpServletRequest;
3132
import org.springframework.mock.web.MockHttpServletResponse;
3233
import org.springframework.mock.web.MockServletContext;
@@ -74,6 +75,8 @@ class WebAuthnRegistrationFilterTests {
7475
@Mock
7576
private FilterChain chain;
7677

78+
private MockHttpServletRequest request = new MockHttpServletRequest();
79+
7780
private MockHttpServletResponse response = new MockHttpServletResponse();
7881

7982
private static final String REGISTRATION_REQUEST_BODY = """
@@ -101,32 +104,26 @@ class WebAuthnRegistrationFilterTests {
101104

102105
private WebAuthnRegistrationFilter filter;
103106

104-
private MockHttpServletRequest request;
105-
106107
@BeforeEach
107108
void setup() {
108109
this.filter = new WebAuthnRegistrationFilter(this.userCredentials, this.operations);
109-
this.request = new MockHttpServletRequest();
110-
this.response = new MockHttpServletResponse();
111-
this.chain = mock(FilterChain.class);
112110
}
113111

114112
@Test
115113
void doFilterWhenCustomRequestRegisterCredentialMatcherThenUses() throws Exception {
116114
RequestMatcher requestMatcher = mock(RequestMatcher.class);
117115
this.filter.setRegisterCredentialMatcher(requestMatcher);
118-
FilterChain mock = mock(FilterChain.class);
119-
this.filter.doFilter(this.request, this.response, mock);
116+
this.filter.doFilter(this.request, this.response, new MockFilterChain());
120117
verify(requestMatcher).matches(any());
121118
}
122119

123120
@Test
124121
void doFilterWhenCustomRequestRemoveCredentialMatcherThenUses() throws Exception {
125122
RequestMatcher requestMatcher = mock(RequestMatcher.class);
123+
given(requestMatcher.matcher(any())).willReturn(RequestMatcher.MatchResult.notMatch());
126124
this.filter.setRemoveCredentialMatcher(requestMatcher);
127-
FilterChain mock = mock(FilterChain.class);
128-
this.filter.doFilter(this.request, this.response, mock);
129-
verify(requestMatcher).matches(any());
125+
this.filter.doFilter(this.request, this.response, new MockFilterChain());
126+
verify(requestMatcher).matcher(any());
130127
}
131128

132129
@Test

0 commit comments

Comments
 (0)