import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.config.internal.Encryption;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
public class AlmSettingDto {
}
@CheckForNull
- public String getPrivateKey() {
+ public String getDecryptedPrivateKey(Encryption encryption) {
+ if (!isNullOrEmpty(privateKey) && encryption.isEncrypted(privateKey)) {
+ return encryption.decrypt(privateKey);
+ }
return privateKey;
}
}
@CheckForNull
- public String getPersonalAccessToken() {
+ public String getDecryptedPersonalAccessToken(Encryption encryption) {
+ if (!isNullOrEmpty(personalAccessToken) && encryption.isEncrypted(personalAccessToken)) {
+ return encryption.decrypt(personalAccessToken);
+ }
return personalAccessToken;
}
}
@CheckForNull
- public String getClientSecret() {
+ public String getDecryptedClientSecret(Encryption encryption) {
+ if (!isNullOrEmpty(clientSecret) && encryption.isEncrypted(clientSecret)) {
+ return encryption.decrypt(clientSecret);
+ }
return clientSecret;
}
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.audit.NoOpAuditPersister;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
@Rule
public DbTester db = DbTester.create(system2);
+ private final Encryption encryption = mock(Encryption.class);
+
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = mock(UuidFactory.class);
@Test
public void selectByUuid() {
when(uuidFactory.create()).thenReturn(A_UUID);
+ when(encryption.isEncrypted(any())).thenReturn(false);
AlmSettingDto almSettingDto = newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
.extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl,
- AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getPersonalAccessToken,
- AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt)
+ AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt,
+ s -> almSettingDto.getDecryptedPrivateKey(encryption),
+ s -> almSettingDto.getDecryptedPersonalAccessToken(encryption),
+ s -> almSettingDto.getDecryptedClientSecret(encryption))
.containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(),
- almSettingDto.getAppId(), almSettingDto.getPrivateKey(),
- almSettingDto.getPersonalAccessToken(), NOW, NOW);
+ almSettingDto.getAppId(), NOW, NOW,
+ almSettingDto.getDecryptedPrivateKey(encryption),
+ almSettingDto.getDecryptedPersonalAccessToken(encryption),
+ almSettingDto.getDecryptedClientSecret(encryption));
assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
}
@Test
public void selectByKey() {
when(uuidFactory.create()).thenReturn(A_UUID);
+ String decrypted = "decrypted";
+ when(encryption.isEncrypted(any())).thenReturn(true);
+ when(encryption.decrypt(any())).thenReturn(decrypted);
AlmSettingDto almSettingDto = AlmSettingsTesting.newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).get())
.extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl,
- AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getPersonalAccessToken,
- AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt)
+ AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt,
+ s -> almSettingDto.getDecryptedPrivateKey(encryption),
+ s -> almSettingDto.getDecryptedPersonalAccessToken(encryption),
+ s -> almSettingDto.getDecryptedClientSecret(encryption))
+ .containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(),
+ almSettingDto.getAppId(), NOW, NOW,
+ almSettingDto.getDecryptedPrivateKey(encryption),
+ null,
+ almSettingDto.getDecryptedClientSecret(encryption));
+
+ assertThat(underTest.selectByKey(dbSession, "foo")).isNotPresent();
+ }
+
+ @Test
+ public void selectByKey_withEmptySecrets() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ String decrypted = "decrypted";
+ when(encryption.isEncrypted(any())).thenReturn(true);
+ when(encryption.decrypt(any())).thenReturn(decrypted);
+
+ AlmSettingDto almSettingDto = AlmSettingsTesting.newAlmSettingDtoWithEmptySecrets();
+ underTest.insert(dbSession, almSettingDto);
+
+ assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).get())
+ .extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl,
+ AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt,
+ s -> almSettingDto.getDecryptedPrivateKey(encryption),
+ s -> almSettingDto.getDecryptedPersonalAccessToken(encryption),
+ s -> almSettingDto.getDecryptedClientSecret(encryption))
.containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(),
- almSettingDto.getAppId(), almSettingDto.getPrivateKey(),
- almSettingDto.getPersonalAccessToken(), NOW, NOW);
+ almSettingDto.getAppId(), NOW, NOW, null, null, null);
assertThat(underTest.selectByKey(dbSession, "foo")).isNotPresent();
}
AlmSettingDto result = underTest.selectByUuid(dbSession, A_UUID).get();
assertThat(result)
.extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl,
- AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getPersonalAccessToken,
+ AlmSettingDto::getAppId,
+ s -> almSettingDto.getDecryptedPrivateKey(encryption),
+ s -> almSettingDto.getDecryptedPersonalAccessToken(encryption),
AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt)
.containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(),
- almSettingDto.getAppId(), almSettingDto.getPrivateKey(),
- almSettingDto.getPersonalAccessToken(), NOW, NOW + 1);
+ almSettingDto.getAppId(), almSettingDto.getDecryptedPrivateKey(encryption),
+ almSettingDto.getDecryptedPersonalAccessToken(encryption), NOW, NOW + 1);
}
@Test
--- /dev/null
+mock-maker-inline
.setAlm(ALM.GITHUB);
}
+ public static AlmSettingDto newAlmSettingDtoWithEmptySecrets() {
+ return new AlmSettingDto()
+ .setKey(randomAlphanumeric(200))
+ .setUrl(randomAlphanumeric(2000))
+ .setAppId(randomNumeric(8))
+ .setClientId(randomNumeric(8))
+ .setAlm(ALM.GITHUB);
+ }
+
public static AlmSettingDto newAzureAlmSettingDto() {
return new AlmSettingDto()
.setKey(randomAlphanumeric(200))
package org.sonar.server.almintegration.validator;
import org.sonar.alm.client.bitbucketserver.BitbucketServerRestClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.server.ServerSide;
import org.sonar.db.alm.setting.AlmSettingDto;
@ServerSide
public class BitbucketServerSettingsValidator {
private final BitbucketServerRestClient bitbucketServerRestClient;
+ private final Encryption encryption;
- public BitbucketServerSettingsValidator(BitbucketServerRestClient bitbucketServerRestClient) {
+ public BitbucketServerSettingsValidator(BitbucketServerRestClient bitbucketServerRestClient, Settings settings) {
this.bitbucketServerRestClient = bitbucketServerRestClient;
+ this.encryption = settings.getEncryption();
}
public void validate(AlmSettingDto almSettingDto) {
String bitbucketUrl = almSettingDto.getUrl();
- String bitbucketToken = almSettingDto.getPersonalAccessToken();
+ String bitbucketToken = almSettingDto.getDecryptedPersonalAccessToken(encryption);
if (bitbucketUrl == null || bitbucketToken == null) {
throw new IllegalArgumentException("Your global Bitbucket Server configuration is incomplete.");
}
import org.sonar.alm.client.github.GithubApplicationClient;
import org.sonar.alm.client.github.GithubApplicationClientImpl;
import org.sonar.alm.client.github.config.GithubAppConfiguration;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.server.ServerSide;
import org.sonar.db.alm.setting.AlmSettingDto;
@ServerSide
public class GithubGlobalSettingsValidator {
+ private final Encryption encryption;
private final GithubApplicationClient githubApplicationClient;
- public GithubGlobalSettingsValidator(GithubApplicationClientImpl githubApplicationClient) {
+ public GithubGlobalSettingsValidator(GithubApplicationClientImpl githubApplicationClient, Settings settings) {
+ this.encryption = settings.getEncryption();
this.githubApplicationClient = githubApplicationClient;
}
if (isBlank(settings.getClientId())) {
throw new IllegalArgumentException("Missing Client Id");
}
- if (isBlank(settings.getClientSecret())) {
+ if (isBlank(settings.getDecryptedClientSecret(encryption))) {
throw new IllegalArgumentException("Missing Client Secret");
}
- GithubAppConfiguration configuration = new GithubAppConfiguration(appId, settings.getPrivateKey(), settings.getUrl());
+ GithubAppConfiguration configuration = new GithubAppConfiguration(appId, settings.getDecryptedPrivateKey(encryption),
+ settings.getUrl());
githubApplicationClient.checkApiEndpoint(configuration);
githubApplicationClient.checkAppPermissions(configuration);
package org.sonar.server.almintegration.validator;
import org.sonar.alm.client.gitlab.GitlabHttpClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.server.ServerSide;
import org.sonar.db.alm.setting.AlmSettingDto;
@ServerSide
public class GitlabGlobalSettingsValidator {
+ private final Encryption encryption;
private final GitlabHttpClient gitlabHttpClient;
- public GitlabGlobalSettingsValidator(GitlabHttpClient gitlabHttpClient) {
+ public GitlabGlobalSettingsValidator(GitlabHttpClient gitlabHttpClient, Settings settings) {
+ this.encryption = settings.getEncryption();
this.gitlabHttpClient = gitlabHttpClient;
}
public void validate(AlmSettingDto almSettingDto) {
String gitlabUrl = almSettingDto.getUrl();
- String accessToken = almSettingDto.getPersonalAccessToken();
+ String accessToken = almSettingDto.getDecryptedPersonalAccessToken(encryption);
if (gitlabUrl == null || accessToken == null) {
throw new IllegalArgumentException("Your Gitlab global configuration is incomplete.");
import org.sonar.alm.client.github.GithubApplicationClientImpl;
import org.sonar.alm.client.github.security.AccessToken;
import org.sonar.alm.client.github.security.UserAccessToken;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
public static final String PARAM_TOKEN = "token";
private final DbClient dbClient;
+ private final Encryption encryption;
private final UserSession userSession;
private final GithubApplicationClient githubApplicationClient;
- public ListGithubOrganizationsAction(DbClient dbClient, UserSession userSession, GithubApplicationClientImpl githubApplicationClient) {
+ public ListGithubOrganizationsAction(DbClient dbClient, Settings settings, UserSession userSession,
+ GithubApplicationClientImpl githubApplicationClient) {
this.dbClient = dbClient;
+ this.encryption = settings.getEncryption();
this.userSession = userSession;
this.githubApplicationClient = githubApplicationClient;
}
if (request.hasParam(PARAM_TOKEN)) {
String code = request.mandatoryParam(PARAM_TOKEN);
String clientId = requireNonNull(almSettingDto.getClientId(), String.format("No clientId set for GitHub ALM '%s'", almSettingKey));
- String clientSecret = requireNonNull(almSettingDto.getClientSecret(), String.format("No clientSecret set for GitHub ALM '%s'", almSettingKey));
+ String clientSecret = requireNonNull(almSettingDto.getDecryptedClientSecret(encryption), String.format("No clientSecret set for GitHub ALM '%s'",
+ almSettingKey));
try {
accessToken = githubApplicationClient.createUserAccessToken(url, clientId, clientSecret, code);
if (isNotBlank(newKey) && !newKey.equals(key)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+
+ if (isNotBlank(pat)) {
+ almSettingDto.setPersonalAccessToken(pat);
+ }
+
dbClient.almSettingDao().update(dbSession, almSettingDto
.setKey(isNotBlank(newKey) ? newKey : key)
- .setPersonalAccessToken(isNotBlank(pat) ? pat : almSettingDto.getPersonalAccessToken())
.setUrl(url),
pat != null);
dbSession.commit();
if (isNotBlank(newKey) && !newKey.equals(key)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+
+ if (isNotBlank(pat)) {
+ almSettingDto.setPersonalAccessToken(pat);
+ }
+
dbClient.almSettingDao().update(dbSession, almSettingDto
.setKey(isNotBlank(newKey) ? newKey : key)
- .setUrl(url)
- .setPersonalAccessToken(isNotBlank(pat) ? pat : almSettingDto.getPersonalAccessToken()),
+ .setUrl(url),
pat != null);
dbSession.commit();
}
if (isNotBlank(newKey) && !newKey.equals(key)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+
+ if (isNotBlank(clientSecret)) {
+ almSettingDto.setClientSecret(clientSecret);
+ }
+
dbClient.almSettingDao().update(dbSession, almSettingDto
.setKey(isNotBlank(newKey) ? newKey : key)
.setClientId(clientId)
- .setAppId(workspace)
- .setClientSecret(isNotBlank(clientSecret) ? clientSecret : almSettingDto.getClientSecret()),
+ .setAppId(workspace),
clientSecret != null);
dbSession.commit();
}
if (isNotBlank(newKey) && !newKey.equals(key)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+
+ if (isNotBlank(privateKey)) {
+ almSettingDto.setPrivateKey(privateKey);
+ }
+
+ if (isNotBlank(clientSecret)) {
+ almSettingDto.setClientSecret(clientSecret);
+ }
+
dbClient.almSettingDao().update(dbSession, almSettingDto
- .setKey(isNotBlank(newKey) ? newKey : key)
- .setUrl(url)
- .setAppId(appId)
- .setPrivateKey(isNotBlank(privateKey) ? privateKey : almSettingDto.getPrivateKey())
- .setClientId(clientId)
- .setClientSecret(isNotBlank(clientSecret) ? clientSecret : almSettingDto.getClientSecret()),
+ .setKey(isNotBlank(newKey) ? newKey : key)
+ .setUrl(url)
+ .setAppId(appId)
+ .setClientId(clientId),
clientSecret != null || privateKey != null);
dbSession.commit();
}
if (isNotBlank(newKey) && !newKey.equals(key)) {
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey);
}
+
+ if (isNotBlank(pat)) {
+ almSettingDto.setPersonalAccessToken(pat);
+ }
+
dbClient.almSettingDao().update(dbSession, almSettingDto
.setKey(isNotBlank(newKey) ? newKey : key)
- .setUrl(url)
- .setPersonalAccessToken(isNotBlank(pat) ? pat : almSettingDto.getPersonalAccessToken()),
+ .setUrl(url),
pat != null);
dbSession.commit();
}
import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
import org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
private static final String PARAM_KEY = "key";
private final DbClient dbClient;
+ private final Encryption encryption;
private final UserSession userSession;
private final AlmSettingsSupport almSettingsSupport;
private final AzureDevOpsHttpClient azureDevOpsHttpClient;
private final BitbucketCloudRestClient bitbucketCloudRestClient;
public ValidateAction(DbClient dbClient,
+ Settings settings,
UserSession userSession,
AlmSettingsSupport almSettingsSupport,
AzureDevOpsHttpClient azureDevOpsHttpClient,
BitbucketServerSettingsValidator bitbucketServerSettingsValidator,
BitbucketCloudRestClient bitbucketCloudRestClient) {
this.dbClient = dbClient;
+ this.encryption = settings.getEncryption();
this.userSession = userSession;
this.almSettingsSupport = almSettingsSupport;
this.azureDevOpsHttpClient = azureDevOpsHttpClient;
private void validateAzure(AlmSettingDto almSettingDto) {
try {
- azureDevOpsHttpClient.checkPAT(almSettingDto.getUrl(), almSettingDto.getPersonalAccessToken());
+ azureDevOpsHttpClient.checkPAT(almSettingDto.getUrl(), almSettingDto.getDecryptedPersonalAccessToken(encryption));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid Azure URL or Personal Access Token", e);
}
}
private void validateBitbucketCloud(AlmSettingDto almSettingDto) {
- bitbucketCloudRestClient.validate(almSettingDto.getClientId(), almSettingDto.getClientSecret(), almSettingDto.getAppId());
+ bitbucketCloudRestClient.validate(almSettingDto.getClientId(), almSettingDto.getDecryptedClientSecret(encryption), almSettingDto.getAppId());
}
}
*/
package org.sonar.server.almintegration.validator;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.sonar.alm.client.bitbucketserver.BitbucketServerRestClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.db.alm.setting.AlmSettingDto;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.sonar.db.almsettings.AlmSettingsTesting.newBitbucketAlmSettingDto;
public class BitbucketServerSettingsValidatorTest {
+ private static final Encryption encryption = mock(Encryption.class);
+ private static final Settings settings = mock(Settings.class);
private final BitbucketServerRestClient bitbucketServerRestClient = mock(BitbucketServerRestClient.class);
- private final BitbucketServerSettingsValidator underTest = new BitbucketServerSettingsValidator(bitbucketServerRestClient);
+ private final BitbucketServerSettingsValidator underTest = new BitbucketServerSettingsValidator(bitbucketServerRestClient, settings);
+
+ @BeforeClass
+ public static void setUp() {
+ when(settings.getEncryption()).thenReturn(encryption);
+ }
@Test
public void validate_success() {
AlmSettingDto almSettingDto = newBitbucketAlmSettingDto()
.setUrl("http://abc.com")
.setPersonalAccessToken("abc");
+ when(encryption.isEncrypted(any())).thenReturn(false);
underTest.validate(almSettingDto);
verify(bitbucketServerRestClient, times(1)).validateReadPermission("http://abc.com", "abc");
}
+ @Test
+ public void validate_success_with_encrypted_token() {
+ String encryptedToken = "abc";
+ String decryptedToken = "decrypted-token";
+ AlmSettingDto almSettingDto = newBitbucketAlmSettingDto()
+ .setUrl("http://abc.com")
+ .setPersonalAccessToken(encryptedToken);
+ when(encryption.isEncrypted(encryptedToken)).thenReturn(true);
+ when(encryption.decrypt(encryptedToken)).thenReturn(decryptedToken);
+
+ underTest.validate(almSettingDto);
+
+ verify(bitbucketServerRestClient, times(1)).validateUrl("http://abc.com");
+ verify(bitbucketServerRestClient, times(1)).validateToken("http://abc.com", decryptedToken);
+ verify(bitbucketServerRestClient, times(1)).validateReadPermission("http://abc.com", decryptedToken);
+ }
+
@Test
public void validate_failure_on_incomplete_configuration() {
AlmSettingDto almSettingDto = newBitbucketAlmSettingDto()
*/
package org.sonar.server.almintegration.validator;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.alm.client.github.GithubApplicationClientImpl;
import org.sonar.alm.client.github.config.GithubAppConfiguration;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.db.alm.setting.AlmSettingDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
public class GithubGlobalSettingsValidatorTest {
+ private static final Encryption encryption = mock(Encryption.class);
+ private static final Settings settings = mock(Settings.class);
+
private final GithubApplicationClientImpl appClient = mock(GithubApplicationClientImpl.class);
- private final GithubGlobalSettingsValidator underTest = new GithubGlobalSettingsValidator(appClient);
+ private final GithubGlobalSettingsValidator underTest = new GithubGlobalSettingsValidator(appClient, settings);
+
+ @BeforeClass
+ public static void setUp() {
+ when(settings.getEncryption()).thenReturn(encryption);
+ }
@Test
public void github_global_settings_validation() {
AlmSettingDto almSettingDto = newGithubAlmSettingDto()
.setClientId("clientId")
.setClientSecret("clientSecret");
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
+ GithubAppConfiguration configuration = underTest.validate(almSettingDto);
+
+ ArgumentCaptor<GithubAppConfiguration> configurationArgumentCaptor = ArgumentCaptor.forClass(GithubAppConfiguration.class);
+ verify(appClient).checkApiEndpoint(configurationArgumentCaptor.capture());
+ verify(appClient).checkAppPermissions(configurationArgumentCaptor.capture());
+ assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(0).getId());
+ assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getId());
+ }
+
+ @Test
+ public void github_global_settings_validation_with_encrypted_key() {
+ String encryptedKey = "encrypted-key";
+ String decryptedKey = "decrypted-key";
+ AlmSettingDto almSettingDto = newGithubAlmSettingDto()
+ .setClientId("clientId")
+ .setPrivateKey(encryptedKey)
+ .setClientSecret("clientSecret");
+ when(encryption.isEncrypted(encryptedKey)).thenReturn(true);
+ when(encryption.decrypt(encryptedKey)).thenReturn(decryptedKey);
GithubAppConfiguration configuration = underTest.validate(almSettingDto);
verify(appClient).checkApiEndpoint(configurationArgumentCaptor.capture());
verify(appClient).checkAppPermissions(configurationArgumentCaptor.capture());
assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(0).getId());
+ assertThat(decryptedKey).isEqualTo(configurationArgumentCaptor.getAllValues().get(0).getPrivateKey());
assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getId());
+ assertThat(decryptedKey).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getPrivateKey());
}
@Test
*/
package org.sonar.server.almintegration.validator;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.sonar.alm.client.gitlab.GitlabHttpClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.db.alm.setting.AlmSettingDto;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class GitlabGlobalSettingsValidatorTest {
+ private static final Encryption encryption = mock(Encryption.class);
+ private static final Settings settings = mock(Settings.class);
private final GitlabHttpClient gitlabHttpClient = mock(GitlabHttpClient.class);
- private final GitlabGlobalSettingsValidator underTest = new GitlabGlobalSettingsValidator(gitlabHttpClient);
+ private final GitlabGlobalSettingsValidator underTest = new GitlabGlobalSettingsValidator(gitlabHttpClient, settings);
+
+ @BeforeClass
+ public static void setUp() {
+ when(settings.getEncryption()).thenReturn(encryption);
+ }
@Test
public void validate_success() {
+ String token = "personal-access-token";
AlmSettingDto almSettingDto = new AlmSettingDto()
.setUrl("https://gitlab.com/api")
.setPersonalAccessToken("personal-access-token");
+ when(encryption.isEncrypted(token)).thenReturn(false);
+
+ underTest.validate(almSettingDto);
+ verify(gitlabHttpClient, times(1)).checkUrl(almSettingDto.getUrl());
+ verify(gitlabHttpClient, times(1)).checkToken(almSettingDto.getUrl(), almSettingDto.getDecryptedPersonalAccessToken(encryption));
+ verify(gitlabHttpClient, times(1)).checkReadPermission(almSettingDto.getUrl(), almSettingDto.getDecryptedPersonalAccessToken(encryption));
+ verify(gitlabHttpClient, times(1)).checkWritePermission(almSettingDto.getUrl(), almSettingDto.getDecryptedPersonalAccessToken(encryption));
+ }
+
+ @Test
+ public void validate_success_with_encrypted_token() {
+ String encryptedToken = "personal-access-token";
+ String decryptedToken = "decrypted-token";
+ AlmSettingDto almSettingDto = new AlmSettingDto()
+ .setUrl("https://gitlab.com/api")
+ .setPersonalAccessToken(encryptedToken);
+ when(encryption.isEncrypted(encryptedToken)).thenReturn(true);
+ when(encryption.decrypt(encryptedToken)).thenReturn(decryptedToken);
underTest.validate(almSettingDto);
+
+ verify(gitlabHttpClient, times(1)).checkUrl(almSettingDto.getUrl());
+ verify(gitlabHttpClient, times(1)).checkToken(almSettingDto.getUrl(), decryptedToken);
+ verify(gitlabHttpClient, times(1)).checkReadPermission(almSettingDto.getUrl(), decryptedToken);
+ verify(gitlabHttpClient, times(1)).checkWritePermission(almSettingDto.getUrl(), decryptedToken);
}
@Test
import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
import org.sonar.alm.client.azure.GsonAzureProject;
import org.sonar.alm.client.azure.GsonAzureRepo;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.core.i18n.I18n;
private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), System2.INSTANCE,
mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestProjectIndexers(), new SequenceUuidFactory());
+ private final Encryption encryption = mock(Encryption.class);
private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
private final ProjectDefaultVisibility projectDefaultVisibility = mock(ProjectDefaultVisibility.class);
private final ImportAzureProjectAction importAzureProjectAction = new ImportAzureProjectAction(db.getDbClient(), userSession,
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
- dto.setPersonalAccessToken(almSetting.getPersonalAccessToken());
+ dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
dto.setUserUuid(user.getUuid());
});
GsonAzureRepo repo = getGsonAzureRepo();
- when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getPersonalAccessToken(), "project-name", "repo-name"))
+ when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption),
+ "project-name", "repo-name"))
.thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest()
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
- dto.setPersonalAccessToken(almSetting.getPersonalAccessToken());
+ dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
dto.setUserUuid(user.getUuid());
});
GsonAzureRepo repo = getEmptyGsonAzureRepo();
- when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getPersonalAccessToken(), "project-name", "repo-name"))
+ when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption),
+ "project-name", "repo-name"))
.thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest()
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
- dto.setPersonalAccessToken(almSetting.getPersonalAccessToken());
+ dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
dto.setUserUuid(user.getUuid());
});
GsonAzureRepo repo = getGsonAzureRepo();
String projectKey = repo.getProject().getName() + "_" + repo.getName();
db.components().insertPublicProject(p -> p.setDbKey(projectKey));
- when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getPersonalAccessToken(), "project-name", "repo-name")).thenReturn(repo);
+ when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption),
+ "project-name", "repo-name")).thenReturn(repo);
TestRequest request = ws.newRequest()
.setParam("almSetting", almSetting.getKey())
.setParam("projectName", "project-name")
import org.sonar.alm.client.azure.GsonAzureProject;
import org.sonar.alm.client.azure.GsonAzureRepo;
import org.sonar.alm.client.azure.GsonAzureRepoList;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.pat.AlmPatDto;
@Rule
public DbTester db = DbTester.create();
- private AzureDevOpsHttpClient azureDevOpsHttpClient = mock(AzureDevOpsHttpClient.class);
- private WsActionTester ws = new WsActionTester(new SearchAzureReposAction(db.getDbClient(), userSession, azureDevOpsHttpClient));
+ private final AzureDevOpsHttpClient azureDevOpsHttpClient = mock(AzureDevOpsHttpClient.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final WsActionTester ws = new WsActionTester(new SearchAzureReposAction(db.getDbClient(), userSession, azureDevOpsHttpClient));
@Before
public void before() {
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
- dto.setPersonalAccessToken(almSetting.getPersonalAccessToken());
+ dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
});
return almSetting;
}
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import org.sonar.alm.client.github.GithubApplicationClient;
import org.sonar.alm.client.github.GithubApplicationClientImpl;
import org.sonar.alm.client.github.security.UserAccessToken;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.alm.pat.AlmPatDto;
import static org.sonar.server.tester.UserSessionRule.standalone;
public class ListGithubOrganizationsActionTest {
+ private static final Encryption encryption = mock(Encryption.class);
+ private static final Settings settings = mock(Settings.class);
@Rule
public UserSessionRule userSession = standalone();
@Rule
public DbTester db = DbTester.create(system2);
- private final WsActionTester ws = new WsActionTester(new ListGithubOrganizationsAction(db.getDbClient(), userSession, appClient));
+ private final WsActionTester ws = new WsActionTester(new ListGithubOrganizationsAction(db.getDbClient(), settings, userSession, appClient));
+
+ @BeforeClass
+ public static void setUp() {
+ when(settings.getEncryption()).thenReturn(encryption);
+ }
@Test
public void fail_when_missing_create_project_permission() {
@Test
public void fail_when_unable_to_create_personal_access_token() {
AlmSettingDto githubAlmSetting = setupAlm();
- when(appClient.createUserAccessToken(githubAlmSetting.getUrl(), githubAlmSetting.getClientId(), githubAlmSetting.getClientSecret(), "abc"))
+ when(appClient.createUserAccessToken(githubAlmSetting.getUrl(), githubAlmSetting.getClientId(),
+ githubAlmSetting.getDecryptedClientSecret(encryption), "abc"))
.thenThrow(IllegalStateException.class);
TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
@Test
public void fail_create_personal_access_token_because_of_invalid_settings() {
AlmSettingDto githubAlmSetting = setupAlm();
- when(appClient.createUserAccessToken(githubAlmSetting.getUrl(), githubAlmSetting.getClientId(), githubAlmSetting.getClientSecret(), "abc"))
+ when(appClient.createUserAccessToken(githubAlmSetting.getUrl(), githubAlmSetting.getClientId(),
+ githubAlmSetting.getDecryptedClientSecret(encryption), "abc"))
.thenThrow(IllegalArgumentException.class);
TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
public void return_organizations_and_store_personal_access_token() {
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
AlmSettingDto githubAlmSettings = setupAlm();
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
+ when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(),
+ githubAlmSettings.getDecryptedClientSecret(encryption), "abc"))
+ .thenReturn(accessToken);
+ setupGhOrganizations(githubAlmSettings, accessToken.getValue());
+
+ ListGithubOrganizationsWsResponse response = ws.newRequest()
+ .setParam(PARAM_ALM_SETTING, githubAlmSettings.getKey())
+ .setParam(PARAM_TOKEN, "abc")
+ .executeProtobuf(ListGithubOrganizationsWsResponse.class);
+
+ assertThat(response.getPaging())
+ .extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal)
+ .containsOnly(1, 100, 2);
+ assertThat(response.getOrganizationsList())
+ .extracting(GithubOrganization::getKey, GithubOrganization::getName)
+ .containsOnly(tuple("github", "github"), tuple("octacat", "octacat"));
+
+ verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(),
+ githubAlmSettings.getDecryptedClientSecret(encryption), "abc");
+ verify(appClient).listOrganizations(githubAlmSettings.getUrl(), accessToken, 1, 100);
+ Mockito.verifyNoMoreInteractions(appClient);
+ assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken())
+ .isEqualTo(accessToken.getValue());
+ }
+
+ @Test
+ public void return_organizations_and_store_personal_access_token_with_encrypted_client_secret() {
+ String decryptedSecret = "decrypted-secret";
+ UserAccessToken accessToken = new UserAccessToken("token_for_abc");
+ AlmSettingDto githubAlmSettings = setupAlm();
+ when(encryption.isEncrypted(any())).thenReturn(true);
+ when(encryption.decrypt(any())).thenReturn(decryptedSecret);
- when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getClientSecret(), "abc"))
+ when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), decryptedSecret, "abc"))
.thenReturn(accessToken);
setupGhOrganizations(githubAlmSettings, accessToken.getValue());
.extracting(GithubOrganization::getKey, GithubOrganization::getName)
.containsOnly(tuple("github", "github"), tuple("octacat", "octacat"));
- verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getClientSecret(), "abc");
+ verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), decryptedSecret, "abc");
verify(appClient).listOrganizations(githubAlmSettings.getUrl(), accessToken, 1, 100);
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken())
// new pat
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
- when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getClientSecret(), "abc"))
+ when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(),
+ githubAlmSettings.getDecryptedClientSecret(encryption), "abc"))
.thenReturn(accessToken);
setupGhOrganizations(githubAlmSettings, accessToken.getValue());
.extracting(GithubOrganization::getKey, GithubOrganization::getName)
.containsOnly(tuple("github", "github"), tuple("octacat", "octacat"));
- verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getClientSecret(), "abc");
+ verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(),
+ githubAlmSettings.getDecryptedClientSecret(encryption), "abc");
verify(appClient).listOrganizations(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(accessToken.getValue())), eq(1), eq(100));
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken())
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new CreateAzureAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getPersonalAccessToken, AlmSettingDto::getUrl)
+ .extracting(AlmSettingDto::getKey,
+ s -> s.getDecryptedPersonalAccessToken(encryption),
+ AlmSettingDto::getUrl)
.containsOnly(tuple("Azure Server - Dev Team", "98765432100", "https://ado.sonarqube.com/"));
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new CreateBitBucketAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple("Bitbucket Server - Dev Team", "https://bitbucket.enterprise.com", "98765432100"));
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new CreateBitbucketCloudAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret, AlmSettingDto::getAppId)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId)
.containsOnly(tuple("Bitbucket Server - Dev Team", "id", "secret", "workspace1"));
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new CreateGithubAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
.containsOnly(tuple("GitHub Server - Dev Team", "https://github.enterprise.com", "12345", "678910", "client_1234", "client_so_secret"));
}
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
.containsOnly(tuple("GitHub Server - Dev Team", "https://github.enterprise.com", "12345", "678910", "client_1234", "client_so_secret"));
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
private static String GITLAB_URL = "gitlab.com/api/v4";
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new CreateGitlabAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null), multipleAlmFeatureProvider)));
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple("Gitlab - Dev Team", GITLAB_URL, "98765432100"));
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
private static String AZURE_URL = "https://ado.sonarqube.com/";
+ private final Encryption encryption = mock(Encryption.class);
+
private WsActionTester ws = new WsActionTester(new UpdateAzureAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
mock(MultipleAlmFeatureProvider.class))));
.setParam("url", AZURE_URL)
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, "10987654321"));
}
.setParam("url", AZURE_URL)
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple("Azure Server - Infra Team", AZURE_URL, "0123456789"));
}
.setParam("url", AZURE_URL)
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
- .containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, almSettingDto.getPersonalAccessToken()));
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
+ .containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption)));
}
@Test
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
+ private final Encryption encryption = mock(Encryption.class);
+
private WsActionTester ws = new WsActionTester(new UpdateBitbucketAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
mock(MultipleAlmFeatureProvider.class))));
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", "10987654321"));
}
.setParam("personalAccessToken", "0123456789")
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple("Bitbucket Server - Infra Team", "https://bitbucket.enterprise-unicorn.com", "0123456789"));
}
.setParam("url", "https://bitbucket.enterprise-unicorn.com")
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
- .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", almSettingDto.getPersonalAccessToken()));
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
+ .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", almSettingDto.getDecryptedPersonalAccessToken(encryption)));
}
@Test
import org.junit.Rule;
import org.junit.Test;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class UpdateBitbucketCloudActionTest {
@Rule
@Rule
public DbTester db = DbTester.create();
+ private final Encryption encryption = mock(Encryption.class);
+
private final WsActionTester ws = new WsActionTester(new UpdateBitbucketCloudAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), mock(ResourceTypes.class)),
mock(MultipleAlmFeatureProvider.class))));
@Test
public void update() {
+ when(encryption.isEncrypted(any())).thenReturn(false);
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret, AlmSettingDto::getAppId)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId,
+ s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId)
.containsOnly(tuple(almSettingDto.getKey(), "id", "secret", "workspace"));
}
@Test
public void update_with_new_key() {
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
.setParam("clientSecret", "secret")
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret, AlmSettingDto::getAppId)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId,
+ s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId)
.containsOnly(tuple("Bitbucket Server - Infra Team", "id", "secret", "workspace"));
}
@Test
public void update_binding_without_changing_the_key() {
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret, AlmSettingDto::getAppId)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId,
+ s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId)
.containsOnly(tuple(almSetting.getKey(), "id", "secret", "workspace"));
}
@Test
public void update_without_secret() {
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
.setParam("clientId", "id")
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret, AlmSettingDto::getAppId)
- .containsOnly(tuple(almSettingDto.getKey(), "id", almSettingDto.getClientSecret(), "workspace"));
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId,
+ s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId)
+ .containsOnly(tuple(almSettingDto.getKey(), "id", almSettingDto.getDecryptedPrivateKey(encryption), "workspace"));
}
@Test
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
@Rule
public DbTester db = DbTester.create();
+ private final Encryption encryption = mock(Encryption.class);
+
private WsActionTester ws = new WsActionTester(new UpdateGithubAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null),
mock(MultipleAlmFeatureProvider.class))));
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
.containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
.containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
.containsOnly(tuple("GitHub Server - Infra Team", "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getPrivateKey, AlmSettingDto::getClientId, AlmSettingDto::getClientSecret)
- .containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", almSettingDto.getPrivateKey(), "client_1234", almSettingDto.getClientSecret()));
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId,
+ s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption))
+ .containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321",
+ almSettingDto.getDecryptedPrivateKey(encryption), "client_1234", almSettingDto.getDecryptedClientSecret(encryption)));
}
@Test
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.Encryption;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDto;
private static String GITLAB_URL = "gitlab.com/api/v4";
- private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
+ private final Encryption encryption = mock(Encryption.class);
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WsActionTester ws = new WsActionTester(new UpdateGitlabAction(db.getDbClient(), userSession,
new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null), multipleAlmFeatureProvider)));
.setParam("personalAccessToken", "10987654321")
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
.containsOnly(tuple(almSettingDto.getKey(), GITLAB_URL, "10987654321"));
}
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getPersonalAccessToken, AlmSettingDto::getUrl)
+ .extracting(AlmSettingDto::getKey, s -> s.getDecryptedPersonalAccessToken(encryption), AlmSettingDto::getUrl)
.containsOnly(tuple("Gitlab - Infra Team", "0123456789", GITLAB_URL));
}
.setParam("url", GITLAB_URL)
.execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession()))
- .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken)
- .containsOnly(tuple(almSettingDto.getKey(), GITLAB_URL, almSettingDto.getPersonalAccessToken()));
+ .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption))
+ .containsOnly(tuple(almSettingDto.getKey(), GITLAB_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption)));
}
@Test
*/
package org.sonar.server.almsettings.ws;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
import org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient;
+import org.sonar.api.config.internal.Encryption;
+import org.sonar.api.config.internal.Settings;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ValidateActionTest {
+ private static final Encryption encryption = mock(Encryption.class);
+ private static final Settings settings = mock(Settings.class);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
private final BitbucketServerSettingsValidator bitbucketServerSettingsValidator = mock(BitbucketServerSettingsValidator.class);
private final BitbucketCloudRestClient bitbucketCloudRestClient = mock(BitbucketCloudRestClient.class);
private final WsActionTester ws = new WsActionTester(
- new ValidateAction(db.getDbClient(), userSession, almSettingsSupport, azureDevOpsHttpClient, githubGlobalSettingsValidator, gitlabSettingsValidator,
- bitbucketServerSettingsValidator, bitbucketCloudRestClient));
+ new ValidateAction(db.getDbClient(), settings, userSession, almSettingsSupport, azureDevOpsHttpClient, githubGlobalSettingsValidator,
+ gitlabSettingsValidator, bitbucketServerSettingsValidator, bitbucketCloudRestClient));
+
+ @BeforeClass
+ public static void setUp() {
+ when(settings.getEncryption()).thenReturn(encryption);
+ }
@Test
public void fail_when_key_does_not_match_existing_alm_setting() {
@Test
public void gitlab_validation_checks() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitlabAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(false);
ws.newRequest()
.setParam("key", almSetting.getKey())
public void github_validation_checks() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitHubAlmSetting(settings -> settings.setClientId("clientId")
.setClientSecret("clientSecret")));
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
+ ws.newRequest()
+ .setParam("key", almSetting.getKey())
+ .execute();
+
+ ArgumentCaptor<AlmSettingDto> almSettingDtoArgumentCaptor = ArgumentCaptor.forClass(AlmSettingDto.class);
+ verify(githubGlobalSettingsValidator).validate(almSettingDtoArgumentCaptor.capture());
+ assertThat(almSettingDtoArgumentCaptor.getAllValues()).hasSize(1);
+ assertThat(almSettingDtoArgumentCaptor.getValue().getClientId()).isEqualTo(almSetting.getClientId());
+ assertThat(almSettingDtoArgumentCaptor.getValue().getDecryptedClientSecret(encryption)).isEqualTo(almSetting.getDecryptedClientSecret(encryption));
+ assertThat(almSettingDtoArgumentCaptor.getValue().getAlm()).isEqualTo(almSetting.getAlm());
+ assertThat(almSettingDtoArgumentCaptor.getValue().getAppId()).isEqualTo(almSetting.getAppId());
+ }
+
+ @Test
+ public void github_validation_checks_with_encrypted_secret() {
+ String secret = "encrypted-secret";
+ String decryptedSecret = "decrypted-secret";
+ AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitHubAlmSetting(settings -> settings.setClientId("clientId")
+ .setClientSecret(secret)));
+ when(encryption.isEncrypted(secret)).thenReturn(true);
+ when(encryption.decrypt(secret)).thenReturn(decryptedSecret);
ws.newRequest()
.setParam("key", almSetting.getKey())
verify(githubGlobalSettingsValidator).validate(almSettingDtoArgumentCaptor.capture());
assertThat(almSettingDtoArgumentCaptor.getAllValues()).hasSize(1);
assertThat(almSettingDtoArgumentCaptor.getValue().getClientId()).isEqualTo(almSetting.getClientId());
- assertThat(almSettingDtoArgumentCaptor.getValue().getClientSecret()).isEqualTo(almSetting.getClientSecret());
+ assertThat(almSettingDtoArgumentCaptor.getValue().getDecryptedClientSecret(encryption)).isEqualTo(decryptedSecret);
assertThat(almSettingDtoArgumentCaptor.getValue().getAlm()).isEqualTo(almSetting.getAlm());
assertThat(almSettingDtoArgumentCaptor.getValue().getAppId()).isEqualTo(almSetting.getAppId());
}
@Test
public void bitbucketServer_validation_checks() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertBitbucketAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(false);
ws.newRequest()
.setParam("key", almSetting.getKey())
@Test
public void azure_devops_validation_checks() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertAzureAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(false);
ws.newRequest()
.setParam("key", almSetting.getKey())
.execute();
- verify(azureDevOpsHttpClient).checkPAT(almSetting.getUrl(), almSetting.getPersonalAccessToken());
+ verify(azureDevOpsHttpClient).checkPAT(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption));
+ }
+
+ @Test
+ public void azure_devops_validation_checks_with_encrypted_token() {
+ AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertAzureAlmSetting());
+ String decryptedToken = "decrypted-token";
+ when(encryption.isEncrypted(any())).thenReturn(true);
+ when(encryption.decrypt(any())).thenReturn(decryptedToken);
+
+ ws.newRequest()
+ .setParam("key", almSetting.getKey())
+ .execute();
+
+ verify(azureDevOpsHttpClient).checkPAT(almSetting.getUrl(), decryptedToken);
}
@Test
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertAzureAlmSetting());
doThrow(IllegalArgumentException.class)
- .when(azureDevOpsHttpClient).checkPAT(almSetting.getUrl(), almSetting.getPersonalAccessToken());
+ .when(azureDevOpsHttpClient).checkPAT(any(), any());
assertThatThrownBy(() -> ws.newRequest()
.setParam("key", almSetting.getKey())
@Test
public void bitbucketcloud_validation_checks() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertBitbucketCloudAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(false);
+
+ ws.newRequest()
+ .setParam("key", almSetting.getKey())
+ .execute();
+
+ verify(bitbucketCloudRestClient).validate(almSetting.getClientId(), almSetting.getDecryptedClientSecret(encryption), almSetting.getAppId());
+ }
+
+ @Test
+ public void bitbucketcloud_validation_checks_with_encrypted_secret() {
+ String decryptedSecret = "decrypted-secret";
+ AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertBitbucketCloudAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(true);
+ when(encryption.decrypt(any())).thenReturn(decryptedSecret);
ws.newRequest()
.setParam("key", almSetting.getKey())
.execute();
- verify(bitbucketCloudRestClient).validate(almSetting.getClientId(), almSetting.getClientSecret(), almSetting.getAppId());
+ verify(bitbucketCloudRestClient).validate(almSetting.getClientId(), decryptedSecret, almSetting.getAppId());
}
@Test
public void bitbucketcloud_validation_check_fails() {
AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertBitbucketCloudAlmSetting());
+ when(encryption.isEncrypted(any())).thenReturn(false);
doThrow(IllegalArgumentException.class)
- .when(bitbucketCloudRestClient).validate(almSetting.getClientId(), almSetting.getClientSecret(), almSetting.getAppId());
+ .when(bitbucketCloudRestClient).validate(any(), any(), any());
TestRequest request = ws.newRequest()
.setParam("key", almSetting.getKey());