|
@@ -22,12 +22,14 @@ 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.context.support.MessageSourceAccessor;
|
|
|
import org.springframework.mock.web.MockHttpSession;
|
|
|
import org.springframework.security.config.ObjectPostProcessor;
|
|
|
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.SpringSecurityMessageSource;
|
|
|
import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
|
@@ -75,6 +77,8 @@ public class DefaultLoginPageConfigurerTests {
|
|
|
@Autowired
|
|
|
MockMvc mvc;
|
|
|
|
|
|
+ MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
|
|
|
+
|
|
|
@Test
|
|
|
public void getWhenFormLoginEnabledThenRedirectsToLoginPage() throws Exception {
|
|
|
this.spring.register(DefaultLoginPageConfig.class).autowire();
|
|
@@ -144,6 +148,8 @@ public class DefaultLoginPageConfigurerTests {
|
|
|
this.mvc.perform(get("/login?error").session((MockHttpSession) mvcResult.getRequest().getSession())
|
|
|
.sessionAttr(csrfAttributeName, csrfToken))
|
|
|
.andExpect((result) -> {
|
|
|
+ String badCredentialsLocalizedMessage = this.messages
|
|
|
+ .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials");
|
|
|
CsrfToken token = (CsrfToken) result.getRequest().getAttribute(CsrfToken.class.getName());
|
|
|
assertThat(result.getResponse().getContentAsString()).isEqualTo("""
|
|
|
<!DOCTYPE html>
|
|
@@ -160,7 +166,7 @@ public class DefaultLoginPageConfigurerTests {
|
|
|
<div class="content">
|
|
|
<form class="login-form" method="post" action="/login">
|
|
|
<h2>Please sign in</h2>
|
|
|
- <div class="alert alert-danger" role="alert">Bad credentials</div>
|
|
|
+ <div class="alert alert-danger" role="alert">%s</div>
|
|
|
<p>
|
|
|
<label for="username" class="screenreader">Username</label>
|
|
|
<input type="text" id="username" name="username" placeholder="Username" required autofocus>
|
|
@@ -178,7 +184,7 @@ public class DefaultLoginPageConfigurerTests {
|
|
|
|
|
|
</div>
|
|
|
</body>
|
|
|
- </html>""".formatted(token.getToken()));
|
|
|
+ </html>""".formatted(badCredentialsLocalizedMessage, token.getToken()));
|
|
|
});
|
|
|
// @formatter:on
|
|
|
}
|