use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method testWebConfigurationFilterChainBadCredentials.
@Test
public void testWebConfigurationFilterChainBadCredentials() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--server.port=0");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters(this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/").header("authorization", "Basic xxx")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(MockMvcResultMatchers.header().string("www-authenticate", Matchers.containsString("realm=\"Spring\"")));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method securityHeadersCanBeDisabled.
@Test
public void securityHeadersCanBeDisabled() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--server.port=0", "--security.headers.content-type=false", "--security.headers.xss=false", "--security.headers.cache=false", "--security.headers.frame=false");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters(this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(MockMvcResultMatchers.header().doesNotExist("X-Content-Type-Options")).andExpect(MockMvcResultMatchers.header().doesNotExist("X-XSS-Protection")).andExpect(MockMvcResultMatchers.header().doesNotExist("Cache-Control")).andExpect(MockMvcResultMatchers.header().doesNotExist("X-Frame-Options"));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method testWebConfigurationFilterChainUnauthenticatedWithAuthorizeModeNone.
@Test
public void testWebConfigurationFilterChainUnauthenticatedWithAuthorizeModeNone() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--server.port=0", "--security.basic.authorize-mode=none");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters(this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isNotFound());
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method welcomePageMappingDoesNotHandleRequestsThatDoNotAcceptTextHtml.
@Test
public void welcomePageMappingDoesNotHandleRequestsThatDoNotAcceptTextHtml() throws Exception {
load("spring.resources.static-locations:classpath:/welcome-page/");
assertThat(this.context.getBeansOfType(WelcomePageHandlerMapping.class)).hasSize(1);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method welcomePageMappingWorksWithNoTrailingSlashOnResourceLocation.
@Test
public void welcomePageMappingWorksWithNoTrailingSlashOnResourceLocation() throws Exception {
load("spring.resources.static-locations:classpath:/welcome-page");
assertThat(this.context.getBeansOfType(WelcomePageHandlerMapping.class)).hasSize(1);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/").accept(MediaType.TEXT_HTML)).andExpect(status().isOk()).andExpect(forwardedUrl("index.html"));
}
Aggregations