我的目标是为oauth编写单元测试 - 检查用户名和标记是否正确。在Spring引导框架中为Oauth编写单元测试
搜索使我这个ARTICAL Faking OAuth SSO
现在,我下面战略#1。
以下是我需要找出它们没有直接提到的依赖关系的代码片段。
@Test
public void testGetAuthenticationInfo() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(springSecurity())
.build();
mockMvc.perform(MockMvcRequestBuilders.get("/api/token")
.with(authentication(getOauthTestAuthentication()))
.sessionAttr("scopedTarget.oauth2ClientContext", getOauth2ClientContext()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.username").value("bwatkins"))
.andExpect(jsonPath("$.token").value("my-fun-token"));
}
我设法为web应用上下文如下安排 -
@Autowired
private WebApplicationContext webApplicationContext;
对于springSecurity()方法,我无法得到正确的依赖。无论我搜索的是什么,都让我相信导入org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers。*会给我这个方法,但我无法获得正确的pom依赖。
问题1:任何人都可以帮助我获得依赖吗? 问题2:对于OAuth这样的标准事件,是不是有一个标准的弹簧启动测试包,应该只需要配置就可以测试oauth是否工作正常