Search in sources :

Example 11 with GithubAppConfiguration

use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.

the class GithubGlobalSettingsValidatorTest method github_global_settings_validation_with_encrypted_key.

@Test
public void github_global_settings_validation_with_encrypted_key() {
    String encryptedKey = "encrypted-key";
    String decryptedKey = "decrypted-key";
    AlmSettingDto almSettingDto = createNewGithubDto("clientId", "clientSecret", EXAMPLE_APP_ID, encryptedKey);
    when(encryption.isEncrypted(encryptedKey)).thenReturn(true);
    when(encryption.decrypt(encryptedKey)).thenReturn(decryptedKey);
    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(decryptedKey).isEqualTo(configurationArgumentCaptor.getAllValues().get(0).getPrivateKey());
    assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getId());
    assertThat(decryptedKey).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getPrivateKey());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) GithubAppConfiguration(org.sonar.alm.client.github.config.GithubAppConfiguration) Test(org.junit.Test)

Aggregations

GithubAppConfiguration (org.sonar.alm.client.github.config.GithubAppConfiguration)11 Test (org.junit.Test)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 IOException (java.io.IOException)2 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Gson (com.google.gson.Gson)1 String.format (java.lang.String.format)1 HTTP_FORBIDDEN (java.net.HttpURLConnection.HTTP_FORBIDDEN)1 HTTP_OK (java.net.HttpURLConnection.HTTP_OK)1 HTTP_UNAUTHORIZED (java.net.HttpURLConnection.HTTP_UNAUTHORIZED)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1