use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class CertificateControllerTestIT method readSingleTest.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void readSingleTest() throws Exception {
CertificateModel expectedCertificate = certTestUtil.createCertificate(certificateActions).orElseThrow(AssertionFailedError::new);
String url = CertificatesController.API_BASE_URL + String.format("/%s", expectedCertificate.getId());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class CertificateControllerTestIT method readAllTest.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void readAllTest() throws Exception {
String url = CertificatesController.API_BASE_URL;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class CertificateControllerTestIT method deleteTest.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void deleteTest() throws Exception {
CertificateModel expectedCertificate = certTestUtil.createCertificate(certificateActions).orElseThrow(AssertionFailedError::new);
String url = CertificatesController.API_BASE_URL + String.format("/%s", expectedCertificate.getId());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.delete(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class CertificateControllerTestIT method updateTest.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void updateTest() throws Exception {
CertificateModel expectedCertificate = certTestUtil.createCertificate(certificateActions).orElseThrow(AssertionFailedError::new);
CertificateModel updatedCertificate = new CertificateModel(expectedCertificate.getId(), "new-alias", expectedCertificate.getCertificateContent(), expectedCertificate.getLastUpdated());
String url = CertificatesController.API_BASE_URL + String.format("/%s", expectedCertificate.getId());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(updatedCertificate)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class SettingsEncryptionControllerTestIT method testValidate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidate() throws Exception {
SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
settingsEncryptionModel.setEncryptionPassword("password");
settingsEncryptionModel.setEncryptionGlobalSalt("globalSalt");
String url = AlertRestConstants.SETTINGS_ENCRYPTION_PATH + "/validate";
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(settingsEncryptionModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Aggregations