From f4eef04f25d07fb47cb530e83c18ff39b82603f6 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 27 Nov 2020 08:34:49 +0100 Subject: [PATCH] Update Orchestrator to support SQ 8.6 (enforce authentication) --- its/tests/pom.xml | 2 +- .../test/java/its/CommercialAnalyzerTest.java | 1 + .../java/its/ConnectedFileMatchingTest.java | 9 ++++++-- .../ConnectedModeExcludeByVersionTest.java | 3 ++- .../its/ConnectedModeRequirementsTest.java | 1 + .../src/test/java/its/ConnectedModeTest.java | 21 ++++++++----------- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/its/tests/pom.xml b/its/tests/pom.xml index 8863f84174..9ff5022482 100644 --- a/its/tests/pom.xml +++ b/its/tests/pom.xml @@ -24,7 +24,7 @@ org.sonarsource.orchestrator sonar-orchestrator - 3.31.0.2646 + 3.34.0.2692 test diff --git a/its/tests/src/test/java/its/CommercialAnalyzerTest.java b/its/tests/src/test/java/its/CommercialAnalyzerTest.java index ec550eb4f9..bf08eb1573 100644 --- a/its/tests/src/test/java/its/CommercialAnalyzerTest.java +++ b/its/tests/src/test/java/its/CommercialAnalyzerTest.java @@ -60,6 +60,7 @@ public class CommercialAnalyzerTest extends AbstractConnectedTest { @ClassRule public static Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .defaultForceAuthentication() .setSonarVersion(SONAR_VERSION) .setEdition(Edition.ENTERPRISE) .restoreProfileAtStartup(FileLocation.ofClasspath("/c-sonarlint.xml")) diff --git a/its/tests/src/test/java/its/ConnectedFileMatchingTest.java b/its/tests/src/test/java/its/ConnectedFileMatchingTest.java index 43e8d8db20..9e4cd6257e 100644 --- a/its/tests/src/test/java/its/ConnectedFileMatchingTest.java +++ b/its/tests/src/test/java/its/ConnectedFileMatchingTest.java @@ -58,6 +58,7 @@ public class ConnectedFileMatchingTest extends AbstractConnectedTest { @ClassRule public static Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .defaultForceAuthentication() .setSonarVersion(SONAR_VERSION) .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", ItUtils.javaVersion)) .build(); @@ -74,7 +75,7 @@ public class ConnectedFileMatchingTest extends AbstractConnectedTest { private static Path sonarUserHome; private ConnectedSonarLintEngine engine; - private List logs = new ArrayList<>(); + private final List logs = new ArrayList<>(); @BeforeClass public static void prepare() { @@ -146,6 +147,7 @@ private ServerConfiguration getServerConfig() { .build(); } + @Override protected ConnectedAnalysisConfiguration createAnalysisConfiguration(String projectKey, String projectDirName, String filePath, String... properties) throws IOException { Path projectDir = Paths.get("projects/" + projectDirName).toAbsolutePath(); List filesToAnalyze = clientTools.collectAllFiles(projectDir) @@ -164,6 +166,9 @@ protected ConnectedAnalysisConfiguration createAnalysisConfiguration(String proj private static void analyzeMavenProject(String projectDirName) { Path projectDir = Paths.get("projects/" + projectDirName).toAbsolutePath(); Path pom = projectDir.resolve("pom.xml"); - ORCHESTRATOR.executeBuild(MavenBuild.create(pom.toFile()).setCleanPackageSonarGoals()); + ORCHESTRATOR.executeBuild(MavenBuild.create(pom.toFile()) + .setCleanPackageSonarGoals() + .setProperty("sonar.login", com.sonar.orchestrator.container.Server.ADMIN_LOGIN) + .setProperty("sonar.password", com.sonar.orchestrator.container.Server.ADMIN_PASSWORD)); } } diff --git a/its/tests/src/test/java/its/ConnectedModeExcludeByVersionTest.java b/its/tests/src/test/java/its/ConnectedModeExcludeByVersionTest.java index b154d9deaf..a04e48cc91 100644 --- a/its/tests/src/test/java/its/ConnectedModeExcludeByVersionTest.java +++ b/its/tests/src/test/java/its/ConnectedModeExcludeByVersionTest.java @@ -62,6 +62,7 @@ public static void beforeClass() { @Rule public Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .defaultForceAuthentication() .setSonarVersion(SONAR_VERSION) .addPlugin(MavenLocation.of("org.sonarsource.python", "sonar-python-plugin", "1.9.0.2010")).build(); @@ -74,7 +75,7 @@ public static void beforeClass() { private static Path sonarUserHome; private ConnectedSonarLintEngine engine; - private List logs = new ArrayList<>(); + private final List logs = new ArrayList<>(); @Before public void prepare() throws Exception { diff --git a/its/tests/src/test/java/its/ConnectedModeRequirementsTest.java b/its/tests/src/test/java/its/ConnectedModeRequirementsTest.java index b2c26e3c62..3ef5eeba2d 100644 --- a/its/tests/src/test/java/its/ConnectedModeRequirementsTest.java +++ b/its/tests/src/test/java/its/ConnectedModeRequirementsTest.java @@ -66,6 +66,7 @@ public class ConnectedModeRequirementsTest extends AbstractConnectedTest { @ClassRule public static Orchestrator ORCHESTRATOR = Orchestrator.builderEnv().setSonarVersion(SONAR_VERSION) + .defaultForceAuthentication() .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", ItUtils.javaVersion)) .addPlugin(MavenLocation.of("org.sonarsource.php", "sonar-php-plugin", ItUtils.phpVersion)) .addPlugin(MavenLocation.of("org.sonarsource.javascript", "sonar-javascript-plugin", ItUtils.javascriptVersion)) diff --git a/its/tests/src/test/java/its/ConnectedModeTest.java b/its/tests/src/test/java/its/ConnectedModeTest.java index 65c325d7ef..c1ea1e1583 100644 --- a/its/tests/src/test/java/its/ConnectedModeTest.java +++ b/its/tests/src/test/java/its/ConnectedModeTest.java @@ -64,7 +64,6 @@ import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; -import org.sonarqube.ws.client.permissions.RemoveGroupRequest; import org.sonarqube.ws.client.qualityprofiles.ActivateRuleRequest; import org.sonarqube.ws.client.qualityprofiles.SearchRequest; import org.sonarqube.ws.client.settings.ResetRequest; @@ -74,8 +73,8 @@ import org.sonarsource.sonarlint.core.NodeJsHelper; import org.sonarsource.sonarlint.core.WsHelperImpl; import org.sonarsource.sonarlint.core.client.api.common.Language; -import org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults; import org.sonarsource.sonarlint.core.client.api.common.TextRange; +import org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults; import org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration; import org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine; import org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine.State; @@ -119,6 +118,7 @@ private static String javaRuleKey(String key) { @ClassRule public static Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .defaultForceAuthentication() .setSonarVersion(SONAR_VERSION) .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", ItUtils.javaVersion)) .addPlugin(MavenLocation.of("org.sonarsource.python", "sonar-python-plugin", ItUtils.pythonVersion)) @@ -310,8 +310,7 @@ public void updateNoAuth() { fail("Exception expected"); } catch (Exception e) { assertThat(e).hasMessage("Not authorized. Please check server credentials."); - } - finally { + } finally { adminWsClient.settings().set(new SetRequest().setKey("sonar.forceAuthentication").setValue("false")); } } @@ -486,7 +485,8 @@ public void canFetchHotspot() throws InvalidProtocolBufferException { SonarLintWsClient slClient = new SonarLintWsClient(getServerConfig()); SecurityHotspotsService securityHotspotsService = new SecurityHotspotsService(slClient); - Optional remoteHotspot = securityHotspotsService.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(slClient, PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT)); + Optional remoteHotspot = securityHotspotsService + .fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(slClient, PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT)); assertThat(remoteHotspot).isNotEmpty(); RemoteHotspot actualHotspot = remoteHotspot.get(); @@ -826,16 +826,13 @@ private ServerConfiguration getServerConfig(boolean redirect) { .build(); } - private static void removeGroupPermission(String groupName, String permission) { - adminWsClient.permissions().removeGroup(new RemoveGroupRequest() - .setGroupName(groupName) - .setPermission(permission)); - } - private static void analyzeMavenProject(String projectDirName) { Path projectDir = Paths.get("projects/" + projectDirName).toAbsolutePath(); Path pom = projectDir.resolve("pom.xml"); - ORCHESTRATOR.executeBuild(MavenBuild.create(pom.toFile()).setCleanPackageSonarGoals()); + ORCHESTRATOR.executeBuild(MavenBuild.create(pom.toFile()) + .setCleanPackageSonarGoals() + .setProperty("sonar.login", com.sonar.orchestrator.container.Server.ADMIN_LOGIN) + .setProperty("sonar.password", com.sonar.orchestrator.container.Server.ADMIN_PASSWORD)); } }