From 204d9b7f21fb8807c8a53756d1234a00023a9206 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Mon, 8 May 2023 11:17:08 +0200 Subject: [PATCH] SONAR-19110 Update Not Authorized message to include sonar.token --- .../scanner/bootstrap/DefaultScannerWsClient.java | 13 +++++++------ .../bootstrap/DefaultScannerWsClientTest.java | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java index 5dfc85f4dd2..e3ba9e36e69 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java @@ -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."); } /** diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java index 84494037505..9b746403496 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java @@ -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 -- 2.39.5