diff options
author | Antoine Vigneau <antoine.vigneau@sonarsource.com> | 2023-06-08 12:10:15 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-06-08 20:03:08 +0000 |
commit | 514e75c10add5b1bbe95387dd6b03db5f6a8aa93 (patch) | |
tree | c912f8fbcc7ad557863dae12d47e48aac951a791 /server/sonar-alm-client/src/test/java | |
parent | 372b5b8026bece925bc9d19803a2e5bc9cedc32d (diff) | |
download | sonarqube-514e75c10add5b1bbe95387dd6b03db5f6a8aa93.tar.gz sonarqube-514e75c10add5b1bbe95387dd6b03db5f6a8aa93.zip |
SONAR-19337 Support invalid GitHub Private Key in the config check
Diffstat (limited to 'server/sonar-alm-client/src/test/java')
-rw-r--r-- | server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/config/GithubProvisioningConfigValidatorTest.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/config/GithubProvisioningConfigValidatorTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/config/GithubProvisioningConfigValidatorTest.java index e743102c734..6adc3467973 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/config/GithubProvisioningConfigValidatorTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/config/GithubProvisioningConfigValidatorTest.java @@ -48,6 +48,7 @@ public class GithubProvisioningConfigValidatorTest { private static final String SUCCESS_STATUS = "SUCCESS"; private static final String GITHUB_CALL_FAILED = "Error response from GitHub: GitHub call failed."; + private static final String APP_FETCHING_FAILED = "Exception while fetching the App."; private static final String INVALID_APP_ID_STATUS = "GitHub App ID must be a number."; private static final String INCOMPLETE_APP_CONFIG_STATUS = "The GitHub App configuration is not complete."; private static final String MISSING_EMAIL_PERMISSION = "Missing permissions: Account permissions -> Email addresses"; @@ -79,6 +80,7 @@ public class GithubProvisioningConfigValidatorTest { assertThat(checkResult.application().jit()).isEqualTo(ConfigStatus.failed(INVALID_APP_ID_STATUS)); assertThat(checkResult.installations()).isEmpty(); } + @Test public void checkConfig_whenAppIdNotValid_shouldReturnFailedAppCheck() { when(gitHubSettings.appId()).thenReturn("not a number"); @@ -102,7 +104,7 @@ public class GithubProvisioningConfigValidatorTest { } @Test - public void checkConfig_whenErrorWhileFetchingTheApp_shouldReturnFailedAppCheck() { + public void checkConfig_whenHttpExceptionWhileFetchingTheApp_shouldReturnFailedAppCheck() { mockGithubConfiguration(); ArgumentCaptor<GithubAppConfiguration> appConfigurationCaptor = ArgumentCaptor.forClass(GithubAppConfiguration.class); @@ -119,6 +121,23 @@ public class GithubProvisioningConfigValidatorTest { } @Test + public void checkConfig_whenIllegalArgumentExceptionWhileFetchingTheApp_shouldReturnFailedAppCheck() { + mockGithubConfiguration(); + ArgumentCaptor<GithubAppConfiguration> appConfigurationCaptor = ArgumentCaptor.forClass(GithubAppConfiguration.class); + + IllegalArgumentException illegalArgumentException = mock(IllegalArgumentException.class); + when(illegalArgumentException.getMessage()).thenReturn("Exception while fetching the App."); + + when(githubClient.getApp(appConfigurationCaptor.capture())).thenThrow(illegalArgumentException); + + ConfigCheckResult checkResult = configValidator.checkConfig(); + + assertThat(checkResult.application().autoProvisioning()).isEqualTo(ConfigStatus.failed(APP_FETCHING_FAILED)); + assertThat(checkResult.application().jit()).isEqualTo(ConfigStatus.failed(APP_FETCHING_FAILED)); + assertThat(checkResult.installations()).isEmpty(); + } + + @Test public void checkConfig_whenAppDoesntHaveEmailsPermissions_shouldReturnFailedAppJitCheck() { mockGithubConfiguration(); ArgumentCaptor<GithubAppConfiguration> appConfigurationCaptor = ArgumentCaptor.forClass(GithubAppConfiguration.class); |