|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.authentication.ui;
|
18 | 18 |
|
| 19 | +import org.junit.jupiter.api.Nested; |
19 | 20 | import org.junit.jupiter.api.Test;
|
20 | 21 |
|
21 | 22 | import org.springframework.test.web.servlet.MockMvc;
|
|
33 | 34 | */
|
34 | 35 | public class DefaultResourcesFilterTests {
|
35 | 36 |
|
36 |
| - private final DefaultResourcesFilter filter = DefaultResourcesFilter.css(); |
| 37 | + @Nested |
| 38 | + class CssFilter { |
37 | 39 |
|
38 |
| - private final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Object()).addFilters(this.filter).build(); |
| 40 | + private final DefaultResourcesFilter cssFilter = DefaultResourcesFilter.css(); |
39 | 41 |
|
40 |
| - @Test |
41 |
| - public void doFilterThenRender() throws Exception { |
42 |
| - this.mockMvc.perform(get("/default-ui.css")) |
43 |
| - .andExpect(status().isOk()) |
44 |
| - .andExpect(content().contentType("text/css;charset=UTF-8")) |
45 |
| - .andExpect(content().string(containsString("body {"))); |
46 |
| - } |
| 42 | + private final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Object()) |
| 43 | + .addFilters(this.cssFilter) |
| 44 | + .build(); |
| 45 | + |
| 46 | + @Test |
| 47 | + void doFilterThenRender() throws Exception { |
| 48 | + this.mockMvc.perform(get("/default-ui.css")) |
| 49 | + .andExpect(status().isOk()) |
| 50 | + .andExpect(content().contentType("text/css;charset=UTF-8")) |
| 51 | + .andExpect(content().string(containsString("body {"))); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void doFilterWhenPathDoesNotMatchThenCallsThrough() throws Exception { |
| 56 | + this.mockMvc.perform(get("/does-not-match")).andExpect(status().isNotFound()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void toStringPrintsPathAndResource() { |
| 61 | + assertThat(this.cssFilter.toString()).isEqualTo( |
| 62 | + "DefaultResourcesFilter [matcher=Ant [pattern='/default-ui.css', GET], resource=org/springframework/security/default-ui.css]"); |
| 63 | + } |
47 | 64 |
|
48 |
| - @Test |
49 |
| - public void doFilterWhenPathDoesNotMatchThenCallsThrough() throws Exception { |
50 |
| - this.mockMvc.perform(get("/does-not-match")).andExpect(status().isNotFound()); |
51 | 65 | }
|
52 | 66 |
|
53 |
| - @Test |
54 |
| - void toStringPrintsPathAndResource() { |
55 |
| - assertThat(this.filter.toString()).isEqualTo( |
56 |
| - "DefaultResourcesFilter [matcher=Ant [pattern='/default-ui.css', GET], resource=org/springframework/security/default-ui.css]"); |
| 67 | + @Nested |
| 68 | + class WebAuthnFilter { |
| 69 | + |
| 70 | + private final DefaultResourcesFilter webauthnFilter = DefaultResourcesFilter.webauthn(); |
| 71 | + |
| 72 | + private final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Object()) |
| 73 | + .addFilters(this.webauthnFilter) |
| 74 | + .build(); |
| 75 | + |
| 76 | + @Test |
| 77 | + void doFilterThenRender() throws Exception { |
| 78 | + this.mockMvc.perform(get("/login/webauthn.js")) |
| 79 | + .andExpect(status().isOk()) |
| 80 | + .andExpect(content().contentType("text/javascript;charset=UTF-8")) |
| 81 | + .andExpect(content().string(containsString("async function authenticate("))); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void doFilterWhenPathDoesNotMatchThenCallsThrough() throws Exception { |
| 86 | + this.mockMvc.perform(get("/does-not-match")).andExpect(status().isNotFound()); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + void toStringPrintsPathAndResource() { |
| 91 | + assertThat(this.webauthnFilter.toString()).isEqualTo( |
| 92 | + "DefaultResourcesFilter [matcher=Ant [pattern='/login/webauthn.js', GET], resource=org/springframework/security/spring-security-webauthn.js]"); |
| 93 | + } |
| 94 | + |
57 | 95 | }
|
58 | 96 |
|
59 | 97 | }
|
0 commit comments