use of org.springframework.test.web.servlet.MockMvc in project spring-security-oauth by spring-projects.
the class ClientConfigurationTests method testAuthCodeRedirect.
@Test
public void testAuthCodeRedirect() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(ClientContext.class);
context.refresh();
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(new OAuth2ClientContextFilter()).build();
mvc.perform(MockMvcRequestBuilders.get("/photos")).andExpect(MockMvcResultMatchers.status().isFound()).andExpect(MockMvcResultMatchers.header().string("Location", CoreMatchers.startsWith("http://example.com/authorize")));
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-security-oauth by spring-projects.
the class ResourceServerConfigurationTests method testWithAuthServerCustomPath.
@Test
public void testWithAuthServerCustomPath() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(ResourceServerAndAuthorizationServerCustomPathContext.class);
context.refresh();
MockMvc mvc = buildMockMvc(context);
mvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.header().string("WWW-Authenticate", containsString("Bearer")));
mvc.perform(MockMvcRequestBuilders.post("/token")).andExpect(MockMvcResultMatchers.header().string("WWW-Authenticate", containsString("Basic")));
mvc.perform(MockMvcRequestBuilders.get("/authorize")).andExpect(MockMvcResultMatchers.redirectedUrl("http://localhost/login"));
mvc.perform(MockMvcRequestBuilders.post("/token").header("Authorization", "Basic " + new String(Base64.encode("client:secret".getBytes())))).andExpect(MockMvcResultMatchers.content().string(containsString("Missing grant type")));
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-security-oauth by spring-projects.
the class ResourceServerConfigurationTests method testCustomTokenServices.
@Test
public void testCustomTokenServices() throws Exception {
tokenStore.storeAccessToken(token, authentication);
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(TokenServicesContext.class);
context.refresh();
MockMvc mvc = buildMockMvc(context);
mvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isUnauthorized());
mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer FOO")).andExpect(MockMvcResultMatchers.status().isNotFound());
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-security-oauth by spring-projects.
the class ResourceServerConfigurationTests method testCustomAuthenticationEntryPoint.
@Test
public void testCustomAuthenticationEntryPoint() throws Exception {
tokenStore.storeAccessToken(token, authentication);
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(AuthenticationEntryPointContext.class);
context.refresh();
MockMvc mvc = buildMockMvc(context);
mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer FOO")).andExpect(MockMvcResultMatchers.status().isFound());
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-security-oauth by spring-projects.
the class ResourceServerConfigurationTests method testDefaults.
@Test
public void testDefaults() throws Exception {
tokenStore.storeAccessToken(token, authentication);
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(ResourceServerContext.class);
context.refresh();
MockMvc mvc = buildMockMvc(context);
mvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isUnauthorized());
mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer FOO")).andExpect(MockMvcResultMatchers.status().isNotFound());
context.close();
}
Aggregations