Search in sources :

Example 31 with Encryption

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

the class UpdateAzureActionTest method update.

@Test
public void update() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertAzureAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("personalAccessToken", "10987654321").setParam("url", AZURE_URL).execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, "10987654321"));
}
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) 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) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 32 with Encryption

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

the class UpdateAzureActionTest 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().insertAzureAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("newKey", "Azure Server - Infra Team").setParam("personalAccessToken", "0123456789").setParam("url", AZURE_URL).execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple("Azure Server - Infra Team", AZURE_URL, "0123456789"));
}
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) 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) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 33 with Encryption

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

the class UpdateAzureActionTest method update_without_pat.

@Test
public void update_without_pat() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertAzureAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", AZURE_URL).execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple(almSettingDto.getKey(), AZURE_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) Test(org.junit.Test) 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) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 34 with Encryption

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

the class UpdateGithubActionTest method update_without_private_key_nor_client_secret.

@Test
public void update_without_private_key_nor_client_secret() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitHubAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", "https://github.enterprise-unicorn.com/").setParam("appId", "54321").setParam("clientId", "client_1234").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(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", almSettingDto.getDecryptedPrivateKey(encryption), "client_1234", almSettingDto.getDecryptedClientSecret(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) 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) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 35 with Encryption

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

the class DefaultConfigurationTest method accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration.

@Test
public void accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration() {
    Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("single").multiValues(false).build(), PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null), ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) {
    };
    assertThat(config.get("multiA")).hasValue("a,b");
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Access to the multi-values/property set property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
    logTester.clear();
    assertThat(config.getStringArray("single")).containsExactly("foo");
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Property 'single' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
    logTester.clear();
    assertThat(config.get("notDeclared")).hasValue("c,d");
    assertThat(config.getStringArray("notDeclared")).containsExactly("c", "d");
    assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}
Also used : Configuration(org.sonar.api.config.Configuration) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) Encryption(org.sonar.api.config.internal.Encryption) 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