use of org.sonar.alm.client.github.security.AppToken in project sonarqube by SonarSource.
the class GithubApplicationClientImplTest method checkAppPermissions_IOException.
@Test
public void checkAppPermissions_IOException() throws IOException {
AppToken appToken = mockAppToken();
when(httpClient.get(appUrl, appToken, "/app")).thenThrow(new IOException("OOPS"));
assertThatThrownBy(() -> underTest.checkAppPermissions(githubAppConfiguration)).isInstanceOf(IllegalArgumentException.class).hasMessage("Failed to validate configuration, check URL and Private Key");
}
use of org.sonar.alm.client.github.security.AppToken in project sonarqube by SonarSource.
the class GithubApplicationClientImplTest method checkAppPermissions_MissingPermissions.
@Test
public void checkAppPermissions_MissingPermissions() throws IOException {
AppToken appToken = mockAppToken();
when(httpClient.get(appUrl, appToken, "/app")).thenReturn(new OkGetResponse("{}"));
assertThatThrownBy(() -> underTest.checkAppPermissions(githubAppConfiguration)).isInstanceOf(IllegalArgumentException.class).hasMessage("Failed to get app permissions, unexpected response body");
}
use of org.sonar.alm.client.github.security.AppToken in project sonarqube by SonarSource.
the class GithubApplicationClientImplTest method mockAppToken.
private AppToken mockAppToken() {
String jwt = randomAlphanumeric(5);
when(appSecurity.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey())).thenReturn(new AppToken(jwt));
return new AppToken(jwt);
}
use of org.sonar.alm.client.github.security.AppToken in project sonarqube by SonarSource.
the class GithubApplicationClientImplTest method checkAppPermissions_ErrorCodes.
@Test
@UseDataProvider("checkAppPermissionsErrorCodes")
public void checkAppPermissions_ErrorCodes(int errorCode, String expectedMessage) throws IOException {
AppToken appToken = mockAppToken();
when(httpClient.get(appUrl, appToken, "/app")).thenReturn(new ErrorGetResponse(errorCode, null));
assertThatThrownBy(() -> underTest.checkAppPermissions(githubAppConfiguration)).isInstanceOf(IllegalArgumentException.class).hasMessage(expectedMessage);
}
use of org.sonar.alm.client.github.security.AppToken in project sonarqube by SonarSource.
the class GithubApplicationClientImplTest method checkAppPermissions.
@Test
public void checkAppPermissions() throws IOException {
AppToken appToken = mockAppToken();
String json = "{" + " \"permissions\": {\n" + " \"checks\": \"write\",\n" + " \"metadata\": \"read\",\n" + " \"statuses\": \"read\",\n" + " \"pull_requests\": \"write\"\n" + " }\n" + "}";
when(httpClient.get(appUrl, appToken, "/app")).thenReturn(new OkGetResponse(json));
assertThatCode(() -> underTest.checkAppPermissions(githubAppConfiguration)).isNull();
}
Aggregations