Search in sources :

Example 1 with ComponentsService

use of org.sonarqube.ws.client.component.ComponentsService in project sonarqube by SonarSource.

the class OrganizationTest method by_default_anonymous_cannot_analyse_project_on_organization.

@Test
public void by_default_anonymous_cannot_analyse_project_on_organization() {
    verifyNoExtraOrganization();
    String orgKeyAndName = "org-key";
    Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder().setName(orgKeyAndName).setKey(orgKeyAndName).build()).getOrganization();
    verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null);
    try {
        ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.organization", orgKeyAndName);
        fail();
    } catch (BuildFailureException e) {
        assertThat(e.getResult().getLogs()).contains("Insufficient privileges");
    }
    ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components();
    assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsCount()).isEqualTo(0);
    adminOrganizationService.delete(orgKeyAndName);
}
Also used : ComponentsService(org.sonarqube.ws.client.component.ComponentsService) BuildFailureException(com.sonar.orchestrator.build.BuildFailureException) Organizations(org.sonarqube.ws.Organizations) CreateWsRequest(org.sonarqube.ws.client.organization.CreateWsRequest) Test(org.junit.Test)

Example 2 with ComponentsService

use of org.sonarqube.ws.client.component.ComponentsService in project sonarqube by SonarSource.

the class OrganizationTest method an_organization_member_can_analyze_project.

@Test
public void an_organization_member_can_analyze_project() {
    verifyNoExtraOrganization();
    String orgKeyAndName = "org-key";
    Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder().setName(orgKeyAndName).setKey(orgKeyAndName).build()).getOrganization();
    verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null);
    userRule.createUser("bob", "bob");
    userRule.removeGroups("sonar-users");
    addPermissionsToUser(orgKeyAndName, "bob", "provisioning", "scan");
    ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.organization", orgKeyAndName, "sonar.login", "bob", "sonar.password", "bob");
    ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components();
    assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsList()).hasSize(1);
    adminOrganizationService.delete(orgKeyAndName);
}
Also used : ComponentsService(org.sonarqube.ws.client.component.ComponentsService) Organizations(org.sonarqube.ws.Organizations) CreateWsRequest(org.sonarqube.ws.client.organization.CreateWsRequest) Test(org.junit.Test)

Example 3 with ComponentsService

use of org.sonarqube.ws.client.component.ComponentsService in project sonarqube by SonarSource.

the class OrganizationTest method deleting_an_organization_also_deletes_group_permissions_and_projects_and_check_security.

@Test
public void deleting_an_organization_also_deletes_group_permissions_and_projects_and_check_security() {
    verifyNoExtraOrganization();
    String orgKeyAndName = "org-key";
    Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder().setName(orgKeyAndName).setKey(orgKeyAndName).build()).getOrganization();
    verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null);
    GroupManagement groupManagement = userRule.forOrganization(orgKeyAndName);
    userRule.createUser("bob", "bob");
    groupManagement.createGroup("grp1");
    groupManagement.createGroup("grp2");
    groupManagement.associateGroupsToUser("bob", "grp1", "grp2");
    assertThat(groupManagement.getUserGroups("bob").getGroups()).extracting(Groups.Group::getName).contains("grp1", "grp2");
    addPermissionsToUser(orgKeyAndName, "bob", "provisioning", "scan");
    ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.organization", orgKeyAndName, "sonar.login", "bob", "sonar.password", "bob");
    ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components();
    assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsList()).hasSize(1);
    adminOrganizationService.delete(orgKeyAndName);
    expect404HttpError(() -> searchSampleProject(orgKeyAndName, componentsService));
    assertThat(groupManagement.getUserGroups("bob").getGroups()).extracting(Groups.Group::getName).doesNotContain("grp1", "grp2");
    verifyNoExtraOrganization();
}
Also used : ComponentsService(org.sonarqube.ws.client.component.ComponentsService) Groups(util.user.Groups) Organizations(org.sonarqube.ws.Organizations) GroupManagement(util.user.GroupManagement) CreateWsRequest(org.sonarqube.ws.client.organization.CreateWsRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Organizations (org.sonarqube.ws.Organizations)3 ComponentsService (org.sonarqube.ws.client.component.ComponentsService)3 CreateWsRequest (org.sonarqube.ws.client.organization.CreateWsRequest)3 BuildFailureException (com.sonar.orchestrator.build.BuildFailureException)1 GroupManagement (util.user.GroupManagement)1 Groups (util.user.Groups)1