【发布时间】:2015-08-05 21:15:45
【问题描述】:
这是我的测试,我正在添加额外的标题测试after testing my filter
@RunWith( SpringJUnit4ClassRunner.class )
@WebAppConfiguration
@EnableWebMvcSecurity
@SpringApplicationConfiguration( classes = {
MockServletContext.class,
HttpSessionConfig.class,
WebSecurityConfig.class
} )
@SuppressWarnings( "PMD.TooManyStaticImports" )
public class HeadersTest {
private MockMvc mockMvc = null;
@Autowired
private WebApplicationContext context;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup( context )
.addFilter( new CORSFilter(), "/*" )
.build();
}
@Test
public void testOptions() throws Exception {
mockMvc.perform( options( "/" ) )
.andExpect( status().is2xxSuccessful() )
.andExpect( header().string( "Access-Control-Allow-Origin", notNullValue() ) )
.andExpect( header().string( "Access-Control-Allow-",
equalToIgnoringCase( "POST, GET, PUT, OPTIONS, DELETE" ) ) )
.andExpect( header().string( "Access-Control-Allow-Headers",
equalToIgnoringCase( "content-type, x-auth-token, x-requested-with" ) ) )
.andExpect( header().string( "Access-Control-Expose-Headers", equalToIgnoringCase( "Location" ) ) )
.andExpect( header().string( "Access-Control-Max-Age", notNullValue() ) )
;
}
}
如果我从配置中删除 WebSecurityConfig.class,则测试有效,但是当我添加它时,我得到了这个异常
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.ObjectPostProcessor]
这是WebSecurityConfig
@Configuration
@Order( SecurityProperties.BASIC_AUTH_ORDER - 1 )
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure( final HttpSecurity http ) throws Exception {
http.httpBasic().and()
.authorizeRequests()
.antMatchers( "/" ).permitAll()
.anyRequest().authenticated();
}
}
如何更改我的测试以使WebSecurityConfig 正确?
【问题讨论】:
标签: java spring spring-mvc spring-security spring-boot