]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19525 Fix selectByKeyCaseInsensitive components query in order to properly...
authorMatteo Mara <matteo.mara@sonarsource.com>
Thu, 8 Jun 2023 21:33:28 +0000 (23:33 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 12 Jun 2023 20:02:49 +0000 (20:02 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java

index 7f897a7090f2766acd6450f58ac594219010a3e4..da43df99c778de68a296ce9a08976b1d1181cfaa 100644 (file)
@@ -39,7 +39,7 @@
     SELECT
       <include refid="componentColumns"/>
     FROM components p
-    inner join project_branches pb on pb.uuid = p.branch_uuid
+    left outer join project_branches pb on pb.uuid = p.branch_uuid
     where
       lower(p.kee)=lower(#{key,jdbcType=VARCHAR})
       and <include refid="mainBranchOrPortfolio"/>
index 2fff57a6f82dd200443df058b8cf9b6ae6bb8f0f..033a357fc1a83418c1fdfe4f5cacfda1298b09dc 100644 (file)
@@ -374,6 +374,24 @@ public class ComponentUpdaterIT {
       .hasMessage("Could not create Project with key: \"%s\". A similar key already exists: \"%s, %s\"", newKey, existingKey, existingKeyLowerCase);
   }
 
+  @Test
+  public void createComponent_shouldFail_whenCreatingComponentWithMultipleExistingPortfolioKeysButDifferentCase() {
+    String existingKey = randomAlphabetic(5).toUpperCase();
+    String existingKeyLowerCase = existingKey.toLowerCase();
+    db.components().insertPrivatePortfolio(portfolio -> portfolio.setKey(existingKey));
+    db.components().insertPrivatePortfolio(portfolio -> portfolio.setKey(existingKeyLowerCase));
+    String newKey = StringUtils.capitalize(existingKeyLowerCase);
+
+    NewComponent newComponent = NewComponent.newComponentBuilder()
+      .setKey(newKey)
+      .setName(DEFAULT_PROJECT_NAME)
+      .build();
+
+    DbSession dbSession = db.getSession();
+    assertThatThrownBy(() -> underTest.create(dbSession, newComponent, null, null))
+      .isInstanceOf(BadRequestException.class)
+      .hasMessage("Could not create Project with key: \"%s\". A similar key already exists: \"%s, %s\"", newKey, existingKey, existingKeyLowerCase);
+  }
 
   @Test
   public void create_createsComponentWithMasterBranchName() {