use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method testWebConfigurationFilterChainUnauthenticated.
@Test
public void testWebConfigurationFilterChainUnauthenticated() 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("/")).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 WebMvcAutoConfigurationTests method welcomePageMappingHandlesRequestsWithNoAcceptHeader.
@Test
public void welcomePageMappingHandlesRequestsWithNoAcceptHeader() 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("/")).andExpect(status().isOk()).andExpect(forwardedUrl("index.html"));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method welcomePageMappingHandlesRequestsThatAcceptTextHtml.
@Test
public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() 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"));
mockMvc.perform(get("/").accept("*/*")).andExpect(status().isOk()).andExpect(forwardedUrl("index.html"));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MvcEndpointIntegrationTests method assertIndentedJsonResponse.
private void assertIndentedJsonResponse(Class<?> configuration) throws Exception {
TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(configuration);
EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.serialization.indent-output:true");
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/mappings")).andExpect(content().string(startsWith("{" + LINE_SEPARATOR)));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MvcEndpointIntegrationTests method nonSensitiveEndpointsAreNotSecureByDefaultWithCustomContextPath.
@Test
public void nonSensitiveEndpointsAreNotSecureByDefaultWithCustomContextPath() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "management.context-path:/management");
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/info")).andExpect(status().isOk());
mockMvc.perform(get("/management")).andExpect(status().isOk());
}
Aggregations