use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.
the class GithubAppSecurityImplTest method createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_corrupted.
@Test
public void createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_corrupted() {
String corruptedPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" + "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI\n" + "YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb\n" + "antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET\n" + "Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3\n" + "oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq\n" + "yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi\n" + "bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC\n" + "HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb\n" + // "B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3\n" +
"g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK\n" + "gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb\n" + "deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n\n" + "ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo\n" + "pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0\n" + "YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk\n" + "xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt\n" + "56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc\n" + "ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV\n" + "kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc\n" + "-----END RSA PRIVATE KEY-----";
GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(corruptedPrivateKey);
assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey())).isInstanceOf(IllegalArgumentException.class).hasCauseInstanceOf(InvalidKeySpecException.class);
}
use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.
the class GithubAppSecurityImplTest method createAppToken_fails_with_IAE_if_privateKey_content_is_garbage.
@Test
public void createAppToken_fails_with_IAE_if_privateKey_content_is_garbage() {
String garbage = randomAlphanumeric(555);
GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(garbage);
assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey())).isInstanceOf(IllegalArgumentException.class).hasRootCauseMessage("Failed to decode Github Application private key");
}
use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.
the class GithubGlobalSettingsValidatorTest method github_global_settings_validation.
@Test
public void github_global_settings_validation() {
AlmSettingDto almSettingDto = createNewGithubDto("clientId", "clientSecret", EXAMPLE_APP_ID, EXAMPLE_PRIVATE_KEY);
when(encryption.isEncrypted(any())).thenReturn(false);
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(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getId());
}
use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.
the class GithubAppSecurityImplTest method getApplicationJWTToken_throws_ISE_if_conf_is_not_complete.
@Test
public void getApplicationJWTToken_throws_ISE_if_conf_is_not_complete() {
GithubAppConfiguration githubAppConfiguration = createAppConfiguration(false);
assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey())).isInstanceOf(IllegalStateException.class);
}
use of org.sonar.alm.client.github.config.GithubAppConfiguration in project sonarqube by SonarSource.
the class GithubAppSecurityImplTest method createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_missing_end_comment.
@Test
public void createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_missing_end_comment() {
String incompletePrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" + "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI\n" + "YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb\n" + "antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET\n" + "Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3\n" + "oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq\n" + "yzT53JW/XI+M5A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5Ox92u1BJXFsk9fk\n" + "xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt\n" + "56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc\n" + "ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV\n" + "kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc";
GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(incompletePrivateKey);
assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey())).isInstanceOf(IllegalArgumentException.class).hasRootCauseInstanceOf(IOException.class).hasRootCauseMessage("-----END RSA PRIVATE KEY not found");
}
Aggregations