Search in sources :

Example 76 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class ValidateActionTest method bitbucketcloud_validation_checks_with_encrypted_secret.

@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(), decryptedSecret, almSetting.getAppId());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 77 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class ValidateActionTest method bitbucketcloud_validation_check_fails.

@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(any(), any(), any());
    TestRequest request = ws.newRequest().setParam("key", almSetting.getKey());
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class);
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 78 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto 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 79 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto 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 80 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class ValidateActionTest method gitlab_validation_checks.

@Test
public void gitlab_validation_checks() {
    AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitlabAlmSetting());
    when(encryption.isEncrypted(any())).thenReturn(false);
    ws.newRequest().setParam("key", almSetting.getKey()).execute();
    verify(gitlabSettingsValidator).validate(any(AlmSettingDto.class));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25