1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 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]
@@ -80,4 +83,74 @@ class WebAuthnDslTests {
80
83
return InMemoryUserDetailsManager (userDetails)
81
84
}
82
85
}
86
+
87
+ @Test
88
+ fun `webauthn and formLogin configured with default registration page` () {
89
+ spring.register(DefaultWebauthnConfig ::class .java).autowire()
90
+
91
+ this .mockMvc.get(" /login/webauthn.js" )
92
+ .andExpect {
93
+ MockMvcResultMatchers .status().isOk
94
+ header {
95
+ string(" content-type" , " text/javascript;charset=UTF-8" )
96
+ }
97
+ content {
98
+ string(Matchers .containsString(" async function authenticate(" ))
99
+ }
100
+ }
101
+ }
102
+
103
+ @Test
104
+ fun `webauthn and formLogin configured with disabled default registration page` () {
105
+ spring.register(FormLoginAndNoDefaultRegistrationPageConfiguration ::class .java).autowire()
106
+
107
+ this .mockMvc.get(" /login/webauthn.js" )
108
+ .andExpect {
109
+ MockMvcResultMatchers .status().isOk
110
+ header {
111
+ string(" content-type" , " text/javascript;charset=UTF-8" )
112
+ }
113
+ content {
114
+ string(Matchers .containsString(" async function authenticate(" ))
115
+ }
116
+ }
117
+ }
118
+
119
+ @Configuration
120
+ @EnableWebSecurity
121
+ open class DefaultWebauthnConfig {
122
+ @Bean
123
+ open fun userDetailsService (): UserDetailsService =
124
+ InMemoryUserDetailsManager ()
125
+
126
+
127
+ @Bean
128
+ open fun securityFilterChain (http : HttpSecurity ): SecurityFilterChain {
129
+ http{
130
+ formLogin { }
131
+ webAuthn { }
132
+ }
133
+ return http.build()
134
+ }
135
+ }
136
+
137
+ @Configuration
138
+ @EnableWebSecurity
139
+ open class FormLoginAndNoDefaultRegistrationPageConfiguration {
140
+ @Bean
141
+ open fun userDetailsService (): UserDetailsService =
142
+ InMemoryUserDetailsManager ()
143
+
144
+
145
+ @Bean
146
+ open fun securityFilterChain (http : HttpSecurity ): SecurityFilterChain {
147
+ http{
148
+ formLogin { }
149
+ webAuthn {
150
+ disableDefaultRegistrationPage = true
151
+ }
152
+ }
153
+ return http.build()
154
+ }
155
+ }
83
156
}
0 commit comments