Search in sources :

Example 46 with AlmSettingDto

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"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) BadRequestException(org.sonar.server.exceptions.BadRequestException) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 47 with AlmSettingDto

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"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) BadRequestException(org.sonar.server.exceptions.BadRequestException) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 48 with AlmSettingDto

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);
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 49 with AlmSettingDto

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");
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 50 with AlmSettingDto

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());
}
Also used : UserAccessToken(org.sonar.alm.client.github.security.UserAccessToken) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ListGithubOrganizationsWsResponse(org.sonarqube.ws.AlmIntegrations.ListGithubOrganizationsWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25