use of org.sonar.wsclient.SonarClient in project sonarqube by SonarSource.
the class IssuesModeTest method load_user_name_in_json_report.
// SONAR-6522
@Test
public void load_user_name_in_json_report() throws Exception {
restoreProfile("one-issue-per-line.xml");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
// First run (publish mode)
SonarScanner runner = configureRunner("shared/xoo-sample");
orchestrator.executeBuild(runner);
SonarClient client = orchestrator.getServer().adminWsClient();
Issues issues = client.issueClient().find(IssueQuery.create());
Issue issue = issues.list().get(0);
UserParameters creationParameters = UserParameters.create().login("julien").name("Julien H").password("password").passwordConfirmation("password");
client.userClient().create(creationParameters);
// Assign issue
client.issueClient().assign(issue.key(), "julien");
// Issues
runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.login", "julien", "sonar.password", "password");
BuildResult result = orchestrator.executeBuild(runner);
JSONObject obj = ItUtils.getJSONReport(result);
Map<String, String> userNameByLogin = Maps.newHashMap();
final JSONArray users = (JSONArray) obj.get("users");
if (users != null) {
for (Object user : users) {
String login = ObjectUtils.toString(((JSONObject) user).get("login"));
String name = ObjectUtils.toString(((JSONObject) user).get("name"));
userNameByLogin.put(login, name);
}
}
assertThat(userNameByLogin.get("julien")).isEqualTo("Julien H");
for (Object issueJson : (JSONArray) obj.get("issues")) {
JSONObject jsonObject = (JSONObject) issueJson;
if (issue.key().equals(jsonObject.get("key"))) {
assertThat(jsonObject.get("assignee")).isEqualTo("julien");
return;
}
}
fail("Issue not found");
}
use of org.sonar.wsclient.SonarClient 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);
}
}
Aggregations