use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class AboutControllerTestIT method testGetControllerPath.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetControllerPath() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
String url = AlertRestConstants.BASE_PATH + "/about";
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 JobConfigControllerTestIT method testValidateConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidateConfig() throws Exception {
final String urlPath = REQUEST_URL + "/validate";
ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API")));
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
JobFieldModel fieldModel = createTestJobFieldModel(null, null, providerGlobalConfig);
request.content(gson.toJson(fieldModel));
request.contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testDeleteConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testDeleteConfig() throws Exception {
DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
String jobId = String.valueOf(distributionJobModel.getJobId());
addGlobalConfiguration(blackDuckProviderKey, Map.of(BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API")));
String urlPath = REQUEST_URL + "/" + jobId;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.delete(urlPath).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 JobConfigControllerTestIT method testUpdateConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdateConfig() throws Exception {
ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of(testProperties.getBlackDuckURL()), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of(testProperties.getBlackDuckAPIToken())));
JobFieldModel fieldModel = createTestJobFieldModel("1", "2", providerGlobalConfig);
Map<String, Collection<String>> fieldValueModels = new HashMap<>();
for (FieldModel newFieldModel : fieldModel.getFieldModels()) {
fieldValueModels.putAll(newFieldModel.getKeyToValues().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getValues())));
}
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(providerGlobalConfig.getConfigurationId());
DistributionJobModel distributionJobModel = addDistributionJob(jobRequestModel);
String configId = String.valueOf(distributionJobModel.getJobId());
String urlPath = REQUEST_URL + "/" + configId;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
fieldModel.setJobId(configId);
request.content(gson.toJson(fieldModel));
request.contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class HomeControllerTestIT method testVerifyNoToken.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testVerifyNoToken() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("X-CSRF-TOKEN", UUID.randomUUID().toString());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(HOME_VERIFY_URL).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
request.headers(headers);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isUnauthorized());
}
Aggregations