1818
1919import java .util .Arrays ;
2020
21+ import jakarta .servlet .FilterChain ;
2122import org .junit .jupiter .api .AfterEach ;
23+ import org .junit .jupiter .api .BeforeEach ;
2224import org .junit .jupiter .api .Test ;
2325import org .junit .jupiter .api .extension .ExtendWith ;
2426import org .mockito .Mock ;
2729import org .springframework .http .HttpHeaders ;
2830import org .springframework .http .HttpStatus ;
2931import org .springframework .http .MediaType ;
32+ import org .springframework .mock .web .MockFilterChain ;
33+ import org .springframework .mock .web .MockHttpServletRequest ;
3034import org .springframework .mock .web .MockHttpServletResponse ;
3135import org .springframework .security .authentication .AnonymousAuthenticationToken ;
3236import org .springframework .security .authentication .TestingAuthenticationToken ;
3337import org .springframework .security .core .authority .AuthorityUtils ;
3438import org .springframework .security .core .context .SecurityContextHolder ;
3539import org .springframework .security .core .context .SecurityContextImpl ;
40+ import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
3641import org .springframework .security .web .webauthn .api .AuthenticatorTransport ;
3742import org .springframework .security .web .webauthn .api .Bytes ;
3843import org .springframework .security .web .webauthn .api .PublicKeyCredentialCreationOptions ;
4752import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
4853import static org .mockito .ArgumentMatchers .any ;
4954import static org .mockito .BDDMockito .given ;
50- import static org .mockito .Mockito .verifyNoInteractions ;
55+ import static org .mockito .Mockito .* ;
5156import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
5257import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
5358import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
@@ -68,11 +73,40 @@ class PublicKeyCredentialCreationOptionsFilterTests {
6873 @ Mock
6974 private WebAuthnRelyingPartyOperations rpOperations ;
7075
76+ private PublicKeyCredentialCreationOptionsFilter filter ;
77+
78+ private MockHttpServletRequest request ;
79+
80+ private MockHttpServletResponse response ;
81+
82+ private FilterChain chain ;
83+
84+ @ BeforeEach
85+ public void setup () {
86+ this .filter = new PublicKeyCredentialCreationOptionsFilter (this .rpOperations );
87+ this .request = new MockHttpServletRequest ();
88+ this .response = new MockHttpServletResponse ();
89+ this .chain = mock (FilterChain .class );
90+ }
91+
7192 @ AfterEach
7293 void clear () {
7394 SecurityContextHolder .clearContext ();
7495 }
7596
97+ @ Test
98+ public void doFilterWhenCustomRequestMatcherThenUses () throws Exception {
99+ this .request .setPathInfo ("/path" );
100+ this .filter .setRequestMatcher (new AntPathRequestMatcher ("/path" ));
101+ this .filter .doFilter (this .request , this .response , this .chain );
102+ verifyNoInteractions (this .chain );
103+ }
104+
105+ @ Test
106+ public void setRequestMatcherWhenNullThenIllegalArgument () {
107+ assertThatIllegalArgumentException ().isThrownBy (() -> this .filter .setRequestMatcher (null ));
108+ }
109+
76110 @ Test
77111 void constructorWhenRpOperationsIsNullThenIllegalArgumentException () {
78112 assertThatIllegalArgumentException ().isThrownBy (() -> new PublicKeyCredentialCreationOptionsFilter (null ))
0 commit comments