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.");
}
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.");
}
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();
}
Aggregations