From 6f85804537da5fb66a091458dfdef4bd12da2572 Mon Sep 17 00:00:00 2001 From: Antoine Vinot Date: Thu, 29 Sep 2022 10:11:41 +0200 Subject: [PATCH] SONAR-17389 - Prevent project creation with existing key but different case --- .../org/sonar/db/component/ComponentDao.java | 4 +++ .../sonar/db/component/ComponentMapper.java | 7 ++-- .../sonar/db/component/ComponentMapper.xml | 8 +++++ .../sonar/db/component/ComponentDaoTest.java | 21 ++++++++++++ .../exceptions/BadRequestException.java | 12 ++++--- .../server/component/ComponentUpdater.java | 32 ++++++++++++------- .../sonar/server/component/NewComponent.java | 4 +++ .../azure/ImportAzureProjectActionTest.java | 8 +++-- .../ImportBitbucketCloudRepoActionTest.java | 8 +++-- ...mportBitbucketServerProjectActionTest.java | 8 +++-- .../component/ComponentUpdaterTest.java | 22 +++++++++++-- .../server/component/NewComponentTest.java | 23 ++++++++++++- 12 files changed, 128 insertions(+), 29 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index afaba3af0e2..b11d2801afd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -241,6 +241,10 @@ public class ComponentDao implements Dao { return Optional.ofNullable(mapper(session).selectByKey(key)); } + public Optional selectByKeyCaseInsensitive(DbSession session, String key) { + return Optional.ofNullable(mapper(session).selectByKeyCaseInsensitive(key)); + } + public Optional selectByKeyAndBranch(DbSession session, String key, String branch) { return Optional.ofNullable(mapper(session).selectBranchByKeyAndBranchKey(key, generateBranchKey(key, branch), branch)); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index 2d827bee828..e62a69a23b7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -31,7 +31,10 @@ import org.apache.ibatis.session.RowBounds; public interface ComponentMapper { @CheckForNull - ComponentDto selectByKey(String key); + ComponentDto selectByKey(@Param("key") String key); + + @CheckForNull + ComponentDto selectByKeyCaseInsensitive(@Param("key") String key); @CheckForNull ComponentDto selectBranchByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); @@ -40,7 +43,7 @@ public interface ComponentMapper { ComponentDto selectPrByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); @CheckForNull - ComponentDto selectByUuid(String uuid); + ComponentDto selectByUuid(@Param("uuid") String uuid); /** * Return sub project of component keys diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 05d2e777fe1..aed19c345e9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -32,6 +32,14 @@ p.kee=#{key,jdbcType=VARCHAR} + +