Search in sources :

Example 56 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class CreateAzureActionTest method create.

@Test
public void create() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    ws.newRequest().setParam("key", "Azure Server - Dev Team").setParam("personalAccessToken", "98765432100").setParam("url", "https://ado.sonarqube.com/").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, s -> s.getDecryptedPersonalAccessToken(encryption), AlmSettingDto::getUrl).containsOnly(tuple("Azure Server - Dev Team", "98765432100", "https://ado.sonarqube.com/"));
}
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 57 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class CreateAzureActionTest method fail_when_key_is_already_used.

@Test
public void fail_when_key_is_already_used() {
    when(multipleAlmFeatureProvider.enabled()).thenReturn(true);
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting();
    assertThatThrownBy(() -> ws.newRequest().setParam("key", azureAlmSetting.getKey()).setParam("personalAccessToken", "98765432100").setParam("url", "https://ado.sonarqube.com/").execute()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(String.format("An ALM setting with key '%s' already exist", azureAlmSetting.getKey()));
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 58 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class CreateBitbucketCloudActionTest method create.

@Test
public void create() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    ws.newRequest().setParam("key", "Bitbucket Server - Dev Team").setParam("clientId", "id").setParam("clientSecret", "secret").setParam("workspace", "workspace1").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple("Bitbucket Server - Dev Team", "id", "secret", "workspace1"));
}
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 59 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class CheckPatActionTest method fail_when_personal_access_token_is_invalid_for_bitbucket.

@Test
public void fail_when_personal_access_token_is_invalid_for_bitbucket() {
    when(bitbucketServerRestClient.getRecentRepo(any(), any())).thenThrow(new IllegalArgumentException("Invalid personal access token"));
    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());
    });
    TestRequest request = ws.newRequest().setParam("almSetting", almSetting.getKey());
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Invalid personal access token");
}
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 60 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class CheckPatActionTest method check_pat_for_azure_devops.

@Test
public void check_pat_for_azure_devops() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
    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(azureDevOpsPrHttpClient).checkPAT(almSetting.getUrl(), PAT_SECRET);
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) 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