/>
<AlmBindingDefinitionFormField
help={
- <FormattedMessage
- defaultMessage={translate('settings.almintegration.form.url.bitbucket.help')}
- id="settings.almintegration.form.url.bitbucket.help"
- values={{ example: 'https://bitbucket-server.your-company.com' }}
- />
+ <>
+ {translate('settings.almintegration.form.url.bitbucket.help')}
+ <br />
+ <br />
+ {translate('settings.almintegration.form.url.bitbucket.pat_warning')}
+ </>
}
id="url.bitbucket"
maxLength={2000}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
}
@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().insertBitbucketAlmSetting();
+
+ TestRequest request = ws.newRequest()
+ .setParam("key", almSettingDto.getKey())
+ .setParam("url", "https://bitbucket.enterprise-unicorn.com");
+
+ assertThatThrownBy(() -> request.execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Please provide the Personal Access Token to update the URL.");
+ }
+
+ @Test
+ public void update_with_url_change_needs_path() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest()
.setParam("key", almSettingDto.getKey())
.setParam("url", "https://bitbucket.enterprise-unicorn.com")
+ .setParam("personalAccessToken", "0123456789")
.execute();
+
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
.extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
- .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", almSettingDto.getDecryptedPersonalAccessToken(encryption)));
+ .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", "0123456789"));
}
@Test
}
public void checkPrivateKeyOnUrlUpdate(AlmSettingDto almSettingDto, String url, @Nullable String privateKey) {
- if (!url.equals(almSettingDto.getUrl()) && isEmpty(privateKey)) {
- throw new IllegalArgumentException("Please provide the Private Key to update the URL.");
+ checkCredentialArtifactOnUrlUpdate(url, almSettingDto, privateKey, "Please provide the Private Key to update the URL.");
+ }
+
+ public void checkPatOnUrlUpdate(AlmSettingDto almSettingDto, String url, @Nullable String pat) {
+ checkCredentialArtifactOnUrlUpdate(url, almSettingDto, pat, "Please provide the Personal Access Token to update the URL.");
+ }
+
+ private static void checkCredentialArtifactOnUrlUpdate(String url, AlmSettingDto almSettingDto, @Nullable String credentialArtifact, String errorMessage) {
+ if (!url.equals(almSettingDto.getUrl()) && isEmpty(credentialArtifact)) {
+ throw new IllegalArgumentException(errorMessage);
}
}
}
private void doHandle(Request request) {
String key = request.mandatoryParam(PARAM_KEY);
String newKey = request.param(PARAM_NEW_KEY);
- String url = request.mandatoryParam(PARAM_URL);
String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN);
try (DbSession dbSession = dbClient.openSession(false)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+ String url = request.mandatoryParam(PARAM_URL);
+ almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat);
+
if (isNotBlank(pat)) {
almSettingDto.setPersonalAccessToken(pat);
}
settings.almintegration.form.url.azure.help1=For Azure DevOps Server, provide the full collection URL:
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: {example}
+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=Please make sure to provide the GitHub App private key for updating the URL.
+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.app_id=GitHub App ID