Search in sources :

Example 1 with GithubGlobalSettingsValidator

use of org.sonar.alm.client.github.GithubGlobalSettingsValidator 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 2 with GithubGlobalSettingsValidator

use of org.sonar.alm.client.github.GithubGlobalSettingsValidator 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)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)2 BeforeClass (org.junit.BeforeClass)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.doThrow (org.mockito.Mockito.doThrow)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 AzureDevOpsHttpClient (org.sonar.alm.client.azure.AzureDevOpsHttpClient)2 AzureDevOpsValidator (org.sonar.alm.client.azure.AzureDevOpsValidator)2 BitbucketCloudRestClient (org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient)2 BitbucketCloudValidator (org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator)2 BitbucketServerSettingsValidator (org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator)2 GithubGlobalSettingsValidator (org.sonar.alm.client.github.GithubGlobalSettingsValidator)2 GitlabGlobalSettingsValidator (org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator)2 Encryption (org.sonar.api.config.internal.Encryption)2