Search in sources :

Example 31 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method jsonExtensionProvided.

@Test
public void jsonExtensionProvided() throws Exception {
    TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/beans.json")).andExpect(status().isOk());
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 32 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method fileExtensionNotFound.

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

Example 33 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method endpointSecurityCanBeDisabledWithCustomContextPath.

@Test
public void endpointSecurityCanBeDisabledWithCustomContextPath() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "management.context-path:/management", "management.security.enabled:false");
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/management/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 34 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class NoSpringSecurityHealthMvcEndpointIntegrationTests method healthWhenRightRoleNotPresentShouldNotExposeHealthDetails.

@Test
public void healthWhenRightRoleNotPresentShouldNotExposeHealthDetails() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(TestConfiguration.class);
    this.context.refresh();
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(get("/health").with(getRequestPostProcessor())).andExpect(status().isOk()).andExpect(content().string("{\"status\":\"UP\"}"));
}
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 35 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class SecurityAutoConfigurationTests method testDisableIgnoredStaticApplicationPaths.

@Test
public void testDisableIgnoredStaticApplicationPaths() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
    this.context.refresh();
    // Just the application endpoints now
    assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains()).hasSize(1);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)244 Test (org.junit.Test)116 MockServletContext (org.springframework.mock.web.MockServletContext)75 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)42 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)30 MockMvc (org.springframework.test.web.servlet.MockMvc)26 ServletRegistration (javax.servlet.ServletRegistration)25 HashMap (java.util.HashMap)24 URI (java.net.URI)23 MapPropertySource (org.springframework.core.env.MapPropertySource)23 StandardEnvironment (org.springframework.core.env.StandardEnvironment)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 Test (org.junit.jupiter.api.Test)17 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13