Search in sources :

Example 6 with WsClient

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();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) Before(org.junit.Before)

Example 7 with WsClient

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");
}
Also used : ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newWsClient(util.ItUtils.newWsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) Test(org.junit.Test)

Example 8 with WsClient

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);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) SearchWsRequest(org.sonarqube.ws.client.usertoken.SearchWsRequest) RevokeWsRequest(org.sonarqube.ws.client.usertoken.RevokeWsRequest) WsResponse(org.sonarqube.ws.client.WsResponse) GenerateWsRequest(org.sonarqube.ws.client.usertoken.GenerateWsRequest) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) WsUserTokens(org.sonarqube.ws.WsUserTokens) Test(org.junit.Test)

Example 9 with WsClient

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}");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) Test(org.junit.Test)

Aggregations

WsClient (org.sonarqube.ws.client.WsClient)9 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)7 Test (org.junit.Test)5 GetRequest (org.sonarqube.ws.client.GetRequest)4 ItUtils.newWsClient (util.ItUtils.newWsClient)4 WsResponse (org.sonarqube.ws.client.WsResponse)3 ItUtils.newUserWsClient (util.ItUtils.newUserWsClient)3 PostRequest (org.sonarqube.ws.client.PostRequest)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 MimeMessage (javax.mail.internet.MimeMessage)1 Before (org.junit.Before)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 ShowWsResponse (org.sonarqube.ws.ServerId.ShowWsResponse)1 WsUserTokens (org.sonarqube.ws.WsUserTokens)1 AddUserWsRequest (org.sonarqube.ws.client.permission.AddUserWsRequest)1 SearchWsRequest (org.sonarqube.ws.client.projectlinks.SearchWsRequest)1 GenerateWsRequest (org.sonarqube.ws.client.usertoken.GenerateWsRequest)1 RevokeWsRequest (org.sonarqube.ws.client.usertoken.RevokeWsRequest)1 SearchWsRequest (org.sonarqube.ws.client.usertoken.SearchWsRequest)1 WiserMessage (org.subethamail.wiser.WiserMessage)1