]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8716 fix check of permissions in api/users
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 2 Feb 2017 14:56:29 +0000 (15:56 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 7 Feb 2017 13:30:41 +0000 (14:30 +0100)
15 files changed:
server/sonar-server/src/main/java/org/sonar/server/setting/ws/CheckSecretKeyAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/EncryptAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/CheckSecretKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java

index 96d9c01574818e1e28cbbeaf0893899a55f9bfdc..acce7a1af46bc3b85cae95e2948b055a8e6fe1c1 100644 (file)
@@ -51,7 +51,7 @@ public class CheckSecretKeyAction implements SettingsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkIsRoot();
 
     writeProtobuf(CheckSecretKeyWsResponse.newBuilder().setSecretKeyAvailable(settings.getEncryption().hasSecretKey()).build(), request, response);
   }
index abc383eb48035058308773c7583c86b2343ec2f8..74044f94e5ae7a5c1df6107b15901caf5764a6de 100644 (file)
@@ -59,7 +59,7 @@ public class EncryptAction implements SettingsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkIsRoot();
 
     String value = request.mandatoryParam(PARAM_VALUE);
     checkRequest(!value.isEmpty(), "Parameter '%s' must not be empty", PARAM_VALUE);
index 5612f0aef5a761d82483c605bda18ea8a6774fe8..dea2b3d08308f72b98215993eb53fe53d69f71d4 100644 (file)
@@ -24,7 +24,6 @@ import java.util.List;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.user.ExternalIdentity;
 import org.sonar.server.user.NewUser;
@@ -107,7 +106,7 @@ public class CreateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkPermission(GlobalPermissions.SYSTEM_ADMIN);
+    userSession.checkLoggedIn().checkIsRoot();
     writeProtobuf(doHandle(toWsRequest(request)), request, response);
   }
 
index 6c840abca92065a6c1aaa2beb9be926f61dc44b2..e2016aeb960f8cb9fb837c9f7c7b3aae31d6a8b9 100644 (file)
@@ -80,7 +80,7 @@ public class DeactivateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkPermission(SYSTEM_ADMIN);
+    userSession.checkLoggedIn().checkIsRoot();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible");
index 5f486cb2edbad299611956e86d7ae582a6f34a1d..3e8c4de790c95daecc66fd5b188b982bd32bb664 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.server.ws.WebService.SelectionMode;
 import org.sonar.api.utils.Paging;
 import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.user.GroupMembershipDto;
@@ -59,7 +58,7 @@ public class GroupsAction implements UsersWsAction {
   @Override
   public void define(NewController context) {
     NewAction action = context.createAction("groups")
-      .setDescription("List the groups a user belongs to.")
+      .setDescription("Lists the groups a user belongs to. Requires Administer System permission.")
       .setHandler(this)
       .setResponseExample(getClass().getResource("example-groups.json"))
       .setSince("5.2");
@@ -78,7 +77,7 @@ public class GroupsAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkPermission(GlobalPermissions.SYSTEM_ADMIN);
+    userSession.checkLoggedIn().checkIsRoot();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
index 2d263cef3df6f6918311403b364aae7d4074a769..5b87558d3ad828216edc63af031aa6b0b655c623 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.user.UserDto;
@@ -97,7 +96,7 @@ public class UpdateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkPermission(GlobalPermissions.SYSTEM_ADMIN);
+    userSession.checkLoggedIn().checkIsRoot();
     UpdateRequest updateRequest = toWsRequest(request);
     try (DbSession dbSession = dbClient.openSession(false)) {
       doHandle(dbSession, toWsRequest(request));
index 00fb87a8705b8985e77a2d87967e9a59a1b69c85..6292e3463f3074d7143587189cf8840a4f6939c8 100644 (file)
@@ -58,7 +58,7 @@ public class ActivityStatusActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().login().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
@@ -143,7 +143,7 @@ public class ActivityStatusActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_root() {
-    userSession.login();
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -153,7 +153,7 @@ public class ActivityStatusActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_administrator_of_requested_project() {
-    userSession.login();
+    userSession.logIn();
     ComponentDto project = db.components().insertProject();
 
     expectedException.expect(ForbiddenException.class);
index e3e2d81d45b5fdffad371f56f5fb8d960e842d82..17dfe922b8498956b9ac83d4e43bf6ca8c2d87e1 100644 (file)
@@ -33,7 +33,6 @@ import org.sonar.api.config.MapSettings;
 import org.sonar.api.config.Settings;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -92,19 +91,9 @@ public class CheckSecretKeyActionTest {
     assertThat(definition.params()).hasSize(0);
   }
 
-  @Test
-  public void throw_UnauthorizedException_if_not_logged_in() {
-    userSession.anonymous();
-
-    expectedException.expect(UnauthorizedException.class);
-    expectedException.expectMessage("Authentication is required");
-
-    call();
-  }
-
   @Test
   public void throw_ForbiddenException_if_not_root() {
-    userSession.login();
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -125,6 +114,6 @@ public class CheckSecretKeyActionTest {
   }
 
   private void logInAsRoot() {
-    userSession.login().setRoot();
+    userSession.logIn().setRoot();
   }
 }
index 73623a21c828a7dd03bd87807183cdb41e571f5c..fa936c234be966aaf606420b3b5c5aaac61f6737 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.api.config.Settings;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -101,7 +100,7 @@ public class EncryptActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSession.login().setNonRoot();
+    userSession.logIn().setNonRoot();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -109,16 +108,6 @@ public class EncryptActionTest {
     call("my value");
   }
 
-  @Test
-  public void throw_UnauthorizedException_if_not_logged_in() throws Exception {
-    userSession.anonymous();
-
-    expectedException.expect(UnauthorizedException.class);
-    expectedException.expectMessage("Authentication is required");
-
-    call("my value");
-  }
-
   @Test
   public void fail_if_value_is_not_provided() {
     logInAsRoot();
@@ -167,6 +156,6 @@ public class EncryptActionTest {
   }
 
   private void logInAsRoot() {
-    userSession.login().setRoot();
+    userSession.logIn().setRoot();
   }
 }
index 27e8dce948aaca03894ffc2b03388252f11b0340..396e989efe6f51947246f1fd743dd4a0c4c7a310 100644 (file)
@@ -45,7 +45,7 @@ public class GenerateSecretKeyActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().login().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
@@ -80,7 +80,7 @@ public class GenerateSecretKeyActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_root() {
-    userSession.login();
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index 38bc520db37a5daf6abb17779231ab60a97cd691..a738ddba297f247f8eea3c10b1a5e180249849a8 100644 (file)
@@ -72,7 +72,7 @@ public class SetActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().login().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
@@ -135,7 +135,7 @@ public class SetActionTest {
   @Test
   public void persist_project_property_with_project_admin_permission() {
     ComponentDto project = db.components().insertProject();
-    userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
 
     callForProjectSettingByKey("my.key", "my value", project.key());
 
@@ -325,7 +325,7 @@ public class SetActionTest {
   }
 
   @Test
-  public void persist_multi_value_with_type_login() {
+  public void persist_multi_value_with_type_logIn() {
     definitions.addComponent(PropertyDefinition
       .builder("my.key")
       .name("foo")
@@ -423,7 +423,7 @@ public class SetActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_root() {
-    userSession.login();
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -472,7 +472,7 @@ public class SetActionTest {
   }
 
   @Test
-  public void fail_when_data_and_login_type_with_invalid_login() {
+  public void fail_when_data_and_login_type_with_invalid_logIn() {
     definitions.addComponent(PropertyDefinition
       .builder("my.key")
       .name("foo")
index 24484efde746f17a0fe0698f2857ecd9e0116e7a..3671da01d3ce27f68d755e408d23875eca8098a4 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.api.config.MapSettings;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.GroupDto;
@@ -88,7 +87,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     CreateWsResponse response = call(CreateRequest.builder()
       .setLogin("john")
@@ -118,7 +117,7 @@ public class CreateActionTest {
 
   @Test
   public void create_local_user() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     call(CreateRequest.builder()
       .setLogin("john")
@@ -134,7 +133,7 @@ public class CreateActionTest {
 
   @Test
   public void create_none_local_user() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     call(CreateRequest.builder()
       .setLogin("john")
@@ -149,7 +148,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_comma_in_scm_account() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     CreateWsResponse response = call(CreateRequest.builder()
       .setLogin("john")
@@ -164,7 +163,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_deprecated_scmAccounts_parameter() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     tester.newRequest()
       .setParam("login", "john")
@@ -178,7 +177,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_deprecated_scm_accounts_parameter() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     tester.newRequest()
       .setParam("login", "john")
@@ -192,7 +191,7 @@ public class CreateActionTest {
 
   @Test
   public void reactivate_user() throws Exception {
-    userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+    logInAsRoot();
 
     db.users().insertUser(newUserDto("john", "John", "john@email.com"));
     db.getDbClient().userDao().deactivateUserByLogin(db.getSession(), "john");
@@ -213,7 +212,7 @@ public class CreateActionTest {
   @Test
   public void create_user_with_root_flag_to_false_if_default_group_is_unset() throws Exception {
     unsetDefaultGroupProperty();
-    authenticateAsAdmin();
+    logInAsRoot();
 
     executeRequest("john");
 
@@ -224,7 +223,7 @@ public class CreateActionTest {
   public void create_user_with_root_flag_to_false_if_default_group_is_non_admin_on_default_organization() throws Exception {
     GroupDto adminGroup = db.users().insertGroup(db.getDefaultOrganization());
     setDefaultGroupProperty(adminGroup);
-    authenticateAsAdmin();
+    logInAsRoot();
 
     executeRequest("foo");
 
@@ -236,7 +235,7 @@ public class CreateActionTest {
     OrganizationDto otherOrganization = db.organizations().insert();
     GroupDto group = db.users().insertGroup(otherOrganization);
     setDefaultGroupProperty(group);
-    authenticateAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(ServerException.class);
     expectedException.expectMessage("The default group '" + group.getName() + "' for new users does not exist. " +
@@ -249,24 +248,16 @@ public class CreateActionTest {
   public void create_user_with_root_flag_to_true_if_default_group_is_admin_on_default_organization() throws Exception {
     GroupDto adminGroup = db.users().insertAdminGroup(db.getDefaultOrganization());
     setDefaultGroupProperty(adminGroup);
-    authenticateAsAdmin();
+    logInAsRoot();
 
     executeRequest("doh");
 
     db.rootFlag().verify("doh", true);
   }
 
-  private void unsetDefaultGroupProperty() {
-    settings.setProperty("sonar.defaultGroup", (String) null);
-  }
-
-  private void setDefaultGroupProperty(GroupDto adminGroup) {
-    settings.setProperty("sonar.defaultGroup", adminGroup.getName());
-  }
-
   @Test
   public void fail_when_missing_login() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Login is mandatory and must not be empty");
@@ -279,7 +270,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_missing_name() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name is mandatory and must not be empty");
@@ -292,7 +283,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_missing_password() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Password is mandatory and must not be empty");
@@ -305,7 +296,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_password_is_set_on_none_local_user() throws Exception {
-    authenticateAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Password should only be set on local user");
@@ -318,13 +309,24 @@ public class CreateActionTest {
   }
 
   @Test
-  public void fail_on_missing_permission() throws Exception {
-    userSessionRule.logIn("not_admin");
+  public void throw_ForbiddenException_if_not_root() throws Exception {
+    userSessionRule.logIn();
+
+    expectedException.expect(ForbiddenException.class);
+    expectedException.expectMessage("");
 
     expectedException.expect(ForbiddenException.class);
     executeRequest("john");
   }
 
+  private void unsetDefaultGroupProperty() {
+    settings.setProperty("sonar.defaultGroup", (String) null);
+  }
+
+  private void setDefaultGroupProperty(GroupDto adminGroup) {
+    settings.setProperty("sonar.defaultGroup", adminGroup.getName());
+  }
+
   private CreateWsResponse executeRequest(String login) throws Exception {
     return call(CreateRequest.builder()
       .setLogin(login)
@@ -335,8 +337,8 @@ public class CreateActionTest {
       .build());
   }
 
-  private void authenticateAsAdmin() {
-    userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+  private void logInAsRoot() {
+    userSessionRule.logIn().setRoot();
   }
 
   private CreateWsResponse call(CreateRequest createRequest) {
index fee8bc6c5dd10957b5ab609bffcf678ae4350986..30ec6176971d47f2cda5ea5bd3183409647d248e 100644 (file)
@@ -101,7 +101,7 @@ public class DeactivateActionTest {
       .setEmail("ada.lovelace@noteg.com")
       .setName("Ada Lovelace")
       .setScmAccounts(singletonList("al")));
-    loginAsAdmin();
+    logInAsRoot();
 
     String json = deactivate(user.getLogin()).getInput();
 
@@ -117,7 +117,7 @@ public class DeactivateActionTest {
   @Test
   public void cannot_deactivate_self() throws Exception {
     UserDto user = createUser();
-    userSession.logIn(user.getLogin()).setGlobalPermissions(SYSTEM_ADMIN);
+    userSession.logIn(user.getLogin()).setRoot();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Self-deactivation is not possible");
@@ -147,7 +147,7 @@ public class DeactivateActionTest {
 
   @Test
   public void fail_if_user_does_not_exist() throws Exception {
-    loginAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User 'someone' doesn't exist");
@@ -157,7 +157,7 @@ public class DeactivateActionTest {
 
   @Test
   public void fail_if_login_is_blank() throws Exception {
-    loginAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User '' doesn't exist");
@@ -169,7 +169,7 @@ public class DeactivateActionTest {
   public void fail_to_deactivate_last_administrator_of_default_organization() throws Exception {
     UserDto admin = createUser();
     db.users().insertPermissionOnUser(admin, SYSTEM_ADMIN);
-    loginAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("User is last administrator, and cannot be deactivated");
@@ -190,7 +190,7 @@ public class DeactivateActionTest {
     db.users().insertPermissionOnUser(org3, user1, SYSTEM_ADMIN);
     UserDto user2 = createUser();
     db.users().insertPermissionOnUser(org3, user2, SYSTEM_ADMIN);
-    loginAsAdmin();
+    logInAsRoot();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("User is last administrator of organizations [org1, org2], and cannot be deactivated");
@@ -205,7 +205,7 @@ public class DeactivateActionTest {
     db.users().insertPermissionOnUser(admin, SYSTEM_ADMIN);
     db.users().insertPermissionOnUser(anotherAdmin, SYSTEM_ADMIN);
     db.commit();
-    loginAsAdmin();
+    logInAsRoot();
 
     deactivate(admin.getLogin());
 
@@ -229,8 +229,8 @@ public class DeactivateActionTest {
     return user;
   }
 
-  private void loginAsAdmin() {
-    userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
+  private void logInAsRoot() {
+    userSession.logIn().setRoot();
   }
 
   private TestResponse deactivate(String login) {
index c6d4690c18e4e31d13e7cc0b800584022ad44673..03433d5b59c3e85793f2c4e7bda366060a1b8da7 100644 (file)
@@ -26,7 +26,6 @@ import org.junit.Test;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.server.ws.WebService.SelectionMode;
 import org.sonar.api.utils.System2;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -52,9 +51,9 @@ public class GroupsActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  WsTester tester;
-  DbClient dbClient;
-  DbSession session;
+  private WsTester tester;
+  private DbClient dbClient;
+  private DbSession session;
 
   @Before
   public void setUp() {
@@ -69,7 +68,7 @@ public class GroupsActionTest {
     session.commit();
 
     tester = new WsTester(new UsersWs(new GroupsAction(dbClient, userSession)));
-    userSession.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+    userSession.logIn().setRoot();
   }
 
   @After
index 9bae14c8744f3051594914648fba11ea736a010f..3fe763ac63e2e44d4bf204d1ecb7115308737fad 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Test;
 import org.sonar.api.config.MapSettings;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -59,8 +58,7 @@ public class UpdateActionTest {
   @Rule
   public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
   @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn("admin")
-    .setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+  public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn().setRoot();
 
   private DbClient dbClient = dbTester.getDbClient();
   private DbSession session = dbTester.getSession();