]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18525 Support of DELETE verb for /api/scim/v2/Groups
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Fri, 24 Feb 2023 12:59:51 +0000 (13:59 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 22 Mar 2023 20:04:06 +0000 (20:04 +0000)
server/sonar-db-dao/src/test/java/org/sonar/db/scim/ScimGroupDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java

index 95fc808f0372839b7b147d68a7a01a04fda950d5..75d52cb5203a459f30556b58ae15a88ea89d701b 100644 (file)
@@ -45,8 +45,8 @@ public class ScimGroupDaoTest {
 
   @Test
   public void findAll_returnsAllEntries() {
-    ScimGroupDto scimGroup1 = insertScimGroup();
-    ScimGroupDto scimGroup2 = insertScimGroup();
+    ScimGroupDto scimGroup1 = db.users().insertScimGroup(db.users().insertGroup());
+    ScimGroupDto scimGroup2 = db.users().insertScimGroup(db.users().insertGroup());
 
     List<ScimGroupDto> underTest = scimGroupDao.findAll(db.getSession());
 
@@ -65,8 +65,8 @@ public class ScimGroupDaoTest {
 
   @Test
   public void findByScimUuid_whenScimUuidFound_shouldReturnDto() {
-    ScimGroupDto scimGroupDto = insertScimGroup();
-    insertScimGroup();
+    ScimGroupDto scimGroupDto = db.users().insertScimGroup(db.users().insertGroup());
+    db.users().insertScimGroup(db.users().insertGroup());
 
     ScimGroupDto underTest = scimGroupDao.findByScimUuid(db.getSession(), scimGroupDto.getScimGroupUuid())
       .orElseGet(() -> fail("Group not found"));
@@ -82,8 +82,8 @@ public class ScimGroupDaoTest {
 
   @Test
   public void findByGroupUuid_whenScimUuidFound_shouldReturnDto() {
-    ScimGroupDto scimGroupDto = insertScimGroup();
-    insertScimGroup();
+    ScimGroupDto scimGroupDto = db.users().insertScimGroup(db.users().insertGroup());
+    db.users().insertScimGroup(db.users().insertGroup());
 
     ScimGroupDto underTest = scimGroupDao.findByGroupUuid(db.getSession(), scimGroupDto.getGroupUuid())
       .orElseGet(() -> fail("Group not found"));
@@ -104,7 +104,7 @@ public class ScimGroupDaoTest {
 
   @Test
   public void deleteByGroupUuid_shouldDeleteScimGroup() {
-    ScimGroupDto scimGroupDto = insertScimGroup();
+    ScimGroupDto scimGroupDto = db.users().insertScimGroup(db.users().insertGroup());
 
     scimGroupDao.deleteByGroupUuid(db.getSession(), scimGroupDto.getGroupUuid());
 
@@ -113,8 +113,8 @@ public class ScimGroupDaoTest {
 
   @Test
   public void deleteByScimUuid_shouldDeleteScimGroup() {
-    ScimGroupDto scimGroupDto1 = insertScimGroup();
-    ScimGroupDto scimGroupDto2 = insertScimGroup();
+    ScimGroupDto scimGroupDto1 = db.users().insertScimGroup(db.users().insertGroup());
+    ScimGroupDto scimGroupDto2 = db.users().insertScimGroup(db.users().insertGroup());
 
     scimGroupDao.deleteByScimUuid(db.getSession(), scimGroupDto1.getScimGroupUuid());
 
@@ -131,7 +131,4 @@ public class ScimGroupDaoTest {
     assertThatCode(() -> scimGroupDao.deleteByGroupUuid(db.getSession(), randomAlphanumeric(6))).doesNotThrowAnyException();
   }
 
-  private ScimGroupDto insertScimGroup() {
-    return scimGroupDao.enableScimForGroup(db.getSession(), randomAlphanumeric(40));
-  }
 }
index 46cacd0142d993326b8f4f2e66e14a308d28d460..190d02994781b60770beda38bf64bfe6d30a3799 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.permission.GroupPermissionDto;
 import org.sonar.db.permission.UserPermissionDto;
 import org.sonar.db.project.ProjectDto;
+import org.sonar.db.scim.ScimGroupDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Arrays.stream;
@@ -136,6 +137,12 @@ public class UserDbTester {
     return dto;
   }
 
+  public ScimGroupDto insertScimGroup(GroupDto dto) {
+    ScimGroupDto result = db.getDbClient().scimGroupDao().enableScimForGroup(db.getSession(), dto.getUuid());
+    db.commit();
+    return result;
+  }
+
   public GroupDto insertDefaultGroup() {
     GroupDto dto = db.getDbClient().groupDao().insert(db.getSession(), newGroupDto().setName(DefaultGroups.USERS).setDescription("Users"));
     db.commit();
index 713ee70379e8b4131fa1e53cb312f37265f840d9..858ea93d32e06dbfd8bc15dace00fc99fafba369 100644 (file)
@@ -180,6 +180,22 @@ public class DeleteActionIT {
     assertThat(db.countRowsOfTable("qgate_group_permissions")).isZero();
   }
 
+  @Test
+  public void delete_scim_group() {
+    addAdmin();
+    insertDefaultGroup();
+    GroupDto group = db.users().insertGroup();
+    db.users().insertScimGroup(group);
+
+    loginAsAdmin();
+
+    newRequest()
+      .setParam(PARAM_GROUP_NAME, group.getName())
+      .execute();
+
+    assertThat(db.countRowsOfTable("scim_groups")).isZero();
+  }
+
 
   @Test
   public void fail_to_delete_default_group() {
index c726a7dd37e486af4d15cc3d977eef7375ccd98e..d8cb25807c948cb674a708541dc3ef9a70e65700 100644 (file)
@@ -76,6 +76,7 @@ public class DeleteAction implements UserGroupsWsAction {
       removeGroupMembers(dbSession, group);
       dbClient.qProfileEditGroupsDao().deleteByGroup(dbSession, group);
       dbClient.qualityGateGroupPermissionsDao().deleteByGroup(dbSession, group);
+      dbClient.scimGroupDao().deleteByGroupUuid(dbSession, group.getUuid());
       dbClient.groupDao().deleteByUuid(dbSession, group.getUuid(), group.getName());
 
       dbSession.commit();