diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-05-23 15:08:17 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-15 09:57:00 +0200 |
commit | 4f3018eb093f9c2d5406df7674eb0e9a7b50e44c (patch) | |
tree | 4187b0d2e72d98c8c1b3a26dd33da1615bdd0150 /tests | |
parent | 1de512a131f84fb1b6656150347d2b075b478780 (diff) | |
download | sonarqube-4f3018eb093f9c2d5406df7674eb0e9a7b50e44c.tar.gz sonarqube-4f3018eb093f9c2d5406df7674eb0e9a7b50e44c.zip |
SONAR-9301 Support HTTP redirect on scanner side
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/Category3Suite.java | 8 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/analysis/RedirectTest.java | 107 |
2 files changed, 112 insertions, 3 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java index 73d44089ac4..51328e715c5 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java @@ -20,6 +20,9 @@ package org.sonarqube.tests; import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; import org.sonarqube.tests.analysis.ExtensionLifecycleTest; import org.sonarqube.tests.analysis.FavoriteTest; import org.sonarqube.tests.analysis.IssueJsonReportTest; @@ -28,6 +31,7 @@ import org.sonarqube.tests.analysis.LinksTest; import org.sonarqube.tests.analysis.MultiLanguageTest; import org.sonarqube.tests.analysis.PermissionTest; import org.sonarqube.tests.analysis.ProjectBuilderTest; +import org.sonarqube.tests.analysis.RedirectTest; import org.sonarqube.tests.analysis.ReportDumpTest; import org.sonarqube.tests.analysis.SSLTest; import org.sonarqube.tests.analysis.ScannerTest; @@ -36,9 +40,6 @@ import org.sonarqube.tests.analysis.TempFolderTest; import org.sonarqube.tests.measure.DecimalScaleMetricTest; import org.sonarqube.tests.plugins.VersionPluginTest; import org.sonarqube.tests.webhook.WebhooksTest; -import org.junit.ClassRule; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; import static util.ItUtils.pluginArtifact; import static util.ItUtils.xooPlugin; @@ -60,6 +61,7 @@ import static util.ItUtils.xooPlugin; ReportDumpTest.class, SSLTest.class, FavoriteTest.class, + RedirectTest.class, // measures DecimalScaleMetricTest.class, WebhooksTest.class diff --git a/tests/src/test/java/org/sonarqube/tests/analysis/RedirectTest.java b/tests/src/test/java/org/sonarqube/tests/analysis/RedirectTest.java new file mode 100644 index 00000000000..4e1ffec8f2a --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/analysis/RedirectTest.java @@ -0,0 +1,107 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.tests.analysis; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.BuildResult; +import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.util.NetworkUtils; +import java.net.InetAddress; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.MovedContextHandler; +import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.RuleChain; +import org.sonarqube.tests.Category3Suite; +import org.sonarqube.tests.Tester; +import util.ItUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RedirectTest { + + public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; + public static Tester tester = new Tester(orchestrator).disableOrganizations(); + + @ClassRule + public static RuleChain chain = RuleChain + .outerRule(orchestrator) + .around(tester); + + private static Server server; + private static int redirectPort; + + @BeforeClass + public static void beforeClass() throws Exception { + // enforce scanners to be authenticated + tester.settings().setGlobalSetting("sonar.forceAuthentication", "true"); + + orchestrator.resetData(); + redirectPort = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); + + QueuedThreadPool threadPool = new QueuedThreadPool(); + threadPool.setMaxThreads(500); + + server = new Server(threadPool); + // HTTP Configuration + HttpConfiguration httpConfig = new HttpConfiguration(); + httpConfig.setSendServerVersion(true); + httpConfig.setSendDateHeader(false); + + // Moved handler + MovedContextHandler movedContextHandler = new MovedContextHandler(); + movedContextHandler.setPermanent(true); + movedContextHandler.setNewContextURL(orchestrator.getServer().getUrl()); + server.setHandler(movedContextHandler); + + // http connector + ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); + http.setPort(redirectPort); + server.addConnector(http); + server.start(); + } + + @AfterClass + public static void after() throws Exception { + server.stop(); + } + + @Test + public void testFollowRedirectWithAuthentication() { + orchestrator.getServer(); + SonarScanner sonarScanner = SonarScanner.create(ItUtils.projectDir("shared/xoo-sample")) + .setScannerVersion("2.7") + .setProperty("sonar.host.url", "http://localhost:" + redirectPort) + .setProperties( + "sonar.login", com.sonar.orchestrator.container.Server.ADMIN_LOGIN, + "sonar.password", com.sonar.orchestrator.container.Server.ADMIN_PASSWORD); + BuildResult buildResult = orchestrator.executeBuild(sonarScanner); + + // logs show original URL + assertThat(buildResult.getLogs()).contains("ANALYSIS SUCCESSFUL, you can browse " + "http://localhost:" + redirectPort); + + } +} |