]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18397 Add SCIM protocol DELETE /Users endpoint.
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Wed, 8 Feb 2023 14:00:03 +0000 (15:00 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Feb 2023 20:03:34 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimUserMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/scim/ScimUserDaoTest.java

index 44fdeb33bc93dc2ed2afb06cb7092a9e82d1521f..9476e7d842d88c585fd78699875317ade650d668 100644 (file)
@@ -66,4 +66,8 @@ public class ScimUserDao implements Dao {
   public void deleteByUserUuid(DbSession dbSession, String userUuid) {
     mapper(dbSession).deleteByUserUuid(userUuid);
   }
+
+  public void deleteByScimUuid(DbSession dbSession, String scimUuid) {
+    mapper(dbSession).deleteByScimUuid(scimUuid);
+  }
 }
index 5958f3967a07f05724949e00f63e838731e11acc..c850448f0f3650feb1054641546c2c3c29748f9f 100644 (file)
@@ -41,4 +41,6 @@ public interface ScimUserMapper {
   int countScimUsers(@Param("query") ScimUserQuery scimUserQuery);
 
   void deleteByUserUuid(@Param("userUuid") String userUuid);
+
+  void deleteByScimUuid(@Param("scimUuid") String scimUuid);
 }
index 2c99a131fc0d514eaccd6f4867c2e27c4bc8826a..734cbb15a262968f375947cfa076444f786085de 100644 (file)
@@ -64,5 +64,9 @@
     delete from scim_users where user_uuid = #{userUuid, jdbcType=VARCHAR}
   </delete>
 
+  <delete id="deleteByScimUuid" parameterType="String">
+    delete from scim_users where scim_uuid = #{scimUuid, jdbcType=VARCHAR}
+  </delete>
+
 </mapper>
 
index 26fc9ae6e451c93d4405ef6e84affe2a8b07f259..ba7983ef674a5dd89e27c54ea67ebe330b8c8bc5 100644 (file)
@@ -201,7 +201,7 @@ public class ScimUserDaoTest {
   }
 
   @Test
-  public void deleteFromUserUuid_shouldDeleteScimUser() {
+  public void deleteByUserUuid_shouldDeleteScimUser() {
     ScimUserTestData scimUserTestData = insertScimUser("scimUser");
 
     scimUserDao.deleteByUserUuid(dbSession, scimUserTestData.getUserUuid());
@@ -209,6 +209,21 @@ public class ScimUserDaoTest {
     assertThat(scimUserDao.findAll(dbSession)).isEmpty();
   }
 
+  @Test
+  public void deleteByScimUuid_shouldDeleteScimUser() {
+    ScimUserTestData scimUserTestData = insertScimUser("scimUser");
+    ScimUserTestData scimUserTestData2 = insertScimUser("scimUser2");
+
+    scimUserDao.deleteByScimUuid(dbSession, scimUserTestData.getScimUserUuid());
+
+    List<ScimUserDto> remainingUsers = scimUserDao.findAll(dbSession);
+    assertThat(remainingUsers).hasSize(1);
+
+    ScimUserDto remainingUser = remainingUsers.get(0);
+    assertThat(remainingUser.getScimUserUuid()).isEqualTo(scimUserTestData2.scimUserUuid);
+    assertThat(remainingUser.getUserUuid()).isEqualTo(scimUserTestData2.userUuid);
+  }
+
   @Test
   public void deleteFromUserUuid_shouldNotFail_whenNoUser() {
     assertThatCode(() -> scimUserDao.deleteByUserUuid(dbSession, randomAlphanumeric(6))).doesNotThrowAnyException();