use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testGetConfig.
@Test
@WithMockUser(roles = "ADMIN")
public void testGetConfig() throws Exception {
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(auditUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class GlobalHipChatConfigControllerTestIT method testTestConfig.
@Test
@Override
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
final String testRestUrl = restUrl + "/test";
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
final GlobalHipChatConfigRestModel globalHipChatConfigRestModel = new GlobalHipChatConfigRestModel(null, testProperties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY), true);
request.content(gson.toJson(globalHipChatConfigRestModel));
request.contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class HomeControllerTestIT method testVerify.
@Test
@WithMockUser(roles = "ADMIN")
public void testVerify() throws Exception {
final HttpHeaders headers = new HttpHeaders();
final MockHttpSession session = new MockHttpSession();
final ServletContext servletContext = webApplicationContext.getServletContext();
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(homeVerifyUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
request.session(session);
final HttpServletRequest httpServletRequest = request.buildRequest(servletContext);
final CsrfToken csrfToken = csrfTokenRepository.generateToken(httpServletRequest);
csrfTokenRepository.saveToken(csrfToken, httpServletRequest, null);
headers.add(csrfToken.getHeaderName(), csrfToken.getToken());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class HomeControllerTestIT method testVerifyMissingCSRFToken.
@Test
@WithMockUser(roles = "ADMIN")
public void testVerifyMissingCSRFToken() throws Exception {
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(homeVerifyUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isUnauthorized());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class HomeControllerTestIT method testVerifyNullStringCSRFToken.
@Test
@WithMockUser(roles = "ADMIN")
public void testVerifyNullStringCSRFToken() throws Exception {
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(homeVerifyUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
final HttpHeaders headers = new HttpHeaders();
headers.add("X-CSRF-TOKEN", "null");
request.headers(headers);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isUnauthorized());
}
Aggregations