use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class ListGithubOrganizationsActionTest method return_organizations_overriding_existing_personal_access_token.
@Test
public void return_organizations_overriding_existing_personal_access_token() {
AlmSettingDto githubAlmSettings = setupAlm();
// old pat
AlmPatDto pat = db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSettings.getUuid()).setUserUuid(userSession.getUuid()));
// new pat
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getDecryptedClientSecret(encryption), "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(), githubAlmSettings.getDecryptedClientSecret(encryption), "abc");
verify(appClient).listOrganizations(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(accessToken.getValue())), eq(1), eq(100));
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken()).isEqualTo(accessToken.getValue());
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SearchAzureReposActionTest method fail_check_pat_alm_setting_not_found.
@Test
public void fail_check_pat_alm_setting_not_found() {
UserDto user = insertUser();
AlmPatDto almPatDto = newAlmPatDto();
db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("ALM Setting 'testKey' not found");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SearchBitbucketCloudReposActionTest method fail_check_pat_alm_setting_not_found.
@Test
public void fail_check_pat_alm_setting_not_found() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessageContaining("ALM Setting 'testKey' not found");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method fail_check_alm_setting_not_found.
@Test
public void fail_check_alm_setting_not_found() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmPatDto almPatDto = newAlmPatDto();
db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
assertThatThrownBy(() -> {
ws.newRequest().setParam("almSetting", "testKey").execute();
}).isInstanceOf(NotFoundException.class).hasMessage("ALM Setting 'testKey' not found");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class DeleteActionTest method delete_alm_setting_also_delete_pat.
@Test
public void delete_alm_setting_also_delete_pat() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
AlmPatDto almPatDto = db.almPats().insert(p -> p.setAlmSettingUuid(almSettingDto.getUuid()), p -> p.setUserUuid(user.getUuid()));
ws.newRequest().setParam("key", almSettingDto.getKey()).execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).isEmpty();
assertThat(db.getDbClient().almPatDao().selectByUuid(db.getSession(), almPatDto.getUuid())).isNotPresent();
}
Aggregations