]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18591 Different warning message if using sonar.login with token
authorEric Giffon <eric.giffon@sonarsource.com>
Mon, 27 Mar 2023 12:59:28 +0000 (14:59 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 29 Mar 2023 20:03:02 +0000 (20:03 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGenerator.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGeneratorTest.java

index 54595d632d058e5c133407c454922568559a2fab..8dfb0eccf3e4690783f2f73009f7e1ff7379017b 100644 (file)
@@ -32,8 +32,12 @@ public class DeprecatedPropertiesWarningGenerator {
   private static final Logger LOG = Loggers.get(DeprecatedPropertiesWarningGenerator.class);
 
   @VisibleForTesting
-  static final String CREDENTIALS_WARN_MESSAGE = String.format("The properties '%s' and '%s' are deprecated. They will not be supported " +
-    "in the future. Please instead use the '%s' parameter.", CoreProperties.LOGIN, CoreProperties.PASSWORD, ScannerWsClientProvider.TOKEN_PROPERTY);
+  static final String PASSWORD_WARN_MESSAGE = String.format("The properties '%s' and '%s' are deprecated and will be removed in the " +
+      "future. Please pass a token with the '%s' property instead.", CoreProperties.LOGIN, CoreProperties.PASSWORD,
+    ScannerWsClientProvider.TOKEN_PROPERTY);
+  @VisibleForTesting
+  static final String LOGIN_WARN_MESSAGE = String.format("The property '%s' is deprecated and will be removed in the future. " +
+    "Please use the '%s' property instead when passing a token.", CoreProperties.LOGIN, ScannerWsClientProvider.TOKEN_PROPERTY);
 
   private final Configuration configuration;
   private final AnalysisWarnings analysisWarnings;
@@ -46,10 +50,12 @@ public class DeprecatedPropertiesWarningGenerator {
   public void execute() {
     Optional<String> login = configuration.get(CoreProperties.LOGIN);
     Optional<String> password = configuration.get(CoreProperties.PASSWORD);
-    if (login.isPresent() || password.isPresent()) {
-      LOG.warn(CREDENTIALS_WARN_MESSAGE);
-      analysisWarnings.addUnique(CREDENTIALS_WARN_MESSAGE);
+    if (password.isPresent()) {
+      LOG.warn(PASSWORD_WARN_MESSAGE);
+      analysisWarnings.addUnique(PASSWORD_WARN_MESSAGE);
+    } else if (login.isPresent()) {
+      LOG.warn(LOGIN_WARN_MESSAGE);
+      analysisWarnings.addUnique(LOGIN_WARN_MESSAGE);
     }
   }
-
 }
index f8cbf8c944d3bceed42766108366f4982f960d8c..c6eb658e6f5919640f92f864ab641d999f8c9bd9 100644 (file)
@@ -33,7 +33,8 @@ import org.sonar.api.utils.log.LoggerLevel;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
-import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.CREDENTIALS_WARN_MESSAGE;
+import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.LOGIN_WARN_MESSAGE;
+import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.PASSWORD_WARN_MESSAGE;
 
 public class DeprecatedPropertiesWarningGeneratorTest {
 
@@ -58,18 +59,19 @@ public class DeprecatedPropertiesWarningGeneratorTest {
 
     underTest.execute();
 
-    verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
-    Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
+    verify(analysisWarnings, times(1)).addUnique(LOGIN_WARN_MESSAGE);
+    Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(LOGIN_WARN_MESSAGE);
   }
 
   @Test
   public void execute_whenUsingPassword_shouldAddWarning() {
+    settings.setProperty(CoreProperties.LOGIN, "test");
     settings.setProperty(CoreProperties.PASSWORD, "winner winner chicken dinner");
 
     underTest.execute();
 
-    verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
-    Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
+    verify(analysisWarnings, times(1)).addUnique(PASSWORD_WARN_MESSAGE);
+    Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(PASSWORD_WARN_MESSAGE);
   }
 
   @Test