|
@@ -0,0 +1,78 @@
|
|
|
+/*
|
|
|
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
+ * or more contributor license agreements. Licensed under the "Elastic License
|
|
|
+ * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
|
|
+ * Public License v 1"; you may not use this file except in compliance with, at
|
|
|
+ * your election, the "Elastic License 2.0", the "GNU Affero General Public
|
|
|
+ * License v3.0 only", or the "Server Side Public License, v 1".
|
|
|
+ */
|
|
|
+
|
|
|
+package org.elasticsearch.upgrades;
|
|
|
+
|
|
|
+import com.carrotsearch.randomizedtesting.annotations.Name;
|
|
|
+
|
|
|
+import org.elasticsearch.common.settings.SecureString;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.util.concurrent.ThreadContext;
|
|
|
+import org.elasticsearch.core.SuppressForbidden;
|
|
|
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
|
|
+import org.elasticsearch.test.cluster.local.distribution.DistributionType;
|
|
|
+import org.elasticsearch.test.cluster.util.Version;
|
|
|
+import org.junit.ClassRule;
|
|
|
+import org.junit.rules.RuleChain;
|
|
|
+import org.junit.rules.TemporaryFolder;
|
|
|
+import org.junit.rules.TestRule;
|
|
|
+
|
|
|
+import java.util.function.Supplier;
|
|
|
+
|
|
|
+public abstract class AbstractRollingUpgradeWithSecurityTestCase extends ParameterizedRollingUpgradeTestCase {
|
|
|
+
|
|
|
+ private static final String USER = "test_admin";
|
|
|
+ private static final String PASS = "x-pack-test-password";
|
|
|
+
|
|
|
+ private static final TemporaryFolder repoDirectory = new TemporaryFolder();
|
|
|
+
|
|
|
+ private static final ElasticsearchCluster cluster = buildCluster();
|
|
|
+
|
|
|
+ private static ElasticsearchCluster buildCluster() {
|
|
|
+ Version oldVersion = Version.fromString(OLD_CLUSTER_VERSION);
|
|
|
+ var cluster = ElasticsearchCluster.local()
|
|
|
+ .distribution(DistributionType.DEFAULT)
|
|
|
+ .version(getOldClusterTestVersion())
|
|
|
+ .nodes(NODE_NUM)
|
|
|
+ .user(USER, PASS)
|
|
|
+ .setting("xpack.security.autoconfiguration.enabled", "false")
|
|
|
+ .setting("path.repo", new Supplier<>() {
|
|
|
+ @Override
|
|
|
+ @SuppressForbidden(reason = "TemporaryFolder only has io.File methods, not nio.File")
|
|
|
+ public String get() {
|
|
|
+ return repoDirectory.getRoot().getPath();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Avoid triggering bogus assertion when serialized parsed mappings don't match with original mappings, because _source key is
|
|
|
+ // inconsistent
|
|
|
+ if (oldVersion.before(Version.fromString("8.18.0"))) {
|
|
|
+ cluster.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper");
|
|
|
+ cluster.jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
|
|
|
+ }
|
|
|
+ return cluster.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ClassRule
|
|
|
+ public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(cluster);
|
|
|
+
|
|
|
+ protected AbstractRollingUpgradeWithSecurityTestCase(@Name("upgradedNodes") int upgradedNodes) {
|
|
|
+ super(upgradedNodes);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ElasticsearchCluster getUpgradeCluster() {
|
|
|
+ return cluster;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Settings restClientSettings() {
|
|
|
+ String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
|
|
|
+ return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
|
|
|
+ }
|
|
|
+}
|