Search in sources :

Example 1 with ListResponse

use of org.sonarqube.ws.Webhooks.ListResponse 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 2 with ListResponse

use of org.sonarqube.ws.Webhooks.ListResponse 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 3 with ListResponse

use of org.sonarqube.ws.Webhooks.ListResponse in project sonarqube by SonarSource.

the class ListActionTest method list_global_webhooks.

@Test
public void list_global_webhooks() {
    WebhookDto dto1 = webhookDbTester.insertGlobalWebhook();
    WebhookDto dto2 = webhookDbTester.insertGlobalWebhook();
    // insert a project-specific webhook, that should not be returned when listing global webhooks
    webhookDbTester.insertWebhook(componentDbTester.insertPrivateProjectDto());
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    assertThat(response.getWebhooksList()).extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl).containsExactlyInAnyOrder(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 4 with ListResponse

use of org.sonarqube.ws.Webhooks.ListResponse in project sonarqube by SonarSource.

the class ListActionTest method list_project_webhooks_when_project_key_param_is_provided.

@Test
public void list_project_webhooks_when_project_key_param_is_provided() {
    ProjectDto project1 = componentDbTester.insertPrivateProjectDto();
    userSession.logIn().addProjectPermission(ADMIN, project1);
    WebhookDto dto1 = webhookDbTester.insertWebhook(project1);
    WebhookDto dto2 = webhookDbTester.insertWebhook(project1);
    ListResponse response = wsActionTester.newRequest().setParam(PROJECT_KEY_PARAM, project1.getKey()).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 : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 5 with ListResponse

use of org.sonarqube.ws.Webhooks.ListResponse in project sonarqube by SonarSource.

the class ListActionTest method list_webhooks_and_their_latest_delivery.

@Test
public void list_webhooks_and_their_latest_delivery() {
    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), 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));
    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null, null);
    webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
    webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    List<Webhooks.ListResponseElement> elements = response.getWebhooksList();
    assertThat(elements.size()).isEqualTo(2);
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook1.getUuid());
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("aaa");
    assertThat(elements.get(0).getLatestDelivery()).isNotNull();
    assertThat(elements.get(0).getLatestDelivery()).extracting(Webhooks.LatestDelivery::getId).isEqualTo("WH1-DELIVERY-2-UUID");
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook2.getUuid());
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("bbb");
    assertThat(elements.get(1).getLatestDelivery()).isNotNull();
    assertThat(elements.get(1).getLatestDelivery()).extracting(Webhooks.LatestDelivery::getId).isEqualTo("WH2-DELIVERY-2-UUID");
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 WebhookDto (org.sonar.db.webhook.WebhookDto)6 Webhooks (org.sonarqube.ws.Webhooks)6 ListResponse (org.sonarqube.ws.Webhooks.ListResponse)6 ProjectDto (org.sonar.db.project.ProjectDto)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 Param (org.sonar.api.server.ws.WebService.Param)1 ADMIN (org.sonar.api.web.UserRole.ADMIN)1 DbClient (org.sonar.db.DbClient)1 DbTester (org.sonar.db.DbTester)1 DbTester.create (org.sonar.db.DbTester.create)1 ComponentDbTester (org.sonar.db.component.ComponentDbTester)1