use of org.springframework.mock.web.MockServletContext 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);
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class SecurityFilterAutoConfigurationTests method filterAutoConfigurationWorksWithoutSecurityAutoConfiguration.
@Test
public void filterAutoConfigurationWorksWithoutSecurityAutoConfiguration() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
try {
context.register(Config.class);
context.refresh();
} finally {
context.close();
}
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class SitePreferenceAutoConfigurationTests method sitePreferenceHandlerInterceptorRegistered.
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, SitePreferenceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class DeviceResolverAutoConfigurationTests method deviceResolverHandlerInterceptorRegistered.
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(DeviceResolverHandlerInterceptor.class);
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter.
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class, SecurityCustomizer.class, SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken("foo", "bar", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user)).isNotNull();
pingAuthenticationListener();
}
Aggregations