Search in sources :

Example 21 with Encryption

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

the class UpdateGitlabActionTest method update_with_url.

@Test
public void update_with_url() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitlabAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", GITLAB_URL).setParam("personalAccessToken", "10987654321").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple(almSettingDto.getKey(), GITLAB_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) 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 22 with Encryption

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

the class DefaultConfigurationTest method accessingPropertySetPropertiesShouldBeConsistentWithDeclaration.

@Test
public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() {
    Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())), new Encryption(null), ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
    };
    assertThat(config.get("props")).hasValue("1,2");
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
    logTester.clear();
    assertThat(config.getStringArray("props")).containsExactly("1", "2");
    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)

Example 23 with Encryption

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

the class DefaultConfigurationTest method getDefaultValues.

@Test
public void getDefaultValues() {
    Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) {
    };
    assertThat(config.get("multiA")).hasValue("foo,bar");
    assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar");
    assertThat(config.get("single")).hasValue("default");
    assertThat(config.getStringArray("single")).containsExactly("default");
}
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)

Example 24 with Encryption

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

the class GenericCoverageSensorTest method loadAllReportPaths.

@Test
public void loadAllReportPaths() {
    Map<String, String> settings = new HashMap<>();
    settings.put(GenericCoverageSensor.REPORT_PATHS_PROPERTY_KEY, "report.xml,report2.xml");
    PropertyDefinitions defs = new PropertyDefinitions(System2.INSTANCE, GenericCoverageSensor.properties());
    DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), settings);
    Set<String> reportPaths = new GenericCoverageSensor(config).loadReportPaths();
    assertThat(reportPaths).containsOnly("report.xml", "report2.xml");
}
Also used : PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) HashMap(java.util.HashMap) DefaultConfiguration(org.sonar.scanner.config.DefaultConfiguration) Encryption(org.sonar.api.config.internal.Encryption) ProjectConfiguration(org.sonar.scanner.scan.ProjectConfiguration) Test(org.junit.Test)

Example 25 with Encryption

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

the class AlmSettingDaoTest method update.

@Test
public void update() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmSettingDto almSettingDto = newGithubAlmSettingDto();
    underTest.insert(dbSession, almSettingDto);
    almSettingDto.setPrivateKey("updated private key");
    almSettingDto.setAppId("updated app id");
    almSettingDto.setUrl("updated url");
    almSettingDto.setPersonalAccessToken("updated pat");
    almSettingDto.setKey("updated key");
    system2.setNow(NOW + 1);
    underTest.update(dbSession, almSettingDto, false);
    AlmSettingDto result = underTest.selectByUuid(dbSession, A_UUID).get();
    assertThat(result).extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> almSettingDto.getDecryptedPrivateKey(encryption), s -> almSettingDto.getDecryptedPersonalAccessToken(encryption), AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt).containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(), almSettingDto.getAppId(), almSettingDto.getDecryptedPrivateKey(encryption), almSettingDto.getDecryptedPersonalAccessToken(encryption), NOW, NOW + 1);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DbTester(org.sonar.db.DbTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) NoOpAuditPersister(org.sonar.db.audit.NoOpAuditPersister) Mockito.when(org.mockito.Mockito.when) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) List(java.util.List) Rule(org.junit.Rule) AlmSettingsTesting(org.sonar.db.almsettings.AlmSettingsTesting) Encryption(org.sonar.api.config.internal.Encryption) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) Mockito.mock(org.mockito.Mockito.mock) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) 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