Search in sources :

Example 1 with OrganizationService

use of org.sonarqube.ws.client.organization.OrganizationService in project sonarqube by SonarSource.

the class OrganizationTest method create_fails_if_user_is_not_root.

@Test
public void create_fails_if_user_is_not_root() {
    userRule.createUser("foo", "bar");
    CreateWsRequest createWsRequest = new CreateWsRequest.Builder().setName("bla bla").build();
    OrganizationService fooUserOrganizationService = ItUtils.newUserWsClient(orchestrator, "foo", "bar").organizations();
    expect403HttpError(() -> fooUserOrganizationService.create(createWsRequest));
    userRule.setRoot("foo");
    assertThat(fooUserOrganizationService.create(createWsRequest).getOrganization().getKey()).isEqualTo("bla-bla");
    // delete org, attempt recreate when no root anymore and ensure it can't anymore
    fooUserOrganizationService.delete("bla-bla");
    userRule.unsetRoot("foo");
    expect403HttpError(() -> fooUserOrganizationService.create(createWsRequest));
}
Also used : OrganizationService(org.sonarqube.ws.client.organization.OrganizationService) CreateWsRequest(org.sonarqube.ws.client.organization.CreateWsRequest) Test(org.junit.Test)

Example 2 with OrganizationService

use of org.sonarqube.ws.client.organization.OrganizationService in project sonarqube by SonarSource.

the class OrganizationTest method verifyUserNotAuthorized.

private void verifyUserNotAuthorized(String login, String password, Consumer<OrganizationService> consumer) {
    try {
        OrganizationService organizationService = ItUtils.newUserWsClient(orchestrator, login, password).organizations();
        consumer.accept(organizationService);
        fail("An HttpException should have been raised");
    } catch (HttpException e) {
        assertThat(e.code()).isEqualTo(403);
    }
}
Also used : OrganizationService(org.sonarqube.ws.client.organization.OrganizationService) HttpException(org.sonarqube.ws.client.HttpException)

Aggregations

OrganizationService (org.sonarqube.ws.client.organization.OrganizationService)2 Test (org.junit.Test)1 HttpException (org.sonarqube.ws.client.HttpException)1 CreateWsRequest (org.sonarqube.ws.client.organization.CreateWsRequest)1