diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-06 15:52:43 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:55 +0200 |
commit | 7e778849d1c669cd87c90de21cb3d1ea6494e759 (patch) | |
tree | 0545591c3034fc933cea52b1f63bda9f64b58e90 /tests/src | |
parent | 3de079f32f95e92f08f03d599d7b483086b87cfa (diff) | |
download | sonarqube-7e778849d1c669cd87c90de21cb3d1ea6494e759.tar.gz sonarqube-7e778849d1c669cd87c90de21cb3d1ea6494e759.zip |
SONAR-9741 add authentication to api/system/health
Diffstat (limited to 'tests/src')
4 files changed, 28 insertions, 7 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java index 74efbf7b53a..58fb754f4b2 100644 --- a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java +++ b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java @@ -37,6 +37,7 @@ class Cluster implements AutoCloseable { private final String clusterName; private final List<Node> nodes = new ArrayList<>(); + private final String systemPassCode = "fooBar2000"; Cluster(@Nullable String name) { this.clusterName = name; @@ -50,6 +51,7 @@ class Cluster implements AutoCloseable { Node addNode(NodeConfig config, Consumer<OrchestratorBuilder> consumer) { OrchestratorBuilder builder = newOrchestratorBuilder(config); + builder.setServerProperty("sonar.web.systemPasscode", systemPassCode); switch (config.getType()) { case SEARCH: @@ -71,7 +73,7 @@ class Cluster implements AutoCloseable { } consumer.accept(builder); Orchestrator orchestrator = builder.build(); - Node node = new Node(config, orchestrator); + Node node = new Node(config, orchestrator, systemPassCode); nodes.add(node); return node; } diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/Node.java b/tests/src/test/java/org/sonarqube/tests/cluster/Node.java index 7826325d34d..e8846c28042 100644 --- a/tests/src/test/java/org/sonarqube/tests/cluster/Node.java +++ b/tests/src/test/java/org/sonarqube/tests/cluster/Node.java @@ -42,12 +42,14 @@ class Node { private final NodeConfig config; private final Orchestrator orchestrator; + private final String systemPassCode; private LogsTailer logsTailer; private final LogsTailer.Content content = new LogsTailer.Content(); - Node(NodeConfig config, Orchestrator orchestrator) { + Node(NodeConfig config, Orchestrator orchestrator, String systemPassCode) { this.config = config; this.orchestrator = orchestrator; + this.systemPassCode = systemPassCode; } NodeConfig getConfig() { @@ -142,7 +144,7 @@ class Node { return Optional.empty(); } try { - return Optional.ofNullable(ItUtils.newAdminWsClient(orchestrator).system().health()); + return Optional.ofNullable(ItUtils.newSystemUserWsClient(orchestrator, systemPassCode).system().health()); } catch (Exception e) { return Optional.empty(); } diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java index b61b5ba8237..a305187d881 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java @@ -24,9 +24,11 @@ import com.sonar.orchestrator.util.NetworkUtils; import java.io.File; import java.io.IOException; import java.net.InetAddress; +import java.util.Arrays; import java.util.Optional; import java.util.function.Supplier; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.RandomStringUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; @@ -38,8 +40,8 @@ import org.sonarqube.ws.WsSystem; import org.sonarqube.ws.client.WsClient; import static com.google.common.base.Preconditions.checkState; -import static java.util.stream.Collectors.joining; import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.newSystemUserWsClient; import static util.ItUtils.newWsClient; import static util.ItUtils.pluginArtifact; @@ -50,10 +52,11 @@ public class SystemStateTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule public TestRule safeguard = new DisableOnDebug(Timeout.seconds(300)); + private final String systemPassCode = RandomStringUtils.randomAlphanumeric(15); + @Test public void test_status_and_health_during_server_lifecycle() throws Exception { try (Commander commander = new Commander()) { @@ -130,6 +133,7 @@ public class SystemStateTest { .setServerProperty("sonar.web.startupLock.path", lock.webFile.getAbsolutePath()) .setServerProperty("sonar.ce.startupLock.path", lock.ceFile.getAbsolutePath()) .setServerProperty("sonar.search.httpPort", "" + esHttpPort) + .setServerProperty("sonar.web.systemPasscode", systemPassCode) .build(); elasticsearch = new Elasticsearch(esHttpPort); @@ -185,7 +189,7 @@ public class SystemStateTest { Optional<WsSystem.HealthResponse> healthResponse() { if (orchestrator.getServer() != null) { - WsClient wsClient = newWsClient(orchestrator); + WsClient wsClient = newSystemUserWsClient(orchestrator, systemPassCode); try { return Optional.of(wsClient.system().health()); } catch (Exception e) { @@ -203,10 +207,11 @@ public class SystemStateTest { void verifyHealth(WsSystem.Health expectedHealth, String... expectedMessages) { WsSystem.HealthResponse response = healthResponse().get(); assertThat(response.getHealth()) - .as(response.getCausesList().stream().map(WsSystem.Cause::getMessage).collect(joining(","))) + .describedAs("Expected status %s in response %s", expectedHealth, response) .isEqualTo(expectedHealth); assertThat(response.getCausesList()) .extracting(WsSystem.Cause::getMessage) + .describedAs("Expected causes %s in response %s", Arrays.asList(expectedMessages), response) .containsExactlyInAnyOrder(expectedMessages); } diff --git a/tests/src/test/java/util/ItUtils.java b/tests/src/test/java/util/ItUtils.java index d86b0b91ffc..05f231afc6c 100644 --- a/tests/src/test/java/util/ItUtils.java +++ b/tests/src/test/java/util/ItUtils.java @@ -130,6 +130,18 @@ public class ItUtils { } /** + * @deprecated replaced by {@link Tester#wsClient()} + */ + @Deprecated + public static WsClient newSystemUserWsClient(Orchestrator orchestrator, @Nullable String systemPassCode) { + Server server = orchestrator.getServer(); + return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() + .url(server.getUrl()) + .systemPassCode(systemPassCode) + .build()); + } + + /** * Locate the directory of sample project * * @param relativePath path related to the directory it/projects, for example "qualitygate/xoo-sample" |