SEC-2593: Add additional test

This commit is contained in:
Rob Winch 2015-02-05 10:58:49 -06:00
parent 1a35292750
commit 9c5cb2f438
1 changed files with 13 additions and 7 deletions

View File

@ -19,12 +19,12 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
@ -35,8 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import javax.servlet.Filter; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -49,19 +48,17 @@ public class SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests {
@Autowired @Autowired
private WebApplicationContext context; private WebApplicationContext context;
@Autowired
private Filter springSecurityFilterChain;
private MockMvc mvc; private MockMvc mvc;
@Before @Before
public void setup() { public void setup() {
mvc = MockMvcBuilders mvc = MockMvcBuilders
.webAppContextSetup(context) .webAppContextSetup(context)
.addFilters(springSecurityFilterChain) .apply(springSecurity())
.build(); .build();
} }
// SEC-2593
@Test @Test
public void userRequestPostProcessorWorksWithStateless() throws Exception { public void userRequestPostProcessorWorksWithStateless() throws Exception {
mvc mvc
@ -69,6 +66,15 @@ public class SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests {
.andExpect(status().is2xxSuccessful()); .andExpect(status().is2xxSuccessful());
} }
// SEC-2593
@WithMockUser
@Test
public void withMockUserWorksWithStateless() throws Exception {
mvc
.perform(get("/"))
.andExpect(status().is2xxSuccessful());
}
@EnableWebSecurity @EnableWebSecurity
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {