Search in sources :

Example 6 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class CreateBitbucketCloudActionTest method create.

@Test
public void create() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    ws.newRequest().setParam("key", "Bitbucket Server - Dev Team").setParam("clientId", "id").setParam("clientSecret", "secret").setParam("workspace", "workspace1").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple("Bitbucket Server - Dev Team", "id", "secret", "workspace1"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) BadRequestException(org.sonar.server.exceptions.BadRequestException) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 7 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class ValidateActionTest method github_validation_checks.

@Test
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());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ComponentFinder(org.sonar.server.component.ComponentFinder) Settings(org.sonar.api.config.internal.Settings) BeforeClass(org.junit.BeforeClass) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GitlabGlobalSettingsValidator(org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) BitbucketServerSettingsValidator(org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator) ALM(org.sonar.db.alm.setting.ALM) GithubGlobalSettingsValidator(org.sonar.alm.client.github.GithubGlobalSettingsValidator) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ResourceTypes(org.sonar.api.resources.ResourceTypes) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) BitbucketCloudRestClient(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) BitbucketCloudValidator(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) AzureDevOpsValidator(org.sonar.alm.client.azure.AzureDevOpsValidator) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) AzureDevOpsHttpClient(org.sonar.alm.client.azure.AzureDevOpsHttpClient) Mockito.mock(org.mockito.Mockito.mock) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 8 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class ValidateActionTest method github_validation_checks_with_encrypted_secret.

@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()).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(decryptedSecret);
    assertThat(almSettingDtoArgumentCaptor.getValue().getAlm()).isEqualTo(almSetting.getAlm());
    assertThat(almSettingDtoArgumentCaptor.getValue().getAppId()).isEqualTo(almSetting.getAppId());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ComponentFinder(org.sonar.server.component.ComponentFinder) Settings(org.sonar.api.config.internal.Settings) BeforeClass(org.junit.BeforeClass) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GitlabGlobalSettingsValidator(org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) BitbucketServerSettingsValidator(org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator) ALM(org.sonar.db.alm.setting.ALM) GithubGlobalSettingsValidator(org.sonar.alm.client.github.GithubGlobalSettingsValidator) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ResourceTypes(org.sonar.api.resources.ResourceTypes) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) BitbucketCloudRestClient(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) BitbucketCloudValidator(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) AzureDevOpsValidator(org.sonar.alm.client.azure.AzureDevOpsValidator) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) AzureDevOpsHttpClient(org.sonar.alm.client.azure.AzureDevOpsHttpClient) Mockito.mock(org.mockito.Mockito.mock) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 9 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateBitbucketActionTest method update_with_new_key.

@Test
public void update_with_new_key() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("newKey", "Bitbucket Server - Infra Team").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("Bitbucket Server - Infra Team", "https://bitbucket.enterprise-unicorn.com", "0123456789"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 10 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateBitbucketActionTest method update_without_pat.

@Test
public void update_without_pat() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", "https://bitbucket.enterprise-unicorn.com").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)));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

Encryption (org.sonar.api.config.internal.Encryption)36 Test (org.junit.Test)35 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)30 Rule (org.junit.Rule)30 Mockito.mock (org.mockito.Mockito.mock)30 DbTester (org.sonar.db.DbTester)30 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)26 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)26 UserDto (org.sonar.db.user.UserDto)26 UserSessionRule (org.sonar.server.tester.UserSessionRule)26 WsActionTester (org.sonar.server.ws.WsActionTester)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 WebService (org.sonar.api.server.ws.WebService)25 MultipleAlmFeatureProvider (org.sonar.server.almsettings.MultipleAlmFeatureProvider)25 ComponentFinder (org.sonar.server.component.ComponentFinder)25 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)25 Mockito.when (org.mockito.Mockito.when)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)20 String.format (java.lang.String.format)17 TestRequest (org.sonar.server.ws.TestRequest)17