Search in sources :

Example 6 with WebhookDto

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);
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ComponentFinder(org.sonar.server.component.ComponentFinder) DbTester.create(org.sonar.db.DbTester.create) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PROJECT_KEY_PARAM(org.sonar.server.webhook.ws.WebhooksWsParameters.PROJECT_KEY_PARAM) ADMINISTER(org.sonar.db.permission.GlobalPermission.ADMINISTER) AssertionsForClassTypes.tuple(org.assertj.core.api.AssertionsForClassTypes.tuple) ADMIN(org.sonar.api.web.UserRole.ADMIN) WebhookTesting.newGlobalWebhook(org.sonar.db.webhook.WebhookTesting.newGlobalWebhook) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Configuration(org.sonar.api.config.Configuration) ResourceTypes(org.sonar.api.resources.ResourceTypes) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) WebhookDbTester(org.sonar.db.webhook.WebhookDbTester) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) WebhookDeliveryTesting.newDto(org.sonar.db.webhook.WebhookDeliveryTesting.newDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Webhooks(org.sonarqube.ws.Webhooks) ComponentDbTester(org.sonar.db.component.ComponentDbTester) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ProjectDto(org.sonar.db.project.ProjectDto) WebhookDeliveryDbTester(org.sonar.db.webhook.WebhookDeliveryDbTester) Mockito.mock(org.mockito.Mockito.mock) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 7 with WebhookDto

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()));
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 8 with WebhookDto

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");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 9 with WebhookDto

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();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 10 with WebhookDto

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");
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

WebhookDto (org.sonar.db.webhook.WebhookDto)28 Test (org.junit.Test)22 ProjectDto (org.sonar.db.project.ProjectDto)16 TestRequest (org.sonar.server.ws.TestRequest)9 Webhooks (org.sonarqube.ws.Webhooks)6 ListResponse (org.sonarqube.ws.Webhooks.ListResponse)6 DbSession (org.sonar.db.DbSession)5 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)5 TestResponse (org.sonar.server.ws.TestResponse)5 WebhookDeliveryLiteDto (org.sonar.db.webhook.WebhookDeliveryLiteDto)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 AssertionsForClassTypes.tuple (org.assertj.core.api.AssertionsForClassTypes.tuple)1 Rule (org.junit.Rule)1 Mockito.mock (org.mockito.Mockito.mock)1 Configuration (org.sonar.api.config.Configuration)1 ResourceTypes (org.sonar.api.resources.ResourceTypes)1 WebService (org.sonar.api.server.ws.WebService)1