use of org.sonarqube.ws.client.WsClient in project sonarqube by SonarSource.
the class IssueNotificationsTest method prepare.
@Before
public void prepare() {
ORCHESTRATOR.resetData();
// Create test user
userRule.createUser(USER_LOGIN, "Tester", USER_EMAIL, USER_LOGIN);
smtpServer.getMessages().clear();
issueClient = ORCHESTRATOR.getServer().adminWsClient().issueClient();
issuesService = newAdminWsClient(ORCHESTRATOR).issues();
setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", null);
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, "Sample");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line-profile");
// Add notifications to the test user
WsClient wsClient = newUserWsClient(ORCHESTRATOR, USER_LOGIN, USER_PASSWORD);
wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewIssues").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "ChangesOnMyIssue").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "SQ-MyNewIssues").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
}
use of org.sonarqube.ws.client.WsClient in project sonarqube by SonarSource.
the class RootTest method root_can_be_set_and_unset_via_web_services.
@Test
public void root_can_be_set_and_unset_via_web_services() {
enableOrganizationSupport();
userRule.createUser("root1", "bar");
userRule.createUser("root2", "bar");
WsClient root1WsClient = newUserWsClient(orchestrator, "root1", "bar");
WsClient root2WsClient = newUserWsClient(orchestrator, "root2", "bar");
// non root can not set or unset root another user not itself
verifyHttpError(() -> root1WsClient.rootService().setRoot("root2"), 403);
verifyHttpError(() -> root1WsClient.rootService().setRoot("root1"), 403);
verifyHttpError(() -> root1WsClient.rootService().unsetRoot("root1"), 403);
verifyHttpError(() -> root2WsClient.rootService().unsetRoot("root1"), 403);
verifyHttpError(() -> root2WsClient.rootService().unsetRoot("root2"), 403);
// admin (the first root) sets root1 as root
newAdminWsClient(orchestrator).rootService().setRoot("root1");
// root1 can set root root2
root1WsClient.rootService().setRoot("root2");
// root2 can unset root root1
root2WsClient.rootService().unsetRoot("root1");
// root2 can unset root itself as it's not the last root
root2WsClient.rootService().unsetRoot("root2");
}
use of org.sonarqube.ws.client.WsClient in project sonarqube by SonarSource.
the class LocalAuthenticationTest method basic_authentication_based_on_token.
@Test
public void basic_authentication_based_on_token() {
String tokenName = "Validate token based authentication";
WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest().setLogin(LOGIN).setName(tokenName));
WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(ORCHESTRATOR.getServer().getUrl()).token(generateWsResponse.getToken()).build());
WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate"));
assertThat(response.content()).isEqualTo("{\"valid\":true}");
WsUserTokens.SearchWsResponse searchResponse = userTokensWsClient.search(new SearchWsRequest().setLogin(LOGIN));
assertThat(searchResponse.getUserTokensCount()).isEqualTo(1);
userTokensWsClient.revoke(new RevokeWsRequest().setLogin(LOGIN).setName(tokenName));
searchResponse = userTokensWsClient.search(new SearchWsRequest().setLogin(LOGIN));
assertThat(searchResponse.getUserTokensCount()).isEqualTo(0);
}
use of org.sonarqube.ws.client.WsClient in project sonarqube by SonarSource.
the class LocalAuthenticationTest method basic_authentication_based_on_login_and_password.
@Test
public void basic_authentication_based_on_login_and_password() {
String userId = UUID.randomUUID().toString();
String login = format("login-%s", userId);
String name = format("name-%s", userId);
String password = "!ascii-only:-)@";
userRule.createUser(login, name, null, password);
// authenticate
WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(ORCHESTRATOR.getServer().getUrl()).credentials(login, password).build());
WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate"));
assertThat(response.content()).isEqualTo("{\"valid\":true}");
}
Aggregations