Search in sources :

Example 36 with GetRequest

use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.

the class ForceAuthenticationTest method batch_ws_does_not_require_authentication.

@Test
public void batch_ws_does_not_require_authentication() throws Exception {
    WsResponse batchIndex = anonymousClient.wsConnector().call(new GetRequest("/batch/index")).failIfNotSuccessful();
    String batchIndexContent = batchIndex.content();
    assertThat(batchIndexContent).isNotEmpty();
    String jar = batchIndexContent.split("\\|")[0];
    assertThat(anonymousClient.wsConnector().call(new GetRequest("/batch/file").setParam("name", jar)).failIfNotSuccessful().contentStream()).isNotNull();
    // As sonar-runner is still using deprecated /batch/key, we have to also verify it
    assertThat(anonymousClient.wsConnector().call(new GetRequest("/batch/" + jar)).failIfNotSuccessful().contentStream()).isNotNull();
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 37 with GetRequest

use of org.sonarqube.ws.client.GetRequest 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 38 with GetRequest

use of org.sonarqube.ws.client.GetRequest 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)

Example 39 with GetRequest

use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.

the class OAuth2IdentityProviderTest method authenticateWithFakeAuthProvider.

private void authenticateWithFakeAuthProvider() {
    WsResponse response = adminWsClient.wsConnector().call(new GetRequest(("/sessions/init/" + FAKE_PROVIDER_KEY)));
    assertThat(response.code()).isEqualTo(200);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 40 with GetRequest

use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.

the class RoutesTest method redirect_profiles_export_to_api_qualityprofiles_export.

@Test
public void redirect_profiles_export_to_api_qualityprofiles_export() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("profiles/export?language=xoo&format=XooFakeExporter"));
    assertThat(response.isSuccessful()).isTrue();
    assertThat(response.requestUrl()).endsWith("/api/qualityprofiles/export?language=xoo&format=XooFakeExporter");
    assertThat(response.content()).isEqualTo("xoo -> Basic -> 1");
    // Check 'name' parameter is taken into account
    assertThat(newWsClient(orchestrator).wsConnector().call(new GetRequest("profiles/export?language=xoo&name=empty&format=XooFakeExporter")).content()).isEqualTo("xoo -> empty -> 0");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Aggregations

GetRequest (org.sonarqube.ws.client.GetRequest)59 Test (org.junit.Test)34 WsResponse (org.sonarqube.ws.client.WsResponse)27 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 Profiler (org.sonar.api.utils.log.Profiler)5 Reader (java.io.Reader)4 HttpException (org.sonarqube.ws.client.HttpException)4 WsClient (org.sonarqube.ws.client.WsClient)4 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)3 File (java.io.File)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 ShowWsResponse (org.sonarqube.ws.ServerId.ShowWsResponse)2 ItUtils.newWsClient (util.ItUtils.newWsClient)2 Gson (com.google.gson.Gson)1 LinkedList (java.util.LinkedList)1 CheckForNull (javax.annotation.CheckForNull)1 LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)1 Metric (org.sonar.api.measures.Metric)1