use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class CreateBitbucketActionTest method create.
@Test
public void create() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest().setParam("key", "Bitbucket Server - Dev Team").setParam("url", "https://bitbucket.enterprise.com").setParam("personalAccessToken", "98765432100").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple("Bitbucket Server - Dev Team", "https://bitbucket.enterprise.com", "98765432100"));
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class CreateGithubActionTest method create.
@Test
public void create() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest().setParam("key", "GitHub Server - Dev Team").setParam("url", "https://github.enterprise.com").setParam("appId", "12345").setParam("privateKey", "678910").setParam("clientId", "client_1234").setParam("clientSecret", "client_so_secret").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption)).containsOnly(tuple("GitHub Server - Dev Team", "https://github.enterprise.com", "12345", "678910", "client_1234", "client_so_secret"));
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class CheckPatActionTest method check_pat_for_bitbucket.
@Test
public void check_pat_for_bitbucket() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
dto.setPersonalAccessToken(PAT_SECRET);
});
ws.newRequest().setParam("almSetting", almSetting.getKey()).execute();
assertThat(almSetting.getUrl()).isNotNull();
verify(bitbucketServerRestClient).getRecentRepo(almSetting.getUrl(), PAT_SECRET);
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class CheckPatActionTest method check_pat_is_missing.
@Test
public void check_pat_is_missing() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
TestRequest request = ws.newRequest().setParam("almSetting", almSetting.getKey());
assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("personal access token for '" + almSetting.getKey() + "' is missing");
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ListGithubOrganizationsActionTest method return_organizations_and_store_personal_access_token.
@Test
public void return_organizations_and_store_personal_access_token() {
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
AlmSettingDto githubAlmSettings = setupAlm();
when(encryption.isEncrypted(any())).thenReturn(false);
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(githubAlmSettings.getUrl(), accessToken, 1, 100);
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken()).isEqualTo(accessToken.getValue());
}
Aggregations