Fix security:ldap-client:test

This commit is contained in:
Sébastien Deleuze
2024-08-13 19:36:14 +02:00
parent 2cdffb420b
commit 9cf4508f49

View File

@@ -7,6 +7,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 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.content;
@@ -22,16 +23,16 @@ public class SecurityLdapApplicationTests {
@Test @Test
void rootWhenAuthenticatedThenSaysHelloUser() throws Exception { void rootWhenAuthenticatedThenSaysHelloUser() throws Exception {
// @formatter:off // @formatter:off
this.mvc.perform(get("/") this.mvc.perform(get("/users")
.with(httpBasic("user", "password"))) .with(httpBasic("user", "password")))
.andExpect(content().string("Hello, user!")); .andExpect(content().string(containsString("Rod Johnson")));
// @formatter:on // @formatter:on
} }
@Test @Test
void rootWhenUnauthenticatedThen401() throws Exception { void rootWhenUnauthenticatedThen401() throws Exception {
// @formatter:off // @formatter:off
this.mvc.perform(get("/")) this.mvc.perform(get("/users"))
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
// @formatter:on // @formatter:on
} }
@@ -39,7 +40,7 @@ public class SecurityLdapApplicationTests {
@Test @Test
void tokenWhenBadCredentialsThen401() throws Exception { void tokenWhenBadCredentialsThen401() throws Exception {
// @formatter:off // @formatter:off
this.mvc.perform(get("/") this.mvc.perform(get("/users")
.with(httpBasic("user", "passwerd"))) .with(httpBasic("user", "passwerd")))
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
// @formatter:on // @formatter:on