|
27 | 27 |
|
28 | 28 | import org.springframework.http.HttpStatus;
|
29 | 29 | import org.springframework.http.converter.GenericHttpMessageConverter;
|
| 30 | +import org.springframework.mock.web.MockFilterChain; |
30 | 31 | import org.springframework.mock.web.MockHttpServletRequest;
|
31 | 32 | import org.springframework.mock.web.MockHttpServletResponse;
|
32 | 33 | import org.springframework.mock.web.MockServletContext;
|
@@ -74,6 +75,8 @@ class WebAuthnRegistrationFilterTests {
|
74 | 75 | @Mock
|
75 | 76 | private FilterChain chain;
|
76 | 77 |
|
| 78 | + private MockHttpServletRequest request = new MockHttpServletRequest(); |
| 79 | + |
77 | 80 | private MockHttpServletResponse response = new MockHttpServletResponse();
|
78 | 81 |
|
79 | 82 | private static final String REGISTRATION_REQUEST_BODY = """
|
@@ -101,32 +104,26 @@ class WebAuthnRegistrationFilterTests {
|
101 | 104 |
|
102 | 105 | private WebAuthnRegistrationFilter filter;
|
103 | 106 |
|
104 |
| - private MockHttpServletRequest request; |
105 |
| - |
106 | 107 | @BeforeEach
|
107 | 108 | void setup() {
|
108 | 109 | this.filter = new WebAuthnRegistrationFilter(this.userCredentials, this.operations);
|
109 |
| - this.request = new MockHttpServletRequest(); |
110 |
| - this.response = new MockHttpServletResponse(); |
111 |
| - this.chain = mock(FilterChain.class); |
112 | 110 | }
|
113 | 111 |
|
114 | 112 | @Test
|
115 | 113 | void doFilterWhenCustomRequestRegisterCredentialMatcherThenUses() throws Exception {
|
116 | 114 | RequestMatcher requestMatcher = mock(RequestMatcher.class);
|
117 | 115 | 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()); |
120 | 117 | verify(requestMatcher).matches(any());
|
121 | 118 | }
|
122 | 119 |
|
123 | 120 | @Test
|
124 | 121 | void doFilterWhenCustomRequestRemoveCredentialMatcherThenUses() throws Exception {
|
125 | 122 | RequestMatcher requestMatcher = mock(RequestMatcher.class);
|
| 123 | + given(requestMatcher.matcher(any())).willReturn(RequestMatcher.MatchResult.notMatch()); |
126 | 124 | 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()); |
130 | 127 | }
|
131 | 128 |
|
132 | 129 | @Test
|
|
0 commit comments