From: Eric Giffon Date: Mon, 27 Mar 2023 12:59:28 +0000 (+0200) Subject: SONAR-18591 Different warning message if using sonar.login with token X-Git-Tag: 10.0.0.68432~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a7e55ceeaa52e4286de4431ebb2d21318d60a4db;p=sonarqube.git SONAR-18591 Different warning message if using sonar.login with token --- diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGenerator.java index 54595d632d0..8dfb0eccf3e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGenerator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGenerator.java @@ -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 login = configuration.get(CoreProperties.LOGIN); Optional 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); } } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGeneratorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGeneratorTest.java index f8cbf8c944d..c6eb658e6f5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGeneratorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DeprecatedPropertiesWarningGeneratorTest.java @@ -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