]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19110 Update Not Authorized message to include sonar.token
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Mon, 8 May 2023 09:17:08 +0000 (11:17 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 8 May 2023 20:03:47 +0000 (20:03 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java

index 5dfc85f4dd269949d110a9572ab5ac93e1761382..e3ba9e36e69561050b3c30ae803ab7e560ff207a 100644 (file)
@@ -105,16 +105,17 @@ public class DefaultScannerWsClient implements ScannerWsClient {
       response.close();
       if (hasCredentials) {
         // credentials are not valid
-        throw MessageException.of(format("Not authorized. Please check the properties %s and %s.",
-          CoreProperties.LOGIN, CoreProperties.PASSWORD));
+        throw MessageException.of(format("Not authorized. Please check the user token in the property '%s' or the credentials in the properties '%s' and '%s'.",
+          ScannerWsClientProvider.TOKEN_PROPERTY, CoreProperties.LOGIN, CoreProperties.PASSWORD));
       }
       // not authenticated - see https://jira.sonarsource.com/browse/SONAR-4048
-      throw MessageException.of(format("Not authorized. Analyzing this project requires authentication. Please provide a user token in %s" +
-        " or other credentials in %s and %s.", ScannerWsClientProvider.TOKEN_PROPERTY, CoreProperties.LOGIN, CoreProperties.PASSWORD));
+      throw MessageException.of(format("Not authorized. Analyzing this project requires authentication. " +
+                                       "Please check the user token in the property '%s' or the credentials in the properties '%s' and '%s'.",
+        ScannerWsClientProvider.TOKEN_PROPERTY, CoreProperties.LOGIN, CoreProperties.PASSWORD));
     }
     if (code == HTTP_FORBIDDEN) {
       throw MessageException.of("You're not authorized to analyze this project or the project doesn't exist on SonarQube" +
-        " and you're not authorized to create it. Please contact an administrator.");
+                                " and you're not authorized to create it. Please contact an administrator.");
     }
     if (code == HTTP_BAD_REQUEST) {
       String jsonMsg = tryParseAsJsonError(response.content());
@@ -153,7 +154,7 @@ public class DefaultScannerWsClient implements ScannerWsClient {
       LOG.warn("Analysis executed with this token will fail after the expiration date.");
     }
     analysisWarnings.addUnique(warningMessage + "\nAfter this date, the token can no longer be used to execute the analysis. "
-      + "Please consider generating a new token and updating it in the locations where it is in use.");
+                               + "Please consider generating a new token and updating it in the locations where it is in use.");
   }
 
   /**
index 844940375054a9e8a0699c60e888813746880da8..9b746403496eec2c08d44b6d8c0e3831881b02e2 100644 (file)
@@ -102,8 +102,8 @@ public class DefaultScannerWsClientTest {
     assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, false,
       new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), analysisWarnings).call(request))
         .isInstanceOf(MessageException.class)
-        .hasMessage("Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.token or other " +
-          "credentials in sonar.login and sonar.password.");
+        .hasMessage("Not authorized. Analyzing this project requires authentication. Please check the user token in the property 'sonar.token' " +
+                    "or the credentials in the properties 'sonar.login' and 'sonar.password'.");
   }
 
   @Test
@@ -115,7 +115,7 @@ public class DefaultScannerWsClientTest {
     assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, /* credentials are configured */true,
       new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), analysisWarnings).call(request))
         .isInstanceOf(MessageException.class)
-        .hasMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
+        .hasMessage("Not authorized. Please check the user token in the property 'sonar.token' or the credentials in the properties 'sonar.login' and 'sonar.password'.");
   }
 
   @Test