aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdana <bogdana.kushnir@sonarsource.com>2024-03-20 12:32:10 +0200
committersonartech <sonartech@sonarsource.com>2024-03-20 20:02:43 +0000
commitf1a28bea68587ca593ac67f3210fdec89a4ca294 (patch)
treeee9b8813eb4d525e71a05cc57ca55f1b079ef2f5
parent0ae8d1634c2369bc24e71d2f46e6193c0db5caa4 (diff)
downloadsonarqube-f1a28bea68587ca593ac67f3210fdec89a4ca294.tar.gz
sonarqube-f1a28bea68587ca593ac67f3210fdec89a4ca294.zip
SONAR-21881 Fix SSF-569 on the LTS
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/almIntegration/BitbucketServerForm.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/almIntegration/GitlabForm.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/BitbucketServerForm-test.tsx.snap2
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GitlabForm-test.tsx.snap6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateGitlabAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java16
-rw-r--r--sonar-core/src/main/resources/org/sonar/l10n/core.properties2
7 files changed, 22 insertions, 11 deletions
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/BitbucketServerForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/BitbucketServerForm.tsx
index 946974835ec..2d6d7ae09c7 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/BitbucketServerForm.tsx
+++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/BitbucketServerForm.tsx
@@ -51,7 +51,7 @@ export default function BitbucketServerForm(props: BitbucketServerFormProps) {
{translate('settings.almintegration.form.url.bitbucket.help')}
<br />
<br />
- {translate('settings.almintegration.form.url.bitbucket.pat_warning')}
+ {translate('settings.almintegration.form.url.pat_warning')}
</>
}
id="url.bitbucket"
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GitlabForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GitlabForm.tsx
index f9958efcefc..542aaadbc7c 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GitlabForm.tsx
+++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/GitlabForm.tsx
@@ -51,6 +51,9 @@ export default function GitlabForm(props: GitlabFormProps) {
{translate('settings.almintegration.form.url.gitlab.help')}
<br />
<em>https://gitlab.com/api/v4</em>
+ <br />
+ <br />
+ {translate('settings.almintegration.form.url.pat_warning')}
</>
}
id="url.gitlab"
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/BitbucketServerForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/BitbucketServerForm-test.tsx.snap
index 7b392e018eb..b850a6aea22 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/BitbucketServerForm-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/BitbucketServerForm-test.tsx.snap
@@ -17,7 +17,7 @@ exports[`should render correctly 1`] = `
settings.almintegration.form.url.bitbucket.help
<br />
<br />
- settings.almintegration.form.url.bitbucket.pat_warning
+ settings.almintegration.form.url.pat_warning
</React.Fragment>
}
id="url.bitbucket"
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GitlabForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GitlabForm-test.tsx.snap
index c7707c964b8..ae1ecf4620d 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GitlabForm-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/GitlabForm-test.tsx.snap
@@ -19,6 +19,9 @@ exports[`should render correctly 1`] = `
<em>
https://gitlab.com/api/v4
</em>
+ <br />
+ <br />
+ settings.almintegration.form.url.pat_warning
</React.Fragment>
}
id="url.gitlab"
@@ -86,6 +89,9 @@ exports[`should render correctly 2`] = `
<em>
https://gitlab.com/api/v4
</em>
+ <br />
+ <br />
+ settings.almintegration.form.url.pat_warning
</React.Fragment>
}
id="url.gitlab"
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateGitlabAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateGitlabAction.java
index 4e1e08acd37..fbab3b5eb8b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateGitlabAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateGitlabAction.java
@@ -96,6 +96,8 @@ public class UpdateGitlabAction implements AlmSettingsWsAction {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+ almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat);
+
if (isNotBlank(pat)) {
almSettingDto.setPersonalAccessToken(pat);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java
index 643951434b0..e125fe838b7 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java
@@ -78,7 +78,7 @@ public class UpdateGitlabActionTest {
}
@Test
- public void update_with_url() {
+ public void update_with_url_needs_pat() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
@@ -114,19 +114,19 @@ public class UpdateGitlabActionTest {
}
@Test
- public void update_without_pat() {
+ public void fail_when_url_updated_without_pat() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSettingDto = db.almSettings().insertGitlabAlmSetting();
- ws.newRequest()
+ TestRequest request = ws.newRequest()
.setParam("key", almSettingDto.getKey())
- .setParam("url", GITLAB_URL)
- .execute();
- assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
- .containsOnly(tuple(almSettingDto.getKey(), GITLAB_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption)));
+ .setParam("url", GITLAB_URL);
+
+ assertThatThrownBy(() -> request.execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Please provide the Personal Access Token to update the URL.");
}
@Test
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
index c2195410c72..fabcfb1630c 100644
--- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties
+++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
@@ -1229,13 +1229,13 @@ settings.almintegration.form.url.azure.help1=For Azure DevOps Server, provide th
settings.almintegration.form.url.azure.help2=For Azure DevOps Services, provide the full organization URL:
settings.almintegration.form.url.bitbucket=Bitbucket Server URL
settings.almintegration.form.url.bitbucket.help=Example: https://bitbucket-server.your-company.com
-settings.almintegration.form.url.bitbucket.pat_warning=For security reasons, please make sure to provide the Personal Access Token to update the URL.
settings.almintegration.form.url.github=GitHub API URL
settings.almintegration.form.url.github.help1=Example for Github Enterprise:
settings.almintegration.form.url.github.help2=If using GitHub.com:
settings.almintegration.form.url.github.private_key_warning=For security reasons, please make sure to provide the GitHub App private key to update the URL.
settings.almintegration.form.url.gitlab=GitLab API URL
settings.almintegration.form.url.gitlab.help=Provide the GitLab API URL. For example:
+settings.almintegration.form.url.pat_warning=For security reasons, please make sure to provide the Personal Access Token to update the URL.
settings.almintegration.form.app_id=GitHub App ID
settings.almintegration.form.client_id.github=Client ID
settings.almintegration.form.client_id.github.help=The Client ID is found on your GitHub App's page.