]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7210 SONAR-7209 WS user_tokens/* add IT
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 19 Jan 2016 18:01:51 +0000 (19:01 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 19 Jan 2016 18:01:51 +0000 (19:01 +0100)
it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/usertoken/UserTokensService.java

index 59e7124c98f051c61de6841dcd2d7be792c88029..818f5cf37fdefbf033e6620699cb1fd6b59c8548 100644 (file)
@@ -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
index 0fdbc00a16d8b0ac181bd8d915dfa034921a79e1..a87734cda3f591a3516177dede35c2f07761f48e 100644 (file)
 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()));
+  }
+
 }