use of org.sonar.alm.client.github.security.UserAccessToken in project sonarqube by SonarSource.
the class ListGithubOrganizationsActionTest method return_organizations_and_store_personal_access_token_with_encrypted_client_secret.
@Test
public void return_organizations_and_store_personal_access_token_with_encrypted_client_secret() {
String decryptedSecret = "decrypted-secret";
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
AlmSettingDto githubAlmSettings = setupAlm();
when(encryption.isEncrypted(any())).thenReturn(true);
when(encryption.decrypt(any())).thenReturn(decryptedSecret);
when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), decryptedSecret, "abc")).thenReturn(accessToken);
setupGhOrganizations(githubAlmSettings, accessToken.getValue());
ListGithubOrganizationsWsResponse response = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSettings.getKey()).setParam(PARAM_TOKEN, "abc").executeProtobuf(ListGithubOrganizationsWsResponse.class);
assertThat(response.getPaging()).extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal).containsOnly(1, 100, 2);
assertThat(response.getOrganizationsList()).extracting(GithubOrganization::getKey, GithubOrganization::getName).containsOnly(tuple("github", "github"), tuple("octacat", "octacat"));
verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), decryptedSecret, "abc");
verify(appClient).listOrganizations(githubAlmSettings.getUrl(), accessToken, 1, 100);
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken()).isEqualTo(accessToken.getValue());
}
Aggregations