From: Teryk Bellahsene Date: Tue, 19 Jan 2016 18:01:51 +0000 (+0100) Subject: SONAR-7210 SONAR-7209 WS user_tokens/* add IT X-Git-Tag: 5.4-M9~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=062387460b8834fdb637f27ac58d56634bad83b2;p=sonarqube.git SONAR-7210 SONAR-7209 WS user_tokens/* add IT --- diff --git a/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java b/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java index 59e7124c98f..818f5cf37fd 100644 --- a/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java +++ b/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java @@ -41,6 +41,8 @@ import org.sonarqube.ws.client.permission.AddGroupWsRequest; import org.sonarqube.ws.client.permission.AddUserWsRequest; import org.sonarqube.ws.client.permission.RemoveGroupWsRequest; import org.sonarqube.ws.client.usertoken.GenerateWsRequest; +import org.sonarqube.ws.client.usertoken.RevokeWsRequest; +import org.sonarqube.ws.client.usertoken.SearchWsRequest; import org.sonarqube.ws.client.usertoken.UserTokensService; import static java.lang.String.format; @@ -97,9 +99,10 @@ public class AuthenticationTest { @Test public void basic_authentication_based_on_token() { + String tokenName = "Validate token based authentication"; WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest() .setLogin(LOGIN) - .setName("Validate token based authentication")); + .setName(tokenName)); WsClient wsClient = new HttpWsClient(new HttpConnector.Builder() .url(ORCHESTRATOR.getServer().getUrl()) .token(generateWsResponse.getToken()).build()); @@ -107,6 +110,12 @@ public class AuthenticationTest { 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); } /** @@ -136,9 +145,10 @@ public class AuthenticationTest { @Test public void run_analysis_with_token_authentication() { + String tokenName = "Analyze Project"; WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest() .setLogin(LOGIN) - .setName("Analyze Project")); + .setName(tokenName)); SonarRunner sampleProject = SonarRunner.create(projectDir("shared/xoo-sample")); sampleProject.setProperties( "sonar.login", generateWsResponse.getToken(), @@ -147,6 +157,7 @@ public class AuthenticationTest { BuildResult buildResult = ORCHESTRATOR.executeBuild(sampleProject); assertThat(buildResult.isSuccess()).isTrue(); + userTokensWsClient.revoke(new RevokeWsRequest().setLogin(LOGIN).setName(tokenName)); } @Test diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensService.java index 0fdbc00a16d..a87734cda3f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensService.java @@ -20,11 +20,15 @@ package org.sonarqube.ws.client.usertoken; import org.sonarqube.ws.WsUserTokens.GenerateWsResponse; +import org.sonarqube.ws.WsUserTokens.SearchWsResponse; import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsConnector; import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_GENERATE; +import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_REVOKE; +import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_SEARCH; import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.CONTROLLER; import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_LOGIN; import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_NAME; @@ -42,4 +46,18 @@ public class UserTokensService extends BaseService { .setParam(PARAM_NAME, request.getName()), GenerateWsResponse.parser()); } + + public SearchWsResponse search(SearchWsRequest request) { + return call( + new GetRequest(path(ACTION_SEARCH)).setParam(PARAM_LOGIN, request.getLogin()), + SearchWsResponse.parser()); + } + + public void revoke(RevokeWsRequest request) { + call( + new PostRequest(path(ACTION_REVOKE)) + .setParam(PARAM_LOGIN, request.getLogin()) + .setParam(PARAM_NAME, request.getName())); + } + }