Search in sources :

Example 1 with SearchWsRequest

use of org.sonarqube.ws.client.usertoken.SearchWsRequest 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

Test (org.junit.Test)1 WsUserTokens (org.sonarqube.ws.WsUserTokens)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 WsClient (org.sonarqube.ws.client.WsClient)1 WsResponse (org.sonarqube.ws.client.WsResponse)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 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)1