SEC-2436: Fix CsrfConfigurerNoWebMvcTests
This commit is contained in:
parent
b7041ed00e
commit
994117ad75
|
@ -16,30 +16,21 @@
|
||||||
package org.springframework.security.config.annotation.web.configurers;
|
package org.springframework.security.config.annotation.web.configurers;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Matchers.eq;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.spy;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({ClassUtils.class})
|
|
||||||
public class CsrfConfigurerNoWebMvcTests {
|
public class CsrfConfigurerNoWebMvcTests {
|
||||||
ConfigurableApplicationContext context;
|
ConfigurableApplicationContext context;
|
||||||
|
|
||||||
|
@ -52,24 +43,30 @@ public class CsrfConfigurerNoWebMvcTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingDispatcherServletPreventsCsrfRequestDataValueProcessor() {
|
public void missingDispatcherServletPreventsCsrfRequestDataValueProcessor() {
|
||||||
spy(ClassUtils.class);
|
loadContext(EnableWebConfig.class);
|
||||||
when(ClassUtils.isPresent(eq("org.springframework.web.servlet.DispatcherServlet"), any(ClassLoader.class))).thenReturn(false);
|
|
||||||
|
|
||||||
loadContext(CsrfDefaultsConfig.class);
|
|
||||||
|
|
||||||
assertThat(context.containsBeanDefinition("requestDataValueProcessor")).isFalse();
|
assertThat(context.containsBeanDefinition("requestDataValueProcessor")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findDispatcherServletPreventsCsrfRequestDataValueProcessor() {
|
public void findDispatcherServletPreventsCsrfRequestDataValueProcessor() {
|
||||||
loadContext(CsrfDefaultsConfig.class);
|
loadContext(EnableWebMvcConfig.class);
|
||||||
|
|
||||||
assertThat(context.containsBeanDefinition("requestDataValueProcessor")).isTrue();
|
assertThat(context.containsBeanDefinition("requestDataValueProcessor")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Configuration
|
@Configuration
|
||||||
static class CsrfDefaultsConfig extends WebSecurityConfigurerAdapter {
|
static class EnableWebConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableWebMvcSecurity
|
||||||
|
@Configuration
|
||||||
|
static class EnableWebMvcConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue