1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org.springframework.security.config.annotation.web
18
18
19
+ import org.hamcrest.Matchers
19
20
import org.junit.jupiter.api.Test
20
21
import org.junit.jupiter.api.extension.ExtendWith
21
22
import org.springframework.beans.factory.annotation.Autowired
@@ -30,7 +31,9 @@ import org.springframework.security.core.userdetails.UserDetailsService
30
31
import org.springframework.security.provisioning.InMemoryUserDetailsManager
31
32
import org.springframework.security.web.SecurityFilterChain
32
33
import org.springframework.test.web.servlet.MockMvc
34
+ import org.springframework.test.web.servlet.get
33
35
import org.springframework.test.web.servlet.post
36
+ import org.springframework.test.web.servlet.result.MockMvcResultMatchers
34
37
35
38
/* *
36
39
* Tests for [WebAuthnDsl]
@@ -55,6 +58,40 @@ class WebAuthnDslTests {
55
58
}
56
59
}
57
60
61
+ @Test
62
+ fun `webauthn and formLogin configured with default registration page` () {
63
+ spring.register(DefaultWebauthnConfig ::class .java).autowire()
64
+
65
+ this .mockMvc.get(" /login/webauthn.js" )
66
+ .andExpect {
67
+ MockMvcResultMatchers .status().isOk
68
+ header {
69
+ string(" content-type" , " text/javascript;charset=UTF-8" )
70
+ }
71
+ content {
72
+ string(Matchers .containsString(" async function authenticate(" ))
73
+ }
74
+ }
75
+ }
76
+
77
+ @Configuration
78
+ @EnableWebSecurity
79
+ open class DefaultWebauthnConfig {
80
+ @Bean
81
+ open fun userDetailsService (): UserDetailsService =
82
+ InMemoryUserDetailsManager ()
83
+
84
+
85
+ @Bean
86
+ open fun securityFilterChain (http : HttpSecurity ): SecurityFilterChain {
87
+ http{
88
+ formLogin { }
89
+ webAuthn { }
90
+ }
91
+ return http.build()
92
+ }
93
+ }
94
+
58
95
@Configuration
59
96
@EnableWebSecurity
60
97
open class WebauthnConfig {
0 commit comments