-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webauthn: use DefaultResourcesFilter#webauthn
- Unconditionally use the DefaultResourcesFilter, because the javascript file is required by the DefaultWebAythnPageGeneratingFilter, which is always registered.
- Loading branch information
Showing
2 changed files
with
80 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...g/springframework/security/config/annotation/web/configurers/WebAuthnConfigurerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.config.annotation.web.configurers; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.test.SpringTestContext; | ||
import org.springframework.security.config.test.SpringTestContextExtension; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* @author Daniel Garnier-Moiroux | ||
*/ | ||
@ExtendWith(SpringTestContextExtension.class) | ||
public class WebAuthnConfigurerTests { | ||
|
||
public final SpringTestContext spring = new SpringTestContext(this); | ||
|
||
@Autowired | ||
MockMvc mvc; | ||
|
||
@Test | ||
public void javascriptWhenWebauthnConfiguredThenServesJavascript() throws Exception { | ||
this.spring.register(DefaultWebauthnConfiguration.class).autowire(); | ||
this.mvc.perform(get("/login/webauthn.js")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().string("content-type", "text/javascript;charset=UTF-8")) | ||
.andExpect(content().string(containsString("async function authenticate("))); | ||
} | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
static class DefaultWebauthnConfiguration { | ||
|
||
@Bean | ||
UserDetailsService userDetailsService() { | ||
return new InMemoryUserDetailsManager(); | ||
} | ||
|
||
@Bean | ||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
return http.webAuthn(Customizer.withDefaults()).build(); | ||
} | ||
|
||
} | ||
|
||
} |