Search in sources :

Example 16 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateBitbucketCloudActionTest method update_without_secret.

@Test
public void update_without_secret() {
    when(encryption.isEncrypted(any())).thenReturn(false);
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("workspace", "workspace").setParam("clientId", "id").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple(almSettingDto.getKey(), "id", almSettingDto.getDecryptedPrivateKey(encryption), "workspace"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) 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) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) 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) ResourceTypes(org.sonar.api.resources.ResourceTypes) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 17 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateBitbucketCloudActionTest method update_binding_without_changing_the_key.

@Test
public void update_binding_without_changing_the_key() {
    when(encryption.isEncrypted(any())).thenReturn(false);
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
    ws.newRequest().setParam("key", almSetting.getKey()).setParam("newKey", almSetting.getKey()).setParam("workspace", "workspace").setParam("clientId", "id").setParam("clientSecret", "secret").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple(almSetting.getKey(), "id", "secret", "workspace"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) 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) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) 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) ResourceTypes(org.sonar.api.resources.ResourceTypes) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 18 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateBitbucketCloudActionTest method update.

@Test
public void update() {
    when(encryption.isEncrypted(any())).thenReturn(false);
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("workspace", "workspace").setParam("clientId", "id").setParam("clientSecret", "secret").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple(almSettingDto.getKey(), "id", "secret", "workspace"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) 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) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) 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) ResourceTypes(org.sonar.api.resources.ResourceTypes) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 19 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateGitlabActionTest method update_with_new_key.

@Test
public void update_with_new_key() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitlabAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("newKey", "Gitlab - Infra Team").setParam("personalAccessToken", "0123456789").setParam("url", GITLAB_URL).execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, s -> s.getDecryptedPersonalAccessToken(encryption), AlmSettingDto::getUrl).containsOnly(tuple("Gitlab - Infra Team", "0123456789", GITLAB_URL));
}
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) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) 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) Assertions(org.assertj.core.api.Assertions) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 20 with Encryption

use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.

the class UpdateGitlabActionTest method update_without_pat.

@Test
public void update_without_pat() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitlabAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", GITLAB_URL).execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple(almSettingDto.getKey(), GITLAB_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption)));
}
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) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) 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) Assertions(org.assertj.core.api.Assertions) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

Encryption (org.sonar.api.config.internal.Encryption)36 Test (org.junit.Test)35 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)30 Rule (org.junit.Rule)30 Mockito.mock (org.mockito.Mockito.mock)30 DbTester (org.sonar.db.DbTester)30 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)26 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)26 UserDto (org.sonar.db.user.UserDto)26 UserSessionRule (org.sonar.server.tester.UserSessionRule)26 WsActionTester (org.sonar.server.ws.WsActionTester)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 WebService (org.sonar.api.server.ws.WebService)25 MultipleAlmFeatureProvider (org.sonar.server.almsettings.MultipleAlmFeatureProvider)25 ComponentFinder (org.sonar.server.component.ComponentFinder)25 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)25 Mockito.when (org.mockito.Mockito.when)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)20 String.format (java.lang.String.format)17 TestRequest (org.sonar.server.ws.TestRequest)17