]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17305 prevent set sonar.global.XX properties in scanner
authorBenjamin Campomenosi <benjamin.campomenosi@sonarsource.com>
Thu, 29 Sep 2022 15:26:32 +0000 (17:26 +0200)
committerPhilippe Perrin <philippe.perrin@sonarsource.com>
Fri, 7 Oct 2022 10:13:56 +0000 (12:13 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettingsProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilter.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleConfigurationProviderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectConfigurationProviderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilterTest.java [new file with mode: 0644]

index 5cb88b0e7b35847f0239792bc2c3b8cbec8b8a1e..72d212bab4391a340c0f0c1365970bda25c29a64 100644 (file)
@@ -30,6 +30,14 @@ import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.springframework.context.annotation.Bean;
 
 public class ModuleConfigurationProvider {
+
+  private final SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter;
+
+  public ModuleConfigurationProvider(SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter) {
+    this.sonarGlobalPropertiesFilter = sonarGlobalPropertiesFilter;
+  }
+
+
   @Bean("ModuleConfiguration")
   public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, GlobalServerSettings globalServerSettings,
     ProjectServerSettings projectServerSettings) {
@@ -38,6 +46,8 @@ public class ModuleConfigurationProvider {
     settings.putAll(projectServerSettings.properties());
     addScannerSideProperties(settings, module.definition());
 
+    settings = sonarGlobalPropertiesFilter.enforceOnlyServerSideSonarGlobalPropertiesAreUsed(settings, globalServerSettings.properties());
+
     return new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings);
   }
 
index d20ff578439d8c54798de0edbfbc5a904d88bb61..e53fe9b44902cbbbd8c8b433afd4685581598684 100644 (file)
@@ -26,7 +26,15 @@ import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.springframework.context.annotation.Bean;
 
+
 public class ProjectConfigurationProvider {
+
+  private final SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter;
+
+  public ProjectConfigurationProvider(SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter) {
+    this.sonarGlobalPropertiesFilter = sonarGlobalPropertiesFilter;
+  }
+
   @Bean("ProjectConfiguration")
   public ProjectConfiguration provide(DefaultInputProject project, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings,
     ProjectServerSettings projectServerSettings, MutableProjectSettings projectSettings) {
@@ -35,8 +43,12 @@ public class ProjectConfigurationProvider {
     settings.putAll(projectServerSettings.properties());
     settings.putAll(project.properties());
 
+    settings = sonarGlobalPropertiesFilter.enforceOnlyServerSideSonarGlobalPropertiesAreUsed(settings, globalServerSettings.properties());
+
     ProjectConfiguration projectConfig = new ProjectConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings);
     projectSettings.complete(projectConfig);
     return projectConfig;
   }
+
+
 }
index 55516177aa946c7384be7964d5be4b62f283e422..3f2825b7288743b08342cf9445ff9097994b676d 100644 (file)
@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Bean;
 
 public class ProjectServerSettingsProvider {
 
-  private static final Logger LOG = Loggers.get(ProjectConfigurationProvider.class);
+  private static final Logger LOG = Loggers.get(ProjectServerSettingsProvider.class);
 
   private static final String MODULE_LEVEL_ARCHIVED_SETTINGS_WARNING = "Settings that were previously configured at " +
     "sub-project level are not used anymore. Transition the settings listed in â€˜General Settings -> General -> " +
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilter.java
new file mode 100644 (file)
index 0000000..2dec130
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.scanner.scan;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SonarGlobalPropertiesFilter {
+
+  @VisibleForTesting
+  static final String SONAR_GLOBAL_PROPERTIES_PREFIX = "sonar.global.";
+
+  public Map<String, String> enforceOnlyServerSideSonarGlobalPropertiesAreUsed(Map<String, String> settingProperties, Map<String, String> globalServerSettingsProperties) {
+    Map<String, String> settings = getNonSonarGlobalProperties(settingProperties);
+    settings.putAll(getSonarGlobalProperties(globalServerSettingsProperties));
+    return settings;
+  }
+
+
+  private static Map<String, String> getNonSonarGlobalProperties(Map<String, String> settingProperties) {
+    return settingProperties.entrySet()
+      .stream()
+      .filter(entry -> !isSonarGlobalProperty(entry.getKey()))
+      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+  }
+
+  private static Map<String, String> getSonarGlobalProperties(Map<String, String> properties) {
+    return properties
+      .entrySet()
+      .stream()
+      .filter(entry -> isSonarGlobalProperty(entry.getKey()))
+      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+  }
+
+  private static boolean isSonarGlobalProperty(String propertiesCode) {
+    return propertiesCode.startsWith(SONAR_GLOBAL_PROPERTIES_PREFIX);
+  }
+
+}
index 4707354a706524e5aea0baf6569d076dbab9c3ed..0f80f0f3c742faaaac7483887919659e316a06ec 100644 (file)
@@ -55,7 +55,8 @@ public class SpringModuleScanContainer extends SpringComponentContainer {
       module.definition(),
       module,
       MutableModuleSettings.class,
-      new ModuleConfigurationProvider(),
+      SonarGlobalPropertiesFilter.class,
+      ModuleConfigurationProvider.class,
 
       ModuleSensorsExecutor.class,
 
index e3d2f50f631046baed76361ec8992ee6408758c8..38198a08e42cc796e0f1badd8528ebdbd337de5a 100644 (file)
@@ -228,7 +228,8 @@ public class SpringProjectScanContainer extends SpringComponentContainer {
 
       MutableProjectSettings.class,
       ScannerProperties.class,
-      new ProjectConfigurationProvider(),
+      SonarGlobalPropertiesFilter.class,
+      ProjectConfigurationProvider.class,
 
       ProjectCoverageAndDuplicationExclusions.class,
 
index e70f14ee4680987929af0c38c34dcdd71809dc92..e648fe77c79f3aff85dca97753d463db822990d9 100644 (file)
@@ -50,6 +50,7 @@ import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.scan.ModuleConfiguration;
 import org.sonar.scanner.scan.ModuleConfigurationProvider;
 import org.sonar.scanner.scan.ProjectServerSettings;
+import org.sonar.scanner.scan.SonarGlobalPropertiesFilter;
 import org.sonar.scanner.scm.ScmConfiguration;
 import org.sonar.scanner.util.ProgressReport;
 
@@ -63,6 +64,7 @@ public class ProjectFileIndexer {
 
   private static final Logger LOG = Loggers.get(ProjectFileIndexer.class);
   private final ProjectExclusionFilters projectExclusionFilters;
+  private final SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter;
   private final ProjectCoverageAndDuplicationExclusions projectCoverageAndDuplicationExclusions;
   private final ScmConfiguration scmConfiguration;
   private final InputComponentStore componentStore;
@@ -77,9 +79,10 @@ public class ProjectFileIndexer {
   private ProgressReport progressReport;
 
   public ProjectFileIndexer(InputComponentStore componentStore, ProjectExclusionFilters exclusionFilters,
-    InputModuleHierarchy inputModuleHierarchy, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings,
+    SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter, InputModuleHierarchy inputModuleHierarchy, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings,
     FileIndexer fileIndexer, ProjectCoverageAndDuplicationExclusions projectCoverageAndDuplicationExclusions, ScmConfiguration scmConfiguration) {
     this.componentStore = componentStore;
+    this.sonarGlobalPropertiesFilter = sonarGlobalPropertiesFilter;
     this.inputModuleHierarchy = inputModuleHierarchy;
     this.globalConfig = globalConfig;
     this.globalServerSettings = globalServerSettings;
@@ -140,7 +143,7 @@ public class ProjectFileIndexer {
 
   private void index(DefaultInputModule module, ExclusionCounter exclusionCounter) {
     // Emulate creation of module level settings
-    ModuleConfiguration moduleConfig = new ModuleConfigurationProvider().provide(globalConfig, module, globalServerSettings, projectServerSettings);
+    ModuleConfiguration moduleConfig = new ModuleConfigurationProvider(sonarGlobalPropertiesFilter).provide(globalConfig, module, globalServerSettings, projectServerSettings);
     ModuleExclusionFilters moduleExclusionFilters = new ModuleExclusionFilters(moduleConfig);
     ModuleCoverageAndDuplicationExclusions moduleCoverageAndDuplicationExclusions = new ModuleCoverageAndDuplicationExclusions(moduleConfig);
     if (componentStore.allModules().size() > 1) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleConfigurationProviderTest.java
new file mode 100644 (file)
index 0000000..c9fcd51
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.scanner.scan;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.System2;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ModuleConfigurationProviderTest {
+
+  private static final String GLOBAL_KEY_PROPERTIES_1 = "sonar.global.key1";
+  private static final String NON_GLOBAL_KEY_PROPERTIES_1 = "sonar.key1";
+  private static final String DEFAULT_KEY_PROPERTIES_1 = "default.key1";
+  private static final String GLOBAL_VALUE_PROPERTIES_1 = "Value for " + GLOBAL_KEY_PROPERTIES_1;
+  private static final String NON_GLOBAL_VALUE_PROPERTIES_1 = "Value for " + NON_GLOBAL_KEY_PROPERTIES_1;
+  private static final String DEFAULT_VALUE_1 = "Value for " + DEFAULT_KEY_PROPERTIES_1;
+
+  private static final Map<String, String> GLOBAL_SERVER_PROPERTIES = Map.of(GLOBAL_KEY_PROPERTIES_1, GLOBAL_VALUE_PROPERTIES_1);
+  private static final Map<String, String> PROJECT_SERVER_PROPERTIES = Map.of(NON_GLOBAL_KEY_PROPERTIES_1, NON_GLOBAL_VALUE_PROPERTIES_1);
+  private static final Map<String, String> DEFAULT_PROJECT_PROPERTIES = Map.of(DEFAULT_KEY_PROPERTIES_1, DEFAULT_VALUE_1);
+
+  private static final Map<String, String> ALL_PROPERTIES_MAP =
+    Stream.of(GLOBAL_SERVER_PROPERTIES, PROJECT_SERVER_PROPERTIES)
+      .flatMap(map -> map.entrySet().stream())
+      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+  private static final Map<String, String> PROPERTIES_AFTER_FILTERING = Map.of("aKey", "aValue");
+
+  @Mock
+  private GlobalServerSettings globalServerSettings;
+  @Mock
+  private ProjectServerSettings projectServerSettings;
+  @Mock
+  private GlobalConfiguration globalConfiguration;
+  @Mock
+  private DefaultInputModule defaultInputProject;
+
+
+  @Mock
+  private SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter;
+
+  @InjectMocks
+  private ModuleConfigurationProvider provider;
+
+  @Before
+  public void init() {
+    when(globalConfiguration.getDefinitions()).thenReturn(new PropertyDefinitions(System2.INSTANCE));
+  }
+
+  @Test
+  public void should_concatAllPropertiesForCallFilterAndApplyFilterChanges() {
+    when(globalServerSettings.properties()).thenReturn(GLOBAL_SERVER_PROPERTIES);
+    when(projectServerSettings.properties()).thenReturn(PROJECT_SERVER_PROPERTIES);
+    when(sonarGlobalPropertiesFilter.enforceOnlyServerSideSonarGlobalPropertiesAreUsed(ALL_PROPERTIES_MAP, GLOBAL_SERVER_PROPERTIES))
+      .thenReturn(PROPERTIES_AFTER_FILTERING);
+
+    ModuleConfiguration provide = provider.provide(globalConfiguration, defaultInputProject, globalServerSettings, projectServerSettings);
+
+    verify(sonarGlobalPropertiesFilter).enforceOnlyServerSideSonarGlobalPropertiesAreUsed(ALL_PROPERTIES_MAP, GLOBAL_SERVER_PROPERTIES);
+    assertThat(provide.getOriginalProperties()).containsExactlyEntriesOf(PROPERTIES_AFTER_FILTERING);
+  }
+
+
+}
\ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectConfigurationProviderTest.java
new file mode 100644 (file)
index 0000000..b3cad5d
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.scanner.scan;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.System2;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ProjectConfigurationProviderTest {
+
+  private static final String GLOBAL_KEY_PROPERTIES_1 = "sonar.global.key1";
+  private static final String NON_GLOBAL_KEY_PROPERTIES_1 = "sonar.key1";
+  private static final String DEFAULT_KEY_PROPERTIES_1 = "default.key1";
+  private static final String GLOBAL_VALUE_PROPERTIES_1 = "Value for " + GLOBAL_KEY_PROPERTIES_1;
+  private static final String NON_GLOBAL_VALUE_PROPERTIES_1 = "Value for " + NON_GLOBAL_KEY_PROPERTIES_1;
+  private static final String DEFAULT_VALUE_1 = "Value for " + DEFAULT_KEY_PROPERTIES_1;
+
+  private static final Map<String, String> GLOBAL_SERVER_PROPERTIES = Map.of(GLOBAL_KEY_PROPERTIES_1, GLOBAL_VALUE_PROPERTIES_1);
+  private static final Map<String, String> PROJECT_SERVER_PROPERTIES = Map.of(NON_GLOBAL_KEY_PROPERTIES_1, NON_GLOBAL_VALUE_PROPERTIES_1);
+  private static final Map<String, String> DEFAULT_PROJECT_PROPERTIES = Map.of(DEFAULT_KEY_PROPERTIES_1, DEFAULT_VALUE_1);
+
+  private static final Map<String, String> ALL_PROPERTIES_MAP =
+    Stream.of(GLOBAL_SERVER_PROPERTIES, PROJECT_SERVER_PROPERTIES, DEFAULT_PROJECT_PROPERTIES)
+      .flatMap(map -> map.entrySet().stream())
+      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+  private static final Map<String, String> PROPERTIES_AFTER_FILTERING = Map.of("aKey", "aValue");
+
+  @Mock
+  private GlobalServerSettings globalServerSettings;
+  @Mock
+  private ProjectServerSettings projectServerSettings;
+  @Mock
+  private GlobalConfiguration globalConfiguration;
+  @Mock
+  private MutableProjectSettings mutableProjectSettings;
+  @Mock
+  private DefaultInputProject defaultInputProject;
+  @Mock
+  private SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter;
+
+  @InjectMocks
+  private ProjectConfigurationProvider provider;
+
+
+  @Before
+  public void init() {
+    when(globalConfiguration.getDefinitions()).thenReturn(new PropertyDefinitions(System2.INSTANCE));
+  }
+
+  @Test
+  public void should_concatAllPropertiesForCallFilterAndApplyFilterChanges() {
+    when(globalServerSettings.properties()).thenReturn(GLOBAL_SERVER_PROPERTIES);
+    when(projectServerSettings.properties()).thenReturn(PROJECT_SERVER_PROPERTIES);
+    when(defaultInputProject.properties()).thenReturn(DEFAULT_PROJECT_PROPERTIES);
+    when(sonarGlobalPropertiesFilter.enforceOnlyServerSideSonarGlobalPropertiesAreUsed(ALL_PROPERTIES_MAP, GLOBAL_SERVER_PROPERTIES))
+      .thenReturn(PROPERTIES_AFTER_FILTERING);
+
+    ProjectConfiguration provide = provider.provide(defaultInputProject, globalConfiguration, globalServerSettings, projectServerSettings, mutableProjectSettings);
+
+    verify(sonarGlobalPropertiesFilter).enforceOnlyServerSideSonarGlobalPropertiesAreUsed(ALL_PROPERTIES_MAP, GLOBAL_SERVER_PROPERTIES);
+    assertThat(provide.getOriginalProperties()).containsExactlyEntriesOf(PROPERTIES_AFTER_FILTERING);
+
+  }
+
+}
\ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/SonarGlobalPropertiesFilterTest.java
new file mode 100644 (file)
index 0000000..f1c02de
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.scanner.scan;
+
+import java.util.Map;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.scanner.scan.SonarGlobalPropertiesFilter.SONAR_GLOBAL_PROPERTIES_PREFIX;
+
+public class SonarGlobalPropertiesFilterTest {
+
+  private static final String SONAR_GLOBAL_KEY_1 = SONAR_GLOBAL_PROPERTIES_PREFIX + "key1";
+  private static final String SONAR_GLOBAL_VALUE_1 = "value for " + SONAR_GLOBAL_KEY_1;
+  private static final String SONAR_GLOBAL_KEY_2 = SONAR_GLOBAL_PROPERTIES_PREFIX + "key2";
+  private static final String SONAR_GLOBAL_KEY_3 = SONAR_GLOBAL_PROPERTIES_PREFIX + "key3";
+  private static final String SONAR_GLOBAL_VALUE_3 = "value for " + SONAR_GLOBAL_KEY_3;
+
+  private static final String SONAR_NON_GLOBAL_KEY_4 = "sonar.key4";
+  private static final String SONAR_NON_GLOBAL_VALUE_4 = "value for " + SONAR_NON_GLOBAL_KEY_4;
+  private static final String ANOTHER_KEY = "another key";
+  private static final String ANOTHER_VALUE = "another value";
+
+  private final SonarGlobalPropertiesFilter sonarGlobalPropertiesFilter = new SonarGlobalPropertiesFilter();
+
+  @Test
+  public void should_filterSonarGlobalProperties() {
+    Map<String, String> settingProperties = Map.of(
+      SONAR_GLOBAL_KEY_1, "shouldBeOverride",
+      SONAR_GLOBAL_KEY_2, "shouldBeRemove",
+      SONAR_NON_GLOBAL_KEY_4, SONAR_NON_GLOBAL_VALUE_4,
+      ANOTHER_KEY, ANOTHER_VALUE);
+
+    Map<String, String> globalServerSettingsProperties = Map.of(
+      SONAR_GLOBAL_KEY_1, SONAR_GLOBAL_VALUE_1,
+      SONAR_GLOBAL_KEY_3, SONAR_GLOBAL_VALUE_3,
+      SONAR_NON_GLOBAL_KEY_4, "shouldBeIgnored"
+    );
+
+    Map<String, String> properties = sonarGlobalPropertiesFilter.enforceOnlyServerSideSonarGlobalPropertiesAreUsed(settingProperties, globalServerSettingsProperties);
+
+    assertThat(properties).hasSize(4)
+      .containsEntry(SONAR_GLOBAL_KEY_1, SONAR_GLOBAL_VALUE_1)
+      .containsEntry(SONAR_GLOBAL_KEY_3, SONAR_GLOBAL_VALUE_3)
+      .containsEntry(SONAR_NON_GLOBAL_KEY_4, SONAR_NON_GLOBAL_VALUE_4)
+      .containsEntry(ANOTHER_KEY, ANOTHER_VALUE);
+
+
+  }
+}
\ No newline at end of file