use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class ListActionTest method obfuscate_credentials_in_webhook_URLs.
@Test
public void obfuscate_credentials_in_webhook_URLs() {
String url = "http://foo:barouf@toto/bop";
String expectedUrl = "http://***:******@toto/bop";
WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null, null);
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null, null);
userSession.logIn().addPermission(ADMINISTER);
ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
List<Webhooks.ListResponseElement> elements = response.getWebhooksList();
assertThat(elements).hasSize(2).extracting(Webhooks.ListResponseElement::getUrl).containsOnly(expectedUrl);
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class ListActionTest method list_global_webhooks_if_project_key_param_missing.
@Test
public void list_global_webhooks_if_project_key_param_missing() {
WebhookDto dto1 = webhookDbTester.insertGlobalWebhook();
WebhookDto dto2 = webhookDbTester.insertGlobalWebhook();
userSession.logIn().addPermission(ADMINISTER);
ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
assertThat(response.getWebhooksList()).extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl).contains(tuple(dto1.getName(), dto1.getUrl()), tuple(dto2.getName(), dto2.getUrl()));
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class UpdateActionTest method fail_if_no_permission_on_webhook_scope_project.
@Test
public void fail_if_no_permission_on_webhook_scope_project() {
ProjectDto project = componentDbTester.insertPrivateProjectDto();
WebhookDto dto = webhookDbTester.insertWebhook(project);
userSession.logIn();
TestRequest request = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001);
assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_a_project_webhook_with_required_fields.
@Test
public void update_a_project_webhook_with_required_fields() {
ProjectDto project = componentDbTester.insertPrivateProjectDto();
WebhookDto dto = webhookDbTester.insertWebhook(project);
userSession.logIn().addProjectPermission(ADMIN, project);
TestResponse response = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001).execute();
assertThat(response.getStatus()).isEqualTo(HTTP_NO_CONTENT);
Optional<WebhookDto> reloaded = webhookDbTester.selectWebhook(dto.getUuid());
assertThat(reloaded).isPresent();
assertThat(reloaded.get().getName()).isEqualTo(NAME_WEBHOOK_EXAMPLE_001);
assertThat(reloaded.get().getUrl()).isEqualTo(URL_WEBHOOK_EXAMPLE_001);
assertThat(reloaded.get().getProjectUuid()).isEqualTo(dto.getProjectUuid());
assertThat(reloaded.get().getSecret()).isNull();
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class UpdateActionTest method fail_if_no_permission_on_webhook_scope_global.
@Test
public void fail_if_no_permission_on_webhook_scope_global() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
userSession.logIn();
TestRequest request = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001);
assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Aggregations