diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-06-08 23:33:28 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-06-12 20:02:49 +0000 |
commit | 8a4213f80ea3ed3f42acb76ce3359c37ee03b34e (patch) | |
tree | 5a60bda64f2b91dc7842ba43005b51a661c2f185 /server | |
parent | a1f697f122a7bf7f4c32d04f55bee1d0bbc5c956 (diff) | |
download | sonarqube-8a4213f80ea3ed3f42acb76ce3359c37ee03b34e.tar.gz sonarqube-8a4213f80ea3ed3f42acb76ce3359c37ee03b34e.zip |
SONAR-19525 Fix selectByKeyCaseInsensitive components query in order to properly return portfolios
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml | 2 | ||||
-rw-r--r-- | server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java | 18 |
2 files changed, 19 insertions, 1 deletions
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 7f897a7090f..da43df99c77 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 @@ -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"/> diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java index 2fff57a6f82..033a357fc1a 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java @@ -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() { |