Search in sources :

Example 1 with SonarClient

use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.

the class IssuePermissionTest method need_administer_issue_permission_on_project_to_bulk_change_severity_and_false_positive.

/**
   * SONAR-2447
   */
@Test
public void need_administer_issue_permission_on_project_to_bulk_change_severity_and_false_positive() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issueOnSample = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    Issue issueOnSample2 = client.issueClient().find(IssueQuery.create().componentRoots("sample2")).list().get(0);
    String user = "user";
    try {
        client.userClient().create(UserParameters.create().login(user).name(user).password("password").passwordConfirmation("password"));
        addUserPermission(user, "sample", "issueadmin");
        Issues.BulkChangeWsResponse response = newUserWsClient(orchestrator, user, "password").issues().bulkChange(BulkChangeRequest.builder().setIssues(asList(issueOnSample.key(), issueOnSample2.key())).setSetSeverity("BLOCKER").setDoTransition("falsepositive").build());
        assertThat(response.getTotal()).isEqualTo(2);
        assertThat(response.getSuccess()).isEqualTo(1);
        assertThat(response.getIgnored()).isEqualTo(1);
    } finally {
        client.userClient().deactivate(user);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonarqube.ws.Issues) SonarClient(org.sonar.wsclient.SonarClient) Test(org.junit.Test)

Example 2 with SonarClient

use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.

the class IssuePermissionTest method need_administer_issue_permission_on_project_to_set_severity.

/**
   * SONAR-2447
   */
@Test
public void need_administer_issue_permission_on_project_to_set_severity() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issueOnSample = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    Issue issueOnSample2 = client.issueClient().find(IssueQuery.create().componentRoots("sample2")).list().get(0);
    String user = "user";
    try {
        client.userClient().create(UserParameters.create().login(user).name(user).password("password").passwordConfirmation("password"));
        addUserPermission(user, "sample", "issueadmin");
        // Without issue admin permission, a user cannot set severity on the issue
        try {
            orchestrator.getServer().wsClient(user, "password").issueClient().setSeverity(issueOnSample2.key(), "BLOCKER");
            fail();
        } catch (Exception e) {
            assertThat(e).isInstanceOf(HttpException.class).describedAs("404");
        }
        // With issue admin permission, a user can set severity on the issue
        assertThat(orchestrator.getServer().wsClient(user, "password").issueClient().setSeverity(issueOnSample.key(), "BLOCKER").severity()).isEqualTo("BLOCKER");
    } finally {
        client.userClient().deactivate(user);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) SonarClient(org.sonar.wsclient.SonarClient) HttpException(org.sonar.wsclient.base.HttpException) Test(org.junit.Test)

Example 3 with SonarClient

use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.

the class IssuePermissionTest method need_user_permission_on_project_to_see_issue.

@Test
public void need_user_permission_on_project_to_see_issue() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    String withBrowsePermission = "with-browse-permission";
    String withoutBrowsePermission = "without-browse-permission";
    try {
        client.userClient().create(UserParameters.create().login(withBrowsePermission).name(withBrowsePermission).password("password").passwordConfirmation("password"));
        addUserPermission(withBrowsePermission, "sample", "user");
        client.userClient().create(UserParameters.create().login(withoutBrowsePermission).name(withoutBrowsePermission).password("password").passwordConfirmation("password"));
        // By default, it's the group anyone that have the permission user, it would be better to remove all groups on this permission
        removeGroupPermission("anyone", "sample", "user");
        // Without user permission, a user cannot see issues on the project
        assertThat(orchestrator.getServer().wsClient(withoutBrowsePermission, "password").issueClient().find(IssueQuery.create().componentRoots("sample")).list()).isEmpty();
        // With user permission, a user can see issues on the project
        assertThat(orchestrator.getServer().wsClient(withBrowsePermission, "password").issueClient().find(IssueQuery.create().componentRoots("sample")).list()).isNotEmpty();
    } finally {
        client.userClient().deactivate(withBrowsePermission);
        client.userClient().deactivate(withoutBrowsePermission);
    }
}
Also used : SonarClient(org.sonar.wsclient.SonarClient) Test(org.junit.Test)

Example 4 with SonarClient

use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.

the class ProjectAdministrationTest method project_deletion.

/**
   * Test updated for SONAR-3570 and SONAR-5923
   */
@Test
public void project_deletion() {
    String projectAdminUser = "project-deletion-with-admin-permission-on-project";
    SonarClient wsClient = orchestrator.getServer().adminWsClient();
    try {
        SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample"));
        orchestrator.executeBuild(scan);
        // Create user having admin permission on previously analysed project
        wsClient.userClient().create(UserParameters.create().login(projectAdminUser).name(projectAdminUser).password("password").passwordConfirmation("password"));
        wsClient.post("api/permissions/add_user", "login", projectAdminUser, "projectKey", "sample", "permission", "admin");
        runSelenese(orchestrator, "/projectAdministration/ProjectAdministrationTest/project-deletion/project-deletion.html");
    } finally {
        wsClient.userClient().deactivate(projectAdminUser);
    }
}
Also used : SonarClient(org.sonar.wsclient.SonarClient) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 5 with SonarClient

use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.

the class IssuePermissionTest method need_administer_issue_permission_on_project_to_flag_as_false_positive.

/**
   * SONAR-2447
   */
@Test
public void need_administer_issue_permission_on_project_to_flag_as_false_positive() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issueOnSample = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    Issue issueOnSample2 = client.issueClient().find(IssueQuery.create().componentRoots("sample2")).list().get(0);
    String user = "user";
    try {
        client.userClient().create(UserParameters.create().login(user).name(user).password("password").passwordConfirmation("password"));
        addUserPermission(user, "sample", "issueadmin");
        // Without issue admin permission, a user cannot flag an issue as false positive
        try {
            orchestrator.getServer().wsClient(user, "password").issueClient().doTransition(issueOnSample2.key(), "falsepositive");
            fail();
        } catch (Exception e) {
            assertThat(e).isInstanceOf(HttpException.class).describedAs("404");
        }
        // With issue admin permission, a user can flag an issue as false positive
        assertThat(orchestrator.getServer().wsClient(user, "password").issueClient().doTransition(issueOnSample.key(), "falsepositive").status()).isEqualTo("RESOLVED");
    } finally {
        client.userClient().deactivate(user);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) SonarClient(org.sonar.wsclient.SonarClient) HttpException(org.sonar.wsclient.base.HttpException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 SonarClient (org.sonar.wsclient.SonarClient)7 Issue (org.sonar.wsclient.issue.Issue)5 HttpException (org.sonar.wsclient.base.HttpException)3 SonarScanner (com.sonar.orchestrator.build.SonarScanner)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Issues (org.sonar.wsclient.issue.Issues)1 UserParameters (org.sonar.wsclient.user.UserParameters)1 Issues (org.sonarqube.ws.Issues)1