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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations