Search in sources :

Example 26 with Issue

use of org.sonar.wsclient.issue.Issue in project sonarqube by SonarSource.

the class IssuePermissionTest method need_user_permission_on_project_to_see_issue_changelog.

/**
   * SONAR-4839
   */
@Test
public void need_user_permission_on_project_to_see_issue_changelog() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issue = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    client.issueClient().assign(issue.key(), "admin");
    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 issue changelog on the project
        try {
            changelog(issue.key(), withoutBrowsePermission, "password");
            fail();
        } catch (Exception e) {
            assertThat(e).isInstanceOf(org.sonarqube.ws.client.HttpException.class).describedAs("403");
        }
        // Without user permission, a user cannot see issues on the project
        assertThat(changelog(issue.key(), withBrowsePermission, "password").getChangelogList()).isNotEmpty();
    } finally {
        client.userClient().deactivate(withBrowsePermission);
        client.userClient().deactivate(withoutBrowsePermission);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) SonarClient(org.sonar.wsclient.SonarClient) HttpException(org.sonar.wsclient.base.HttpException) Test(org.junit.Test)

Example 27 with Issue

use of org.sonar.wsclient.issue.Issue in project sonarqube by SonarSource.

the class AutoAssignTest method update_author_and_assignee_when_scm_is_activated.

/**
   * SONAR-7098
   *
   * Given two versions of same project:
   * v1: issue, but no SCM data
   * v2: old issue and SCM data
   * Expected: all issues should be associated with authors
   */
@Test
public void update_author_and_assignee_when_scm_is_activated() {
    createUser(SIMON_USER, SIMON_USER);
    // Run a first analysis without SCM
    projectAnalysis.withProperties("sonar.scm.disabled", "true").run();
    List<Issue> issues = searchIssues();
    assertThat(issues).isNotEmpty();
    // No author and assignee are set
    for (Issue issue : issues) {
        assertThat(issue.author()).isEmpty();
    }
    assertThat(search(IssueQuery.create().assigned(true)).list()).isEmpty();
    // Run a second analysis with SCM
    projectAnalysis.run();
    issues = searchIssues();
    assertThat(issues).isNotEmpty();
    // Authors and assignees are set
    for (Issue issue : issues) {
        assertThat(issue.author()).isNotEmpty();
    }
    assertThat(search(IssueQuery.create().assignees(SIMON_USER)).list()).hasSize(3);
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)27 Issue (org.sonar.wsclient.issue.Issue)27 Issues (org.sonar.wsclient.issue.Issues)7 SonarClient (org.sonar.wsclient.SonarClient)5 IssueClient (org.sonar.wsclient.issue.IssueClient)4 BuildResult (com.sonar.orchestrator.build.BuildResult)3 SonarScanner (com.sonar.orchestrator.build.SonarScanner)3 HttpException (org.sonar.wsclient.base.HttpException)3 Changelog (org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog)3 MimeMessage (javax.mail.internet.MimeMessage)2 Issues (org.sonarqube.ws.Issues)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 MavenBuild (com.sonar.orchestrator.build.MavenBuild)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Component (org.sonar.wsclient.component.Component)1 UserParameters (org.sonar.wsclient.user.UserParameters)1