Search in sources :

Example 81 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class NoSpringSecurityHealthMvcEndpointIntegrationTests method healthDetailPresent.

@Test
public void healthDetailPresent() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(TestConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "management.security.enabled:false");
    this.context.refresh();
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(get("/health")).andExpect(status().isOk()).andExpect(content().string(containsString("\"status\":\"UP\",\"test\":{\"status\":\"UP\",\"hello\":\"world\"}")));
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 82 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method endpointSecurityCanBeDisabled.

@Test
public void endpointSecurityCanBeDisabled() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "management.security.enabled:false");
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/beans")).andExpect(status().isOk());
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 83 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method nonSensitiveEndpointsAreNotSecureByDefault.

@Test
public void nonSensitiveEndpointsAreNotSecureByDefault() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/info")).andExpect(status().isOk());
    mockMvc.perform(get("/actuator")).andExpect(status().isOk());
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 84 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method sensitiveEndpointsAreSecureByDefaultWithCustomContextPath.

@Test
public void sensitiveEndpointsAreSecureByDefaultWithCustomContextPath() 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/beans")).andExpect(status().isUnauthorized());
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 85 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method sensitiveEndpointsAreSecureByDefault.

@Test
public void sensitiveEndpointsAreSecureByDefault() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/beans")).andExpect(status().isUnauthorized());
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

MockMvc (org.springframework.test.web.servlet.MockMvc)97 Test (org.junit.Test)91 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)25 Todo (org.springframework.sync.Todo)16 List (java.util.List)15 TodoRepository (org.springframework.sync.TodoRepository)15 Filter (javax.servlet.Filter)13 MockServletContext (org.springframework.mock.web.MockServletContext)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)9 MvcResult (org.springframework.test.web.servlet.MvcResult)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 Ignore (org.junit.Ignore)3 FilterChainProxy (org.springframework.security.web.FilterChainProxy)3 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 HttpSession (javax.servlet.http.HttpSession)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2