Skip to content

Commit

Permalink
Update Orchestrator to support SQ 8.6 (enforce authentication)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Nov 27, 2020
1 parent dd3013c commit f4eef04
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion its/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>org.sonarsource.orchestrator</groupId>
<artifactId>sonar-orchestrator</artifactId>
<version>3.31.0.2646</version>
<version>3.34.0.2692</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions its/tests/src/test/java/its/CommercialAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 7 additions & 2 deletions its/tests/src/test/java/its/ConnectedFileMatchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -74,7 +75,7 @@ public class ConnectedFileMatchingTest extends AbstractConnectedTest {
private static Path sonarUserHome;

private ConnectedSonarLintEngine engine;
private List<String> logs = new ArrayList<>();
private final List<String> logs = new ArrayList<>();

@BeforeClass
public static void prepare() {
Expand Down Expand Up @@ -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<ClientInputFile> filesToAnalyze = clientTools.collectAllFiles(projectDir)
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -74,7 +75,7 @@ public static void beforeClass() {
private static Path sonarUserHome;

private ConnectedSonarLintEngine engine;
private List<String> logs = new ArrayList<>();
private final List<String> logs = new ArrayList<>();

@Before
public void prepare() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 9 additions & 12 deletions its/tests/src/test/java/its/ConnectedModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"));
}
}
Expand Down Expand Up @@ -486,7 +485,8 @@ public void canFetchHotspot() throws InvalidProtocolBufferException {
SonarLintWsClient slClient = new SonarLintWsClient(getServerConfig());
SecurityHotspotsService securityHotspotsService = new SecurityHotspotsService(slClient);

Optional<RemoteHotspot> remoteHotspot = securityHotspotsService.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(slClient, PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT));
Optional<RemoteHotspot> remoteHotspot = securityHotspotsService
.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(slClient, PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT));

assertThat(remoteHotspot).isNotEmpty();
RemoteHotspot actualHotspot = remoteHotspot.get();
Expand Down Expand Up @@ -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));
}

}

0 comments on commit f4eef04

Please sign in to comment.