Search in sources :

Example 21 with WsResponse

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

the class EventTest method old_ws_events_does_not_allow_creating_events_on_modules.

@Test
public void old_ws_events_does_not_allow_creating_events_on_modules() {
    SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-multi-modules-sample"));
    orchestrator.executeBuild(sampleProject);
    WsConnector wsConnector = ItUtils.newAdminWsClient(orchestrator).wsConnector();
    WsResponse response = wsConnector.call(newCreateEventRequest("com.sonarsource.it.samples:multi-modules-sample", "bar"));
    assertThat(response.code()).isEqualTo(200);
    assertThat(wsConnector.call(newCreateEventRequest("com.sonarsource.it.samples:multi-modules-sample:module_a", "bar")).code()).isEqualTo(400);
}
Also used : WsConnector(org.sonarqube.ws.client.WsConnector) WsResponse(org.sonarqube.ws.client.WsResponse) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 22 with WsResponse

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

the class UserRule method getUsers.

public Users getUsers() {
    WsResponse response = adminWsClient().wsConnector().call(new GetRequest("api/users/search"));
    assertThat(response.code()).isEqualTo(200);
    return Users.parse(response.content());
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 23 with WsResponse

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

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

the class ForceAuthenticationTest method verifyPathRequiresAuthentication.

private void verifyPathRequiresAuthentication(String path, WsRequest.Method method) {
    assertThat(call(anonymousClient, path, method).code()).isEqualTo(401);
    WsResponse wsResponse = call(adminWsClient, path, method);
    assertThat(wsResponse.isSuccessful()).as("code is %s on path %s", wsResponse.code(), path).isTrue();
}
Also used : WsResponse(org.sonarqube.ws.client.WsResponse)

Example 25 with WsResponse

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

Aggregations

WsResponse (org.sonarqube.ws.client.WsResponse)38 Test (org.junit.Test)23 GetRequest (org.sonarqube.ws.client.GetRequest)21 WsRequest (org.sonarqube.ws.client.WsRequest)9 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)5 WsClient (org.sonarqube.ws.client.WsClient)3 TempFolder (org.sonar.api.utils.TempFolder)2 HttpException (org.sonarqube.ws.client.HttpException)2 PostRequest (org.sonarqube.ws.client.PostRequest)2 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 CheckForNull (javax.annotation.CheckForNull)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 MessageException (org.sonar.api.utils.MessageException)1