diff options
author | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-11-01 17:12:18 +0100 |
---|---|---|
committer | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-11-01 17:12:18 +0100 |
commit | 44c99f89c63a9beb0071989c2f66e77be58f90dd (patch) | |
tree | 561899f4616907bc5d4b67e04adeb3bf41ec3ec0 /server | |
parent | ee9b4cce454a518b0ae67f04efd967d618f69872 (diff) | |
parent | 3c797da78da8fce31876d8ac02b271e9ef6663a2 (diff) | |
download | sonarqube-44c99f89c63a9beb0071989c2f66e77be58f90dd.tar.gz sonarqube-44c99f89c63a9beb0071989c2f66e77be58f90dd.zip |
Automatic merge from branch-6.7
* origin/branch-6.7:
SONAR-9863 Disabled commercial plugins from PluginsTest
SONAR-9863 Do not return licenses hashed in api/settings/value
SONAR-9863 Drop old licenses
Diffstat (limited to 'server')
15 files changed, 173 insertions, 215 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index 46b1d3b4a7c..70545bfe881 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -36,11 +36,9 @@ import org.sonar.api.web.UserRole; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; -import org.sonar.db.WildcardPosition; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang.StringUtils.repeat; -import static org.sonar.db.DaoDatabaseUtils.buildLikeValue; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput; @@ -163,10 +161,6 @@ public class PropertiesDao implements Dao { return executeLargeInputs(componentIds, getMapper(session)::selectByComponentIds); } - public List<PropertyDto> selectGlobalPropertiesByKeyQuery(DbSession session, String keyQuery) { - return getMapper(session).selectGlobalPropertiesByKeyQuery(buildLikeValue(keyQuery, WildcardPosition.BEFORE_AND_AFTER)); - } - /** * Saves the specified property and its value. * <p> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index f5571ebe90f..eb6f2943942 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -157,17 +157,6 @@ </where> </select> - <select id="selectGlobalPropertiesByKeyQuery" resultType="ScrapProperty"> - select - <include refid="columnsToScrapPropertyDto"/> - from - properties p - where - p.resource_id is null - and p.user_id is null - and p.prop_key like #{textQuery,jdbcType=VARCHAR} - </select> - <select id="selectIdsByOrganizationAndUser" parameterType="map" resultType="long"> select py.id from properties py diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index c066f2caa83..ef917fbbf53 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -437,24 +437,6 @@ public class PropertiesDaoTest { } @Test - public void select_global_properties_by_key_query() throws SQLException { - // global - insertProperty("sonar.plugin1.licenseHash.secured", "one", null, null); - insertProperty("sonar.plugin2.licenseHash.secured", "two", null, null); - // on component and user - insertProperty("sonar.plugin1.licenseHash.secure", "one", 10L, null); - insertProperty("sonar.plugin1.licenseHash.secure", "two", 10L, 100); - - assertThat(underTest.selectGlobalPropertiesByKeyQuery(dbTester.getSession(), ".licenseHash.secured")).extracting(PropertyDto::getKey, PropertyDto::getValue) - .containsOnly(tuple("sonar.plugin1.licenseHash.secured", "one"), tuple("sonar.plugin2.licenseHash.secured", "two")); - assertThat(underTest.selectGlobalPropertiesByKeyQuery(dbTester.getSession(), "plugin1.licenseHash.secured")).extracting(PropertyDto::getKey, PropertyDto::getValue) - .containsOnly(tuple("sonar.plugin1.licenseHash.secured", "one")); - assertThat(underTest.selectGlobalPropertiesByKeyQuery(dbTester.getSession(), "plugin1")).extracting(PropertyDto::getKey, PropertyDto::getValue) - .containsOnly(tuple("sonar.plugin1.licenseHash.secured", "one")); - assertThat(underTest.selectGlobalPropertiesByKeyQuery(dbTester.getSession(), "unknown")).isEmpty(); - } - - @Test public void saveProperty_inserts_global_properties_when_they_do_not_exist_in_db() { when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4, DATE_5); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java index 0f06e00377e..f72c75bbed5 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java @@ -33,6 +33,7 @@ public class DbVersion67 implements DbVersion { .add(1834, "Set WEBHOOK_DELIVERIES.CE_TASK_UUID as nullable", UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.class) .add(1835, "Populate WEBHOOK_DELIVERIES.ANALYSIS_UUID", PopulateAnalysisUuidColumnOnWebhookDeliveries.class) .add(1836, "Migrate 'previous_analysis' leak periods to 'previous_version'", MigratePreviousAnalysisToPreviousVersion.class) + .add(1837, "Drop old licenses", DropOldLicenses.class) ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicenses.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicenses.java new file mode 100644 index 00000000000..8fed77fdf96 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicenses.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.platform.db.migration.version.v67; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class DropOldLicenses extends DataChange { + + private static final String LICENSE_HASH_SECURED_SUFFIX = ".licenseHash.secured"; + private static final String LICENSE_SECURED_SUFFIX = ".license.secured"; + + public DropOldLicenses(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select prop_key from properties where prop_key like ?") + .setString(1, "%" + LICENSE_HASH_SECURED_SUFFIX); + massUpdate.update("delete from properties where prop_key = ? or prop_key = ?"); + massUpdate.rowPluralName("old license properties"); + massUpdate.execute((row, update) -> { + String licenseHashKey = row.getString(1); + String licenseKey = licenseHashKey.replace(LICENSE_HASH_SECURED_SUFFIX, "") + LICENSE_SECURED_SUFFIX; + update.setString(1, licenseHashKey); + update.setString(2, licenseKey); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java index de678701f0b..c418c66ef62 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java @@ -36,7 +36,7 @@ public class DbVersion67Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 7); + verifyMigrationCount(underTest, 8); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest.java new file mode 100644 index 00000000000..0f35f73dddd --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest.java @@ -0,0 +1,80 @@ +package org.sonar.server.platform.db.migration.version.v67; +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import java.sql.SQLException; +import java.util.stream.Collectors; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; + +public class DropOldLicensesTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropOldLicensesTest.class, "properties.sql"); + + private DropOldLicenses underTest = new DropOldLicenses(db.database()); + + @Test + public void remove_old_licenses() throws SQLException { + insertProperty("sonar.cpp.license.secured"); + insertProperty("sonar.cpp.licenseHash.secured"); + insertProperty("sonar.objc.license.secured"); + insertProperty("sonar.objc.licenseHash.secured"); + + underTest.execute(); + + assertPropertiesIsEmpty(); + } + + @Test + public void ignore_existing_none_related_licenses_settings() throws SQLException { + insertProperty("my.property"); + insertProperty("custom.license"); + + underTest.execute(); + + assertProperties("my.property", "custom.license"); + } + + private void assertPropertiesIsEmpty() { + assertProperties(); + } + + private void assertProperties(String... expectedSettingKeys) { + assertThat(db.select("SELECT PROP_KEY FROM PROPERTIES") + .stream() + .map(map -> map.get("PROP_KEY")) + .collect(Collectors.toList())) + .containsExactlyInAnyOrder(expectedSettingKeys); + } + + public void insertProperty(String propertyKey) { + db.executeInsert( + "properties", + "prop_key", propertyKey, + "is_empty", "false", + "text_value", randomAlphabetic(2)); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest/properties.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest/properties.sql new file mode 100644 index 00000000000..dfc39d8d285 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/DropOldLicensesTest/properties.sql @@ -0,0 +1,11 @@ +CREATE TABLE "PROPERTIES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PROP_KEY" VARCHAR(512) NOT NULL, + "RESOURCE_ID" INTEGER, + "USER_ID" INTEGER, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB(2147483647), + "CREATED_AT" BIGINT +); +CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ScannerSettings.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ScannerSettings.java deleted file mode 100644 index 6cb20ba0546..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ScannerSettings.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.setting.ws; - -import com.google.common.collect.ImmutableSet; -import java.util.Set; -import java.util.stream.Stream; -import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.property.PropertyDto; - -import static java.util.stream.Collectors.toSet; -import static java.util.stream.Stream.concat; -import static org.sonar.api.CoreProperties.SERVER_ID; -import static org.sonar.api.CoreProperties.SERVER_STARTTIME; -import static org.sonar.api.PropertyType.LICENSE; -import static org.sonar.server.setting.ws.SettingsWsSupport.LICENSE_HASH_SUFFIX; - -/** - * This class returns the list of settings required on scanner side (licenses, license hashes, server ids, etc.) - */ -public class ScannerSettings { - - private static final Set<String> SERVER_SETTING_KEYS = ImmutableSet.of(SERVER_STARTTIME, SERVER_ID); - - private final DbClient dbClient; - private final PropertyDefinitions propertyDefinitions; - - public ScannerSettings(DbClient dbClient, PropertyDefinitions propertyDefinitions) { - this.dbClient = dbClient; - this.propertyDefinitions = propertyDefinitions; - } - - Set<String> getScannerSettingKeys(DbSession dbSession) { - return concat(concat(loadLicenseKeys(), loadLicenseHashKeys(dbSession)), - SERVER_SETTING_KEYS.stream()).collect(toSet()); - } - - private Stream<String> loadLicenseHashKeys(DbSession dbSession) { - return dbClient.propertiesDao().selectGlobalPropertiesByKeyQuery(dbSession, LICENSE_HASH_SUFFIX).stream().map(PropertyDto::getKey); - } - - private Stream<String> loadLicenseKeys() { - return propertyDefinitions.getAll() - .stream() - .filter(setting -> setting.type().equals(LICENSE)) - .map(PropertyDefinition::key); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsModule.java index d647521f210..16c06c1bd58 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsModule.java @@ -36,7 +36,6 @@ public class SettingsWsModule extends Module { GenerateSecretKeyAction.class, CheckSecretKeyAction.class, SettingsUpdater.class, - SettingValidations.class, - ScannerSettings.class); + SettingValidations.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsSupport.java index 89541441ed5..f690a5f75e3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsSupport.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SettingsWsSupport.java @@ -46,7 +46,7 @@ public class SettingsWsSupport { public static final String DOT_SECURED = ".secured"; public static final String DOT_LICENSE = ".license"; private static final String LICENSE_SUFFIX = DOT_LICENSE + DOT_SECURED; - static final String LICENSE_HASH_SUFFIX = ".licenseHash" + DOT_SECURED; + private static final String LICENSE_HASH_SUFFIX = ".licenseHash" + DOT_SECURED; private final DefaultOrganizationProvider defaultOrganizationProvider; private final UserSession userSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index db6e2c21e31..f6776aaa46b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -20,9 +20,9 @@ package org.sonar.server.setting.ws; import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -47,6 +47,8 @@ import org.sonarqube.ws.client.setting.ValuesRequest; import static java.lang.String.format; import static java.util.stream.Stream.concat; import static org.apache.commons.lang.StringUtils.isEmpty; +import static org.sonar.api.CoreProperties.SERVER_ID; +import static org.sonar.api.CoreProperties.SERVER_STARTTIME; import static org.sonar.api.PropertyType.PROPERTY_SET; import static org.sonar.api.web.UserRole.USER; import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; @@ -61,6 +63,7 @@ public class ValuesAction implements SettingsWsAction { private static final Splitter COMMA_SPLITTER = Splitter.on(","); private static final String COMMA_ENCODED_VALUE = "%2C"; + private static final Set<String> SERVER_SETTING_KEYS = ImmutableSet.of(SERVER_STARTTIME, SERVER_ID); private final DbClient dbClient; private final ComponentFinder componentFinder; @@ -68,17 +71,15 @@ public class ValuesAction implements SettingsWsAction { private final PropertyDefinitions propertyDefinitions; private final SettingsFinder settingsFinder; private final SettingsWsSupport settingsWsSupport; - private final ScannerSettings scannerSettings; public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions, SettingsFinder settingsFinder, - SettingsWsSupport settingsWsSupport, ScannerSettings scannerSettings) { + SettingsWsSupport settingsWsSupport) { this.dbClient = dbClient; this.componentFinder = componentFinder; this.userSession = userSession; this.propertyDefinitions = propertyDefinitions; this.settingsFinder = settingsFinder; this.settingsWsSupport = settingsWsSupport; - this.scannerSettings = scannerSettings; } @Override @@ -120,7 +121,7 @@ public class ValuesAction implements SettingsWsAction { ValuesRequest valuesRequest = toWsRequest(request); Optional<ComponentDto> component = loadComponent(dbSession, valuesRequest); - Set<String> keys = loadKeys(dbSession, valuesRequest); + Set<String> keys = loadKeys(valuesRequest); Map<String, String> keysToDisplayMap = getKeysToDisplayMap(keys); List<Setting> settings = loadSettings(dbSession, component, keysToDisplayMap.keySet()); return new ValuesResponseBuilder(settings, component, keysToDisplayMap).build(); @@ -137,12 +138,10 @@ public class ValuesAction implements SettingsWsAction { return builder.build(); } - private Set<String> loadKeys(DbSession dbSession, ValuesRequest valuesRequest) { + private Set<String> loadKeys(ValuesRequest valuesRequest) { List<String> keys = valuesRequest.getKeys(); - if (keys.isEmpty()) { - return concat(propertyDefinitions.getAll().stream().map(PropertyDefinition::key), scannerSettings.getScannerSettingKeys(dbSession).stream()).collect(Collectors.toSet()); - } - return new HashSet<>(keys); + return keys.isEmpty() ? concat(propertyDefinitions.getAll().stream().map(PropertyDefinition::key), SERVER_SETTING_KEYS.stream()).collect(Collectors.toSet()) + : ImmutableSet.copyOf(keys); } private Optional<ComponentDto> loadComponent(DbSession dbSession, ValuesRequest valuesRequest) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ScannerSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ScannerSettingsTest.java deleted file mode 100644 index 6ee20dbe5ea..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ScannerSettingsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.setting.ws; - -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.api.PropertyType.LICENSE; -import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto; - -public class ScannerSettingsTest { - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - - private PropertyDefinitions definitions = new PropertyDefinitions(); - - private ScannerSettings underTest = new ScannerSettings(db.getDbClient(), definitions); - - @Test - public void return_license_keys() throws Exception { - definitions.addComponents(asList( - PropertyDefinition.builder("foo").build(), - PropertyDefinition.builder("myplugin.license.secured").type(LICENSE).build())); - - assertThat(underTest.getScannerSettingKeys(db.getSession())).contains("myplugin.license.secured"); - } - - @Test - public void return_license_hash_keys() throws Exception { - db.properties().insertProperty(newGlobalPropertyDto("sonar.myplugin.licenseHash.secured", "hash")); - - assertThat(underTest.getScannerSettingKeys(db.getSession())).contains("sonar.myplugin.licenseHash.secured"); - } - - @Test - public void return_server_settings() throws Exception { - definitions.addComponents(asList( - PropertyDefinition.builder("foo").build(), - PropertyDefinition.builder("myplugin.license.secured").type(LICENSE).build())); - - assertThat(underTest.getScannerSettingKeys(db.getSession())).contains("sonar.core.id", "sonar.core.startTime"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SettingsWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SettingsWsModuleTest.java index d8c99396e1f..cc1436c77e4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SettingsWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SettingsWsModuleTest.java @@ -29,6 +29,6 @@ public class SettingsWsModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new SettingsWsModule().configure(container); - assertThat(container.size()).isEqualTo(13 + 2); + assertThat(container.size()).isEqualTo(12 + 2); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 5e4afa54144..0177ef1889e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -88,13 +88,12 @@ public class ValuesActionTest { private ComponentDbTester componentDb = new ComponentDbTester(db); private PropertyDefinitions definitions = new PropertyDefinitions(); private SettingsFinder settingsFinder = new SettingsFinder(dbClient, definitions); - private ScannerSettings scannerSettings = new ScannerSettings(db.getDbClient(), definitions); private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); private SettingsWsSupport support = new SettingsWsSupport(defaultOrganizationProvider, userSession); private ComponentDto project; private WsActionTester ws = new WsActionTester( - new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, settingsFinder, support, scannerSettings)); + new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, settingsFinder, support)); @Before public void setUp() throws Exception { @@ -518,7 +517,7 @@ public class ValuesActionTest { } @Test - public void return_license_with_hash_settings_when_authenticated_but_not_admin() throws Exception { + public void return_license_settings_when_authenticated_but_not_admin() throws Exception { logIn(); definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), @@ -529,13 +528,11 @@ public class ValuesActionTest { newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password"), newGlobalPropertyDto().setKey("commercial.plugin").setValue("ABCD"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD")); ValuesWsResponse result = executeRequestForGlobalProperties(); - assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "commercial.plugin", "plugin.license.secured", - "sonar.plugin.licenseHash.secured"); + assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "commercial.plugin", "plugin.license.secured"); } @Test @@ -550,13 +547,11 @@ public class ValuesActionTest { newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password"), newGlobalPropertyDto().setKey("commercial.plugin").setValue("ABCD"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD")); ValuesWsResponse result = executeRequestForGlobalProperties(); - assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "commercial.plugin", "plugin.license.secured", - "sonar.plugin.licenseHash.secured"); + assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "commercial.plugin", "plugin.license.secured"); } @Test @@ -575,13 +570,12 @@ public class ValuesActionTest { newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password"), newComponentPropertyDto(project).setKey("commercial.plugin").setValue("ABCD"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD")); ValuesWsResponse result = executeRequestForProjectProperties(); assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "global.secret.secured", "secret.secured", "commercial.plugin", - "plugin.license.secured", "sonar.plugin.licenseHash.secured"); + "plugin.license.secured"); } @Test @@ -606,12 +600,11 @@ public class ValuesActionTest { propertyDb.insertProperties( newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD")); ValuesWsResponse result = executeRequestForGlobalProperties(); - assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured", "sonar.plugin.licenseHash.secured"); + assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured"); } @Test @@ -626,13 +619,11 @@ public class ValuesActionTest { newComponentPropertyDto(project).setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD")); ValuesWsResponse result = executeRequestForProjectProperties(); - assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "global.secret.secured", "secret.secured", "plugin.license.secured", - "sonar.plugin.licenseHash.secured"); + assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "global.secret.secured", "secret.secured", "plugin.license.secured"); } @Test @@ -702,16 +693,12 @@ public class ValuesActionTest { logInAsAdmin(); definitions.addComponent(PropertyDefinition.builder("plugin.license.secured").type(LICENSE).build()); propertyDb.insertProperties( - newGlobalPropertyDto().setKey("sonar.server_id").setValue("12345"), newGlobalPropertyDto().setKey("sonar.core.id").setValue("ID"), - newGlobalPropertyDto().setKey("sonar.core.startTime").setValue("2017-01-01"), - newGlobalPropertyDto().setKey("plugin.license.secured").setValue("ABCD"), - newGlobalPropertyDto().setKey("sonar.plugin.licenseHash.secured").setValue("987654321")); + newGlobalPropertyDto().setKey("sonar.core.startTime").setValue("2017-01-01")); ValuesWsResponse result = executeRequestForGlobalProperties(); - assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("sonar.core.id", "sonar.core.startTime", "plugin.license.secured", - "sonar.plugin.licenseHash.secured"); + assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("sonar.core.id", "sonar.core.startTime"); } @Test @@ -735,7 +722,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition.builder("sonar.leak.period").onQualifiers(PROJECT).build()); propertyDb.insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("two")); - ValuesWsResponse result = ws.newRequest() + ValuesWsResponse result = ws.newRequest() .setParam("keys", "sonar.leak.period") .setParam("component", branch.getKey()) .setParam("branch", branch.getBranch()) @@ -753,7 +740,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition.builder("sonar.leak.period").onQualifiers(PROJECT).build()); propertyDb.insertProperties(newComponentPropertyDto(project).setKey("sonar.leak.period").setValue("two")); - ValuesWsResponse result = ws.newRequest() + ValuesWsResponse result = ws.newRequest() .setParam("keys", "sonar.leak.period") .setParam("component", branch.getKey()) .setParam("branch", branch.getBranch()) |