]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8761 remove misleading UserSession#checkIsRoot()
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 10 Feb 2017 14:22:56 +0000 (15:22 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 10 Feb 2017 22:07:21 +0000 (23:07 +0100)
116 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/user/CeUserSession.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityStatusAction.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/CancelAction.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/CancelAllAction.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java
server/sonar-server/src/main/java/org/sonar/server/email/ws/SendAction.java
server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java
server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/metric/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java
server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/LogsAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/AvailableAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/CancelAllAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PendingAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UninstallAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdateAction.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesAction.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/BulkDeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootAction.java
server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java
server/sonar-server/src/main/java/org/sonar/server/serverid/ws/GenerateAction.java
server/sonar-server/src/main/java/org/sonar/server/serverid/ws/ShowAction.java
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/setting/ws/GenerateSecretKeyAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/ResetAction.java
server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java
server/sonar-server/src/main/java/org/sonar/server/updatecenter/ws/UploadAction.java
server/sonar-server/src/main/java/org/sonar/server/user/AbstractUserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/ChangePasswordAction.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/ActivityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/CancelAllActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/email/ws/SendActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/LogsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/AvailableActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/CancelAllActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PendingActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginsWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/UninstallActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/UpdatesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/property/ws/IndexActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootActionTest.java
server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/serverid/ws/GenerateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/serverid/ws/ShowActionTest.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/ResetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java
server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/SettingsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/updatecenter/ws/UploadActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.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/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java

index bf1d6302fa1fc0eea1ed0f2f54ad72edfb432e2a..a73959432acfc4c080ab2906defee955c48dd3b4 100644 (file)
@@ -64,11 +64,6 @@ public class CeUserSession implements UserSession {
     throw notImplemented();
   }
 
-  @Override
-  public UserSession checkIsRoot() {
-    throw notImplemented();
-  }
-
   @Override
   public UserSession checkLoggedIn() {
     throw notImplemented();
index 91ec0f0045ced4ae5a29091fa927d115f14f44d9..ec0cea60a2d766bf0c442601ccf247c6cef26e9e 100644 (file)
@@ -185,7 +185,7 @@ public class ActivityAction implements CeWsAction {
     userSession.checkLoggedIn();
 
     if (request.getComponentId() == null) {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     } else {
       userSession.checkComponentUuidPermission(UserRole.ADMIN, request.getComponentId());
     }
index f1e6519646bc124638b25270b3f66d3c2bba1627..9348e275e491800a234dbb3bc7cfd1d7884155c3 100644 (file)
@@ -104,7 +104,7 @@ public class ActivityStatusAction implements CeWsAction {
     if (component.isPresent()) {
       userSession.checkComponentPermission(UserRole.ADMIN, component.get());
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     }
   }
 
index 4d0142a1c117b18fd9d31c95556e580f79e2ac12..1914df86da43722f767cbb1ef0eeec5c3c287715 100644 (file)
@@ -56,7 +56,7 @@ public class CancelAction implements CeWsAction {
 
   @Override
   public void handle(Request wsRequest, Response wsResponse) {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
     String taskId = wsRequest.mandatoryParam(PARAM_TASK_ID);
     queue.cancel(taskId);
     wsResponse.noContent();
index 6f3d5b133fe430241ded9b2d9684a6ce94307b2a..fc5f64a2947e7edb90852ca7cfd23d3c5c57ba38 100644 (file)
@@ -47,7 +47,7 @@ public class CancelAllAction implements CeWsAction {
 
   @Override
   public void handle(Request wsRequest, Response wsResponse) {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
     queue.cancelAll();
     wsResponse.noContent();
   }
index fe96ec35b4ddf7e38fa56578f1d4f931419bb0e7..b59b991a7faff27961d0cbf8fd484bf982fc8b53 100644 (file)
@@ -125,7 +125,7 @@ public class TaskAction implements CeWsAction {
       }
 
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     }
   }
 
index 28a16e541380dbeba1c8a6f32e860b932a488b1a..c8bbdf620a4d32c737f62a3f8edce83c055364ac 100644 (file)
@@ -71,7 +71,7 @@ public class SendAction implements EmailsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
     try {
       emailNotificationChannel.sendTestEmail(request.mandatoryParam(PARAM_TO), request.param(PARAM_SUBJECT), request.mandatoryParam(PARAM_MESSAGE));
     } catch (EmailException emailException) {
index 327871011536ae317fdb11c5036552aa879a840c..7d8a676279988f1196b30752a9b781be97362d74 100644 (file)
@@ -80,7 +80,7 @@ public class ListAction implements WsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     try (DbSession dbSession = dbClient.openSession(true)) {
       writeProtobuf(doHandle(dbSession), request, response);
index db54ce991d1ff3c6518739e6caba7d42f2ebaa23..c25a164b95e8de87a3c9f205fb61542af80a18fa 100644 (file)
@@ -93,7 +93,7 @@ public class CreateAction implements MetricsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
     String key = request.mandatoryParam(PARAM_KEY);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
index f2671a451519f456d224c29054c12b4df232fda9..01cd652cebd7cf4fd48edf11f6f68b1225e33a27 100644 (file)
@@ -62,7 +62,7 @@ public class DeleteAction implements MetricsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
 
     try (DbSession dbSession = dbClient.openSession(false)) {
       List<Integer> ids = loadIds(dbSession, request);
index fed64c185932aa51cf09cd568ad0950e5735a959..cbd0ff6342ed8beaf382ed18c923b8a6a9337e67 100644 (file)
@@ -95,7 +95,7 @@ public class UpdateAction implements MetricsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
     int id = request.mandatoryParamAsInt(PARAM_ID);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
index de22c988c72d486777ea73dbcef88cf911a898b0..ae7e2440dff7ae2c0d819167815131e17c312c60 100644 (file)
@@ -89,7 +89,7 @@ public class CreateAction implements OrganizationsAction {
     if (settings.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_ANYONE_CAN_CREATE)) {
       userSession.checkLoggedIn();
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     }
 
     String name = wsSupport.getAndCheckMandatoryName(request);
index 81713602ffd3b9384803a694fe9b1393c44d74d7..5fea4d459646f1726567d26466bb144bb5873926 100644 (file)
@@ -88,7 +88,7 @@ public class DeleteAction implements OrganizationsAction {
         key);
 
       if (organizationDto.isGuarded()) {
-        userSession.checkIsRoot();
+        userSession.checkIsSystemAdministrator();
       } else {
         userSession.checkOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
       }
index 71bd9b6727ecff587c05b5d57cd330b9206bc93d..05782735d64aeb119aaa2a43177cafb7e4c718ed 100644 (file)
@@ -128,7 +128,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
       ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, projectRef.get());
       PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectId(project)));
     } else {
-      userSession.checkLoggedIn().checkIsRoot();
+      userSession.checkLoggedIn().checkIsSystemAdministrator();
     }
   }
 
index 4689ebeba6520bfdbbe716d2355afdbcc61d425c..9bc42601479ccd6ea38d9bd270e14a3827a5b6ea 100644 (file)
@@ -66,7 +66,7 @@ public class ChangeLogLevelAction implements SystemWsAction {
 
   @Override
   public void handle(Request wsRequest, Response wsResponse) {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     LoggerLevel level = LoggerLevel.valueOf(wsRequest.mandatoryParam(PARAM_LEVEL));
     db.enableSqlLogging(level.equals(LoggerLevel.TRACE));
index 24847aa3b464037ac0961f220e85fc94b7952ed8..4b49b83825ced9a8bacf6c6d6e722fb680f8fb52 100644 (file)
@@ -59,7 +59,7 @@ public class InfoAction implements SystemWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     JsonWriter json = response.newJsonWriter();
     writeJson(json);
index db7868b663dd74e292a6ff6674ba01cb9438bf45..2be3a516bc497e900128c3a413138af6addf0eca 100644 (file)
@@ -66,7 +66,7 @@ public class LogsAction implements SystemWsAction {
 
   @Override
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     String processKey = wsRequest.mandatoryParam(PROCESS_PROPERTY);
     ProcessId processId = ProcessId.fromKey(processKey);
index 5bc08436aaa56d835236ed51b1b1549e927fa986..cb9e045d80daebd8eda06ea44b18e9ecee07c459 100644 (file)
@@ -72,7 +72,7 @@ public class RestartAction implements SystemWsAction {
         restartFlagHolder.unset();
       }
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
 
       LOGGER.info("SonarQube restart requested by {}", userSession.getLogin());
       restartFlagHolder.set();
index ac9ed510953f93949e0dd2d79acbef3c28b7f513..5352671ab7e67a2e27cea29f9abfa52a2ac40d87 100644 (file)
@@ -71,7 +71,7 @@ public class AvailableAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     JsonWriter jsonWriter = response.newJsonWriter();
     jsonWriter.beginObject();
index 52b9ebf990301535512076135a1b1a85a754bf70..db6c24d22c1fb15b4d2b12b534776887c3ea2bad 100644 (file)
@@ -51,7 +51,7 @@ public class CancelAllAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     pluginDownloader.cancelDownloads();
     pluginRepository.cancelUninstalls();
index dbcbeaed9976464e4e9311d7c3058b993759962d..fd81866e14865514b8cdee24e5af6024efeba153 100644 (file)
@@ -71,7 +71,7 @@ public class InstallAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     String key = request.mandatoryParam(PARAM_KEY);
     PluginUpdate pluginUpdate = findAvailablePluginByKey(key);
index 449cfe5109b17b31ae8c73083e001121ed9a2ffa..a8bd9fcd6fa9a311d2cdf5c43d944e6830116aec 100644 (file)
@@ -79,7 +79,7 @@ public class InstalledAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     Collection<PluginInfo> pluginInfoList = searchPluginInfoList();
 
index 301faf7ac6b631194e672d61468a43414cf84aa9..510b6ae3b707e0feca67649a014de9bb3f9e4ad1 100644 (file)
@@ -80,7 +80,7 @@ public class PendingAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     ImmutableMap<String, Plugin> compatiblePluginsByKey = compatiblePluginsByKey(updateCenterMatrixFactory);
 
index b43584223dd00d0ff99448c77e0c6c872d862fed..3d18adbc20abae8c5f0144352cbb5efd0312eec4 100644 (file)
@@ -58,7 +58,7 @@ public class UninstallAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     String key = request.mandatoryParam(PARAM_KEY);
     ensurePluginIsInstalled(key);
index a0b100958462dc342b77daf575b0b460080de315..5034b892c669bd889c5e579a2fc7ac8a4d59cc1a 100644 (file)
@@ -72,7 +72,7 @@ public class UpdateAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     String key = request.mandatoryParam(PARAM_KEY);
     PluginUpdate pluginUpdate = findPluginUpdateByKey(key);
index 19189049a2968140a6959dea02d432ed8d8538d4..76d5beee859c935f0420f4e346e295f5d39023a2 100644 (file)
@@ -84,7 +84,7 @@ public class UpdatesAction implements PluginsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     JsonWriter jsonWriter = response.newJsonWriter();
     jsonWriter.beginObject();
index 7fa7a8db5f3857eebeb9e81a990351c95ba8591c..dda804a317c02a7ae90ae04d49fa477ba4417576 100644 (file)
@@ -97,7 +97,7 @@ public class BulkDeleteAction implements ProjectsWsAction {
 
   private Optional<OrganizationDto> loadOrganizationByKey(DbSession dbSession, @Nullable String orgKey) {
     if (orgKey == null) {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
       return Optional.empty();
     }
     OrganizationDto org = support.getOrganization(dbSession, orgKey);
index 39b520387e37016a124da51893f3aa60b61fd77a..f260216f69c211f025e0d7b0400a95ad45d3cecd 100644 (file)
@@ -80,7 +80,7 @@ public class QualityGates {
   }
 
   public QualityGateDto rename(long idToRename, String name) {
-    checkRoot();
+    checkIsSystemAdministrator();
     QualityGateDto toRename = getNonNullQgate(idToRename);
     validateQualityGate(idToRename, name);
     toRename.setName(name);
@@ -89,7 +89,7 @@ public class QualityGates {
   }
 
   public QualityGateDto copy(long sourceId, String destinationName) {
-    checkRoot();
+    checkIsSystemAdministrator();
     getNonNullQgate(sourceId);
     validateQualityGate(null, destinationName);
     QualityGateDto destinationGate = new QualityGateDto().setName(destinationName);
@@ -114,7 +114,7 @@ public class QualityGates {
   }
 
   public void delete(long idToDelete) {
-    checkRoot();
+    checkIsSystemAdministrator();
     QualityGateDto qGate = getNonNullQgate(idToDelete);
     DbSession session = dbClient.openSession(false);
     try {
@@ -130,7 +130,7 @@ public class QualityGates {
   }
 
   public void setDefault(DbSession dbSession, @Nullable Long idToUseAsDefault) {
-    checkRoot();
+    checkIsSystemAdministrator();
     if (idToUseAsDefault == null) {
       propertiesDao.deleteGlobalProperty(SONAR_QUALITYGATE_PROPERTY, dbSession);
     } else {
@@ -172,7 +172,7 @@ public class QualityGates {
   }
 
   public void deleteCondition(Long condId) {
-    checkRoot();
+    checkIsSystemAdministrator();
     conditionDao.delete(getNonNullCondition(condId));
   }
 
@@ -243,8 +243,8 @@ public class QualityGates {
     errors.check(isModifyingCurrentQgate || existingQgate == null, Validation.IS_ALREADY_USED_MESSAGE, "Name");
   }
 
-  private void checkRoot() {
-    userSession.checkIsRoot();
+  private void checkIsSystemAdministrator() {
+    userSession.checkIsSystemAdministrator();
   }
 
   private void checkProjectAdmin(ComponentDto project) {
index 01d328ac93622de54079698368c2ebe631e94259..2ba5c9f9f3b4e463f531fbb1879839abfc2b2a80 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.db.user.UserDto;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.WsRoot;
 
+import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class SearchAction implements RootsWsAction {
@@ -54,7 +55,7 @@ public class SearchAction implements RootsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    checkIsRoot();
 
     try (DbSession dbSession = dbClient.openSession(false)) {
       List<UserDto> userDtos = dbClient.userDao().selectUsers(
@@ -85,4 +86,12 @@ public class SearchAction implements RootsWsAction {
     }
     return builder.build();
   }
+
+  private void checkIsRoot() {
+    if (!userSession.isRoot()) {
+      throw insufficientPrivilegesException();
+    }
+  }
+
+
 }
index 5458a079b2d5af3258fd1a1b10044696ec94fb88..fb11d512797646dd5934a31cb0aa3dce5fb17ae5 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.user.UserSession;
 
 import static java.lang.String.format;
+import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
 
 public class SetRootAction implements RootsWsAction {
   private static final String PARAM_LOGIN = "login";
@@ -60,7 +61,7 @@ public class SetRootAction implements RootsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    checkIsRoot();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     try (DbSession dbSession = dbClient.openSession(false)) {
@@ -76,4 +77,10 @@ public class SetRootAction implements RootsWsAction {
     }
     response.noContent();
   }
+
+  private void checkIsRoot() {
+    if (!userSession.isRoot()) {
+      throw insufficientPrivilegesException();
+    }
+  }
 }
index d21015d4f972d7aa334bd4359b65139bcd9e0bd0..050795c0095a1810832a85c5897236cbec809a22 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.user.UserSession;
 
 import static java.lang.String.format;
+import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
 
 public class UnsetRootAction implements RootsWsAction {
   private static final String PARAM_LOGIN = "login";
@@ -61,7 +62,7 @@ public class UnsetRootAction implements RootsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    checkIsRoot();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     try (DbSession dbSession = dbClient.openSession(false)) {
@@ -80,4 +81,10 @@ public class UnsetRootAction implements RootsWsAction {
     }
     response.noContent();
   }
+
+  private void checkIsRoot() {
+    if (!userSession.isRoot()) {
+      throw insufficientPrivilegesException();
+    }
+  }
 }
index b340881f15159fcee2556c6bfc7bb37f21767a54..c5bbb4d46190d48332c16b861abb6c7b01a42c87 100644 (file)
@@ -77,7 +77,7 @@ public class GenerateAction implements ServerIdWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     try (DbSession dbSession = dbClient.openSession(true)) {
       writeProtobuf(doHandle(dbSession, toGenerateRequest(request)), request, response);
index b3e00c73c3fce2c189465a3863c910d81ec91ad5..97297d7ff7d890efe665e16c29f70e64e5931ad3 100644 (file)
@@ -71,7 +71,7 @@ public class ShowAction implements ServerIdWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
     try (DbSession dbSession = dbClient.openSession(true)) {
       Map<String, PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, SETTINGS_KEYS).stream()
         .collect(Collectors.uniqueIndex(PropertyDto::getKey, Function.identity()));
index 8f460f4fd69dfc293fd4f14a29ef3a30e7612b3f..0230d49aca408745237362944755f77169428717 100644 (file)
@@ -50,7 +50,7 @@ public class CheckSecretKeyAction implements SettingsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     writeProtobuf(CheckSecretKeyWsResponse.newBuilder().setSecretKeyAvailable(settings.getEncryption().hasSecretKey()).build(), request, response);
   }
index c30dfda35af8c5545eb05d312a24068543c76d5f..30fd8acde768449da1840ce66c6b4231d7166d33 100644 (file)
@@ -58,7 +58,7 @@ public class EncryptAction implements SettingsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     String value = request.mandatoryParam(PARAM_VALUE);
     checkRequest(!value.isEmpty(), "Parameter '%s' must not be empty", PARAM_VALUE);
index 681d616547c8ba0eb62fbb357840f8d8192e7e17..af982fc279dae11852ecffa253d03e8d8109126d 100644 (file)
@@ -50,7 +50,7 @@ public class GenerateSecretKeyAction implements SettingsWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     writeProtobuf(GenerateSecretKeyWsResponse.newBuilder().setSecretKey(settings.getEncryption().generateRandomSecretKey()).build(), request, response);
   }
index 22b9cc86c130cce19f2a1aa6c8a37a13fa6d6e88..ca71f596b753057c40e3062772c9acbaff5c5e32 100644 (file)
@@ -137,7 +137,7 @@ public class ResetAction implements SettingsWsAction {
     if (component.isPresent()) {
       userSession.checkComponentPermission(UserRole.ADMIN, component.get());
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     }
   }
 }
index 9b0c4199a5ee33549b8cc250905f8718209f38da..bdcfee1f6a3093d557925a7072e68eb8bb23aaa4 100644 (file)
@@ -267,7 +267,7 @@ public class SetAction implements SettingsWsAction {
     if (component.isPresent()) {
       userSession.checkComponentPermission(UserRole.ADMIN, component.get());
     } else {
-      userSession.checkIsRoot();
+      userSession.checkIsSystemAdministrator();
     }
   }
 
index 2b7985b4b680ca204b82ea4d58dbac52fef362b2..da80cc3783a6696618a88dfc7c1a47012125485d 100644 (file)
@@ -61,7 +61,7 @@ public class UploadAction implements UpdateCenterWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
+    userSession.checkIsSystemAdministrator();
 
     Part part = request.mandatoryParamAsPart(PARAM_FILE);
     String fileName = part.getFileName();
index a402261ec26ba6a20b9d6b99c0fb1fc724ce2c55..6b445cdfec45ad9544ea5d840f2bdc4f4cd7e7cf 100644 (file)
@@ -37,14 +37,6 @@ public abstract class AbstractUserSession implements UserSession {
     return this;
   }
 
-  @Override
-  public final UserSession checkIsRoot() {
-    if (!isRoot()) {
-      throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE);
-    }
-    return this;
-  }
-
   @Override
   public final boolean hasOrganizationPermission(String organizationUuid, String permission) {
     return isRoot() || hasOrganizationPermissionImpl(organizationUuid, permission);
index 05dfd16c2acb0675aa4848b1fbb8d37a7a1a85c7..66de0e4c960834bbd164b42484961fb6a07f7ce8 100644 (file)
@@ -85,12 +85,6 @@ public class ThreadLocalUserSession implements UserSession {
     return get().isRoot();
   }
 
-  @Override
-  public UserSession checkIsRoot() {
-    get().checkIsRoot();
-    return this;
-  }
-
   @Override
   public UserSession checkLoggedIn() {
     get().checkLoggedIn();
index ff44ba1a54eb41523641159f0224c0e2cf2d5749..243821ed0fe485ff1f727a06d0cb760d8631f314 100644 (file)
@@ -59,16 +59,11 @@ public interface UserSession {
   boolean isLoggedIn();
 
   /**
-   * Whether the user has root privileges when organizations are enabled.
-   * Always returns {@code false} when organizations are disabled.
+   * Whether the user has root privileges. If {@code true}, then user automatically
+   * benefits from all the permissions on all organizations and projects.
    */
   boolean isRoot();
 
-  /**
-   * Ensures that user is root otherwise throws {@link org.sonar.server.exceptions.ForbiddenException}.
-   */
-  UserSession checkIsRoot();
-
   /**
    * Ensures that user is logged in otherwise throws {@link org.sonar.server.exceptions.UnauthorizedException}.
    */
@@ -130,7 +125,7 @@ public interface UserSession {
   UserSession checkComponentUuidPermission(String permission, String componentUuid);
 
   /**
-   * Whether user can administrate system, for example to use cross-organizations services
+   * Whether user can administrate system, for example for using cross-organizations services
    * like update center, system info or management of users.
    *
    * Returns {@code true} if:
index 8f1a1de89ab3bb7a31d7315384c5174144bada3c..bd9733878923547f5cd87da05039d768af1e2c42 100644 (file)
@@ -84,7 +84,7 @@ public class ChangePasswordAction implements UsersWsAction {
         String previousPassword = request.mandatoryParam(PARAM_PREVIOUS_PASSWORD);
         checkCurrentPassword(dbSession, login, previousPassword);
       } else {
-        userSession.checkIsRoot();
+        userSession.checkIsSystemAdministrator();
       }
 
       String password = request.mandatoryParam(PARAM_PASSWORD);
index e96d7183155cff7ce2517d64c141950cd83e6fa5..501f0123843c243504dae9a3f98da55e30a2ed16 100644 (file)
@@ -106,7 +106,7 @@ public class CreateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
     writeProtobuf(doHandle(toWsRequest(request)), request, response);
   }
 
index d5620b77d2a192314cb55287fca7c96fb9d8762b..1dfbb350a72b947f3ceea1ef5947b297daa8c34e 100644 (file)
@@ -80,7 +80,7 @@ public class DeactivateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible");
index 9ef37af004ecbae7af0147276e6b0015767ce9f6..9bfd6f41d24259ba3d6a2a9530b9ceaa6a3a9379 100644 (file)
@@ -77,7 +77,7 @@ public class GroupsAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
 
     String login = request.mandatoryParam(PARAM_LOGIN);
     int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
index db413969bfa55a05e520ee558d2fb5b474698c96..fbf136efe4760077e1bb3388ec9ec9ed46ae64ec 100644 (file)
@@ -96,7 +96,7 @@ public class UpdateAction implements UsersWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn().checkIsRoot();
+    userSession.checkLoggedIn().checkIsSystemAdministrator();
     UpdateRequest updateRequest = toWsRequest(request);
     try (DbSession dbSession = dbClient.openSession(false)) {
       doHandle(dbSession, toWsRequest(request));
index e8780aade13b75dc6f8a85a248af222ca55a1432..16b592cbd332d71909042f67a73141a491e36b66 100644 (file)
@@ -81,7 +81,7 @@ public class ActivityActionTest {
 
   @Test
   public void get_all_past_activity() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     OrganizationDto org1 = dbTester.organizations().insert();
     dbTester.components().insertProject(org1, "PROJECT_1");
     OrganizationDto org2 = dbTester.organizations().insert();
@@ -112,7 +112,7 @@ public class ActivityActionTest {
 
   @Test
   public void filter_by_status() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
     dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_2");
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
@@ -129,7 +129,7 @@ public class ActivityActionTest {
 
   @Test
   public void filter_by_max_executed_at_exclude() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
     insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
@@ -143,7 +143,7 @@ public class ActivityActionTest {
 
   @Test
   public void filter_by_min_submitted_and_max_executed_at_include_day() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     OrganizationDto organizationDto = dbTester.organizations().insert();
     dbTester.components().insertProject(organizationDto, "PROJECT_1");
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
@@ -159,7 +159,7 @@ public class ActivityActionTest {
   @Test
   public void filter_on_current_activities() {
     dbTester.components().insertProject(dbTester.organizations().insert(), "PROJECT_1");
-    logInAsRoot();
+    logInAsSystemAdministrator();
     // T2 is the current activity (the most recent one)
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "PROJECT_1", CeActivityDto.Status.FAILED);
@@ -175,7 +175,7 @@ public class ActivityActionTest {
 
   @Test
   public void limit_results() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     OrganizationDto organizationDto = dbTester.organizations().insert();
     dbTester.components().insertProject(organizationDto, "PROJECT_1");
     dbTester.components().insertProject(organizationDto, "PROJECT_2");
@@ -237,7 +237,7 @@ public class ActivityActionTest {
     dbTester.components().insertProjectAndSnapshot(struts);
     dbTester.components().insertProjectAndSnapshot(zookeeper);
     dbTester.components().insertProjectAndSnapshot(eclipse);
-    logInAsRoot();
+    logInAsSystemAdministrator();
     insertActivity("T1", "P1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "P2", CeActivityDto.Status.SUCCESS);
     insertActivity("T3", "P3", CeActivityDto.Status.SUCCESS);
@@ -254,7 +254,7 @@ public class ActivityActionTest {
     ComponentDto developer = newDeveloper(organizationDto, "Apache Developer").setUuid("D1").setProjectUuid("D1");
     dbTester.components().insertDeveloperAndSnapshot(developer);
     dbTester.components().insertViewAndSnapshot(apacheView);
-    logInAsRoot();
+    logInAsSystemAdministrator();
     insertActivity("T1", "D1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "V1", CeActivityDto.Status.SUCCESS);
 
@@ -265,7 +265,7 @@ public class ActivityActionTest {
 
   @Test
   public void search_task_id_in_queue_ignoring_other_parameters() throws IOException {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
     insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
 
@@ -280,7 +280,7 @@ public class ActivityActionTest {
 
   @Test
   public void search_task_id_in_activity() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
 
@@ -307,10 +307,10 @@ public class ActivityActionTest {
 
   @Test
   public void search_task_by_component_id() {
-    dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
+    ComponentDto project = dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
     insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
-    logInAsRoot();
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
 
     ActivityResponse result = call(ws.newRequest()
       .setParam(PARAM_COMPONENT_ID, "PROJECT_1")
@@ -344,7 +344,7 @@ public class ActivityActionTest {
 
   @Test
   public void fail_if_date_is_not_well_formatted() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Date 'ill-formatted-date' cannot be parsed as either a date or date+time");
@@ -356,7 +356,7 @@ public class ActivityActionTest {
 
   @Test
   public void support_json_response() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     TestResponse wsResponse = ws.newRequest()
       .setMediaType(MediaTypes.JSON)
       .execute();
@@ -364,8 +364,8 @@ public class ActivityActionTest {
     JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}");
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
index 6779524b7cd874fb29a20c658a821e8c05b397f6..9a8fbb0f50b9a9792b72340d57d4cb9e1295a2f2 100644 (file)
@@ -56,7 +56,7 @@ public class ActivityStatusActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
index 47bc835e71b6bcf87be4bfb55227de97bb03bd6a..34a6430c0ed1423b2934ef1781708a2395c1b08c 100644 (file)
@@ -44,7 +44,7 @@ public class CancelActionTest {
 
   @Test
   public void cancel_pending_task() {
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     tester.newRequest()
       .setParam("id", "T1")
@@ -55,7 +55,7 @@ public class CancelActionTest {
 
   @Test
   public void throw_IllegalArgumentException_if_missing_id() {
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'id' parameter is missing");
@@ -66,8 +66,8 @@ public class CancelActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -78,4 +78,8 @@ public class CancelActionTest {
 
     verifyZeroInteractions(queue);
   }
+
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
+  }
 }
index 9c766657e26f41b59347ee52637185e5db3b037b..452b14bef47740d3606d3e6368407aa38671a498 100644 (file)
@@ -45,7 +45,7 @@ public class CancelAllActionTest {
 
   @Test
   public void cancel_all_pending_tasks() {
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
 
     call();
 
@@ -53,8 +53,8 @@ public class CancelAllActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index c5d9a87fd7721e743f7ad4466b506d5cd5e235da..44d02902e1e8c952bf228cf257e27773abf7dc14 100644 (file)
@@ -266,16 +266,16 @@ public class TaskActionTest {
   }
 
   @Test
-  public void getting_global_queue_task_requires_root_permission() {
-    userSession.logIn().setRoot();
+  public void getting_global_queue_task_requires_to_be_system_administrator() {
+    logInAsSystemAdministrator();
     CeQueueDto task = createAndPersistQueueTask(null);
 
     call(task.getUuid());
   }
 
   @Test
-  public void getting_global_queue_throws_ForbiddenException_if_not_root() {
-    userSession.logIn().setNonRoot();
+  public void getting_global_queue_throws_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
     CeQueueDto task = createAndPersistQueueTask(null);
 
     expectedException.expect(ForbiddenException.class);
@@ -310,16 +310,16 @@ public class TaskActionTest {
   }
 
   @Test
-  public void getting_global_archived_task_requires_root_permission() {
-    userSession.logIn().setRoot();
+  public void getting_global_archived_task_requires_to_be_system_administrator() {
+    logInAsSystemAdministrator();
     CeActivityDto task = createAndPersistArchivedTask(null);
 
     call(task.getUuid());
   }
 
   @Test
-  public void getting_global_archived_throws_ForbiddenException_if_not_root() {
-    userSession.logIn().setNonRoot();
+  public void getting_global_archived_throws_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
     CeActivityDto task = createAndPersistArchivedTask(null);
 
     expectedException.expect(ForbiddenException.class);
@@ -383,6 +383,10 @@ public class TaskActionTest {
     dbTester.commit();
   }
 
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
+  }
+
   private void logInAsRoot() {
     userSession.logIn().setRoot();
   }
index e1cbdf421f9fd0b1f2fcac3612235fd8590ada93..204698c958b15ed2d78f21dc0d0e93ab3eacf673 100644 (file)
@@ -67,7 +67,7 @@ public class ComponentServiceUpdateKeyTest {
 
     dbSession.commit();
 
-    userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
     underTest.updateKey(dbSession, project, "sample2:root");
     dbSession.commit();
 
@@ -92,7 +92,7 @@ public class ComponentServiceUpdateKeyTest {
     ComponentDto file = ComponentTesting.newFileDto(module, null).setKey("sample:root:module:src/File.xoo");
     dbClient.componentDao().insert(dbSession, file);
     dbSession.commit();
-    userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
 
     underTest.updateKey(dbSession, module, "sample:root2:module");
     dbSession.commit();
@@ -110,7 +110,7 @@ public class ComponentServiceUpdateKeyTest {
 
     dbSession.commit();
 
-    userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid());
+    logInAsProjectAdministrator(provisionedProject);
     underTest.updateKey(dbSession, provisionedProject, "provisionedProject2");
     dbSession.commit();
 
@@ -130,9 +130,9 @@ public class ComponentServiceUpdateKeyTest {
 
   @Test
   public void fail_if_old_key_and_new_key_are_the_same() {
-    logInAsRoot();
     ComponentDto project = insertSampleRootProject();
     ComponentDto anotherProject = componentDb.insertProject();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Impossible to update key: a component with key \"" + anotherProject.key() + "\" already exists.");
@@ -142,8 +142,8 @@ public class ComponentServiceUpdateKeyTest {
 
   @Test
   public void fail_if_new_key_is_empty() {
-    logInAsRoot();
     ComponentDto project = insertSampleRootProject();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Malformed key for ''. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
@@ -153,8 +153,8 @@ public class ComponentServiceUpdateKeyTest {
 
   @Test
   public void fail_if_new_key_is_not_formatted_correctly() {
-    logInAsRoot();
     ComponentDto project = insertSampleRootProject();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Malformed key for 'sample?root'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
@@ -164,9 +164,9 @@ public class ComponentServiceUpdateKeyTest {
 
   @Test
   public void fail_if_update_is_not_on_module_or_project() {
-    logInAsRoot();
     ComponentDto project = insertSampleRootProject();
     ComponentDto file = componentDb.insertComponent(newFileDto(project, null));
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Component updated must be a module or a key");
@@ -200,10 +200,6 @@ public class ComponentServiceUpdateKeyTest {
     assertThat(dbClient.componentDao().selectByKey(dbSession, key)).isPresent();
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
-  }
-
   private ComponentDto insertSampleRootProject() {
     return insertProject("sample:root");
   }
@@ -217,4 +213,8 @@ public class ComponentServiceUpdateKeyTest {
     assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
     assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
   }
+
+  private void logInAsProjectAdministrator(ComponentDto provisionedProject) {
+    userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid());
+  }
 }
index 9688a370a341dd090001e714e55b1fb344bd52cd..77cf5d27c0091f6998bc74f6c86c1506ef4060b8 100644 (file)
@@ -239,13 +239,12 @@ public class BulkUpdateKeyActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root_administrator() {
-    userSession.anonymous();
+  public void throw_ForbiddenException_if_not_project_administrator() {
+    userSession.logIn();
     ComponentDto project = insertMyProject();
 
     expectedException.expect(ForbiddenException.class);
 
-
     callDryRunByUuid(project.uuid(), FROM, TO);
   }
 
index be9f955b9eea4fcf4b20581b3c2c0c7a5cfe26b9..a9e559e485eb668ebd7cd2786ae7b5f0ef6acc75 100644 (file)
@@ -54,7 +54,7 @@ public class ShowActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
@@ -64,6 +64,7 @@ public class ShowActionTest {
 
   @Test
   public void json_example() throws IOException {
+    userSession.logIn().setRoot();
     insertJsonExampleComponentsAndSnapshots();
 
     String response = ws.newRequest()
@@ -86,6 +87,7 @@ public class ShowActionTest {
 
   @Test
   public void show_provided_project() {
+    userSession.logIn().setRoot();
     componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setEnabled(false));
 
     ShowWsResponse response = newRequest("project-uuid", null);
@@ -94,8 +96,8 @@ public class ShowActionTest {
   }
 
   @Test
-  public void fail_if_not_enough_privilege() {
-    userSession.anonymous();
+  public void throw_ForbiddenException_if_user_doesnt_have_browse_permission_on_project() {
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid"));
index d3b2e1b724d748b651b226208ad2de81ad80a57d..5354124ede27ae45c3397d5e524289eca37bfd13 100644 (file)
@@ -88,7 +88,6 @@ public class TreeActionTest {
 
   @Before
   public void setUp() {
-    userSession.logIn().setRoot();
     ws = new WsActionTester(new TreeAction(dbClient, new ComponentFinder(dbClient), resourceTypes, userSession, Mockito.mock(I18n.class)));
     resourceTypes.setChildrenQualifiers(Qualifiers.MODULE, Qualifiers.FILE, Qualifiers.DIRECTORY);
     resourceTypes.setLeavesQualifiers(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
@@ -97,7 +96,7 @@ public class TreeActionTest {
   @Test
   public void json_example() throws IOException {
     ComponentDto project = initJsonExampleComponents();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    logInWithBrowsePermission(project);
 
     String response = ws.newRequest()
       .setParam(PARAM_BASE_COMPONENT_ID, project.uuid())
@@ -122,6 +121,7 @@ public class TreeActionTest {
     componentDb.insertComponent(directory);
     componentDb.insertComponent(newFileDto(module, directory, 10));
     db.commit();
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "children")
@@ -151,6 +151,7 @@ public class TreeActionTest {
     componentDb.insertComponent(directory);
     componentDb.insertComponent(newFileDto(module, directory, 1));
     db.commit();
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
@@ -174,6 +175,7 @@ public class TreeActionTest {
     componentDb.insertComponent(newFileDto(project, 2));
     componentDb.insertComponent(newModuleDto("module-uuid-1", project));
     db.commit();
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
@@ -195,6 +197,7 @@ public class TreeActionTest {
     componentDb.insertComponent(directory);
     componentDb.insertComponent(newFileDto(module, directory, 3));
     db.commit();
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "leaves")
@@ -216,6 +219,7 @@ public class TreeActionTest {
     componentDb.insertComponent(module);
     componentDb.insertComponent(newDirectory(project, "path/directory/", "directory-uuid-1"));
     db.commit();
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
@@ -235,6 +239,7 @@ public class TreeActionTest {
     componentDb.insertComponent(newProjectCopy("project-uuid-1-copy", project, view));
     componentDb.insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
     db.commit();
+    logInWithBrowsePermission(view);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_STRATEGY, "children")
@@ -248,7 +253,8 @@ public class TreeActionTest {
 
   @Test
   public void response_is_empty_on_provisioned_projects() {
-    componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    logInWithBrowsePermission(project);
 
     TreeWsResponse response = call(ws.newRequest()
       .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid"));
@@ -268,6 +274,7 @@ public class TreeActionTest {
     componentDb.insertDeveloperAndSnapshot(developer);
     componentDb.insertComponent(newDevProjectCopy("project-copy-uuid", project, developer));
     db.commit();
+    logInWithBrowsePermission(developer);
 
     TreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, developer.uuid()));
 
@@ -284,6 +291,7 @@ public class TreeActionTest {
     ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
     componentDb.insertViewAndSnapshot(view);
     componentDb.insertComponent(newProjectCopy("project-copy-uuid", project, view));
+    logInWithBrowsePermission(view);
 
     TreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, view.uuid()));
 
@@ -295,12 +303,13 @@ public class TreeActionTest {
 
   @Test
   public void fail_when_not_enough_privileges() {
-    expectedException.expect(ForbiddenException.class);
-    userSession.anonymous().logIn()
+    userSession.logIn()
       .addProjectUuidPermissions(UserRole.CODEVIEWER, "project-uuid");
     componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
     db.commit();
 
+    expectedException.expect(ForbiddenException.class);
+
     ws.newRequest()
       .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
       .execute();
@@ -426,4 +435,8 @@ public class TreeActionTest {
     JsonElement jsonElement = jsonObject.get(field);
     return jsonElement == null ? null : jsonElement.getAsString();
   }
+
+  private void logInWithBrowsePermission(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+  }
 }
index d4d5a4f7485a0daa200d5300a747dd18475d9e36..a0885176a5feb6b10960c925c66140baae481a09 100644 (file)
@@ -54,7 +54,7 @@ public class SendActionTest {
 
   @Test
   public void send_test_email() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     executeRequest("john@doo.com", "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000");
 
@@ -63,7 +63,7 @@ public class SendActionTest {
 
   @Test
   public void does_not_fail_when_subject_param_is_missing() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     executeRequest("john@doo.com", null, "This is a test message from SonarQube at http://localhost:9000");
 
@@ -72,7 +72,7 @@ public class SendActionTest {
 
   @Test
   public void fail_when_to_param_is_missing() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -81,7 +81,7 @@ public class SendActionTest {
 
   @Test
   public void fail_when_message_param_is_missing() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -89,8 +89,8 @@ public class SendActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -100,7 +100,7 @@ public class SendActionTest {
 
   @Test
   public void fail_with_BadRequestException_when_EmailException_is_generated() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     IllegalArgumentException exception1 = new IllegalArgumentException("root cause");
     IllegalArgumentException exception2 = new IllegalArgumentException("parent cause", exception1);
     IllegalArgumentException exception3 = new IllegalArgumentException("child cause", exception2);
@@ -140,8 +140,8 @@ public class SendActionTest {
     request.execute();
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
 }
index 62ba16d0523e716695b344636c04f19873a358e0..06c9f67f168fe4ef6d3207044a6fe28d720796cb 100644 (file)
@@ -669,7 +669,7 @@ public class SearchActionComponentsMediumTest {
   }
 
   private void setAnyoneProjectPermission(ComponentDto project, String permission) {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
     // TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
     // for each organization
     GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()));
index fb3f985549d82d07031600fd6b682874cd145edd..7921386355dec09b544f6deef543b7be4ce67773 100644 (file)
@@ -78,7 +78,7 @@ public class ListActionTest {
 
   @Test
   public void return_licenses() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings("12345");
     String data = createBase64License("SonarSource", "governance", "12345", "2099-01-01", "PRODUCTION", ImmutableMap.of("other", "value"));
     addLicenseSetting("sonar.governance.license.secured", "Governance", data);
@@ -104,7 +104,7 @@ public class ListActionTest {
 
   @Test
   public void return_licenses_even_if_no_value_set_in_database() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings("12345");
     definitions.addComponent(PropertyDefinition.builder("sonar.governance.license.secured").type(LICENSE).build());
 
@@ -128,7 +128,7 @@ public class ListActionTest {
 
   @Test
   public void return_information_when_no_licence_set() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings(SERVER_ID_SAMPLE);
     addLicenseSetting(LICENSE_KEY_SAMPLE, null, toBase64(""));
 
@@ -153,7 +153,7 @@ public class ListActionTest {
 
   @Test
   public void return_license_with_bad_product() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings(SERVER_ID_SAMPLE);
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, "Other", SERVER_ID_SAMPLE, EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap()));
@@ -170,7 +170,7 @@ public class ListActionTest {
 
   @Test
   public void return_license_with_bad_server_id() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings(SERVER_ID_SAMPLE);
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, PRODUCT_SAMPLE, "Other", EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap()));
@@ -187,7 +187,7 @@ public class ListActionTest {
 
   @Test
   public void return_bad_server_id_when_server_has_no_server_id() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, PRODUCT_SAMPLE, SERVER_ID_SAMPLE, EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap()));
 
@@ -200,7 +200,7 @@ public class ListActionTest {
 
   @Test
   public void does_not_return_invalid_server_id_when_all_servers_accepted_and_no_server_id_setting() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, PRODUCT_SAMPLE, "*", EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap()));
 
@@ -214,7 +214,7 @@ public class ListActionTest {
 
   @Test
   public void return_license_when_all_servers_are_accepted() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings(SERVER_ID_SAMPLE);
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, PRODUCT_SAMPLE, "*", EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap()));
@@ -229,7 +229,7 @@ public class ListActionTest {
 
   @Test
   public void return_license_when_expired() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     addServerIdSettings(SERVER_ID_SAMPLE);
     addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE,
       createBase64License(ORGANIZATION_SAMPLE, PRODUCT_SAMPLE, SERVER_ID_SAMPLE, "2010-01-01", TYPE_SAMPLE, Collections.emptyMap()));
@@ -246,7 +246,7 @@ public class ListActionTest {
 
   @Test
   public void none_license_type_settings_are_not_returned() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").build());
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("value"));
 
@@ -256,8 +256,8 @@ public class ListActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -284,8 +284,8 @@ public class ListActionTest {
     }
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void addLicenseSetting(String key, @Nullable String name, String value) {
index 7cef57c6b2a54c7486fee94f333457cf77d1c3d5..f8c2a445f7fe5a60d10e2534afaa21f5f76fbcb7 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.measure.custom.ws;
 
 import java.util.List;
 import org.assertj.core.data.Offset;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -90,20 +89,15 @@ public class CreateActionTest {
   public void setUp() {
     ws = new WsTester(new CustomMeasuresWs(new CreateAction(dbClient, userSession, System2.INSTANCE, new CustomMeasureValidator(newFullTypeValidations()),
       new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), new ComponentFinder(dbClient))));
-    userSession.logIn("login").setRoot();
 
     db.getDbClient().userDao().insert(dbSession, new UserDto()
       .setLogin("login")
       .setName("Login")
       .setEmail("login@login.com")
-      .setActive(true)
-      );
+      .setActive(true));
     dbSession.commit();
-  }
 
-  @After
-  public void tearDown() {
-    dbSession.close();
+    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
   }
 
   @Test
@@ -275,6 +269,7 @@ public class CreateActionTest {
     dbClient.componentDao().insert(dbSession, ComponentTesting.newView(db.organizations().insert(), viewUuid));
     dbSession.commit();
     MetricDto metric = insertMetric(BOOL);
+    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, viewUuid);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, viewUuid)
@@ -298,6 +293,7 @@ public class CreateActionTest {
     dbClient.componentDao().insert(dbSession, ComponentTesting.newSubView(view, subViewUuid, "SUB_VIEW_KEY"));
     dbSession.commit();
     MetricDto metric = insertMetric(BOOL);
+    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, view.uuid());
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, subViewUuid)
@@ -457,12 +453,13 @@ public class CreateActionTest {
   }
 
   @Test
-  public void fail_when_not_enough_permission() throws Exception {
-    expectedException.expect(ForbiddenException.class);
-    userSession.logIn("login");
+  public void fail_when_not_project_administrator() throws Exception {
+    userSession.logIn();
     insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
+    expectedException.expect(ForbiddenException.class);
+
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
       .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
index 8959e50c36424d1eb9f33d4d34383c09878ec04a..c96d9d8daa606e08b702982f283765dd2e32831a 100644 (file)
@@ -61,21 +61,6 @@ public class DeleteActionTest {
     ws = new WsTester(new CustomMeasuresWs(new DeleteAction(dbClient, userSession)));
   }
 
-  @Test
-  public void root_users_can_delete_custom_measures() throws Exception {
-    userSession.logIn().setRoot();
-    ComponentDto project = db.components().insertProject();
-
-    long id = insertCustomMeasure(project);
-    long anotherId = insertCustomMeasure(project);
-
-    WsTester.Result response = newRequest().setParam(PARAM_ID, valueOf(id)).execute();
-
-    assertThat(dbClient.customMeasureDao().selectById(dbSession, id)).isNull();
-    assertThat(dbClient.customMeasureDao().selectById(dbSession, anotherId)).isNotNull();
-    response.assertNoContent();
-  }
-
   @Test
   public void project_administrator_can_delete_custom_measures() throws Exception {
     ComponentDto project = db.components().insertProject();
@@ -95,17 +80,17 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_administrator() throws Exception {
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
     ComponentDto project = db.components().insertProject();
     long id = insertCustomMeasure(project);
-    userSession.logIn().setNonRoot();
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     newRequest().setParam(PARAM_ID, valueOf(id)).execute();
   }
 
   @Test
-  public void throw_UnauthorizedException_if_not_administrator() throws Exception {
+  public void throw_UnauthorizedException_if_not_logged_in() throws Exception {
     ComponentDto project = db.components().insertProject();
     long id = insertCustomMeasure(project);
     userSession.anonymous();
index c2bc30a868026f87fbba93938b5511a092caaaaa..b5e151d363884f6a0cd3c7a3a0da55b3b2611cd5 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.config.MapSettings;
 import org.sonar.api.measures.Metric.ValueType;
 import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -65,17 +66,17 @@ public class UpdateActionTest {
   public DbTester db = DbTester.create(System2.INSTANCE);
   @Rule
   public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
-  DbClient dbClient = db.getDbClient();
-  DbSession dbSession = db.getSession();
-  System2 system = mock(System2.class);
-  WsTester ws;
+
+  private DbClient dbClient = db.getDbClient();
+  private DbSession dbSession = db.getSession();
+  private System2 system = mock(System2.class);
+  private WsTester ws;
 
   @Before
   public void setUp() {
     CustomMeasureValidator validator = new CustomMeasureValidator(newFullTypeValidations());
 
     ws = new WsTester(new CustomMeasuresWs(new UpdateAction(dbClient, userSessionRule, system, validator, new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule)))));
-    userSessionRule.logIn("login").setRoot();
 
     db.getDbClient().userDao().insert(dbSession, new UserDto()
       .setLogin("login")
@@ -96,12 +97,14 @@ public class UpdateActionTest {
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
     when(system.now()).thenReturn(123_456_789L);
+    logInAsProjectAdministrator(component);
 
     ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
       .setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
       .setParam(PARAM_VALUE, "new-text-measure-value")
       .execute();
+    logInAsProjectAdministrator(component);
 
     CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
     assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("new-text-measure-value");
@@ -120,6 +123,7 @@ public class UpdateActionTest {
       .setValue(42d);
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
+    logInAsProjectAdministrator(component);
 
     ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
@@ -149,6 +153,7 @@ public class UpdateActionTest {
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
     when(system.now()).thenReturn(123_456_789L);
+    logInAsProjectAdministrator(component);
 
     WsTester.Result response = ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
@@ -173,11 +178,13 @@ public class UpdateActionTest {
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
     when(system.now()).thenReturn(123_456_789L);
+    logInAsProjectAdministrator(component);
 
     ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
       .setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
       .execute();
+    logInAsProjectAdministrator(component);
 
     CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
     assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("text-measure-value");
@@ -200,6 +207,7 @@ public class UpdateActionTest {
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
     when(system.now()).thenReturn(123_456_789L);
+    logInAsProjectAdministrator(component);
 
     ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
@@ -239,7 +247,6 @@ public class UpdateActionTest {
   @Test
   public void fail_if_insufficient_privileges() throws Exception {
     userSessionRule.logIn();
-    expectedException.expect(ForbiddenException.class);
     MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
     dbClient.metricDao().insert(dbSession, metric);
     ComponentDto component = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid");
@@ -253,6 +260,8 @@ public class UpdateActionTest {
     dbClient.customMeasureDao().insert(dbSession, customMeasure);
     dbSession.commit();
 
+    expectedException.expect(ForbiddenException.class);
+
     ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION)
       .setParam(PARAM_ID, String.valueOf(customMeasure.getId()))
       .setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
@@ -317,4 +326,8 @@ public class UpdateActionTest {
       .setComponentUuid(project.uuid())
       .setCreatedAt(system.now());
   }
+
+  private void logInAsProjectAdministrator(ComponentDto component) {
+    userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, component.uuid());
+  }
 }
index feaafb46f709586b0217d71048f4836c743fe348..abf404de18db7c4c0e1a5b91b8b68867d22fef29 100644 (file)
@@ -66,7 +66,7 @@ public class CreateActionTest {
   @Before
   public void setUp() {
     ws = new WsTester(new MetricsWs(new CreateAction(dbClient, userSessionRule)));
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
   }
 
   @Test
@@ -228,8 +228,8 @@ public class CreateActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSessionRule.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index 361d389a8e0714053843c0f52ae682332558bb17..5ededf14bcb8b9d697f55aec50d1665aecbfc9c3 100644 (file)
@@ -57,7 +57,7 @@ public class DeleteActionTest {
 
   @Before
   public void setUp() {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
     ws = new WsTester(new MetricsWs(new DeleteAction(dbClient, userSessionRule)));
     metricDao = dbClient.metricDao();
   }
@@ -124,8 +124,8 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSessionRule.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
     insertCustomEnabledMetrics(1);
 
     expectedException.expect(ForbiddenException.class);
index a6bf6be9f7f7dc6b60af65c95f875028035813bb..defa61c563f43a08e3a2c5d65fb179dd97c7045a 100644 (file)
@@ -66,7 +66,7 @@ public class UpdateActionTest {
   @Before
   public void setUp() {
     ws = new WsTester(new MetricsWs(new UpdateAction(dbClient, userSessionRule)));
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
   }
 
   @Test
@@ -182,8 +182,8 @@ public class UpdateActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSessionRule.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index 0c0f123183d2a6d2b0d121aba702d44fe2e3d6ff..96f8cb318bdaca1630cd20809a1148cbc4d78006 100644 (file)
@@ -131,7 +131,7 @@ public class CreateActionTest {
 
   @Test
   public void verify_response_example() throws URISyntaxException, IOException {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(Uuids.UUID_EXAMPLE_01, SOME_DATE);
 
     String response = executeJsonRequest("Foo Company", "foo-company", "The Foo company produces quality software for Bar.", "https://www.foo.com", "https://www.foo.com/foo.png");
@@ -161,7 +161,7 @@ public class CreateActionTest {
   }
 
   @Test
-  public void request_fails_if_user_is_not_root_and_logged_in_users_cannot_create_organizations() {
+  public void request_fails_if_user_is_not_system_administrator_and_logged_in_users_cannot_create_organizations() {
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
@@ -171,16 +171,16 @@ public class CreateActionTest {
   }
 
   @Test
-  public void request_succeeds_if_user_is_root_and_logged_in_users_cannot_create_organizations() {
-    logInAsRoot();
+  public void request_succeeds_if_user_is_system_administrator_and_logged_in_users_cannot_create_organizations() {
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     verifyResponseAndDb(executeRequest("foo"), SOME_UUID, "foo", "foo", SOME_DATE);
   }
 
   @Test
-  public void request_succeeds_if_user_is_root_and_logged_in_users_can_create_organizations() {
-    logInAsRoot();
+  public void request_succeeds_if_user_is_system_administrator_and_logged_in_users_can_create_organizations() {
+    logInAsSystemAdministrator();
     settings.setProperty(ORGANIZATIONS_ANYONE_CAN_CREATE, true);
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
@@ -188,7 +188,7 @@ public class CreateActionTest {
   }
 
   @Test
-  public void request_succeeds_if_user_is_not_root_and_logged_in_users_can_create_organizations() {
+  public void request_succeeds_if_user_is_not_system_administrator_and_logged_in_users_can_create_organizations() {
     userSession.logIn();
     settings.setProperty(ORGANIZATIONS_ANYONE_CAN_CREATE, true);
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
@@ -198,7 +198,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_name_param_is_missing() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'name' parameter is missing");
@@ -208,7 +208,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_name_is_one_char_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name 'a' must be at least 2 chars long");
@@ -218,7 +218,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_name_is_two_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     verifyResponseAndDb(executeRequest("ab"), SOME_UUID, "ab", "ab", SOME_DATE);
@@ -226,7 +226,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_name_is_65_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
@@ -236,7 +236,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_name_is_64_char_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     String name = STRING_65_CHARS_LONG.substring(0, 64);
@@ -246,7 +246,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_key_one_char_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Key 'a' must be at least 2 chars long");
@@ -256,7 +256,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_key_is_33_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     String key = STRING_65_CHARS_LONG.substring(0, 33);
 
@@ -268,7 +268,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_key_is_2_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     verifyResponseAndDb(executeRequest("foo", "ab"), SOME_UUID, "foo", "ab", SOME_DATE);
@@ -276,7 +276,7 @@ public class CreateActionTest {
 
   @Test
   public void requests_succeeds_if_key_is_32_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     String key = STRING_65_CHARS_LONG.substring(0, 32);
@@ -286,28 +286,28 @@ public class CreateActionTest {
 
   @Test
   public void requests_fails_if_key_contains_non_ascii_chars_but_dash() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     requestFailsWithInvalidCharInKey("ab@");
   }
 
   @Test
   public void request_fails_if_key_starts_with_a_dash() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     requestFailsWithInvalidCharInKey("-ab");
   }
 
   @Test
   public void request_fails_if_key_ends_with_a_dash() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     requestFailsWithInvalidCharInKey("ab-");
   }
 
   @Test
   public void request_fails_if_key_contains_space() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     requestFailsWithInvalidCharInKey("a b");
   }
@@ -321,7 +321,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_key_is_specified_and_already_exists_in_DB() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     OrganizationDto org = insertOrganization("the-key");
 
     expectedException.expect(IllegalArgumentException.class);
@@ -332,7 +332,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_key_computed_from_name_already_exists_in_DB() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     String key = STRING_65_CHARS_LONG.substring(0, 32);
     insertOrganization(key);
 
@@ -346,7 +346,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_description_url_and_avatar_are_not_specified() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     CreateWsResponse response = executeRequest("foo", "bar", null, null, null);
@@ -355,7 +355,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_description_url_and_avatar_are_specified() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     CreateWsResponse response = executeRequest("foo", "bar", "moo", "doo", "boo");
@@ -364,7 +364,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_to_generate_key_from_name_more_then_32_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     String name = STRING_65_CHARS_LONG.substring(0, 33);
@@ -375,7 +375,7 @@ public class CreateActionTest {
 
   @Test
   public void request_generates_key_ignoring_multiple_following_spaces() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
 
     String name = "ab   cd";
@@ -386,7 +386,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_description_is_257_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -396,7 +396,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_description_is_256_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
     String description = STRING_257_CHARS_LONG.substring(0, 256);
 
@@ -406,7 +406,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_url_is_257_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -416,7 +416,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_url_is_256_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
     String url = STRING_257_CHARS_LONG.substring(0, 256);
 
@@ -426,7 +426,7 @@ public class CreateActionTest {
 
   @Test
   public void request_fails_if_avatar_is_257_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -436,7 +436,7 @@ public class CreateActionTest {
 
   @Test
   public void request_succeeds_if_avatar_is_256_chars_long() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
     String avatar = STRING_257_CHARS_LONG.substring(0, 256);
 
@@ -447,8 +447,8 @@ public class CreateActionTest {
   @Test
   public void request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it() {
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
-    UserDto user = dbTester.users().makeRoot(dbTester.users().insertUser());
-    userSession.logIn(user).setRoot();
+    UserDto user = dbTester.users().insertUser();
+    userSession.logIn(user).setSystemAdministrator();
 
     executeRequest("orgFoo");
 
@@ -471,8 +471,8 @@ public class CreateActionTest {
   @Test
   public void request_creates_default_template_for_owner_group_and_anyone() {
     mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
-    UserDto user = dbTester.users().makeRoot(dbTester.users().insertUser());
-    userSession.logIn(user).setRoot();
+    UserDto user = dbTester.users().insertUser();
+    userSession.logIn(user).setSystemAdministrator();
 
     executeRequest("orgFoo");
 
@@ -492,9 +492,9 @@ public class CreateActionTest {
   }
 
   @Test
-  public void request_fails_with_IllegalStateException_if_organization_feature_is_disabled() {
+  public void request_fails_with_IllegalStateException_if_organization_support_is_disabled() {
     organizationFlags.setEnabled(false);
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Organization support is disabled");
@@ -594,7 +594,7 @@ public class CreateActionTest {
     return dto;
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 8b103429116ef93bf1232a909167ac9b91bbc0f7..c33983050d4bf8a300e5f288150e0e3ba66ac3c5 100644 (file)
@@ -89,7 +89,7 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void request_fails_with_IllegalStateException_if_organization_feature_is_disabled() {
+  public void request_fails_with_IllegalStateException_if_organization_support_is_disabled() {
     organizationFlags.setEnabled(false);
     userSession.logIn();
 
@@ -110,7 +110,7 @@ public class DeleteActionTest {
 
   @Test
   public void request_fails_with_IAE_if_key_param_is_missing() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'key' parameter is missing");
@@ -120,7 +120,7 @@ public class DeleteActionTest {
 
   @Test
   public void request_fails_with_IAE_if_key_is_the_one_of_default_organization() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Default Organization can't be deleted");
@@ -130,7 +130,7 @@ public class DeleteActionTest {
 
   @Test
   public void request_fails_with_NotFoundException_if_organization_with_specified_key_does_not_exist() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Organization with key 'foo' not found");
@@ -139,7 +139,7 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root_and_is_not_administrator_of_specified_organization() {
+  public void request_fails_with_ForbiddenException_when_user_is_not_administrator_of_specified_organization() {
     OrganizationDto organization = dbTester.organizations().insert();
     userSession.logIn();
 
@@ -150,7 +150,18 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root_and_is_administrator_of_other_organization() {
+  public void request_fails_with_ForbiddenException_when_user_is_system_administrator() {
+    OrganizationDto organization = dbTester.organizations().insert();
+    userSession.logIn().setSystemAdministrator();
+
+    expectedException.expect(ForbiddenException.class);
+    expectedException.expectMessage("Insufficient privileges");
+
+    sendRequest(organization);
+  }
+
+  @Test
+  public void request_fails_with_ForbiddenException_when_user_is_administrator_of_other_organization() {
     OrganizationDto organization = dbTester.organizations().insert();
     logInAsAdministrator(dbTester.getDefaultOrganization());
 
@@ -171,9 +182,9 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void request_deletes_specified_organization_if_exists_and_user_is_root() {
+  public void request_deletes_specified_organization_if_exists_and_user_is_organization_administrator() {
     OrganizationDto organization = dbTester.organizations().insert();
-    userSession.logIn().setRoot();
+    logInAsAdministrator(organization);
 
     sendRequest(organization);
 
@@ -181,9 +192,9 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void request_deletes_specified_guarded_organization_if_exists_and_user_is_root() {
+  public void request_deletes_specified_guarded_organization_if_exists_and_user_is_system_administrator() {
     OrganizationDto organization = dbTester.organizations().insert(dto -> dto.setGuarded(true));
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     sendRequest(organization);
 
@@ -192,8 +203,6 @@ public class DeleteActionTest {
 
   @Test
   public void request_also_deletes_components_of_specified_organization() {
-    logInAsRoot();
-
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertProject(organization);
     ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
@@ -204,6 +213,7 @@ public class DeleteActionTest {
     ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view, "v1", "ksv1"));
     ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1, "v2", "ksv2"));
     ComponentDto projectCopy = dbTester.components().insertComponent(ComponentTesting.newProjectCopy("pc1", project, subview1));
+    logInAsAdministrator(organization);
 
     sendRequest(organization);
 
@@ -215,8 +225,6 @@ public class DeleteActionTest {
 
   @Test
   public void request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization() {
-    logInAsRoot();
-
     OrganizationDto org = dbTester.organizations().insert();
     OrganizationDto otherOrg = dbTester.organizations().insert();
 
@@ -245,6 +253,7 @@ public class DeleteActionTest {
 
     PermissionTemplateDto templateDto = dbTester.permissionTemplates().insertTemplate(org);
     PermissionTemplateDto otherTemplateDto = dbTester.permissionTemplates().insertTemplate(otherOrg);
+    logInAsAdministrator(org);
 
     sendRequest(org);
 
@@ -281,8 +290,8 @@ public class DeleteActionTest {
       .execute();
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void logInAsAdministrator(OrganizationDto organization) {
index 46ee0eca1c64f2838d110627bca8a342f6f76f06..08dc07629bb5c9c1f2ac18434d31e4f270fe75df 100644 (file)
@@ -100,7 +100,7 @@ public class UpdateActionTest {
   }
 
   @Test
-  public void request_fails_with_IllegalStateException_if_organization_feature_is_disabled() {
+  public void request_fails_with_IllegalStateException_if_organization_support_is_disabled() {
     organizationFlags.setEnabled(false);
     userSession.logIn();
 
@@ -111,9 +111,9 @@ public class UpdateActionTest {
   }
 
   @Test
-  public void request_succeeds_if_user_is_root() {
-    logInAsRoot();
+  public void request_succeeds_if_user_is_organization_administrator() {
     OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(dto);
 
     verifyResponseAndDb(executeKeyRequest(dto.getKey(), "ab"), dto, "ab", DATE_2);
   }
@@ -135,7 +135,7 @@ public class UpdateActionTest {
   }
 
   @Test
-  public void request_fails_if_user_is_not_root_and_is_not_organization_administrator() {
+  public void request_fails_if_user_is_not_system_administrator_and_is_not_organization_administrator() {
     OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
     userSession.logIn();
 
@@ -158,7 +158,7 @@ public class UpdateActionTest {
 
   @Test
   public void request_fails_if_key_is_missing() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'key' parameter is missing");
@@ -168,15 +168,15 @@ public class UpdateActionTest {
 
   @Test
   public void request_with_only_key_param_succeeds_and_updates_only_updateAt_field() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
-    verifyResponseAndDb(executeKeyRequest(dto.getKey(), null), dto, dto.getName(), DATE_2);
+    verifyResponseAndDb(executeKeyRequest(org.getKey(), null), org, org.getName(), DATE_2);
   }
 
   @Test
   public void request_fails_if_name_is_one_char_long() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name 'a' must be at least 2 chars long");
@@ -186,15 +186,15 @@ public class UpdateActionTest {
 
   @Test
   public void request_succeeds_if_name_is_two_chars_long() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
-    verifyResponseAndDb(executeKeyRequest(dto.getKey(), "ab"), dto, "ab", DATE_2);
+    verifyResponseAndDb(executeKeyRequest(org.getKey(), "ab"), org, "ab", DATE_2);
   }
 
   @Test
   public void request_fails_if_name_is_65_chars_long() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
@@ -204,35 +204,35 @@ public class UpdateActionTest {
 
   @Test
   public void request_succeeds_if_name_is_64_char_long() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
     String name = STRING_65_CHARS_LONG.substring(0, 64);
 
-    verifyResponseAndDb(executeKeyRequest(dto.getKey(), name), dto, name, DATE_2);
+    verifyResponseAndDb(executeKeyRequest(org.getKey(), name), org, name, DATE_2);
   }
 
   @Test
   public void request_succeeds_if_description_url_and_avatar_are_not_specified() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bar", null, null, null);
-    verifyResponseAndDb(response, dto, "bar", DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bar", null, null, null);
+    verifyResponseAndDb(response, org, "bar", DATE_2);
   }
 
   @Test
   public void request_succeeds_if_description_url_and_avatar_are_specified() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bar", "moo", "doo", "boo");
-    verifyResponseAndDb(response, dto, "bar", "moo", "doo", "boo", DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bar", "moo", "doo", "boo");
+    verifyResponseAndDb(response, org, "bar", "moo", "doo", "boo", DATE_2);
   }
 
   @Test
   public void request_fails_if_description_is_257_chars_long() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -242,17 +242,17 @@ public class UpdateActionTest {
 
   @Test
   public void request_succeeds_if_description_is_256_chars_long() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
     String description = STRING_257_CHARS_LONG.substring(0, 256);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bar", description, null, null);
-    verifyResponseAndDb(response, dto, "bar", description, dto.getUrl(), dto.getAvatarUrl(), DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bar", description, null, null);
+    verifyResponseAndDb(response, org, "bar", description, org.getUrl(), org.getAvatarUrl(), DATE_2);
   }
 
   @Test
   public void request_fails_if_url_is_257_chars_long() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -262,17 +262,17 @@ public class UpdateActionTest {
 
   @Test
   public void request_succeeds_if_url_is_256_chars_long() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
     String url = STRING_257_CHARS_LONG.substring(0, 256);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bar", null, url, null);
-    verifyResponseAndDb(response, dto, "bar", dto.getDescription(), url, dto.getAvatarUrl(), DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bar", null, url, null);
+    verifyResponseAndDb(response, org, "bar", org.getDescription(), url, org.getAvatarUrl(), DATE_2);
   }
 
   @Test
   public void request_fails_if_avatar_is_257_chars_long() {
-    logInAsRoot();
+    userSession.logIn();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@@ -282,21 +282,21 @@ public class UpdateActionTest {
 
   @Test
   public void request_succeeds_if_avatar_is_256_chars_long() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
     String avatar = STRING_257_CHARS_LONG.substring(0, 256);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bar", null, null, avatar);
-    verifyResponseAndDb(response, dto, "bar", dto.getDescription(), dto.getUrl(), avatar, DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bar", null, null, avatar);
+    verifyResponseAndDb(response, org, "bar", org.getDescription(), org.getUrl(), avatar, DATE_2);
   }
 
   @Test
   public void request_removes_optional_parameters_when_associated_parameter_are_empty() {
-    logInAsRoot();
-    OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    OrganizationDto org = mockForSuccessfulUpdate(DATE_1, DATE_2);
+    logInAsAdministrator(org);
 
-    Organizations.UpdateWsResponse response = executeKeyRequest(dto.getKey(), "bla", "", "", "");
-    verifyResponseAndDb(response, dto, "bla", null, null, null, DATE_2);
+    Organizations.UpdateWsResponse response = executeKeyRequest(org.getKey(), "bla", "", "", "");
+    verifyResponseAndDb(response, org, "bla", null, null, null, DATE_2);
   }
 
   private OrganizationDto mockForSuccessfulUpdate(long createdAt, long nextNow) {
@@ -375,10 +375,6 @@ public class UpdateActionTest {
     assertThat(newDto.getUpdatedAt()).isEqualTo(updateAt);
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
-  }
-
   private void logInAsAdministrator(OrganizationDto organizationDto) {
     userSession.logIn().addOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
   }
index e2bb89bea00499eaf38cf9ea0307fd5f22d11eec..dade64593db4211ee358664d4c7abf3adfa2976b 100644 (file)
@@ -57,7 +57,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
   @Before
   public void setUp() {
     i18n.setProjectPermissions();
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
   }
 
   @Override
index 1e91924193af1b4c7e0abc94ad3ca73eb1e7794d..1d03eafa8c9bebe493f1209484d97908b2975600 100644 (file)
@@ -56,8 +56,8 @@ public class ChangeLogLevelActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() {
-    userSession.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -66,7 +66,7 @@ public class ChangeLogLevelActionTest {
 
   @Test
   public void enable_debug_logs() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     actionTester.newRequest()
       .setParam("level", "DEBUG")
@@ -80,7 +80,7 @@ public class ChangeLogLevelActionTest {
 
   @Test
   public void enable_trace_logs() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     actionTester.newRequest()
       .setParam("level", "TRACE")
@@ -94,7 +94,7 @@ public class ChangeLogLevelActionTest {
 
   @Test
   public void fail_if_unsupported_level() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -106,7 +106,7 @@ public class ChangeLogLevelActionTest {
 
   @Test
   public void fail_if_missing_level() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -115,7 +115,7 @@ public class ChangeLogLevelActionTest {
       .execute();
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 9f82b65ad09d3aea5ce820765c675cb5961962bd..4f245cb601e13f5d506cb5db4610676e73387ad0 100644 (file)
@@ -67,8 +67,8 @@ public class InfoActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() {
-    userSessionRule.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -77,7 +77,7 @@ public class InfoActionTest {
 
   @Test
   public void write_json() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     Map<String, Object> attributes1 = new LinkedHashMap<>();
     attributes1.put("foo", "bar");
@@ -95,7 +95,7 @@ public class InfoActionTest {
     assertThat(response.getInput()).isEqualTo("{\"Monitor One\":{\"foo\":\"bar\"},\"Monitor Two\":{\"one\":1,\"two\":2}}");
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
   }
 }
index 66f86854f356f9c28b42f5789b21dc4ff2ea937b..e94fc7456236a1c58858380de02bb9801efae6ab 100644 (file)
@@ -66,7 +66,7 @@ public class LogsActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() {
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() {
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
@@ -76,7 +76,7 @@ public class LogsActionTest {
 
   @Test
   public void get_app_logs_by_default() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     createAllLogsFiles();
 
@@ -87,7 +87,7 @@ public class LogsActionTest {
 
   @Test
   public void return_404_not_found_if_file_does_not_exist() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     createLogsDir();
 
@@ -97,7 +97,7 @@ public class LogsActionTest {
 
   @Test
   public void get_ce_logs() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     createAllLogsFiles();
 
@@ -110,7 +110,7 @@ public class LogsActionTest {
 
   @Test
   public void get_es_logs() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     createAllLogsFiles();
 
@@ -123,7 +123,7 @@ public class LogsActionTest {
 
   @Test
   public void get_web_logs() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     createAllLogsFiles();
 
@@ -136,7 +136,7 @@ public class LogsActionTest {
 
   @Test
   public void do_not_return_rotated_files() throws IOException {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     File dir = createLogsDir();
     FileUtils.write(new File(dir, "sonar.1.log"), "{old}");
@@ -164,7 +164,7 @@ public class LogsActionTest {
     return dir;
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 3c3a60a3eacf6daa726fcd1e095ee89ab1e86122..85708a638654fdb3f78129058c0448ba69fb086d 100644 (file)
@@ -99,8 +99,8 @@ public class RestartActionTest {
   }
 
   @Test
-  public void request_fails_in_production_mode_with_ForbiddenException_when_user_is_not_root() {
-    userSessionRule.logIn();
+  public void request_fails_in_production_mode_with_ForbiddenException_when_user_is_not_system_administrator() {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -109,7 +109,7 @@ public class RestartActionTest {
 
   @Test
   public void calls_ProcessCommandWrapper_requestForSQRestart_in_production_mode() throws Exception {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
 
     actionTester.newRequest().execute();
 
@@ -120,7 +120,7 @@ public class RestartActionTest {
   @Test
   public void logs_login_of_authenticated_user_requesting_the_restart_in_production_mode() throws Exception {
     String login = "BigBother";
-    userSessionRule.logIn(login).setRoot();
+    userSessionRule.logIn(login).setSystemAdministrator();
 
     actionTester.newRequest().execute();
 
index b385bb69f4fcc256ec5dcc20e64839728bd0dbf1..05034b1397c5967f0a128af4c47f6c7836c0acdd 100644 (file)
@@ -70,7 +70,7 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
   @Test
   public void action_available_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
 
@@ -94,8 +94,8 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSession.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -104,7 +104,7 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
   @Test
   public void empty_array_is_returned_when_there_is_no_plugin_available() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     underTest.handle(request, response);
 
     assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST);
@@ -112,7 +112,7 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
   @Test
   public void empty_array_is_returned_when_update_center_is_not_accessible() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());
 
     underTest.handle(request, response);
@@ -122,7 +122,7 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
   @Test
   public void verify_properties_displayed_in_json_per_plugin() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenter.findAvailablePlugins()).thenReturn(of(
       pluginUpdate(FULL_PROPERTIES_PLUGIN_RELEASE, COMPATIBLE)));
 
@@ -133,25 +133,25 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
   @Test
   public void status_COMPATIBLE_is_displayed_COMPATIBLE_in_JSON() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     checkStatusDisplayedInJson(COMPATIBLE, "COMPATIBLE");
   }
 
   @Test
   public void status_INCOMPATIBLE_is_displayed_INCOMPATIBLE_in_JSON() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     checkStatusDisplayedInJson(INCOMPATIBLE, "INCOMPATIBLE");
   }
 
   @Test
   public void status_REQUIRE_SONAR_UPGRADE_is_displayed_REQUIRES_SYSTEM_UPGRADE_in_JSON() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     checkStatusDisplayedInJson(REQUIRE_SONAR_UPGRADE, "REQUIRES_SYSTEM_UPGRADE");
   }
 
   @Test
   public void status_DEPENDENCIES_REQUIRE_SONAR_UPGRADE_is_displayed_DEPS_REQUIRE_SYSTEM_UPGRADE_in_JSON() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     checkStatusDisplayedInJson(DEPENDENCIES_REQUIRE_SONAR_UPGRADE, "DEPS_REQUIRE_SYSTEM_UPGRADE");
   }
 
@@ -173,8 +173,8 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
         "}");
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
 }
index 929adc78138729922e0cad3f55fe6588d2c6238c..8afbd90df8b9f2f4fabd7971c7c895752dc1c809 100644 (file)
@@ -78,8 +78,8 @@ public class CancelAllActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSessionRule.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -89,7 +89,7 @@ public class CancelAllActionTest {
 
   @Test
   public void triggers_cancel_for_downloads_and_uninstalls() throws Exception {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
 
     underTest.handle(request, response);
 
index 99ef148eec25b19508862e6e65b69548742af1fc..cf44b13927c42d603fa860d59e6ea57fd13f0638 100644 (file)
@@ -80,8 +80,8 @@ public class InstallActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSessionRule.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -91,7 +91,7 @@ public class InstallActionTest {
 
   @Test
   public void action_install_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
@@ -116,7 +116,7 @@ public class InstallActionTest {
 
   @Test
   public void IAE_is_raised_when_key_param_is_not_provided() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     expectedException.expect(IllegalArgumentException.class);
 
     invalidRequest.execute();
@@ -124,7 +124,7 @@ public class InstallActionTest {
 
   @Test
   public void IAE_is_raised_when_there_is_no_available_plugin_for_the_key() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("No plugin with key 'pluginKey'");
 
@@ -133,7 +133,7 @@ public class InstallActionTest {
 
   @Test
   public void IAE_is_raised_when_update_center_is_unavailable() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());
 
     expectedException.expect(IllegalArgumentException.class);
@@ -144,7 +144,7 @@ public class InstallActionTest {
 
   @Test
   public void if_plugin_is_found_available_download_is_triggered_with_latest_version_from_updatecenter() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     Version version = Version.create("1.0");
     when(updateCenter.findAvailablePlugins()).thenReturn(ImmutableList.of(
       PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY), version), PluginUpdate.Status.COMPATIBLE)
@@ -156,7 +156,7 @@ public class InstallActionTest {
     result.assertNoContent();
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
   }
 }
index dd2180518aed053b1ef37e9647c043775675e174..44ab6b201732c7285282fdfe50d1ead88dc6ed80 100644 (file)
@@ -67,7 +67,7 @@ public class InstalledActionTest {
 
   @Test
   public void action_installed_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
 
@@ -91,8 +91,8 @@ public class InstalledActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSession.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -101,7 +101,7 @@ public class InstalledActionTest {
 
   @Test
   public void empty_array_is_returned_when_there_is_not_plugin_installed() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     underTest.handle(request, response);
 
     assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_PLUGIN_LIST);
@@ -109,7 +109,7 @@ public class InstalledActionTest {
 
   @Test
   public void empty_array_when_update_center_is_unavailable() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.<UpdateCenter>absent());
 
     underTest.handle(request, response);
@@ -119,7 +119,7 @@ public class InstalledActionTest {
 
   @Test
   public void empty_fields_are_not_serialized_to_json() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(pluginRepository.getPluginInfos()).thenReturn(
       of(new PluginInfo("").setName("")));
 
@@ -130,7 +130,7 @@ public class InstalledActionTest {
 
   @Test
   public void verify_properties_displayed_in_json_per_plugin() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     String jarFilename = getClass().getSimpleName() + "/" + "some.jar";
     when(pluginRepository.getPluginInfos()).thenReturn(of(
       new PluginInfo("plugKey")
@@ -173,7 +173,7 @@ public class InstalledActionTest {
 
   @Test
   public void category_is_returned_when_in_additional_fields() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     String jarFilename = getClass().getSimpleName() + "/" + "some.jar";
     when(pluginRepository.getPluginInfos()).thenReturn(of(
       new PluginInfo("plugKey")
@@ -225,7 +225,7 @@ public class InstalledActionTest {
 
   @Test
   public void plugins_are_sorted_by_name_then_key_and_only_one_plugin_can_have_a_specific_name() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(pluginRepository.getPluginInfos()).thenReturn(
       of(
         plugin("A", "name2"),
@@ -252,7 +252,7 @@ public class InstalledActionTest {
 
   @Test
   public void only_one_plugin_can_have_a_specific_name_and_key() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(pluginRepository.getPluginInfos()).thenReturn(
       of(
         plugin("A", "name2"),
@@ -277,8 +277,8 @@ public class InstalledActionTest {
     return new PluginInfo(key).setName(name).setVersion(Version.create("1.0"));
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
 }
index 5d68840de57423c457e591d57ab6c4903e3a8928..eee591dc71a2ba45b30b461a563e9ecb4ce3761a 100644 (file)
@@ -63,7 +63,7 @@ public class PendingActionTest {
 
   @Test
   public void action_pending_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
 
@@ -87,8 +87,8 @@ public class PendingActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSession.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -97,7 +97,7 @@ public class PendingActionTest {
 
   @Test
   public void empty_arrays_are_returned_when_there_nothing_pending() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     underTest.handle(request, response);
 
     assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(
@@ -110,7 +110,7 @@ public class PendingActionTest {
 
   @Test
   public void empty_arrays_are_returned_when_update_center_is_unavailable() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.<UpdateCenter>absent());
 
     underTest.handle(request, response);
@@ -125,7 +125,7 @@ public class PendingActionTest {
 
   @Test
   public void verify_properties_displayed_in_json_per_installing_plugin() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     newUpdateCenter("scmgit");
     when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(newScmGitPluginInfo()));
 
@@ -156,7 +156,7 @@ public class PendingActionTest {
 
   @Test
   public void verify_properties_displayed_in_json_per_removing_plugin() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(newScmGitPluginInfo()));
 
     underTest.handle(request, response);
@@ -185,7 +185,7 @@ public class PendingActionTest {
 
   @Test
   public void verify_properties_displayed_in_json_per_updating_plugin() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     newUpdateCenter("scmgit");
     when(serverPluginRepository.getPluginInfos()).thenReturn(of(newScmGitPluginInfo()));
     when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(newScmGitPluginInfo()));
@@ -207,7 +207,7 @@ public class PendingActionTest {
 
   @Test
   public void verify_properties_displayed_in_json_per_installing_removing_and_updating_plugins() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     PluginInfo installed = newPluginInfo("java");
     PluginInfo removedPlugin = newPluginInfo("js");
     PluginInfo newPlugin = newPluginInfo("php");
@@ -244,7 +244,7 @@ public class PendingActionTest {
 
   @Test
   public void installing_plugins_are_sorted_by_name_then_key_and_are_unique() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(
       newPluginInfo(0).setName("Foo"),
       newPluginInfo(3).setName("Bar"),
@@ -276,7 +276,7 @@ public class PendingActionTest {
 
   @Test
   public void removing_plugins_are_sorted_and_unique() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(
       newPluginInfo(0).setName("Foo"),
       newPluginInfo(3).setName("Bar"),
@@ -338,7 +338,7 @@ public class PendingActionTest {
     return new PluginInfo("key" + id).setName("name" + id);
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 0291e3f83e5490262b19d3ef7aeafe3f370c6a69..33b88bea6ce82cb20f6b04df0a3a0ef43ec848c8 100644 (file)
@@ -51,7 +51,7 @@ public class PluginsWsMediumTest {
     WsTester wsTester = new WsTester(serverTester.get(PluginsWs.class));
 
     // 1 - check what's installed, available and pending
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
     wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
       "  \"plugins\": [" +
       "    {" +
@@ -115,7 +115,7 @@ public class PluginsWsMediumTest {
     wsTester = restartServerTester();
 
     // 4 - make sure plugin is installed
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
     wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
       "  \"plugins\": [" +
       "    {" +
@@ -148,7 +148,7 @@ public class PluginsWsMediumTest {
     wsTester = restartServerTester();
 
     // 7 - make sure plugin has been uninstalled
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
     wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
       "  \"plugins\": [" +
       "    {" +
index 61d5dcba8d8b3369eb7550690d7143c30fb01747..a0c5ea72136ac3dda17a21ff6f7a5715575594c7 100644 (file)
@@ -63,8 +63,8 @@ public class UninstallActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSessionRule.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -74,7 +74,7 @@ public class UninstallActionTest {
 
   @Test
   public void action_uninstall_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
@@ -99,7 +99,7 @@ public class UninstallActionTest {
 
   @Test
   public void IAE_is_raised_when_key_param_is_not_provided() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -108,7 +108,7 @@ public class UninstallActionTest {
 
   @Test
   public void IAE_is_raised_when_plugin_is_not_installed() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Plugin [findbugs] is not installed");
@@ -118,7 +118,7 @@ public class UninstallActionTest {
 
   @Test
   public void if_plugin_is_installed_uninstallation_is_triggered() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(pluginRepository.hasPlugin(PLUGIN_KEY)).thenReturn(true);
 
     underTest.handle(validRequest, response);
@@ -127,8 +127,8 @@ public class UninstallActionTest {
     assertThat(response.outputAsString()).isEmpty();
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
   }
 
 }
index a059cdba5b9c6f6d2e154bbc1815d4ebde2d117f..bc1bbfda0d48085ad52d5b0362c628f038adc62b 100644 (file)
@@ -82,8 +82,8 @@ public class UpdateActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
-    userSessionRule.logIn();
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -93,7 +93,7 @@ public class UpdateActionTest {
 
   @Test
   public void action_update_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
@@ -118,7 +118,7 @@ public class UpdateActionTest {
 
   @Test
   public void IAE_is_raised_when_key_param_is_not_provided() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -127,7 +127,7 @@ public class UpdateActionTest {
 
   @Test
   public void IAE_is_raised_when_there_is_no_plugin_update_for_the_key() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("No plugin with key 'pluginKey'");
@@ -137,7 +137,7 @@ public class UpdateActionTest {
 
   @Test
   public void IAE_is_raised_when_update_center_is_unavailable() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());
 
     expectedException.expect(IllegalArgumentException.class);
@@ -148,7 +148,7 @@ public class UpdateActionTest {
 
   @Test
   public void if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     Version version = Version.create("1.0");
     when(updateCenter.findPluginUpdates()).thenReturn(ImmutableList.of(
       PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY), version), Status.COMPATIBLE)
@@ -160,8 +160,8 @@ public class UpdateActionTest {
     assertThat(response.outputAsString()).isEmpty();
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
   }
 
 }
index 0037a92d4d9d257717eab713857fceda3e3c639b..5dee3e9082da3dcc5a5c7cd89d14e3475af434c1 100644 (file)
@@ -84,7 +84,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
   @Test
   public void action_updatable_is_defined() {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     WsTester wsTester = new WsTester();
     WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
@@ -109,7 +109,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
+  public void request_fails_with_ForbiddenException_when_user_is_not_system_administrator() throws Exception {
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
@@ -118,7 +118,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
   @Test
   public void empty_array_is_returned_when_there_is_no_plugin_available() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
 
     underTest.handle(request, response);
 
@@ -127,7 +127,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
   @Test
   public void verify_response_against_example() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenter.findPluginUpdates()).thenReturn(of(
       pluginUpdate(ABAP_32, COMPATIBLE),
       pluginUpdate(ABAP_31, INCOMPATIBLE),
@@ -140,7 +140,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
   @Test
   public void status_COMPATIBLE_is_displayed_COMPATIBLE_in_JSON() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenter.findPluginUpdates()).thenReturn(of(
       pluginUpdate(release(PLUGIN_1, "1.0.0"), COMPATIBLE)));
 
@@ -162,7 +162,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
   @Test
   public void plugins_are_sorted_by_name_and_made_unique() throws Exception {
-    makeAuthenticatedUserRoot();
+    logInAsSystemAdministrator();
     when(updateCenter.findPluginUpdates()).thenReturn(of(
       pluginUpdate("key2", "name2"),
       pluginUpdate("key2", "name2"),
@@ -190,7 +190,7 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
         "}");
   }
 
-  private void makeAuthenticatedUserRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 68a8227a776cb5ed72f3a3110565ee9d0e6baa12..bfd741255e394c5aa0f7a9991ca9b0e8d2f15da0 100644 (file)
@@ -72,8 +72,8 @@ public class BulkDeleteActionTest {
   }
 
   @Test
-  public void root_deletes_projects_by_uuids_in_all_organizations() throws Exception {
-    userSession.logIn().setRoot();
+  public void system_administrator_deletes_projects_by_uuids_in_all_organizations() throws Exception {
+    userSession.logIn().setSystemAdministrator();
     ComponentDto toDeleteInOrg1 = db.components().insertProject(org1);
     ComponentDto toDeleteInOrg2 = db.components().insertProject(org2);
     ComponentDto toKeep = db.components().insertProject(org2);
@@ -87,8 +87,8 @@ public class BulkDeleteActionTest {
   }
 
   @Test
-  public void root_deletes_projects_by_keys_in_all_organizations() throws Exception {
-    userSession.logIn().setRoot();
+  public void system_administrator_deletes_projects_by_keys_in_all_organizations() throws Exception {
+    userSession.logIn().setSystemAdministrator();
     ComponentDto toDeleteInOrg1 = db.components().insertProject(org1);
     ComponentDto toDeleteInOrg2 = db.components().insertProject(org2);
     ComponentDto toKeep = db.components().insertProject(org2);
@@ -103,7 +103,7 @@ public class BulkDeleteActionTest {
 
   @Test
   public void projects_that_dont_exist_are_ignored_and_dont_break_bulk_deletion() throws Exception {
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
     ComponentDto toDelete1 = db.components().insertProject(org1);
     ComponentDto toDelete2 = db.components().insertProject(org1);
 
@@ -157,8 +157,8 @@ public class BulkDeleteActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_param_organization_is_not_set_and_not_root() throws Exception {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_param_organization_is_not_set_and_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index af735a7f27d822f35b7fcb3db618fc02e172bc87..9b963650094b88e295ae25aff9dff72e480045e7 100644 (file)
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.server.project.ws.DeleteAction.PARAM_ID;
 import static org.sonar.server.project.ws.DeleteAction.PARAM_KEY;
 import static org.sonarqube.ws.client.project.ProjectsWsParameters.CONTROLLER;
@@ -77,10 +78,10 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void root_administrator_deletes_project_by_id() throws Exception {
+  public void organization_administrator_deletes_project_by_id() throws Exception {
     ComponentDto project = componentDbTester.insertProject();
+    userSessionRule.logIn().addOrganizationPermission(project.getOrganizationUuid(), SYSTEM_ADMIN);
 
-    userSessionRule.logIn().setRoot();
     WsTester.TestRequest request = newRequest().setParam(PARAM_ID, project.uuid());
     call(request);
 
@@ -88,10 +89,10 @@ public class DeleteActionTest {
   }
 
   @Test
-  public void root_administrator_deletes_project_by_key() throws Exception {
+  public void organization_administrator_deletes_project_by_key() throws Exception {
     ComponentDto project = componentDbTester.insertProject();
+    userSessionRule.logIn().addOrganizationPermission(project.getOrganizationUuid(), SYSTEM_ADMIN);
 
-    userSessionRule.logIn().setRoot();
     call(newRequest().setParam(PARAM_KEY, project.key()));
 
     assertThat(verifyDeletedKey()).isEqualTo(project.key());
index 21df28ec91911c3768a5de91cc6a6cf2a95a3ce6..9f37bae452a976bbbdb932966e12f40f2758d710 100644 (file)
@@ -54,27 +54,12 @@ public class DeleteActionTest {
 
   private WsActionTester ws = new WsActionTester(new DeleteAction(dbClient, userSession));
 
-  @Test
-  public void root_administrator_deletes_analysis() {
-    ComponentDto project = db.components().insertProject();
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_PROCESSED));
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setLast(true).setStatus(STATUS_PROCESSED));
-    userSession.logIn().setRoot();
-
-    call("A1");
-
-    db.commit();
-    assertThat(dbClient.snapshotDao().selectByUuids(dbSession, newArrayList("A1", "A2"))).extracting(SnapshotDto::getUuid, SnapshotDto::getStatus).containsExactly(
-      tuple("A1", STATUS_UNPROCESSED),
-      tuple("A2", STATUS_PROCESSED));
-  }
-
   @Test
   public void project_administrator_deletes_analysis() {
     ComponentDto project = db.components().insertProject();
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_PROCESSED));
     db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setLast(true).setStatus(STATUS_PROCESSED));
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
 
     call("A1");
 
@@ -97,7 +82,7 @@ public class DeleteActionTest {
   public void last_analysis_cannot_be_deleted() {
     ComponentDto project = db.components().insertProject();
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(true));
-    userSession.logIn().setRoot();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The last analysis 'A1' cannot be deleted");
@@ -117,9 +102,9 @@ public class DeleteActionTest {
 
   @Test
   public void fail_when_analysis_is_unprocessed() {
-    userSession.logIn().setRoot();
     ComponentDto project = db.components().insertProject();
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_UNPROCESSED));
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Analysis 'A1' not found");
@@ -129,9 +114,9 @@ public class DeleteActionTest {
 
   @Test
   public void fail_when_not_enough_permission() {
-    userSession.logIn();
     ComponentDto project = db.components().insertProject();
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false));
+    userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -143,4 +128,8 @@ public class DeleteActionTest {
       .setParam(PARAM_ANALYSIS, analysis)
       .execute();
   }
+
+  private void logInAsProjectAdministrator(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+  }
 }
index b8582407d835c8a904aad2dc78be79060bfad762..d9be6b3b90a2c915f213903780e2dc9d04729dbc 100644 (file)
@@ -173,7 +173,7 @@ public class UpdateEventActionTest {
 
   @Test
   public void fail_if_event_is_not_found() {
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Event 'E42' not found");
index 0d8702b61600d4dff96881fe99ee12be9864df5c..9904cc869f2bee5eb9bd785e2d1a477098c4e01d 100644 (file)
@@ -77,13 +77,12 @@ public class CreateActionTest {
     ComponentFinder componentFinder = new ComponentFinder(dbClient);
     underTest = new CreateAction(dbClient, userSession, componentFinder);
     ws = new WsActionTester(underTest);
-
-    userSession.logIn().setRoot();
   }
 
   @Test
   public void example_with_key() {
     ComponentDto project = insertProject();
+    logInAsProjectAdministrator(project);
 
     String result = ws.newRequest()
         .setMethod("POST")
@@ -98,6 +97,7 @@ public class CreateActionTest {
   @Test
   public void example_with_id() {
     ComponentDto project = insertProject();
+    logInAsProjectAdministrator(project);
 
     String result = ws.newRequest()
         .setMethod("POST")
@@ -112,13 +112,14 @@ public class CreateActionTest {
   @Test
   public void require_project_admin() throws IOException {
     ComponentDto project = insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
     createAndTest(project);
   }
 
   @Test
   public void with_long_name() throws IOException {
     ComponentDto project = insertProject();
+    logInAsProjectAdministrator(project);
 
     String longName = StringUtils.leftPad("", 60, "a");
     String expectedType = StringUtils.leftPad("", 20, "a");
@@ -128,6 +129,7 @@ public class CreateActionTest {
   @Test
   public void fail_if_no_name() {
     expectedException.expect(IllegalArgumentException.class);
+
     ws.newRequest()
         .setParam(PARAM_PROJECT_KEY, "unknown")
         .setParam(PARAM_URL, "http://example.org")
@@ -227,4 +229,8 @@ public class CreateActionTest {
   private void createAndTest(ComponentDto project) throws IOException {
     createAndTest(project, "Custom", "http://example.org", "custom");
   }
+
+  private void logInAsProjectAdministrator(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+  }
 }
index 9b24ba2b4c7453bb9b508fc82defd4e8becf431e..7463d6bdb69a172b1334d7501c87c8dd12ec62c9 100644 (file)
@@ -73,7 +73,7 @@ public class DeleteActionTest {
   public void no_response() {
     ComponentDto project = insertProject();
     ComponentLinkDto link = insertCustomLink(project.uuid());
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
 
     TestResponse response = deleteLink(link.getId());
 
@@ -86,7 +86,7 @@ public class DeleteActionTest {
     ComponentDto project = insertProject();
     ComponentLinkDto link = insertCustomLink(project.uuid());
     long id = link.getId();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    logInAsProjectAdministrator(project);
 
     deleteLink(id);
     assertLinkIsDeleted(id);
@@ -111,7 +111,7 @@ public class DeleteActionTest {
   public void fail_when_delete_provided_link() {
     ComponentDto project = insertProject();
     ComponentLinkDto link = insertHomepageLink(project.uuid());
-    userSession.logIn().setRoot();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(BadRequestException.class);
 
@@ -203,4 +203,8 @@ public class DeleteActionTest {
   private void assertLinkIsNotDeleted(Long id) {
     assertThat(dbClient.componentLinkDao().selectById(dbSession, id)).isNotNull();
   }
+
+  private void logInAsProjectAdministrator(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+  }
 }
index 93271a3841d6b66844a53723d09cc917c00015bd..301eca7f86b127a0eb56a8449ba6ba88246c79ef 100644 (file)
@@ -78,10 +78,10 @@ public class SearchActionTest {
 
   @Test
   public void example() {
-    logInAsRoot();
     ComponentDto project = insertProject();
     insertHomepageLink(project.uuid());
     insertCustomLink(project.uuid());
+    logInAsProjectAdministrator(project);
 
     String result = ws.newRequest()
       .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
@@ -92,9 +92,9 @@ public class SearchActionTest {
 
   @Test
   public void request_by_project_id() throws IOException {
-    logInAsRoot();
     ComponentDto project = insertProject();
     insertHomepageLink(project.uuid());
+    logInAsProjectAdministrator(project);
 
     SearchWsResponse response = callByUuid(project.uuid());
 
@@ -104,9 +104,9 @@ public class SearchActionTest {
 
   @Test
   public void request_by_project_key() throws IOException {
-    logInAsRoot();
     ComponentDto project = insertProject();
     insertHomepageLink(project.uuid());
+    logInAsProjectAdministrator(project);
 
     SearchWsResponse response = callByKey(project.key());
 
@@ -116,10 +116,10 @@ public class SearchActionTest {
 
   @Test
   public void response_fields() throws IOException {
-    logInAsRoot();
     ComponentDto project = insertProject();
     ComponentLinkDto homepageLink = insertHomepageLink(project.uuid());
     ComponentLinkDto customLink = insertCustomLink(project.uuid());
+    logInAsProjectAdministrator(project);
 
     SearchWsResponse response = callByKey(project.key());
 
@@ -132,11 +132,11 @@ public class SearchActionTest {
 
   @Test
   public void several_projects() throws IOException {
-    logInAsRoot();
     ComponentDto project1 = insertProject();
     ComponentDto project2 = insertProject("another", "abcd");
     ComponentLinkDto customLink1 = insertCustomLink(project1.uuid());
     insertCustomLink(project2.uuid());
+    userSession.logIn().setRoot();
 
     SearchWsResponse response = callByKey(project1.key());
 
@@ -146,20 +146,20 @@ public class SearchActionTest {
 
   @Test
   public void request_does_not_fail_when_link_has_no_name() throws IOException {
-    logInAsRoot();
     ComponentDto project = db.components().insertProject();
     ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setType("type");
     insertLink(foo);
+    logInAsProjectAdministrator(project);
 
     callByKey(project.key());
   }
 
   @Test
   public void request_does_not_fail_when_link_has_no_type() throws IOException {
-    logInAsRoot();
     ComponentDto project = db.components().insertProject();
     ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setName("name");
     insertLink(foo);
+    logInAsProjectAdministrator(project);
 
     callByKey(project.key());
   }
@@ -198,7 +198,7 @@ public class SearchActionTest {
   @Test
   public void fail_when_both_id_and_key_are_provided() {
     ComponentDto project = insertProject();
-    logInAsRoot();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(IllegalArgumentException.class);
     ws.newRequest()
@@ -272,7 +272,7 @@ public class SearchActionTest {
     assertThat(response.getLinks(0).getName()).isEqualTo("Homepage");
   }
 
-  private UserSessionRule logInAsRoot() {
-    return userSession.logIn().setRoot();
+  private void logInAsProjectAdministrator(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
   }
 }
index f4b3e839683fdcc828ab37afdbeb1c4a5a4cf48d..7d254e01226188f0423554c8b57f05223b572c50 100644 (file)
@@ -296,7 +296,7 @@ public class IndexActionTest {
 
   @Test
   public void return_secured_and_license_settings_when_system_admin() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build(),
@@ -328,7 +328,7 @@ public class IndexActionTest {
 
   @Test
   public void return_secured_and_license_settings_in_property_set_when_system_admin() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition
       .builder("foo")
       .type(PropertyType.PROPERTY_SET)
@@ -345,7 +345,7 @@ public class IndexActionTest {
 
   @Test
   public void return_all_settings_when_no_component_and_no_key() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build(),
@@ -471,8 +471,8 @@ public class IndexActionTest {
     userSession.logIn().addProjectUuidPermissions(USER, project.uuid());
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void logInAsProjectAdmin() {
index 4502c88a76950d86e25ea4c3ba292b5c5d72d007..f5868bb7d566f5718ce070af0095169c7eaffb24 100644 (file)
@@ -95,7 +95,7 @@ public class QualityGatesTest {
 
     underTest = new QualityGates(dbClient, metricFinder, userSession);
 
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
   }
 
   @Test
index e4cc42255cdee7e296d04ccb7e65ba5c6e127f49..4b6df910f9655f333932f2e51532a8a5495bd1ba 100644 (file)
@@ -75,7 +75,7 @@ public class DeselectActionTest {
 
   @Test
   public void deselect_by_id() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
 
     ComponentDto anotherProject = db.components().insertProject();
     String gateId = String.valueOf(gate.getId());
@@ -90,7 +90,7 @@ public class DeselectActionTest {
 
   @Test
   public void deselect_by_uuid() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
 
     String gateId = String.valueOf(gate.getId());
     associateProjectToQualityGate(project.getId(), gateId);
@@ -102,7 +102,7 @@ public class DeselectActionTest {
 
   @Test
   public void deselect_by_key() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
 
     String gateId = String.valueOf(gate.getId());
     associateProjectToQualityGate(project.getId(), gateId);
@@ -223,4 +223,8 @@ public class DeselectActionTest {
   private void assertSelected(String qGateId, long projectId) {
     assertThat(dbClient.propertiesDao().selectProjectProperty(projectId, SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(qGateId);
   }
+
+  private void logInAsRoot() {
+    userSession.logIn().setRoot();
+  }
 }
index d517a27f26bce30dc00ad917182435fce7a397e1..b55d30ff9d09019c6ee5bf375ccf805bb557ddb1 100644 (file)
@@ -193,7 +193,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_if_no_snapshot_id_found() {
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Analysis with id 'task-uuid' is not found");
@@ -215,7 +215,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_if_project_id_and_ce_task_id_provided() {
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
@@ -228,7 +228,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_if_no_parameter_provided() {
-    userSession.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
@@ -259,4 +259,8 @@ public class ProjectStatusActionTest {
       throw Throwables.propagate(e);
     }
   }
+
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
+  }
 }
index 8294f1072f7a6856a559a21f95660f6901bca9ea..eccbc6af3a254f69277f1319dab06284e853053c 100644 (file)
@@ -69,7 +69,7 @@ public class SelectActionTest {
 
   @Test
   public void select_by_id() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
     String gateId = String.valueOf(gate.getId());
 
     callById(gateId, project.getId());
@@ -79,7 +79,7 @@ public class SelectActionTest {
 
   @Test
   public void select_by_uuid() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
     String gateId = String.valueOf(gate.getId());
 
     callByUuid(gateId, project.uuid());
@@ -89,7 +89,7 @@ public class SelectActionTest {
 
   @Test
   public void select_by_key() throws Exception {
-    userSession.logIn().setRoot();
+    logInAsRoot();
     String gateId = String.valueOf(gate.getId());
 
     callByKey(gateId, project.getKey());
@@ -200,4 +200,8 @@ public class SelectActionTest {
   private void assertSelected(String gateId, Long projectId) {
     assertThat(dbClient.propertiesDao().selectProjectProperty(projectId, SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(gateId);
   }
+
+  private void logInAsRoot() {
+    userSession.logIn().setRoot();
+  }
 }
index dd5556517470da4b6de1dae47e28812c5b93169f..77e97c97b27c58dbf30b540e825e1a456344694e 100644 (file)
@@ -88,14 +88,14 @@ public class SearchActionTest {
 
   @Test
   public void execute_returns_empty_list_of_root_when_DB_is_empty() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     assertThat(executeRequest()).isEmpty();
   }
 
   @Test
-  public void execute_does_not_fail_when_root_user_has_neither_email_nor_name() {
-    makeAuthenticatedUserRoot();
+  public void execute_succeeds_when_root_user_has_neither_email_nor_name() {
+    logInAsRoot();
     UserDto rootDto = userDao.insert(dbSession, UserTesting.newUserDto().setName(null).setEmail(null));
     userDao.setRoot(dbSession, rootDto.getLogin(), true);
     dbSession.commit();
@@ -110,7 +110,7 @@ public class SearchActionTest {
 
   @Test
   public void execute_returns_root_users_sorted_by_name() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
     userDao.insert(dbSession, UserTesting.newUserDto().setName("ddd"));
     UserDto root1 = userDao.insert(dbSession, UserTesting.newUserDto().setName("ccc"));
     userDao.setRoot(dbSession, root1.getLogin(), true);
@@ -124,7 +124,7 @@ public class SearchActionTest {
       .containsExactly("bbb", "ccc");
   }
 
-  private UserSessionRule makeAuthenticatedUserRoot() {
+  private UserSessionRule logInAsRoot() {
     return userSessionRule.logIn().setRoot();
   }
 
index e94eb3cde3e26e87ae4d81d75f339f20bd37e83e..f086a2bd6e19dcc232e343273fc706f6b8e893c6 100644 (file)
@@ -95,7 +95,7 @@ public class SetRootActionTest {
 
   @Test
   public void execute_fails_with_IAE_when_login_param_is_not_provided() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'login' parameter is missing");
@@ -109,7 +109,7 @@ public class SetRootActionTest {
     userDao.insert(dbSession, otherUser);
     userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
     dbSession.commit();
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     executeRequest(SOME_LOGIN);
 
@@ -124,7 +124,7 @@ public class SetRootActionTest {
     userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
     userDao.setRoot(dbSession, SOME_LOGIN, true);
     dbSession.commit();
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     executeRequest(SOME_LOGIN);
 
@@ -134,7 +134,7 @@ public class SetRootActionTest {
 
   @Test
   public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User with login 'foo_bar' not found");
@@ -147,7 +147,7 @@ public class SetRootActionTest {
     UserDto userDto = UserTesting.newUserDto().setActive(false);
     userDao.insert(dbSession, userDto);
     dbSession.commit();
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
@@ -155,7 +155,7 @@ public class SetRootActionTest {
     executeRequest(userDto.getLogin());
   }
 
-  private void makeAuthenticatedUserRoot() {
+  private void logInAsRoot() {
     userSessionRule.logIn().setRoot();
   }
 
index b5ddbc02873ca5171a0afedef958fb692ae53e6b..63e4cb64dbf65e326b7a011616df240464779e05 100644 (file)
@@ -96,7 +96,7 @@ public class UnsetRootActionTest {
 
   @Test
   public void execute_fails_with_IAE_when_login_param_is_not_provided() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'login' parameter is missing");
@@ -108,7 +108,7 @@ public class UnsetRootActionTest {
   public void execute_makes_user_with_specified_login_not_root_when_it_is() {
     UserDto otherUser = insertRootUser(newUserDto());
     insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     executeRequest(SOME_LOGIN);
 
@@ -120,7 +120,7 @@ public class UnsetRootActionTest {
   public void execute_has_no_effect_when_user_is_already_not_root() {
     UserDto otherUser = insertRootUser(newUserDto());
     insertNonRootUser(newUserDto(SOME_LOGIN, "name", "email"));
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     executeRequest(SOME_LOGIN);
 
@@ -132,7 +132,7 @@ public class UnsetRootActionTest {
   public void execute_fails_with_BadRequestException_when_attempting_to_unset_root_on_last_root_user() {
     insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
     insertNonRootUser(newUserDto());
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Last root can't be unset");
@@ -144,7 +144,7 @@ public class UnsetRootActionTest {
   public void execute_fails_with_BadRequestException_when_attempting_to_unset_non_root_and_there_is_no_root_at_all() {
     UserDto userDto1 = newUserDto(SOME_LOGIN, "name", "email");
     insertNonRootUser(userDto1);
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Last root can't be unset");
@@ -154,7 +154,7 @@ public class UnsetRootActionTest {
 
   @Test
   public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User with login 'bar_foo' not found");
@@ -165,7 +165,7 @@ public class UnsetRootActionTest {
   @Test
   public void execute_fails_with_NotFoundException_when_user_for_specified_login_is_inactive() {
     UserDto userDto = insertRootUser(newUserDto().setActive(false));
-    makeAuthenticatedUserRoot();
+    logInAsRoot();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
@@ -186,7 +186,7 @@ public class UnsetRootActionTest {
     return dto;
   }
 
-  private void makeAuthenticatedUserRoot() {
+  private void logInAsRoot() {
     userSessionRule.logIn().setRoot();
   }
 
index ff2b3c3adbd1714c83e059932341ee1617cf0608..59d911d17b73df97bcdf58e8d6f2040329c8024a 100644 (file)
@@ -46,7 +46,7 @@ public class CreateActionMediumTest {
   public static ServerTester tester = new ServerTester().withEsIndexes();
 
   @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn().setRoot();
+  public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn().setSystemAdministrator();
 
   WsTester wsTester;
   RuleDao ruleDao;
index ab7572f12bd976f2f7b61e44cd126cc286a6a835..0d9fae02a37bfcc323d6efe7e13a256901632069 100644 (file)
@@ -68,7 +68,7 @@ public class GenerateActionTest {
 
   @Test
   public void persist_settings() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     when(generator.generate("SonarSource", "10.51.42.255")).thenReturn("server_id");
 
@@ -82,7 +82,7 @@ public class GenerateActionTest {
 
   @Test
   public void json_example() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     when(generator.generate("SonarSource", "127.0.0.1")).thenReturn("1818a1eefb26f9g");
 
@@ -96,7 +96,7 @@ public class GenerateActionTest {
 
   @Test
   public void log_message_when_id_generated() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     when(generator.generate("SonarSource", "127.0.0.1")).thenReturn("server_id");
 
     call("SonarSource", "127.0.0.1");
@@ -117,8 +117,8 @@ public class GenerateActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
 
@@ -127,7 +127,7 @@ public class GenerateActionTest {
 
   @Test
   public void fail_if_no_organization() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -136,7 +136,7 @@ public class GenerateActionTest {
 
   @Test
   public void fail_if_empty_organization() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -145,7 +145,7 @@ public class GenerateActionTest {
 
   @Test
   public void fail_if_no_ip() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -154,7 +154,7 @@ public class GenerateActionTest {
 
   @Test
   public void fail_if_empty_ip() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -189,7 +189,7 @@ public class GenerateActionTest {
     }
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 6f067ee53f566b3fe10db52b10ed8c932380349a..c3ba64096576d75e52580a6b97177e2d311f7696 100644 (file)
@@ -65,7 +65,7 @@ public class ShowActionTest {
 
   @Test
   public void return_server_id_info() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     when(generator.validate("home", "127.0.0.1", "1818a1eefb26f9g")).thenReturn(true);
     setAvailableIpAdresses("192.168.1.1", "127.0.0.1");
@@ -82,7 +82,7 @@ public class ShowActionTest {
 
   @Test
   public void return_invalid_server_id() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     when(generator.validate("home", "127.0.0.1", "1818a1eefb26f9g")).thenReturn(true);
     insertConfiguration("invalid", null, null);
 
@@ -97,7 +97,7 @@ public class ShowActionTest {
 
   @Test
   public void return_no_server_id_info_when_no_settings_and_no_available_ips() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     ShowWsResponse response = executeRequest();
 
@@ -110,7 +110,7 @@ public class ShowActionTest {
 
   @Test
   public void return_no_server_id_info_when_no_server_id_but_other_settings() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     insertConfiguration(null, "home", "127.0.0.1");
 
     ShowWsResponse response = executeRequest();
@@ -124,7 +124,7 @@ public class ShowActionTest {
 
   @Test
   public void return_available_ips_even_if_no_settings() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     setAvailableIpAdresses("192.168.1.1", "127.0.0.1");
 
     ShowWsResponse response = executeRequest();
@@ -137,8 +137,8 @@ public class ShowActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -158,7 +158,7 @@ public class ShowActionTest {
 
   @Test
   public void test_example_json_response() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     when(generator.validate("home", "127.0.0.1", "1818a1eefb26f9g")).thenReturn(true);
     setAvailableIpAdresses("192.168.1.1", "127.0.0.1");
     insertConfiguration("1818a1eefb26f9g", "home", "127.0.0.1");
@@ -203,7 +203,7 @@ public class ShowActionTest {
     }
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index ccd40ef87aa8136f62d80e0bde93b26249611422..426e71337af95b3844f52423c478bca200729cf0 100644 (file)
@@ -56,7 +56,7 @@ public class CheckSecretKeyActionTest {
 
   @Test
   public void json_example() throws IOException {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     File secretKeyFile = temporaryFolder.newFile();
     FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g==");
@@ -69,7 +69,7 @@ public class CheckSecretKeyActionTest {
 
   @Test
   public void false_when_no_secret_key() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     encryption.setPathToSecretKey("unknown/path/to_secret_key.txt");
 
@@ -91,8 +91,8 @@ public class CheckSecretKeyActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -112,7 +112,7 @@ public class CheckSecretKeyActionTest {
     }
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 1b19e67b8261ebd283efd3fb0e0c010cfd2b6157..a92fc5532334dff687bc09dea1d6fb84b4757cef 100644 (file)
@@ -60,7 +60,7 @@ public class EncryptActionTest {
 
   @Before
   public void setUpSecretKey() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     File secretKeyFile = folder.newFile();
     FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g==");
@@ -70,7 +70,7 @@ public class EncryptActionTest {
 
   @Test
   public void json_example() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     String result = ws.newRequest().setParam("value", "my value").execute().getInput();
 
@@ -79,7 +79,7 @@ public class EncryptActionTest {
 
   @Test
   public void encrypt() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     EncryptWsResponse result = call("my value!");
 
@@ -98,8 +98,8 @@ public class EncryptActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSession.logIn().setNonRoot();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -109,7 +109,7 @@ public class EncryptActionTest {
 
   @Test
   public void fail_if_value_is_not_provided() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
 
@@ -118,7 +118,7 @@ public class EncryptActionTest {
 
   @Test
   public void fail_if_value_is_empty() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Parameter 'value' must not be empty");
@@ -128,7 +128,7 @@ public class EncryptActionTest {
 
   @Test
   public void fail_if_no_secret_key_available() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     encryption.setPathToSecretKey("unknown/path/to/secret/key");
 
@@ -154,7 +154,7 @@ public class EncryptActionTest {
     }
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 }
index 4c8e1fcde3e2f5229691be6febca8e328e201e6e..07bb31a61f0e722a337d1e3b4fc8794d3444c091 100644 (file)
@@ -44,7 +44,7 @@ public class GenerateSecretKeyActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
@@ -78,8 +78,8 @@ public class GenerateSecretKeyActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index 61b1517acd8abc79fb5508999196c48d7d058036..a1aa790a07224a908bb3bc84d664c8853de29914 100644 (file)
@@ -89,7 +89,7 @@ public class ResetActionTest {
 
   @Test
   public void remove_global_setting() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").build());
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
 
@@ -99,7 +99,7 @@ public class ResetActionTest {
 
   @Test
   public void remove_global_setting_even_if_not_defined() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     executeRequestOnGlobalSetting("foo");
@@ -127,7 +127,7 @@ public class ResetActionTest {
 
   @Test
   public void remove_hidden_setting() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").hidden().build());
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
 
@@ -137,7 +137,7 @@ public class ResetActionTest {
 
   @Test
   public void ignore_project_setting_when_removing_global_setting() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
     propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
 
@@ -161,7 +161,7 @@ public class ResetActionTest {
 
   @Test
   public void ignore_user_setting_when_removing_global_setting() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
     propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
 
@@ -181,14 +181,14 @@ public class ResetActionTest {
 
   @Test
   public void ignore_unknown_setting_key() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     executeRequestOnGlobalSetting("unknown");
   }
 
   @Test
   public void remove_setting_by_deprecated_key() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").deprecatedKey("old").build());
     propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
 
@@ -198,7 +198,7 @@ public class ResetActionTest {
 
   @Test
   public void empty_204_response() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     TestResponse result = ws.newRequest()
       .setParam("keys", "my.key")
       .execute();
@@ -218,8 +218,8 @@ public class ResetActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_global_setting_and_not_root() throws Exception {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_global_setting_and_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").build());
 
     expectedException.expect(ForbiddenException.class);
@@ -239,9 +239,20 @@ public class ResetActionTest {
     executeRequestOnComponentSetting("foo", project);
   }
 
+  @Test
+  public void throw_ForbiddenException_if_project_setting_and_system_administrator() throws Exception {
+    logInAsSystemAdministrator();
+    definitions.addComponent(PropertyDefinition.builder("foo").build());
+
+    expectedException.expect(ForbiddenException.class);
+    expectedException.expectMessage("Insufficient privileges");
+
+    executeRequestOnComponentSetting("foo", project);
+  }
+
   @Test
   public void fail_when_not_global_and_no_component() {
-    logInAsRoot();
+    logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo")
       .onlyOnQualifiers(VIEW)
       .build());
@@ -254,7 +265,7 @@ public class ResetActionTest {
 
   @Test
   public void fail_when_qualifier_not_included() {
-    logInAsRoot();
+    userSession.logIn().setRoot();
     definitions.addComponent(PropertyDefinition.builder("foo")
       .onQualifiers(VIEW)
       .build());
@@ -268,7 +279,8 @@ public class ResetActionTest {
 
   @Test
   public void fail_to_reset_setting_component_when_setting_is_global() {
-    logInAsRoot();
+    userSession.logIn().setRoot();
+
     definitions.addComponent(PropertyDefinition.builder("foo").build());
     i18n.put("qualifier." + PROJECT, "project");
 
@@ -300,8 +312,8 @@ public class ResetActionTest {
     request.execute();
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void logInAsProjectAdmin() {
index ef5c7b7ac3b0644381009d337cb48c3413852264..efb9db0f16a532de3047d9a419f88ccf520aad6b 100644 (file)
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
 import java.net.HttpURLConnection;
 import java.util.List;
 import javax.annotation.Nullable;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -71,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();
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
@@ -89,6 +90,12 @@ public class SetActionTest {
 
   private WsActionTester ws = new WsActionTester(underTest);
 
+  @Before
+  public void setUp() {
+    // by default test doesn't care about permissions
+    userSession.logIn().setSystemAdministrator();
+  }
+
   @Test
   public void empty_204_response() {
     TestResponse result = ws.newRequest()
@@ -123,6 +130,7 @@ public class SetActionTest {
   public void persist_new_project_setting() {
     propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
     ComponentDto project = db.components().insertProject();
+    logInAsProjectAdministrator(project);
 
     callForProjectSettingByKey("my.key", "my project value", project.key());
 
@@ -134,7 +142,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());
+    logInAsProjectAdministrator(project);
 
     callForProjectSettingByKey("my.key", "my value", project.key());
 
@@ -147,6 +155,7 @@ public class SetActionTest {
     ComponentDto project = db.components().insertProject();
     propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project));
     assertComponentSetting("my.key", "my project value", project.getId());
+    logInAsProjectAdministrator(project);
 
     callForProjectSettingByKey("my.key", "my new project value", project.key());
 
@@ -282,6 +291,7 @@ public class SetActionTest {
       newComponentPropertyDto("my.key", "1", project),
       newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project),
       newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project));
+    logInAsProjectAdministrator(project);
 
     callForComponentPropertySet("my.key", newArrayList(
       GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")),
@@ -421,8 +431,8 @@ public class SetActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -542,6 +552,7 @@ public class SetActionTest {
     i18n.put("qualifier." + Qualifiers.VIEW, "View");
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Setting 'my.key' cannot be set on a View");
+    logInAsProjectAdministrator(view);
 
     callForProjectSettingByKey("my.key", "My Value", view.key());
   }
@@ -786,6 +797,7 @@ public class SetActionTest {
       .build());
     i18n.put("qualifier." + Qualifiers.PROJECT, "Project");
     ComponentDto project = db.components().insertProject();
+    logInAsProjectAdministrator(project);
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Setting 'my.key' cannot be set on a Project");
@@ -871,8 +883,8 @@ public class SetActionTest {
   }
 
   private static class FakeSettingsNotifier extends SettingsChangeNotifier {
-    private final DbClient dbClient;
 
+    private final DbClient dbClient;
     private boolean wasCalled = false;
 
     private FakeSettingsNotifier(DbClient dbClient) {
@@ -886,5 +898,9 @@ public class SetActionTest {
 
       assertThat(property.getValue()).isEqualTo(value);
     }
+
+  }
+  private void logInAsProjectAdministrator(ComponentDto project) {
+    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
   }
 }
index b38481f22ca8133a778262d37862218f5d896fff..20e4b2ef9bfd20239903e0c2f7731fcf27fe38d4 100644 (file)
@@ -82,6 +82,6 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession>
 
   @Override
   public boolean isSystemAdministrator() {
-    return systemAdministrator;
+    return isRoot() || systemAdministrator;
   }
 }
index f71e74df9469db75ba9b1b1f55d6df0a0ce9160d..13e76f9bdab724d0877a421daee6302605bd7019 100644 (file)
@@ -285,12 +285,6 @@ public class UserSessionRule implements TestRule, UserSession {
     return currentUserSession.isRoot();
   }
 
-  @Override
-  public UserSession checkIsRoot() {
-    currentUserSession.checkIsRoot();
-    return this;
-  }
-
   @Override
   public UserSession checkLoggedIn() {
     currentUserSession.checkLoggedIn();
index 742c1f23f2a9dd0a1aaa833d1111f02e31fe2565..a1bc33f96f25d5223ac0c35a2cc7e46ae39438d2 100644 (file)
@@ -46,35 +46,35 @@ public class SettingsActionTest {
   private WsActionTester ws;
 
   @Test
-  public void empty() throws Exception {
+  public void empty() {
     init();
-    userSessionRule.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     executeAndVerify("empty.json");
   }
 
   @Test
-  public void with_pages() throws Exception {
+  public void returns_page_settings() {
     init(createPages());
-    userSessionRule.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     executeAndVerify("with_pages.json");
   }
 
   @Test
-  public void with_update_center() throws Exception {
+  public void returns_update_center_settings() {
     init();
     settings.setProperty(WebConstants.SONAR_UPDATECENTER_ACTIVATE, true);
-    userSessionRule.logIn().setRoot();
+    logInAsSystemAdministrator();
 
     executeAndVerify("with_update_center.json");
   }
 
   @Test
-  public void with_views_and_update_center_but_not_root_administrator() throws Exception {
+  public void request_succeeds_but_settings_are_not_returned_when_user_is_not_system_administrator() {
     init(createPages());
     settings.setProperty(WebConstants.SONAR_UPDATECENTER_ACTIVATE, true);
-    userSessionRule.logIn().setNonRoot();
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     executeAndVerify("empty.json");
   }
@@ -101,4 +101,8 @@ public class SettingsActionTest {
 
     return new Page[] {firstPage, secondPage};
   }
+
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
+  }
 }
index 1ebaf730b12ecb907558025d59f8051653eea535..e27fd8b147d6ca0a2bb75bc268808c8122fac80a 100644 (file)
@@ -66,7 +66,7 @@ public class UploadActionTest {
 
   @Test
   public void upload_plugin() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     TestResponse response = call(newInputStream(plugin.toPath()), PLUGIN_NAME);
 
@@ -76,7 +76,7 @@ public class UploadActionTest {
 
   @Test
   public void erase_existing_plugin_if_already_exists() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     File plugin1 = new File(getClass().getResource("UploadActionTest/plugin.jar").getFile());
     call(newInputStream(plugin1.toPath()), PLUGIN_NAME);
@@ -91,7 +91,7 @@ public class UploadActionTest {
 
   @Test
   public void fail_when_plugin_extension_is_not_jar() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Only jar file is allowed");
@@ -100,7 +100,7 @@ public class UploadActionTest {
 
   @Test
   public void fail_when_no_files_param() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'file' parameter is missing");
@@ -109,7 +109,7 @@ public class UploadActionTest {
 
   @Test
   public void input_stream_should_be_closed() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     InputStream inputStream = newInputStream(plugin.toPath());
     call(inputStream, PLUGIN_NAME);
@@ -120,8 +120,8 @@ public class UploadActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSession.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSession.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -135,8 +135,8 @@ public class UploadActionTest {
       .execute();
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void assertPluginIsUploaded(String pluginName) {
index 8ea0020235ad2e0efe84e279dfc19f4fbd37f799..a4e852065d9ab14feb1e6073a82d9daa1dbc7faa 100644 (file)
@@ -119,20 +119,6 @@ public class ServerUserSessionTest {
     assertThat(newUserSession(NON_ROOT_USER_DTO).isRoot()).isFalse();
   }
 
-  @Test
-  public void checkIsRoot_fails_with_ForbiddenException_when_flag_is_false_on_UserDto() {
-    expectInsufficientPrivilegesForbiddenException();
-
-    newUserSession(NON_ROOT_USER_DTO).checkIsRoot();
-  }
-
-  @Test
-  public void checkIsRoot_does_not_fails_when_flag_is_true_on_UserDto() {
-    ServerUserSession underTest = newUserSession(ROOT_USER_DTO);
-
-    assertThat(underTest.checkIsRoot()).isSameAs(underTest);
-  }
-
   @Test
   public void hasComponentUuidPermission_returns_true_if_user_has_project_permission_for_given_uuid_in_db() {
     addProjectPermissions(project, UserRole.USER);
index d0d1ab19647372a5a79448a274228b579997dc25..78db3b899592368e41ded11d5f4cfcaf1229e5d6 100644 (file)
@@ -82,7 +82,7 @@ public class ChangePasswordActionTest {
 
   @Test
   public void fail_on_unknown_user() throws Exception {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
 
     expectedException.expect(NotFoundException.class);
 
@@ -93,8 +93,8 @@ public class ChangePasswordActionTest {
   }
 
   @Test
-  public void root_can_update_password_of_user() throws Exception {
-    userSessionRule.logIn().setRoot();
+  public void system_administrator_can_update_password_of_user() throws Exception {
+    userSessionRule.logIn().setSystemAdministrator();
     createUser();
     String originalPassword = db.getDbClient().userDao().selectOrFailByLogin(db.getSession(), "john").getCryptedPassword();
 
@@ -152,7 +152,7 @@ public class ChangePasswordActionTest {
 
   @Test
   public void fail_to_update_password_on_external_auth() throws Exception {
-    userSessionRule.logIn().setRoot();
+    userSessionRule.logIn().setSystemAdministrator();
 
     userUpdater.create(NewUser.builder()
       .setEmail("john@email.com")
index c5347fc49b9f77bf107117f52f1be856de713369..003b29d968024369d58c32dc78442e057eeed567 100644 (file)
@@ -90,7 +90,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     CreateWsResponse response = call(CreateRequest.builder()
       .setLogin("john")
@@ -121,7 +121,7 @@ public class CreateActionTest {
 
   @Test
   public void create_local_user() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     call(CreateRequest.builder()
       .setLogin("john")
@@ -137,7 +137,7 @@ public class CreateActionTest {
 
   @Test
   public void create_none_local_user() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     call(CreateRequest.builder()
       .setLogin("john")
@@ -152,7 +152,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_comma_in_scm_account() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     CreateWsResponse response = call(CreateRequest.builder()
       .setLogin("john")
@@ -167,7 +167,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_deprecated_scmAccounts_parameter() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     tester.newRequest()
       .setParam("login", "john")
@@ -181,7 +181,7 @@ public class CreateActionTest {
 
   @Test
   public void create_user_with_deprecated_scm_accounts_parameter() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     tester.newRequest()
       .setParam("login", "john")
@@ -195,7 +195,7 @@ public class CreateActionTest {
 
   @Test
   public void reactivate_user() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     db.users().insertUser(newUserDto("john", "John", "john@email.com"));
     db.getDbClient().userDao().deactivateUserByLogin(db.getSession(), "john");
@@ -218,7 +218,7 @@ public class CreateActionTest {
     OrganizationDto otherOrganization = db.organizations().insert();
     GroupDto group = db.users().insertGroup(otherOrganization);
     setDefaultGroupProperty(group);
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(ServerException.class);
     expectedException.expectMessage("The default group '" + group.getName() + "' for new users does not exist. " +
@@ -229,7 +229,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_missing_login() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Login is mandatory and must not be empty");
@@ -242,7 +242,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_missing_name() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name is mandatory and must not be empty");
@@ -255,7 +255,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_missing_password() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Password is mandatory and must not be empty");
@@ -268,7 +268,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_password_is_set_on_none_local_user() throws Exception {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Password should only be set on local user");
@@ -281,8 +281,8 @@ public class CreateActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_root() throws Exception {
-    userSessionRule.logIn();
+  public void throw_ForbiddenException_if_not_system_administrator() throws Exception {
+    userSessionRule.logIn().setNonSystemAdministrator();
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("");
@@ -305,8 +305,8 @@ public class CreateActionTest {
       .build());
   }
 
-  private void logInAsRoot() {
-    userSessionRule.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSessionRule.logIn().setSystemAdministrator();
   }
 
   private CreateWsResponse call(CreateRequest createRequest) {
index 9e46c609013f18460cb2859c65962ec63aabf440..783cce58adb6b8952f6ed50ba18c08105ff8ad3d 100644 (file)
@@ -101,7 +101,7 @@ public class DeactivateActionTest {
       .setEmail("ada.lovelace@noteg.com")
       .setName("Ada Lovelace")
       .setScmAccounts(singletonList("al")));
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     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()).setRoot();
+    userSession.logIn(user.getLogin()).setSystemAdministrator();
 
     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 {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     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 {
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     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);
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     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);
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     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();
-    logInAsRoot();
+    logInAsSystemAdministrator();
 
     deactivate(admin.getLogin());
 
@@ -229,8 +229,8 @@ public class DeactivateActionTest {
     return user;
   }
 
-  private void logInAsRoot() {
-    userSession.logIn().setRoot();
+  private void logInAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private TestResponse deactivate(String login) {
index 5449d97a380e4f32b8a258f36ae26354da38218d..a5d414eb2a6af5b3bf164be274eb894b198e7bd6 100644 (file)
@@ -68,7 +68,7 @@ public class GroupsActionTest {
     session.commit();
 
     tester = new WsTester(new UsersWs(new GroupsAction(dbClient, userSession)));
-    userSession.logIn().setRoot();
+    userSession.logIn().setSystemAdministrator();
   }
 
   @After
index 9c071a42c1942636215a68881f771dca18c3cb6d..1c32c67a955ef53c763d667b3c8b84d6cd426e32 100644 (file)
@@ -93,7 +93,7 @@ public class SearchActionTest {
     dbClient.userTokenDao().insert(dbSession, newUserToken().setLogin(fmallet.getLogin()));
     db.commit();
     userIndexer.index();
-    loginAsRoot();
+    loginAsSystemAdministrator();
 
     String response = ws.newGetRequest("api/users", "search").execute().outputAsString();
 
@@ -176,7 +176,7 @@ public class SearchActionTest {
       .doesNotContain("scmAccounts")
       .doesNotContain("groups");
 
-    loginAsRoot();
+    loginAsSystemAdministrator();
 
     assertThat(ws.newGetRequest("api/users", "search").execute().outputAsString())
       .contains("login")
@@ -195,7 +195,7 @@ public class SearchActionTest {
 
   @Test
   public void search_with_groups() throws Exception {
-    loginAsRoot();
+    loginAsSystemAdministrator();
     List<UserDto> users = injectUsers(1);
 
     GroupDto group1 = dbClient.groupDao().insert(dbSession, newGroupDto().setName("sonar-users"));
@@ -259,8 +259,8 @@ public class SearchActionTest {
     return userDtos;
   }
 
-  private void loginAsRoot() {
-    userSession.logIn().setRoot();
+  private void loginAsSystemAdministrator() {
+    userSession.logIn().setSystemAdministrator();
   }
 
   private void loginAsSimpleUser() {
index 0fe41a514719e2a86105927ed68ee89ee9d89c32..08c66a222c18c033584495fd8f3b2b06e638b8ac 100644 (file)
@@ -61,7 +61,7 @@ public class UpdateActionTest {
   @Rule
   public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
   @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn().setRoot();
+  public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn().setSystemAdministrator();
 
   private DbClient dbClient = dbTester.getDbClient();
   private DbSession session = dbTester.getSession();