use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_bitbucketcloud_pat.
@Test
public void set_new_bitbucketcloud_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
String pat = "12345678987654321";
String username = "test-user";
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", pat).setParam("username", username).execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo(CredentialsEncoderHelper.encodeCredentials(ALM.BITBUCKET_CLOUD, pat, username));
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_azuredevops_pat.
@Test
public void set_new_azuredevops_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "12345678987654321").execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("12345678987654321");
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_gitlab_pat.
@Test
public void set_new_gitlab_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertGitlabAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "12345678987654321").execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("12345678987654321");
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class CheckPatActionTest 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).hasMessage("ALM Setting 'testKey' not found");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class ListGithubOrganizationsActionTest method return_organizations_using_existing_personal_access_token.
@Test
public void return_organizations_using_existing_personal_access_token() {
AlmSettingDto githubAlmSettings = setupAlm();
AlmPatDto pat = db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSettings.getUuid()).setUserUuid(userSession.getUuid()));
setupGhOrganizations(githubAlmSettings, pat.getPersonalAccessToken());
ListGithubOrganizationsWsResponse response = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSettings.getKey()).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, never()).createUserAccessToken(any(), any(), any(), any());
verify(appClient).listOrganizations(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(pat.getPersonalAccessToken())), eq(1), eq(100));
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken()).isEqualTo(pat.getPersonalAccessToken());
}
Aggregations