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