aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire Villard <claire.villard@sonarsource.com>2024-12-18 15:57:28 +0100
committersonartech <sonartech@sonarsource.com>2024-12-19 20:03:04 +0000
commitdf62520f58574f1737d8a0761c8a724235a0aaee (patch)
treed7c0890fd63d061b55749f3abc4917c881799406
parent5bb7879366bffed259b4278d7d004feb175050cc (diff)
downloadsonarqube-df62520f58574f1737d8a0761c8a724235a0aaee.tar.gz
sonarqube-df62520f58574f1737d8a0761c8a724235a0aaee.zip
SONAR-23968 Log a warning when encrypted properties are used on Scanner side
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java14
2 files changed, 16 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java
index 85b0fcd41bd..a766101f54a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java
@@ -23,6 +23,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.config.internal.Encryption;
import static org.sonar.api.CoreProperties.ENCRYPTION_SECRET_KEY_PATH;
@@ -33,6 +35,7 @@ import static org.sonar.api.CoreProperties.PROJECT_KEY_PROPERTY;
*/
@Immutable
public class ScannerProperties {
+ private static final Logger LOG = LoggerFactory.getLogger(ScannerProperties.class);
private final Map<String, String> properties;
private final Encryption encryption;
@@ -43,6 +46,7 @@ public class ScannerProperties {
for (Map.Entry<String, String> entry : properties.entrySet()) {
String value = entry.getValue();
if (value != null && encryption.isEncrypted(value)) {
+ LOG.warn("Property '{}' is encrypted. The encryption of scanner properties is deprecated and will soon be removed.", entry.getKey());
try {
value = encryption.decrypt(value);
} catch (Exception e) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java
index 358c5820467..cb218245de4 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java
@@ -20,12 +20,18 @@
package org.sonar.scanner.bootstrap;
import com.google.common.collect.ImmutableMap;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.event.Level;
+import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class ScannerPropertiesTest {
+class ScannerPropertiesTest {
+
+ @RegisterExtension
+ LogTesterJUnit5 logTester = new LogTesterJUnit5();
@Test
public void initialization() {
@@ -60,6 +66,10 @@ public class ScannerPropertiesTest {
ScannerProperties underTest = new ScannerProperties(map);
assertThat(underTest.property("prop-1")).isEqualTo("foo");
+
+ assertThat(logTester.logs(Level.WARN))
+ .contains(
+ "Property 'prop-1' is encrypted. The encryption of scanner properties is deprecated and will soon be removed.");
}
}