Search in sources :

Example 56 with WsResponse

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

the class DefaultScannerWsClientTest method fail_if_credentials_are_not_valid.

@Test
public void fail_if_credentials_are_not_valid() {
    WsRequest request = newRequest();
    WsResponse response = newResponse().setCode(401);
    when(wsClient.wsConnector().call(request)).thenReturn(response);
    assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, /* credentials are configured */
    true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)).isInstanceOf(MessageException.class).hasMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) MessageException(org.sonar.api.utils.MessageException) WsResponse(org.sonarqube.ws.client.WsResponse) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 57 with WsResponse

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

the class DefaultScannerWsClientTest method fail_if_requires_credentials.

@Test
public void fail_if_requires_credentials() {
    WsRequest request = newRequest();
    WsResponse response = newResponse().setCode(401);
    when(wsClient.wsConnector().call(request)).thenReturn(response);
    assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)).isInstanceOf(MessageException.class).hasMessage("Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.login or other " + "credentials in sonar.login and sonar.password.");
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) MessageException(org.sonar.api.utils.MessageException) WsResponse(org.sonarqube.ws.client.WsResponse) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 58 with WsResponse

use of org.sonarqube.ws.client.WsResponse in project sonar-scanner-jenkins by SonarSource.

the class HttpClient method getHttp.

public String getHttp(String url, @Nullable String token) {
    String baseUrl = StringUtils.substringBeforeLast(url, "/");
    String path = StringUtils.substringAfterLast(url, "/");
    HttpConnector httpConnector = HttpConnector.newBuilder().userAgent("Scanner for Jenkins").url(baseUrl).credentials(token, null).build();
    WsResponse response = httpConnector.call(new GetRequest(path));
    response.failIfNotSuccessful();
    return response.content();
}
Also used : HttpConnector(org.sonarqube.ws.client.HttpConnector) GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Aggregations

WsResponse (org.sonarqube.ws.client.WsResponse)58 Test (org.junit.Test)34 GetRequest (org.sonarqube.ws.client.GetRequest)27 WsRequest (org.sonarqube.ws.client.WsRequest)20 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)15 MessageException (org.sonar.api.utils.MessageException)6 HttpException (org.sonarqube.ws.client.HttpException)6 PipedInputStream (java.io.PipedInputStream)5 PipedOutputStream (java.io.PipedOutputStream)5 PostRequest (org.sonarqube.ws.client.PostRequest)3 WsClient (org.sonarqube.ws.client.WsClient)3 File (java.io.File)2 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)2 Profiler (org.sonar.api.utils.log.Profiler)2 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CheckForNull (javax.annotation.CheckForNull)1