Use TestEnvironment factory method to create test Environment objects (elastic/x-pack-elasticsearch#2860)
This is the X-Pack side of elastic/elasticsearch#27235. To force people who construct an Environment object in production code to think about the correct setting of configPath there is no longer a single argument constructor in the Environment class. Instead there is a factory method in the test framework to replace it. Having this in the test framework ensures that there is no way to use it in production code. Original commit: elastic/x-pack-elasticsearch@4860e92d90
This commit is contained in:
parent
5b85453c9a
commit
7b36046f33
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit;
|
|||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.mocksocket.MockServerSocket;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.http.MockResponse;
|
||||
|
@ -61,7 +62,7 @@ public class HttpClientTests extends ESTestCase {
|
|||
private MockWebServer webServer = new MockWebServer();
|
||||
private HttpClient httpClient;
|
||||
private HttpAuthRegistry authRegistry;
|
||||
private Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
private Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.http.conn.ConnectTimeoutException;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
|
||||
|
@ -24,7 +25,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
|
|||
|
||||
@Network
|
||||
public void testDefaultTimeout() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class),
|
||||
new SSLService(environment.settings(), environment));
|
||||
|
||||
|
@ -49,7 +50,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
|
|||
|
||||
@Network
|
||||
public void testDefaultTimeoutCustom() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
HttpClient httpClient = new HttpClient(Settings.builder()
|
||||
.put("xpack.http.default_connection_timeout", "5s").build()
|
||||
, mock(HttpAuthRegistry.class), new SSLService(environment.settings(), environment));
|
||||
|
@ -75,7 +76,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
|
|||
|
||||
@Network
|
||||
public void testTimeoutCustomPerRequest() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
HttpClient httpClient = new HttpClient(Settings.builder()
|
||||
.put("xpack.http.default_connection_timeout", "10s").build()
|
||||
, mock(HttpAuthRegistry.class), new SSLService(environment.settings(), environment));
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.common.http;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.http.MockResponse;
|
||||
import org.elasticsearch.test.http.MockWebServer;
|
||||
|
@ -39,7 +39,7 @@ public class HttpReadTimeoutTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultTimeout() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class),
|
||||
new SSLService(environment.settings(), environment));
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class HttpReadTimeoutTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultTimeoutCustom() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
|
||||
HttpClient httpClient = new HttpClient(Settings.builder()
|
||||
.put("xpack.http.default_read_timeout", "3s").build()
|
||||
|
@ -81,7 +81,7 @@ public class HttpReadTimeoutTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testTimeoutCustomPerRequest() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
|
||||
HttpClient httpClient = new HttpClient(Settings.builder()
|
||||
.put("xpack.http.default_read_timeout", "10s").build()
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.cli.UserException;
|
|||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -27,8 +28,6 @@ import java.nio.file.Path;
|
|||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
@ -43,7 +42,7 @@ public class InstallXPackExtensionCommandTests extends ESTestCase {
|
|||
super.setUp();
|
||||
home = createTempDir();
|
||||
Files.createDirectories(home.resolve("org/elasticsearch/xpack/extensions").resolve("xpack").resolve("extensions"));
|
||||
env = new Environment(Settings.builder().put("path.home", home.toString()).build());
|
||||
env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home.toString()).build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +88,7 @@ public class InstallXPackExtensionCommandTests extends ESTestCase {
|
|||
}
|
||||
|
||||
static MockTerminal installExtension(String extensionUrl, Path home) throws Exception {
|
||||
Environment env = new Environment(Settings.builder().put("path.home", home).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home).build());
|
||||
MockTerminal terminal = new MockTerminal();
|
||||
new InstallXPackExtensionCommand().execute(terminal, extensionUrl, true, env);
|
||||
return terminal;
|
||||
|
@ -175,4 +174,4 @@ public class InstallXPackExtensionCommandTests extends ESTestCase {
|
|||
assertTrue(e.getMessage(), e.getMessage().contains("x-pack-extension-descriptor.properties"));
|
||||
assertInstallCleaned(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.cli.Terminal;
|
|||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -37,7 +38,7 @@ public class ListXPackExtensionCommandTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put("path.home", home)
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
Files.createDirectories(extensionsFile(env));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.cli.MockTerminal;
|
|||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -17,8 +18,6 @@ import java.io.IOException;
|
|||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@LuceneTestCase.SuppressFileSystems("*")
|
||||
public class RemoveXPackExtensionCommandTests extends ESTestCase {
|
||||
|
@ -30,7 +29,7 @@ public class RemoveXPackExtensionCommandTests extends ESTestCase {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
home = createTempDir();
|
||||
env = new Environment(Settings.builder().put("path.home", home.toString()).build());
|
||||
env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home.toString()).build());
|
||||
}
|
||||
|
||||
Path createExtensionDir(Environment env) throws IOException {
|
||||
|
@ -39,7 +38,7 @@ public class RemoveXPackExtensionCommandTests extends ESTestCase {
|
|||
}
|
||||
|
||||
static MockTerminal removeExtension(String name, Path home) throws Exception {
|
||||
Environment env = new Environment(Settings.builder().put("path.home", home).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home).build());
|
||||
MockTerminal terminal = new MockTerminal();
|
||||
new RemoveXPackExtensionCommand().execute(terminal, name, env);
|
||||
return terminal;
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.XPackFeatureSet;
|
||||
|
@ -88,8 +89,8 @@ public class MachineLearningFeatureSetTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testAvailable() throws Exception {
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(new Environment(commonSettings), clusterService, client,
|
||||
licenseState);
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(TestEnvironment.newEnvironment(commonSettings), clusterService,
|
||||
client, licenseState);
|
||||
boolean available = randomBoolean();
|
||||
when(licenseState.isMachineLearningAllowed()).thenReturn(available);
|
||||
assertThat(featureSet.available(), is(available));
|
||||
|
@ -113,8 +114,8 @@ public class MachineLearningFeatureSetTests extends ESTestCase {
|
|||
settings.put("xpack.ml.enabled", enabled);
|
||||
}
|
||||
boolean expected = enabled || useDefault;
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(new Environment(settings.build()), clusterService, client,
|
||||
licenseState);
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(TestEnvironment.newEnvironment(settings.build()),
|
||||
clusterService, client, licenseState);
|
||||
assertThat(featureSet.enabled(), is(expected));
|
||||
PlainActionFuture<Usage> future = new PlainActionFuture<>();
|
||||
featureSet.usage(future);
|
||||
|
@ -147,8 +148,8 @@ public class MachineLearningFeatureSetTests extends ESTestCase {
|
|||
buildDatafeedStats(DatafeedState.STOPPED)
|
||||
));
|
||||
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(new Environment(settings.build()), clusterService, client,
|
||||
licenseState);
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(TestEnvironment.newEnvironment(settings.build()),
|
||||
clusterService, client, licenseState);
|
||||
PlainActionFuture<Usage> future = new PlainActionFuture<>();
|
||||
featureSet.usage(future);
|
||||
XPackFeatureSet.Usage mlUsage = future.get();
|
||||
|
@ -214,7 +215,7 @@ public class MachineLearningFeatureSetTests extends ESTestCase {
|
|||
settings.put("xpack.ml.enabled", true);
|
||||
when(clusterService.state()).thenReturn(ClusterState.EMPTY_STATE);
|
||||
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(new Environment(settings.build()),
|
||||
MachineLearningFeatureSet featureSet = new MachineLearningFeatureSet(TestEnvironment.newEnvironment(settings.build()),
|
||||
clusterService, client, licenseState);
|
||||
PlainActionFuture<Usage> future = new PlainActionFuture<>();
|
||||
featureSet.usage(future);
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.process;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ml.utils.NamedPipeHelper;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -49,7 +50,7 @@ public class NativeControllerTests extends ESTestCase {
|
|||
command.add("--arg2=42");
|
||||
command.add("--arg3=something with spaces");
|
||||
|
||||
NativeController nativeController = new NativeController(new Environment(settings), namedPipeHelper);
|
||||
NativeController nativeController = new NativeController(TestEnvironment.newEnvironment(settings), namedPipeHelper);
|
||||
nativeController.startProcess(command);
|
||||
|
||||
assertEquals("start\tmy_process\t--arg1\t--arg2=42\t--arg3=something with spaces\n",
|
||||
|
@ -64,7 +65,7 @@ public class NativeControllerTests extends ESTestCase {
|
|||
ByteArrayOutputStream commandStream = new ByteArrayOutputStream();
|
||||
when(namedPipeHelper.openNamedPipeOutputStream(contains("command"), any(Duration.class))).thenReturn(commandStream);
|
||||
|
||||
NativeController nativeController = new NativeController(new Environment(settings), namedPipeHelper);
|
||||
NativeController nativeController = new NativeController(TestEnvironment.newEnvironment(settings), namedPipeHelper);
|
||||
nativeController.tailLogsInThread();
|
||||
Map<String, Object> nativeCodeInfo = nativeController.getNativeCodeInfo();
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class NativeControllerTests extends ESTestCase {
|
|||
ByteArrayOutputStream commandStream = new ByteArrayOutputStream();
|
||||
when(namedPipeHelper.openNamedPipeOutputStream(contains("command"), any(Duration.class))).thenReturn(commandStream);
|
||||
|
||||
NativeController nativeController = new NativeController(new Environment(settings), namedPipeHelper);
|
||||
NativeController nativeController = new NativeController(TestEnvironment.newEnvironment(settings), namedPipeHelper);
|
||||
nativeController.tailLogsInThread();
|
||||
|
||||
// As soon as the log stream ends startProcess should think the native controller has died
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
||||
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
||||
|
@ -31,7 +32,7 @@ public class ProcessCtrlTests extends ESTestCase {
|
|||
|
||||
public void testBuildAutodetectCommand() {
|
||||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Job.Builder job = buildJobBuilder("unit-test-job");
|
||||
|
||||
Detector.Builder detectorBuilder = new Detector.Builder("mean", "value");
|
||||
|
@ -77,7 +78,7 @@ public class ProcessCtrlTests extends ESTestCase {
|
|||
|
||||
public void testBuildAutodetectCommand_defaultTimeField() {
|
||||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Job.Builder job = buildJobBuilder("unit-test-job");
|
||||
|
||||
List<String> command = ProcessCtrl.buildAutodetectCommand(env, settings, job.build(), logger, pid);
|
||||
|
@ -88,7 +89,7 @@ public class ProcessCtrlTests extends ESTestCase {
|
|||
public void testBuildAutodetectCommand_givenPersistModelState() {
|
||||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||
.put(ProcessCtrl.DONT_PERSIST_MODEL_STATE_SETTING.getKey(), true).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Job.Builder job = buildJobBuilder("unit-test-job");
|
||||
|
||||
int expectedPersistInterval = 10800 + ProcessCtrl.calculateStaggeringInterval(job.getId());
|
||||
|
@ -97,14 +98,14 @@ public class ProcessCtrlTests extends ESTestCase {
|
|||
assertFalse(command.contains(ProcessCtrl.PERSIST_INTERVAL_ARG + expectedPersistInterval));
|
||||
|
||||
settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
|
||||
command = ProcessCtrl.buildAutodetectCommand(env, settings, job.build(), logger, pid);
|
||||
assertTrue(command.contains(ProcessCtrl.PERSIST_INTERVAL_ARG + expectedPersistInterval));
|
||||
}
|
||||
|
||||
public void testBuildNormalizerCommand() throws IOException {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
String jobId = "unit-test-job";
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.ml.job.process;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ml.utils.NamedPipeHelper;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -30,7 +31,7 @@ public class ProcessPipesTests extends ESTestCase {
|
|||
|
||||
public void testProcessPipes() throws IOException {
|
||||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
|
||||
NamedPipeHelper namedPipeHelper = Mockito.mock(NamedPipeHelper.class);
|
||||
when(namedPipeHelper.openNamedPipeInputStream(contains("log"), any(Duration.class)))
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.ml.utils;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -25,7 +26,7 @@ public class NamedPipeHelperTests extends ESTestCase {
|
|||
NamedPipeHelper NAMED_PIPE_HELPER = new NamedPipeHelper();
|
||||
|
||||
public void testOpenForInputGivenPipeDoesNotExist() {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
IOException ioe = ESTestCase.expectThrows(FileNotFoundException.class,
|
||||
() -> NAMED_PIPE_HELPER.openNamedPipeInputStream(
|
||||
|
@ -38,7 +39,7 @@ public class NamedPipeHelperTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testOpenForOutputGivenPipeDoesNotExist() {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
IOException ioe = ESTestCase.expectThrows(FileNotFoundException.class,
|
||||
() -> NAMED_PIPE_HELPER.openNamedPipeOutputStream(
|
||||
|
@ -50,7 +51,7 @@ public class NamedPipeHelperTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testOpenForInputGivenPipeIsRegularFile() throws IOException {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
Path tempFile = Files.createTempFile(env.tmpFile(), "not a named pipe", null);
|
||||
|
||||
|
@ -63,7 +64,7 @@ public class NamedPipeHelperTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testOpenForOutputGivenPipeIsRegularFile() throws IOException {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
Path tempFile = Files.createTempFile(env.tmpFile(), "not a named pipe", null);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
|
@ -80,7 +81,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
|
|||
private final boolean remoteClusterAllowsWatcher = randomBoolean();
|
||||
private final boolean currentLicenseAllowsWatcher = true;
|
||||
private final boolean watcherAlreadyExists = randomBoolean();
|
||||
private final Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
private final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
|
||||
private MockWebServer webServer;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.security;
|
|||
import org.elasticsearch.bootstrap.BootstrapContext;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.pki.PkiRealm;
|
||||
import org.elasticsearch.xpack.ssl.SSLService;
|
||||
|
@ -16,8 +17,8 @@ public class PkiRealmBootstrapCheckTests extends ESTestCase {
|
|||
|
||||
public void testPkiRealmBootstrapDefault() throws Exception {
|
||||
assertFalse(new PkiRealmBootstrapCheck(new SSLService(Settings.EMPTY,
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build()))).check((new BootstrapContext(Settings
|
||||
.EMPTY, null))).isFailure());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build()))).check(
|
||||
new BootstrapContext(Settings.EMPTY, null)).isFailure());
|
||||
}
|
||||
|
||||
public void testBootstrapCheckWithPkiRealm() throws Exception {
|
||||
|
@ -25,7 +26,7 @@ public class PkiRealmBootstrapCheckTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.test_pki.type", PkiRealm.TYPE)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
assertTrue(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// enable transport tls
|
||||
|
@ -38,35 +39,35 @@ public class PkiRealmBootstrapCheckTests extends ESTestCase {
|
|||
settings = Settings.builder().put(settings)
|
||||
.put("xpack.ssl.client_authentication", "none")
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertTrue(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// enable ssl for http
|
||||
settings = Settings.builder().put(settings)
|
||||
.put("xpack.security.http.ssl.enabled", true)
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertTrue(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// enable client auth for http
|
||||
settings = Settings.builder().put(settings)
|
||||
.put("xpack.security.http.ssl.client_authentication", randomFrom("required", "optional"))
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertFalse(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// disable http ssl
|
||||
settings = Settings.builder().put(settings)
|
||||
.put("xpack.security.http.ssl.enabled", false)
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertTrue(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// set transport client auth
|
||||
settings = Settings.builder().put(settings)
|
||||
.put("xpack.security.transport.client_authentication", randomFrom("required", "optional"))
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertTrue(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
|
||||
// test with transport profile
|
||||
|
@ -74,7 +75,7 @@ public class PkiRealmBootstrapCheckTests extends ESTestCase {
|
|||
.put("xpack.security.transport.client_authentication", "none")
|
||||
.put("transport.profiles.foo.xpack.security.ssl.client_authentication", randomFrom("required", "optional"))
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
assertFalse(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ public class PkiRealmBootstrapCheckTests extends ESTestCase {
|
|||
.put("xpack.ssl.client_authentication", "none")
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
assertFalse(new PkiRealmBootstrapCheck(new SSLService(settings, env)).check(new BootstrapContext(settings, null)).isFailure());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Setting;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.License;
|
||||
import org.elasticsearch.license.TestUtils;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
|
@ -78,7 +79,7 @@ public class SecurityTests extends ESTestCase {
|
|||
throw new IllegalStateException("Security object already exists (" + security + ")");
|
||||
}
|
||||
Settings settings = Settings.builder().put(testSettings).put("path.home", createTempDir()).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
security = new Security(settings, env, new XPackLicenseState(), new SSLService(settings, env));
|
||||
ThreadPool threadPool = mock(ThreadPool.class);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.common.ValidationException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.security.SecurityLifecycleService;
|
||||
import org.elasticsearch.xpack.security.authc.esnative.NativeUsersStore;
|
||||
|
@ -119,7 +119,7 @@ public class TransportPutUserActionTests extends ESTestCase {
|
|||
when(securityLifecycleService.isSecurityIndexAvailable()).thenReturn(true);
|
||||
ReservedRealmTests.mockGetAllReservedUserInfo(usersStore, Collections.emptyMap());
|
||||
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
ReservedRealm reservedRealm = new ReservedRealm(new Environment(settings), settings, usersStore,
|
||||
ReservedRealm reservedRealm = new ReservedRealm(TestEnvironment.newEnvironment(settings), settings, usersStore,
|
||||
new AnonymousUser(settings), securityLifecycleService, new ThreadContext(settings));
|
||||
PlainActionFuture<Collection<User>> userFuture = new PlainActionFuture<>();
|
||||
reservedRealm.users(userFuture);
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.elasticsearch.common.transport.TransportAddress;
|
|||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -128,8 +129,9 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|||
XPackLicenseState licenseState = mock(XPackLicenseState.class);
|
||||
when(licenseState.allowedRealmType()).thenReturn(XPackLicenseState.AllowedRealmType.ALL);
|
||||
when(licenseState.isAuthAllowed()).thenReturn(true);
|
||||
realms = new TestRealms(Settings.EMPTY, new Environment(settings), Collections.<String, Realm.Factory>emptyMap(), licenseState,
|
||||
threadContext, mock(ReservedRealm.class), Arrays.asList(firstRealm, secondRealm), Collections.singletonList(firstRealm));
|
||||
realms = new TestRealms(Settings.EMPTY, TestEnvironment.newEnvironment(settings), Collections.<String, Realm.Factory>emptyMap(),
|
||||
licenseState, threadContext, mock(ReservedRealm.class), Arrays.asList(firstRealm, secondRealm),
|
||||
Collections.singletonList(firstRealm));
|
||||
|
||||
auditTrail = mock(AuditTrailService.class);
|
||||
client = mock(Client.class);
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.xpack.security.authc;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
|
@ -39,11 +39,11 @@ public class InternalRealmsTests extends ESTestCase {
|
|||
verifyZeroInteractions(lifecycleService);
|
||||
|
||||
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
factories.get(NativeRealm.TYPE).create(new RealmConfig("test", Settings.EMPTY, settings, new Environment(settings),
|
||||
factories.get(NativeRealm.TYPE).create(new RealmConfig("test", Settings.EMPTY, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(settings)));
|
||||
verify(lifecycleService).addSecurityIndexHealthChangeListener(isA(BiConsumer.class));
|
||||
|
||||
factories.get(NativeRealm.TYPE).create(new RealmConfig("test", Settings.EMPTY, settings, new Environment(settings),
|
||||
factories.get(NativeRealm.TYPE).create(new RealmConfig("test", Settings.EMPTY, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(settings)));
|
||||
verify(lifecycleService, times(2)).addSecurityIndexHealthChangeListener(isA(BiConsumer.class));
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.license.XPackLicenseState.AllowedRealmType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -75,7 +76,7 @@ public class RealmsTests extends ESTestCase {
|
|||
orderToIndex.put(orders.get(i), i);
|
||||
}
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm);
|
||||
|
||||
Iterator<Realm> iterator = realms.iterator();
|
||||
|
@ -102,7 +103,7 @@ public class RealmsTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.realm_2.order", 1)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
try {
|
||||
new Realms(settings, env, factories, licenseState, threadContext, reservedRealm);
|
||||
fail("Expected IllegalArgumentException");
|
||||
|
@ -112,8 +113,8 @@ public class RealmsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testWithEmptySettings() throws Exception {
|
||||
Realms realms = new Realms(Settings.EMPTY, new Environment(Settings.builder().put("path.home", createTempDir()).build()),
|
||||
factories, licenseState, threadContext, reservedRealm);
|
||||
Realms realms = new Realms(Settings.EMPTY, TestEnvironment.newEnvironment(Settings.builder().put("path.home",
|
||||
createTempDir()).build()), factories, licenseState, threadContext, reservedRealm);
|
||||
Iterator<Realm> iter = realms.iterator();
|
||||
assertThat(iter.hasNext(), is(true));
|
||||
Realm realm = iter.next();
|
||||
|
@ -144,7 +145,7 @@ public class RealmsTests extends ESTestCase {
|
|||
orderToIndex.put(orders.get(i), i);
|
||||
}
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm);
|
||||
|
||||
// this is the iterator when licensed
|
||||
|
@ -205,7 +206,7 @@ public class RealmsTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.custom.type", "type_0")
|
||||
.put("xpack.security.authc.realms.custom.order", "1");
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm );
|
||||
Iterator<Realm> iter = realms.iterator();
|
||||
assertThat(iter.hasNext(), is(true));
|
||||
|
@ -261,7 +262,7 @@ public class RealmsTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.native.type", type)
|
||||
.put("xpack.security.authc.realms.native.order", "1");
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm );
|
||||
Iterator<Realm> iter = realms.iterator();
|
||||
assertThat(iter.hasNext(), is(true));
|
||||
|
@ -306,7 +307,7 @@ public class RealmsTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm );
|
||||
Iterator<Realm> iterator = realms.iterator();
|
||||
Realm realm = iterator.next();
|
||||
|
@ -343,7 +344,7 @@ public class RealmsTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.realm_1.type", FileRealm.TYPE)
|
||||
.put("xpack.security.authc.realms.realm_1.order", 0)
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm );
|
||||
|
||||
assertThat(realms.iterator().hasNext(), is(true));
|
||||
|
@ -361,7 +362,7 @@ public class RealmsTests extends ESTestCase {
|
|||
.put("xpack.security.authc.realms.bar.type", "type_0")
|
||||
.put("xpack.security.authc.realms.bar.order", "1");
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
Realms realms = new Realms(settings, env, factories, licenseState, threadContext, reservedRealm );
|
||||
|
||||
Map<String, Object> usageStats = realms.usageStats();
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.cli.UserException;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
||||
|
||||
|
@ -48,7 +49,7 @@ public class ESNativeRealmMigrateToolTests extends CommandTestCase {
|
|||
protected Environment createEnv(Terminal terminal, Map<String, String> settings) throws UserException {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
settings.forEach((k,v) -> builder.put(k, v));
|
||||
return new Environment(builder.build());
|
||||
return TestEnvironment.newEnvironment(builder.build());
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|||
import org.elasticsearch.cluster.health.ClusterIndexHealth;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
|
||||
|
@ -24,7 +24,8 @@ public class NativeRealmTests extends ESTestCase {
|
|||
final AtomicInteger numInvalidation = new AtomicInteger(0);
|
||||
int expectedInvalidation = 0;
|
||||
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
RealmConfig config = new RealmConfig("native", Settings.EMPTY, settings, new Environment(settings), new ThreadContext(settings));
|
||||
RealmConfig config = new RealmConfig("native", Settings.EMPTY, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(settings));
|
||||
final NativeRealm nativeRealm = new NativeRealm(config, mock(NativeUsersStore.class)) {
|
||||
@Override
|
||||
void clearCache() {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.esnative.ReservedRealm;
|
||||
import org.elasticsearch.xpack.security.support.Validation;
|
||||
import org.elasticsearch.xpack.security.user.ElasticUser;
|
||||
|
@ -102,7 +103,7 @@ public class SetupPasswordToolTests extends CommandTestCase {
|
|||
protected Environment createEnv(Terminal terminal, Map<String, String> settings) throws UserException {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
settings.forEach((k,v) -> builder.put(k, v));
|
||||
return new Environment(builder.build());
|
||||
return TestEnvironment.newEnvironment(builder.build());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ public class SetupPasswordToolTests extends CommandTestCase {
|
|||
protected Environment createEnv(Terminal terminal, Map<String, String> settings) throws UserException {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
settings.forEach((k,v) -> builder.put(k, v));
|
||||
return new Environment(builder.build());
|
||||
return TestEnvironment.newEnvironment(builder.build());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.action.support.PlainActionFuture;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
import org.elasticsearch.xpack.security.authc.AuthenticationResult;
|
||||
|
@ -62,7 +62,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
when(userPasswdStore.verifyPassword(eq("user1"), eq(new SecureString("test123")), any(Supplier.class)))
|
||||
.thenAnswer(VERIFY_PASSWORD_ANSWER);
|
||||
when(userRolesStore.roles("user1")).thenReturn(new String[] { "role1", "role2" });
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
FileRealm realm = new FileRealm(config, userPasswdStore, userRolesStore);
|
||||
PlainActionFuture<AuthenticationResult> future = new PlainActionFuture<>();
|
||||
realm.authenticate(new UsernamePasswordToken("user1", new SecureString("test123")), future);
|
||||
|
@ -80,7 +80,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put("cache.hash_algo", Hasher.values()[randomIntBetween(0, Hasher.values().length - 1)].name().toLowerCase(Locale.ROOT))
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("file-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
when(userPasswdStore.verifyPassword(eq("user1"), eq(new SecureString("test123")), any(Supplier.class)))
|
||||
.thenAnswer(VERIFY_PASSWORD_ANSWER);
|
||||
when(userRolesStore.roles("user1")).thenReturn(new String[]{"role1", "role2"});
|
||||
|
@ -95,7 +95,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testAuthenticateCachingRefresh() throws Exception {
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
userPasswdStore = spy(new UserPasswdStore(config));
|
||||
userRolesStore = spy(new UserRolesStore(config));
|
||||
when(userPasswdStore.verifyPassword(eq("user1"), eq(new SecureString("test123")), any(Supplier.class)))
|
||||
|
@ -134,7 +134,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testToken() throws Exception {
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
when(userPasswdStore.verifyPassword(eq("user1"), eq(new SecureString("test123")), any(Supplier.class)))
|
||||
.thenAnswer(VERIFY_PASSWORD_ANSWER);
|
||||
when(userRolesStore.roles("user1")).thenReturn(new String[]{"role1", "role2"});
|
||||
|
@ -153,7 +153,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
public void testLookup() throws Exception {
|
||||
when(userPasswdStore.userExists("user1")).thenReturn(true);
|
||||
when(userRolesStore.roles("user1")).thenReturn(new String[] { "role1", "role2" });
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
FileRealm realm = new FileRealm(config, userPasswdStore, userRolesStore);
|
||||
|
||||
PlainActionFuture<User> future = new PlainActionFuture<>();
|
||||
|
@ -170,7 +170,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
public void testLookupCaching() throws Exception {
|
||||
when(userPasswdStore.userExists("user1")).thenReturn(true);
|
||||
when(userRolesStore.roles("user1")).thenReturn(new String[] { "role1", "role2" });
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
FileRealm realm = new FileRealm(config, userPasswdStore, userRolesStore);
|
||||
|
||||
PlainActionFuture<User> future = new PlainActionFuture<>();
|
||||
|
@ -185,7 +185,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testLookupCachingWithRefresh() throws Exception {
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
userPasswdStore = spy(new UserPasswdStore(config));
|
||||
userRolesStore = spy(new UserRolesStore(config));
|
||||
doReturn(true).when(userPasswdStore).userExists("user1");
|
||||
|
@ -231,7 +231,7 @@ public class FileRealmTests extends ESTestCase {
|
|||
int order = randomIntBetween(0, 10);
|
||||
settings.put("order", order);
|
||||
|
||||
RealmConfig config = new RealmConfig("file-realm", settings.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("file-realm", settings.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
FileRealm realm = new FileRealm(config, userPasswdStore, userRolesStore);
|
||||
|
||||
Map<String, Object> usage = realm.usageStats();
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -55,7 +56,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
|
|||
.put("resource.reload.interval.high", "2s")
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
threadPool = new TestThreadPool("test");
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -56,7 +57,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
|
|||
.put("resource.reload.interval.high", "2s")
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
threadPool = new TestThreadPool("test");
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
|
|||
.put("files.users_roles", usersRoles.toAbsolutePath())
|
||||
.build();
|
||||
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
RealmConfig config = new RealmConfig("file-test", fileSettings, settings, env, new ThreadContext(Settings.EMPTY));
|
||||
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
||||
FileUserRolesStore store = new FileUserRolesStore(config, watcherService);
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.google.common.jimfs.Jimfs;
|
|||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.cli.Command;
|
||||
import org.elasticsearch.cli.CommandTestCase;
|
||||
import org.elasticsearch.cli.EnvironmentAwareCommand;
|
||||
import org.elasticsearch.cli.ExitCodes;
|
||||
import org.elasticsearch.cli.Terminal;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
|
@ -19,9 +18,9 @@ import org.elasticsearch.common.io.PathUtilsForTesting;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.XPackSettings;
|
||||
import org.elasticsearch.xpack.security.authc.UserTokenTests;
|
||||
import org.elasticsearch.xpack.security.authc.support.Hasher;
|
||||
import org.elasticsearch.xpack.security.authz.store.ReservedRolesStore;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
|
@ -295,7 +294,7 @@ public class UsersToolTests extends CommandTestCase {
|
|||
}
|
||||
|
||||
public void testParseUnknownRole() throws Exception {
|
||||
UsersTool.parseRoles(terminal, new Environment(settings), "test_r1,r2,r3");
|
||||
UsersTool.parseRoles(terminal, TestEnvironment.newEnvironment(settings), "test_r1,r2,r3");
|
||||
String output = terminal.getOutput();
|
||||
assertTrue(output, output.contains("The following roles [r2,r3] are not in the ["));
|
||||
}
|
||||
|
@ -303,21 +302,21 @@ public class UsersToolTests extends CommandTestCase {
|
|||
public void testParseReservedRole() throws Exception {
|
||||
final String reservedRoleName = randomFrom(ReservedRolesStore.names().toArray(Strings.EMPTY_ARRAY));
|
||||
String rolesArg = randomBoolean() ? "test_r1," + reservedRoleName : reservedRoleName;
|
||||
UsersTool.parseRoles(terminal, new Environment(settings), rolesArg);
|
||||
UsersTool.parseRoles(terminal, TestEnvironment.newEnvironment(settings), rolesArg);
|
||||
String output = terminal.getOutput();
|
||||
assertTrue(output, output.isEmpty());
|
||||
}
|
||||
|
||||
public void testParseInvalidRole() throws Exception {
|
||||
UserException e = expectThrows(UserException.class, () -> {
|
||||
UsersTool.parseRoles(terminal, new Environment(settings), "fóóbár");
|
||||
UsersTool.parseRoles(terminal, TestEnvironment.newEnvironment(settings), "fóóbár");
|
||||
});
|
||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Invalid role [fóóbár]"));
|
||||
}
|
||||
|
||||
public void testParseMultipleRoles() throws Exception {
|
||||
String[] roles = UsersTool.parseRoles(terminal, new Environment(settings), "test_r1,test_r2");
|
||||
String[] roles = UsersTool.parseRoles(terminal, TestEnvironment.newEnvironment(settings), "test_r1,test_r2");
|
||||
assertEquals(Objects.toString(roles), 2, roles.length);
|
||||
assertEquals("test_r1", roles[0]);
|
||||
assertEquals("test_r2", roles[1]);
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security.authc.ldap;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSearchScope;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
|
@ -55,7 +56,7 @@ public class AbstractActiveDirectoryIntegTests extends ESTestCase {
|
|||
builder.put("xpack.security.authc.realms.bar.ssl.verification_mode", VerificationMode.CERTIFICATE);
|
||||
}
|
||||
globalSettings = builder.build();
|
||||
Environment environment = new Environment(globalSettings);
|
||||
Environment environment = TestEnvironment.newEnvironment(globalSettings);
|
||||
sslService = new SSLService(globalSettings, environment);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.AuthenticationResult;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactory.DownLevelADAuthenticator;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactory.UpnADAuthenticator;
|
||||
|
@ -114,7 +114,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
threadPool = new TestThreadPool("active directory realm tests");
|
||||
resourceWatcherService = new ResourceWatcherService(Settings.EMPTY, threadPool);
|
||||
globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
sslService = new SSLService(globalSettings, new Environment(globalSettings));
|
||||
sslService = new SSLService(globalSettings, TestEnvironment.newEnvironment(globalSettings));
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -133,7 +133,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateUserPrincipleName() throws Exception {
|
||||
Settings settings = settings();
|
||||
RealmConfig config = new RealmConfig("testAuthenticateUserPrincipleName", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testAuthenticateUserPrincipleName", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -149,7 +149,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateSAMAccountName() throws Exception {
|
||||
Settings settings = settings();
|
||||
RealmConfig config = new RealmConfig("testAuthenticateSAMAccountName", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testAuthenticateSAMAccountName", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -173,7 +173,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateCachesSuccessfulAuthentications() throws Exception {
|
||||
Settings settings = settings();
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachesSuccesfulAuthentications", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachesSuccesfulAuthentications", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = spy(new ActiveDirectorySessionFactory(config, sslService, threadPool));
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -191,7 +191,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateCachingCanBeDisabled() throws Exception {
|
||||
Settings settings = settings(Settings.builder().put(CachingUsernamePasswordRealm.CACHE_TTL_SETTING.getKey(), -1).build());
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachingCanBeDisabled", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachingCanBeDisabled", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = spy(new ActiveDirectorySessionFactory(config, sslService, threadPool));
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -209,7 +209,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateCachingClearsCacheOnRoleMapperRefresh() throws Exception {
|
||||
Settings settings = settings();
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachingClearsCacheOnRoleMapperRefresh", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testAuthenticateCachingClearsCacheOnRoleMapperRefresh", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = spy(new ActiveDirectorySessionFactory(config, sslService, threadPool));
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -251,7 +251,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
.put(ActiveDirectorySessionFactory.BIND_PASSWORD.getKey(), PASSWORD)
|
||||
.build());
|
||||
RealmConfig config = new RealmConfig("testUnauthenticatedLookupWithConnectionPool", settings, globalSettings,
|
||||
new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -268,7 +268,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
Settings settings = settings(Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, getDataPath("role_mapping.yml"))
|
||||
.build());
|
||||
RealmConfig config = new RealmConfig("testRealmMapsGroupsToRoles", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testRealmMapsGroupsToRoles", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -284,7 +284,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
Settings settings = settings(Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, getDataPath("role_mapping.yml"))
|
||||
.build());
|
||||
RealmConfig config = new RealmConfig("testRealmMapsGroupsToRoles", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("testRealmMapsGroupsToRoles", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.AD_TYPE, config, sessionFactory, roleMapper, threadPool);
|
||||
|
@ -302,7 +302,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
.put(ROLE_MAPPING_FILE_SETTING, getDataPath("role_mapping.yml"))
|
||||
.put("load_balance.type", loadBalanceType)
|
||||
.build());
|
||||
RealmConfig config = new RealmConfig("testRealmUsageStats", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("testRealmUsageStats", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = new DnRoleMapper(config, resourceWatcherService);
|
||||
|
@ -319,7 +319,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
|
||||
public void testDefaultSearchFilters() throws Exception {
|
||||
Settings settings = settings();
|
||||
RealmConfig config = new RealmConfig("testDefaultSearchFilters", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("testDefaultSearchFilters", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
assertEquals("(&(objectClass=user)(|(sAMAccountName={0})(userPrincipalName={0}@ad.test.elasticsearch.com)))",
|
||||
|
@ -334,7 +334,7 @@ public class ActiveDirectoryRealmTests extends ESTestCase {
|
|||
.put(ActiveDirectorySessionFactory.AD_UPN_USER_SEARCH_FILTER_SETTING, "(objectClass=upn)")
|
||||
.put(ActiveDirectorySessionFactory.AD_DOWN_LEVEL_USER_SEARCH_FILTER_SETTING, "(objectClass=down level)")
|
||||
.build());
|
||||
RealmConfig config = new RealmConfig("testDefaultSearchFilters", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("testDefaultSearchFilters", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool);
|
||||
assertEquals("(objectClass=default)", sessionFactory.defaultADAuthenticator.getUserSearchFilter());
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSearchScope;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSession;
|
||||
|
@ -62,7 +62,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
public void testAdAuth() throws Exception {
|
||||
RealmConfig config = new RealmConfig("ad-test",
|
||||
buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false),
|
||||
globalSettings, new Environment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String userName = "ironman";
|
||||
|
@ -85,7 +85,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
public void testNetbiosAuth() throws Exception {
|
||||
final String adUrl = randomFrom("ldap://54.213.145.20:3268", "ldaps://54.213.145.20:3269", AD_LDAP_URL);
|
||||
RealmConfig config = new RealmConfig("ad-test", buildAdSettings(adUrl, AD_DOMAIN, false), globalSettings,
|
||||
new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String userName = "ades\\ironman";
|
||||
|
@ -114,7 +114,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put(SessionFactory.TIMEOUT_TCP_READ_SETTING, "1ms")
|
||||
.build();
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
PlainActionFuture<List<String>> groups = new PlainActionFuture<>();
|
||||
|
@ -126,7 +126,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
|
||||
public void testAdAuthAvengers() throws Exception {
|
||||
RealmConfig config = new RealmConfig("ad-test", buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false), globalSettings,
|
||||
new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String[] users = new String[]{"cap", "hawkeye", "hulk", "ironman", "thor", "blackwidow"};
|
||||
|
@ -143,7 +143,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
Settings settings = buildAdSettings(AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
||||
LdapSearchScope.ONE_LEVEL, false);
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String userName = "hulk";
|
||||
|
@ -166,7 +166,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
public void testAuthenticateBaseUserSearch() throws Exception {
|
||||
Settings settings = buildAdSettings(AD_LDAP_URL, AD_DOMAIN, "CN=Bruce Banner, CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
||||
LdapSearchScope.BASE, false);
|
||||
RealmConfig config = new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put(ActiveDirectorySessionFactory.AD_GROUP_SEARCH_SCOPE_SETTING, LdapSearchScope.BASE)
|
||||
.build();
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String userName = "hulk";
|
||||
|
@ -212,7 +212,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
Settings settings = buildAdSettings(AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
||||
LdapSearchScope.ONE_LEVEL, false);
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
//Login with the UserPrincipalName
|
||||
|
@ -232,7 +232,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
Settings settings = buildAdSettings(AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
||||
LdapSearchScope.ONE_LEVEL, false);
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
//login with sAMAccountName
|
||||
|
@ -258,7 +258,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
"(&(objectclass=user)(userPrincipalName={0}@ad.test.elasticsearch.com))")
|
||||
.build();
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
//Login with the UserPrincipalName
|
||||
|
@ -291,7 +291,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put("ssl.truststore.password", "changeit")
|
||||
.build();
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put("ssl.truststore.password", "changeit")
|
||||
.build();
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -355,7 +355,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put("ssl.truststore.password", "changeit")
|
||||
.build();
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -373,7 +373,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
|
||||
public void testAdAuthWithHostnameVerification() throws Exception {
|
||||
RealmConfig config = new RealmConfig("ad-test", buildAdSettings(AD_LDAP_URL, AD_DOMAIN, true), globalSettings,
|
||||
new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = new ActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
String userName = "ironman";
|
||||
|
@ -395,7 +395,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
.put("ssl.verification_mode", VerificationMode.FULL)
|
||||
.build();
|
||||
RealmConfig config =
|
||||
new RealmConfig("ad-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
new RealmConfig("ad-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
String user = "Bruce Banner";
|
||||
|
@ -410,7 +410,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryI
|
|||
public void testADLookup() throws Exception {
|
||||
RealmConfig config = new RealmConfig("ad-test",
|
||||
buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false, true),
|
||||
globalSettings, new Environment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
||||
|
||||
List<String> users = randomSubsetOf(Arrays.asList("cap", "hawkeye", "hulk", "ironman", "thor", "blackwidow",
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.support.PlainActionFuture;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
|
@ -67,7 +67,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
threadPool = new TestThreadPool("ldap realm tests");
|
||||
resourceWatcherService = new ResourceWatcherService(Settings.EMPTY, threadPool);
|
||||
globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
sslService = new SSLService(globalSettings, new Environment(globalSettings));
|
||||
sslService = new SSLService(globalSettings, TestEnvironment.newEnvironment(globalSettings));
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -80,7 +80,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
String groupSearchBase = "o=sevenSeas";
|
||||
String userTemplate = VALID_USER_TEMPLATE;
|
||||
Settings settings = buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase, LdapSearchScope.SUB_TREE);
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
LdapRealm ldap = new LdapRealm(LdapRealm.LDAP_TYPE, config, ldapFactory, buildGroupAsRoleMapper(resourceWatcherService),
|
||||
threadPool);
|
||||
|
@ -104,7 +104,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase, LdapSearchScope.ONE_LEVEL))
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
LdapRealm ldap =
|
||||
|
@ -129,7 +129,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
ldapFactory = spy(ldapFactory);
|
||||
|
@ -154,7 +154,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
DnRoleMapper roleMapper = buildGroupAsRoleMapper(resourceWatcherService);
|
||||
|
@ -187,7 +187,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put(buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.put(CachingUsernamePasswordRealm.CACHE_TTL_SETTING.getKey(), -1)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
ldapFactory = spy(ldapFactory);
|
||||
|
@ -214,7 +214,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put("group_search.scope", LdapSearchScope.SUB_TREE)
|
||||
.put("ssl.verification_mode", VerificationMode.CERTIFICATE)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
SessionFactory sessionFactory = LdapRealm.sessionFactory(config, sslService, threadPool, LdapRealm.LDAP_TYPE);
|
||||
assertThat(sessionFactory, is(instanceOf(LdapSessionFactory.class)));
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put("group_search.scope", LdapSearchScope.SUB_TREE)
|
||||
.put("ssl.verification_mode", VerificationMode.CERTIFICATE)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
SessionFactory sessionFactory = LdapRealm.sessionFactory(config, sslService, threadPool, LdapRealm.LDAP_TYPE);
|
||||
try {
|
||||
assertThat(sessionFactory, is(instanceOf(LdapUserSearchSessionFactory.class)));
|
||||
|
@ -248,7 +248,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put("group_search.scope", LdapSearchScope.SUB_TREE)
|
||||
.put("ssl.verification_mode", VerificationMode.CERTIFICATE)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> LdapRealm.sessionFactory(config, null, threadPool, LdapRealm.LDAP_TYPE));
|
||||
assertThat(e.getMessage(),
|
||||
|
@ -264,7 +264,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put("group_search.scope", LdapSearchScope.SUB_TREE)
|
||||
.put("ssl.verification_mode", VerificationMode.CERTIFICATE)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-user-search", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> LdapRealm.sessionFactory(config, null, threadPool, LdapRealm.LDAP_TYPE));
|
||||
assertThat(e.getMessage(),
|
||||
|
@ -281,7 +281,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
.put(DnRoleMapper.ROLE_MAPPING_FILE_SETTING.getKey(),
|
||||
getDataPath("/org/elasticsearch/xpack/security/authc/support/role_mapping.yml"))
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-userdn", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm-userdn", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
LdapRealm ldap = new LdapRealm(LdapRealm.LDAP_TYPE, config, ldapFactory,
|
||||
|
@ -308,7 +308,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
String groupSearchBase = "o=sevenSeas";
|
||||
String userTemplate = VALID_USER_TEMPLATE;
|
||||
Settings settings = buildLdapSettings(new String[] { url.toString() }, userTemplate, groupSearchBase, LdapSearchScope.SUB_TREE);
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("test-ldap-realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
LdapRealm ldap = new LdapRealm(LdapRealm.LDAP_TYPE, config, ldapFactory, buildGroupAsRoleMapper(resourceWatcherService),
|
||||
threadPool);
|
||||
|
@ -342,7 +342,7 @@ public class LdapRealmTests extends LdapTestCase {
|
|||
settings.put("user_search.base_dn", "");
|
||||
}
|
||||
|
||||
RealmConfig config = new RealmConfig("ldap-realm", settings.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("ldap-realm", settings.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
LdapRealm realm = new LdapRealm(LdapRealm.LDAP_TYPE, config, ldapFactory,
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSearchScope;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSession;
|
||||
|
@ -43,7 +43,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
@Before
|
||||
public void setup() throws Exception {
|
||||
globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
sslService = new SSLService(globalSettings, new Environment(globalSettings));
|
||||
sslService = new SSLService(globalSettings, TestEnvironment.newEnvironment(globalSettings));
|
||||
threadPool = new TestThreadPool("LdapSessionFactoryTests thread pool");
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
|
||||
RealmConfig config = new RealmConfig("ldap_realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("ldap_realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
String user = "Horatio Hornblower";
|
||||
SecureString userPass = new SecureString("pass");
|
||||
|
@ -94,7 +94,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
.put(SessionFactory.TIMEOUT_TCP_CONNECTION_SETTING, "1ms") //1 millisecond
|
||||
.build();
|
||||
|
||||
RealmConfig config = new RealmConfig("ldap_realm", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("ldap_realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
String user = "Horatio Hornblower";
|
||||
SecureString userPass = new SecureString("pass");
|
||||
|
@ -116,7 +116,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
"cn={0},ou=people,o=sevenSeas", //this last one should work
|
||||
};
|
||||
RealmConfig config = new RealmConfig("ldap_realm", buildLdapSettings(ldapUrls(), userTemplates, groupSearchBase,
|
||||
LdapSearchScope.SUB_TREE), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSearchScope.SUB_TREE), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
"asdf={0},ou=people,o=sevenSeas", //none of these should work
|
||||
};
|
||||
RealmConfig config = new RealmConfig("ldap_realm", buildLdapSettings(ldapUrls(), userTemplates, groupSearchBase,
|
||||
LdapSearchScope.SUB_TREE), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSearchScope.SUB_TREE), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFac = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "o=sevenSeas";
|
||||
String userTemplate = "cn={0},ou=people,o=sevenSeas";
|
||||
RealmConfig config = new RealmConfig("ldap_realm", buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase,
|
||||
LdapSearchScope.SUB_TREE), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSearchScope.SUB_TREE), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFac = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -172,7 +172,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "ou=crews,ou=groups,o=sevenSeas";
|
||||
String userTemplate = "cn={0},ou=people,o=sevenSeas";
|
||||
RealmConfig config = new RealmConfig("ldap_realm", buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase,
|
||||
LdapSearchScope.ONE_LEVEL), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSearchScope.ONE_LEVEL), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFac = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -187,7 +187,7 @@ public class LdapSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas";
|
||||
String userTemplate = "cn={0},ou=people,o=sevenSeas";
|
||||
RealmConfig config = new RealmConfig("ldap_realm", buildLdapSettings(ldapUrls(), userTemplate, groupSearchBase,
|
||||
LdapSearchScope.BASE), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapSearchScope.BASE), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapSessionFactory ldapFac = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.SessionFactory;
|
||||
|
@ -48,7 +49,7 @@ public class LdapTestUtils {
|
|||
secureSettings.setString("xpack.security.authc.realms.bar.ssl.truststore.secure_password", "changeit");
|
||||
}
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
SSLService sslService = new SSLService(settings, env);
|
||||
|
||||
LDAPURL ldapurl = new LDAPURL(url);
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSearchScope;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSession;
|
||||
|
@ -37,7 +38,6 @@ import org.junit.Before;
|
|||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -54,7 +54,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
@Before
|
||||
public void init() throws Exception {
|
||||
Path keystore = getDataPath("support/ldaptrust.jks");
|
||||
Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
/*
|
||||
* Prior to each test we reinitialize the socket factory with a new SSLService so that we get a new SSLContext.
|
||||
* If we re-use a SSLContext, previously connected sessions can get re-established which breaks hostname
|
||||
|
@ -95,7 +95,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -127,7 +127,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -173,7 +173,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -210,7 +210,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -256,7 +256,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -293,7 +293,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(cn={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -338,7 +338,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
} else {
|
||||
builder.put("user_search.filter", "(uid1={0})");
|
||||
}
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("ldap_realm", builder.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
@ -368,7 +368,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
.put("bind_password", "pass")
|
||||
.put("user_search.pool.enabled", randomBoolean())
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -414,8 +414,8 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
|
||||
});
|
||||
Settings fullSettings = builder.build();
|
||||
sslService = new SSLService(fullSettings, new Environment(fullSettings));
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
sslService = new SSLService(fullSettings, TestEnvironment.newEnvironment(fullSettings));
|
||||
RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
||||
String user = "Bruce Banner";
|
||||
|
@ -454,7 +454,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
.put("bind_password", "pass")
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LDAPConnectionPool connectionPool = LdapUserSearchSessionFactory.createConnectionPool(config, new SingleServerSet("localhost",
|
||||
randomFrom(ldapServers).getListenPort()), TimeValue.timeValueSeconds(5), NoOpLogger.INSTANCE,
|
||||
|
@ -485,7 +485,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("user_search.pool.initial_size", 10)
|
||||
.put("user_search.pool.size", 12)
|
||||
.put("user_search.pool.health_check.enabled", false)
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LDAPConnectionPool connectionPool = LdapUserSearchSessionFactory.createConnectionPool(config, new SingleServerSet("localhost",
|
||||
randomFrom(ldapServers).getListenPort()), TimeValue.timeValueSeconds(5), NoOpLogger.INSTANCE,
|
||||
|
@ -508,7 +508,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.put("user_search.base_dn", userSearchBase)
|
||||
.put("bind_password", "pass")
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory searchSessionFactory = null;
|
||||
try {
|
||||
|
@ -528,7 +528,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("user_search.base_dn", userSearchBase)
|
||||
.put("user_search.pool.enabled", false)
|
||||
.put("bind_password", "pass")
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
|
||||
LdapUserSearchSessionFactory searchSessionFactory = null;
|
||||
try {
|
||||
|
@ -581,7 +581,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("user_search.pool.enabled", randomBoolean())
|
||||
.build();
|
||||
|
||||
RealmConfig config = new RealmConfig("ldap_realm", ldapSettings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("ldap_realm", ldapSettings, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
LdapUserSearchSessionFactory searchSessionFactory = null;
|
||||
try {
|
||||
searchSessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.LdapSessionFactory;
|
||||
import org.elasticsearch.xpack.security.authc.support.DnRoleMapper;
|
||||
|
@ -136,7 +136,8 @@ public abstract class LdapTestCase extends ESTestCase {
|
|||
.put(DnRoleMapper.USE_UNMAPPED_GROUPS_AS_ROLES_SETTING.getKey(), true)
|
||||
.build();
|
||||
Settings global = Settings.builder().put("path.home", createTempDir()).build();
|
||||
RealmConfig config = new RealmConfig("ldap1", settings, global, new Environment(global), new ThreadContext(Settings.EMPTY));
|
||||
RealmConfig config = new RealmConfig("ldap1", settings, global, TestEnvironment.newEnvironment(global),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
|
||||
return new DnRoleMapper(config, resourceWatcherService);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.mocksocket.MockServerSocket;
|
||||
import org.elasticsearch.mocksocket.MockSocket;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
|
@ -223,9 +223,10 @@ public class SessionFactoryLoadBalancingTests extends LdapTestCase {
|
|||
Settings settings = buildLdapSettings(ldapUrls(), new String[] { userTemplate }, groupSearchBase,
|
||||
LdapSearchScope.SUB_TREE, loadBalancing);
|
||||
Settings globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
RealmConfig config = new RealmConfig("test-session-factory", settings, globalSettings, new Environment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
return new TestSessionFactory(config, new SSLService(Settings.EMPTY, new Environment(config.globalSettings())), threadPool);
|
||||
RealmConfig config = new RealmConfig("test-session-factory", settings, globalSettings,
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
return new TestSessionFactory(config, new SSLService(Settings.EMPTY, TestEnvironment.newEnvironment(config.globalSettings())),
|
||||
threadPool);
|
||||
}
|
||||
|
||||
static class TestSessionFactory extends SessionFactory {
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
|
@ -43,7 +44,7 @@ public class SessionFactoryTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testConnectionFactoryReturnsCorrectLDAPConnectionOptionsWithDefaultSettings() throws Exception {
|
||||
final Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
RealmConfig realmConfig = new RealmConfig("conn settings", Settings.EMPTY, environment.settings(), environment,
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(environment.settings(), environment),
|
||||
|
@ -63,7 +64,7 @@ public class SessionFactoryTests extends ESTestCase {
|
|||
.put(SessionFactory.FOLLOW_REFERRALS_SETTING, "false")
|
||||
.build();
|
||||
|
||||
final Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
RealmConfig realmConfig = new RealmConfig("conn settings", settings, environment.settings(), environment, new ThreadContext(Settings.EMPTY));
|
||||
LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(environment.settings(), environment),
|
||||
logger);
|
||||
|
@ -107,7 +108,7 @@ public class SessionFactoryTests extends ESTestCase {
|
|||
private SessionFactory createSessionFactory() {
|
||||
Settings global = Settings.builder().put("path.home", createTempDir()).build();
|
||||
final RealmConfig realmConfig = new RealmConfig("_name", Settings.builder().put("url", "ldap://localhost:389").build(),
|
||||
global, new Environment(global), new ThreadContext(Settings.EMPTY));
|
||||
global, TestEnvironment.newEnvironment(global), new ThreadContext(Settings.EMPTY));
|
||||
return new SessionFactory(realmConfig, null, threadPool) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.AuthenticationResult;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
|
@ -60,7 +60,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testTokenSupport() {
|
||||
RealmConfig config = new RealmConfig("", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
RealmConfig config = new RealmConfig("", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
PkiRealm realm = new PkiRealm(config, mock(UserRoleMapper.class));
|
||||
|
||||
assertThat(realm.supports(null), is(false));
|
||||
|
@ -72,7 +72,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
X509Certificate certificate = readCert(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"));
|
||||
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
||||
threadContext.putTransient(PkiRealm.PKI_CERT_HEADER_NAME, new X509Certificate[] { certificate });
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), mock(UserRoleMapper.class));
|
||||
|
||||
X509AuthenticationToken token = realm.token(threadContext);
|
||||
|
@ -97,7 +97,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
X509Certificate certificate = readCert(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"));
|
||||
X509AuthenticationToken token = new X509AuthenticationToken(new X509Certificate[] { certificate }, "Elasticsearch Test Node", dn);
|
||||
UserRoleMapper roleMapper = mock(UserRoleMapper.class);
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), roleMapper);
|
||||
Mockito.doAnswer(invocation -> {
|
||||
final UserRoleMapper.UserData userData = (UserRoleMapper.UserData) invocation.getArguments()[0];
|
||||
|
@ -125,7 +125,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
public void testCustomUsernamePattern() throws Exception {
|
||||
X509Certificate certificate = readCert(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"));
|
||||
UserRoleMapper roleMapper = mock(UserRoleMapper.class);
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.builder().put("username_pattern", "OU=(.*?),").build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings)),
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", Settings.builder().put("username_pattern", "OU=(.*?),").build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)),
|
||||
roleMapper);
|
||||
Mockito.doAnswer(invocation -> {
|
||||
ActionListener<Set<String>> listener = (ActionListener<Set<String>>) invocation.getArguments()[1];
|
||||
|
@ -155,7 +155,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
.put("truststore.path", getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks"))
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", settings, globalSettings, new Environment(globalSettings),
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), roleMapper);
|
||||
Mockito.doAnswer(invocation -> {
|
||||
ActionListener<Set<String>> listener = (ActionListener<Set<String>>) invocation.getArguments()[1];
|
||||
|
@ -186,7 +186,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode-client-profile.jks"))
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", settings, globalSettings, new Environment(globalSettings),
|
||||
PkiRealm realm = new PkiRealm(new RealmConfig("", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), roleMapper);
|
||||
Mockito.doAnswer(invocation -> {
|
||||
ActionListener<Set<String>> listener = (ActionListener<Set<String>>) invocation.getArguments()[1];
|
||||
|
@ -210,7 +210,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode-client-profile.jks"))
|
||||
.build();
|
||||
try {
|
||||
new PkiRealm(new RealmConfig("mypki", settings, globalSettings, new Environment(globalSettings),
|
||||
new PkiRealm(new RealmConfig("mypki", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), mock(UserRoleMapper.class));
|
||||
fail("exception should have been thrown");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -225,7 +225,7 @@ public class PkiRealmTests extends ESTestCase {
|
|||
getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode-client-profile.jks"))
|
||||
.put("truststore.password", "testnode-client-profile")
|
||||
.build();
|
||||
new PkiRealm(new RealmConfig("mypki", settings, globalSettings, new Environment(globalSettings),
|
||||
new PkiRealm(new RealmConfig("mypki", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(globalSettings)), mock(UserRoleMapper.class));
|
||||
assertSettingDeprecationsAndWarnings(new Setting[] { SSLConfigurationSettings.withoutPrefix().legacyTruststorePassword });
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.security.authc.AuthenticationResult;
|
||||
|
@ -56,7 +56,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
.put(CachingUsernamePasswordRealm.CACHE_TTL_SETTING.getKey(), ttl)
|
||||
.build();
|
||||
|
||||
RealmConfig config = new RealmConfig("test_realm", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("test_realm", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm("test", config) {
|
||||
@Override
|
||||
|
@ -228,7 +228,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(CachingUsernamePasswordRealm.CACHE_TTL_SETTING.getKey(), ttl)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test_cache_ttl", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("test_cache_ttl", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
AlwaysAuthenticateCachingRealm realm = new AlwaysAuthenticateCachingRealm(config);
|
||||
|
||||
|
@ -257,7 +257,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
Settings settings = Settings.builder()
|
||||
.put(CachingUsernamePasswordRealm.CACHE_TTL_SETTING.getKey(), ttl)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("test_cache_ttl", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("test_cache_ttl", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
AlwaysAuthenticateCachingRealm realm = new AlwaysAuthenticateCachingRealm(config);
|
||||
|
||||
|
@ -334,7 +334,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
final SecureString randomPassword = new SecureString(randomAlphaOfLength(password.length()).toCharArray());
|
||||
|
||||
final String passwordHash = new String(Hasher.BCRYPT.hash(password));
|
||||
RealmConfig config = new RealmConfig("test_realm", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("test_realm", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm("test", config) {
|
||||
@Override
|
||||
|
@ -398,7 +398,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
public void testUserLookupConcurrency() throws Exception {
|
||||
final String username = "username";
|
||||
|
||||
RealmConfig config = new RealmConfig("test_realm", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("test_realm", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm("test", config) {
|
||||
@Override
|
||||
|
@ -452,7 +452,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
static class FailingAuthenticationRealm extends CachingUsernamePasswordRealm {
|
||||
|
||||
FailingAuthenticationRealm(Settings settings, Settings global) {
|
||||
super("failing", new RealmConfig("failing-test", settings, global, new Environment(global),
|
||||
super("failing", new RealmConfig("failing-test", settings, global, TestEnvironment.newEnvironment(global),
|
||||
new ThreadContext(Settings.EMPTY)));
|
||||
}
|
||||
|
||||
|
@ -470,7 +470,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
static class ThrowingAuthenticationRealm extends CachingUsernamePasswordRealm {
|
||||
|
||||
ThrowingAuthenticationRealm(Settings settings, Settings globalSettings) {
|
||||
super("throwing", new RealmConfig("throwing-test", settings, globalSettings, new Environment(globalSettings),
|
||||
super("throwing", new RealmConfig("throwing-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY)));
|
||||
}
|
||||
|
||||
|
@ -493,7 +493,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
private boolean usersEnabled = true;
|
||||
|
||||
AlwaysAuthenticateCachingRealm(Settings globalSettings) {
|
||||
this(new RealmConfig("always-test", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
this(new RealmConfig("always-test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY)));
|
||||
}
|
||||
|
||||
|
@ -525,8 +525,8 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|||
public final AtomicInteger lookupInvocationCounter = new AtomicInteger(0);
|
||||
|
||||
LookupNotSupportedRealm(Settings globalSettings) {
|
||||
super("lookup", new RealmConfig("lookup-notsupported-test", Settings.EMPTY, globalSettings, new Environment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY)));
|
||||
super("lookup", new RealmConfig("lookup-notsupported-test", Settings.EMPTY, globalSettings,
|
||||
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,10 +24,10 @@ import com.unboundid.ldap.sdk.DN;
|
|||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.bootstrap.BootstrapCheck;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -40,7 +40,6 @@ import org.junit.Before;
|
|||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
|
@ -75,7 +74,7 @@ public class DnRoleMapperTests extends ESTestCase {
|
|||
.put("resource.reload.interval.high", "100ms")
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
if (Files.exists(env.configFile()) == false) {
|
||||
Files.createDirectory(env.configFile());
|
||||
}
|
||||
|
@ -283,7 +282,8 @@ public class DnRoleMapperTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, new Environment(settings), new ThreadContext(Settings.EMPTY));
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
|
||||
DnRoleMapper mapper = new DnRoleMapper(config, new ResourceWatcherService(settings, threadPool));
|
||||
|
||||
|
@ -297,7 +297,8 @@ public class DnRoleMapperTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(USE_UNMAPPED_GROUPS_AS_ROLES_SETTING_KEY, true)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, new Environment(settings), new ThreadContext(Settings.EMPTY));
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
|
||||
DnRoleMapper mapper = new DnRoleMapper(config, new ResourceWatcherService(settings, threadPool));
|
||||
|
||||
|
@ -311,7 +312,7 @@ public class DnRoleMapperTests extends ESTestCase {
|
|||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.put(USE_UNMAPPED_GROUPS_AS_ROLES_SETTING_KEY, false)
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("ldap-userdn-role", ldapSettings, settings, new Environment(settings),
|
||||
RealmConfig config = new RealmConfig("ldap-userdn-role", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
|
||||
DnRoleMapper mapper = new DnRoleMapper(config, new ResourceWatcherService(settings, threadPool));
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.bootstrap.BootstrapCheck;
|
|||
import org.elasticsearch.bootstrap.BootstrapContext;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
import org.junit.Before;
|
||||
|
@ -43,7 +43,7 @@ public class RoleMappingFileBootstrapCheckTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, new Environment(settings),
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final BootstrapCheck check = RoleMappingFileBootstrapCheck.create(config);
|
||||
assertThat(check, notNullValue());
|
||||
|
@ -57,7 +57,7 @@ public class RoleMappingFileBootstrapCheckTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, new Environment(settings),
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final BootstrapCheck check = RoleMappingFileBootstrapCheck.create(config);
|
||||
assertThat(check, notNullValue());
|
||||
|
@ -77,7 +77,7 @@ public class RoleMappingFileBootstrapCheckTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, new Environment(settings),
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final BootstrapCheck check = RoleMappingFileBootstrapCheck.create(config);
|
||||
assertThat(check, notNullValue());
|
||||
|
@ -97,7 +97,7 @@ public class RoleMappingFileBootstrapCheckTests extends ESTestCase {
|
|||
Settings ldapSettings = Settings.builder()
|
||||
.put(ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, new Environment(settings),
|
||||
RealmConfig config = new RealmConfig("the-realm-name", ldapSettings, settings, TestEnvironment.newEnvironment(settings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
final BootstrapCheck check = RoleMappingFileBootstrapCheck.create(config);
|
||||
assertThat(check, notNullValue());
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.lucene.util.automaton.MinimizationOperations;
|
|||
import org.apache.lucene.util.automaton.Operations;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
|
@ -312,7 +313,7 @@ public class FileRolesStoreTests extends ESTestCase {
|
|||
.put("resource.reload.interval.high", "500ms")
|
||||
.put("path.home", home);
|
||||
Settings settings = builder.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
threadPool = new TestThreadPool("test");
|
||||
watcherService = new ResourceWatcherService(settings, threadPool);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
@ -440,7 +441,7 @@ public class FileRolesStoreTests extends ESTestCase {
|
|||
.put("path.home", home)
|
||||
.put(XPackSettings.DLS_FLS_ENABLED.getKey(), flsDlsEnabled)
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
FileRolesStore store = new FileRolesStore(settings, env, mock(ResourceWatcherService.class), new XPackLicenseState());
|
||||
|
||||
Map<String, Object> usageStats = store.usageStats();
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.cli.UserException;
|
|||
import org.elasticsearch.common.io.PathUtilsForTesting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
import org.junit.After;
|
||||
|
@ -52,7 +53,7 @@ public class SystemKeyToolTests extends CommandTestCase {
|
|||
protected Environment createEnv(Terminal terminal, Map<String, String> settings) throws UserException {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
settings.forEach((k,v) -> builder.put(k, v));
|
||||
return new Environment(builder.build());
|
||||
return TestEnvironment.newEnvironment(builder.build());
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.settings.MockSecureSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.http.HttpTransportSettings;
|
||||
import org.elasticsearch.http.NullDispatcher;
|
||||
import org.elasticsearch.http.netty4.Netty4HttpMockUtil;
|
||||
|
@ -52,7 +53,7 @@ public class SecurityNetty4HttpServerTransportTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
sslService = new SSLService(settings, env);
|
||||
}
|
||||
|
||||
|
@ -140,7 +141,7 @@ public class SecurityNetty4HttpServerTransportTests extends ESTestCase {
|
|||
.put(XPackSettings.HTTP_SSL_ENABLED.getKey(), true)
|
||||
.put("xpack.security.http.ssl.supported_protocols", "TLSv1.2")
|
||||
.build();
|
||||
sslService = new SSLService(settings, new Environment(settings));
|
||||
sslService = new SSLService(settings, TestEnvironment.newEnvironment(settings));
|
||||
transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()),
|
||||
mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher());
|
||||
Netty4HttpMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
@ -189,7 +190,7 @@ public class SecurityNetty4HttpServerTransportTests extends ESTestCase {
|
|||
.put(XPackSettings.HTTP_SSL_ENABLED.getKey(), true)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
sslService = new SSLService(settings, env);
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class),
|
||||
|
@ -206,7 +207,7 @@ public class SecurityNetty4HttpServerTransportTests extends ESTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
sslService = new SSLService(settings, env);
|
||||
SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings,
|
||||
new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService,
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.MockSecureSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -47,7 +48,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
sslService = new SSLService(settings, env);
|
||||
}
|
||||
|
||||
|
@ -196,7 +197,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.put("path.home", createTempDir());
|
||||
Settings settings = builder.build();
|
||||
env = new Environment(settings);
|
||||
env = TestEnvironment.newEnvironment(settings);
|
||||
sslService = new SSLService(settings, env);
|
||||
SecurityNetty4Transport transport = createTransport(settings);
|
||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.elasticsearch.common.io.PathUtils;
|
|||
import org.elasticsearch.common.network.NetworkAddress;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.ssl.CertificateGenerateTool.CAInfo;
|
||||
|
@ -351,7 +352,7 @@ public class CertificateGenerateToolTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testGetCAInfo() throws Exception {
|
||||
Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Path testNodeCertPath = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt");
|
||||
Path testNodeKeyPath = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem");
|
||||
final boolean passwordPrompt = randomBoolean();
|
||||
|
|
|
@ -71,6 +71,7 @@ import org.elasticsearch.common.network.NetworkAddress;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.xpack.ssl.CertificateTool.CAInfo;
|
||||
|
@ -379,7 +380,7 @@ public class CertificateToolTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testGetCAInfo() throws Exception {
|
||||
Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Path testNodeCertPath = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt");
|
||||
Path testNodeKeyPath = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem");
|
||||
final boolean passwordPrompt = randomBoolean();
|
||||
|
@ -520,7 +521,7 @@ public class CertificateToolTests extends ESTestCase {
|
|||
final Path tempDir = initTempDir();
|
||||
|
||||
final Terminal terminal = new MockTerminal();
|
||||
Environment env = new Environment(Settings.builder().put("path.home", tempDir).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", tempDir).build());
|
||||
|
||||
final Path caFile = tempDir.resolve("ca.p12");
|
||||
final Path node1File = tempDir.resolve("node1.p12").toAbsolutePath();
|
||||
|
@ -650,7 +651,7 @@ public class CertificateToolTests extends ESTestCase {
|
|||
final Path tempDir = initTempDir();
|
||||
|
||||
final MockTerminal terminal = new MockTerminal();
|
||||
Environment env = new Environment(Settings.builder().put("path.home", tempDir).build());
|
||||
Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", tempDir).build());
|
||||
|
||||
final Path pkcs12Zip = tempDir.resolve("p12.zip");
|
||||
final Path pemZip = tempDir.resolve("pem.zip");
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.ssl;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -21,7 +22,7 @@ public class RestrictedTrustConfigTests extends ESTestCase {
|
|||
public void testDelegationOfFilesToMonitor() throws Exception {
|
||||
Path homeDir = createTempDir();
|
||||
Settings settings = Settings.builder().put("path.home", homeDir).build();
|
||||
Environment environment = new Environment(settings);
|
||||
Environment environment = TestEnvironment.newEnvironment(settings);
|
||||
|
||||
final int numOtherFiles = randomIntBetween(0, 4);
|
||||
List<Path> otherFiles = new ArrayList<>(numOtherFiles);
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder;
|
|||
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -83,7 +84,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.put("xpack.ssl.keystore.path", keystorePath)
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
final Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
final Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
|
||||
final BiConsumer<X509ExtendedKeyManager, SSLConfiguration> keyManagerPreChecks = (keyManager, config) -> {
|
||||
// key manager checks
|
||||
|
@ -154,7 +155,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
final Environment env = randomBoolean() ? null :
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
|
||||
final SetOnce<PrivateKey> privateKey = new SetOnce<>();
|
||||
final BiConsumer<X509ExtendedKeyManager, SSLConfiguration> keyManagerPreChecks = (keyManager, config) -> {
|
||||
|
@ -217,7 +218,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
|
||||
final SetOnce<Integer> trustedCount = new SetOnce<>();
|
||||
final BiConsumer<X509ExtendedTrustManager, SSLConfiguration> trustManagerPreChecks = (trustManager, config) -> {
|
||||
|
@ -260,7 +261,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.putList("xpack.ssl.certificate_authorities", clientCertPath.toString())
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
|
||||
final BiConsumer<X509ExtendedTrustManager, SSLConfiguration> trustManagerPreChecks = (trustManager, config) -> {
|
||||
// trust manager checks
|
||||
|
@ -304,7 +305,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
final SSLService sslService = new SSLService(settings, env);
|
||||
final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY);
|
||||
new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) {
|
||||
|
@ -346,7 +347,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
final SSLService sslService = new SSLService(settings, env);
|
||||
final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY);
|
||||
new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) {
|
||||
|
@ -381,7 +382,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
final SSLService sslService = new SSLService(settings, env);
|
||||
final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY);
|
||||
new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) {
|
||||
|
@ -413,7 +414,7 @@ public class SSLConfigurationReloaderTests extends ESTestCase {
|
|||
.putList("xpack.ssl.certificate_authorities", clientCertPath.toString())
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Environment env = randomBoolean() ? null : new Environment(settings);
|
||||
Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings);
|
||||
final SSLService sslService = new SSLService(settings, env);
|
||||
final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY);
|
||||
new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.MockSecureSettings;
|
|||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ssl.TrustConfig.CombiningTrustConfig;
|
||||
|
||||
|
@ -295,7 +296,7 @@ public class SSLConfigurationTests extends ESTestCase {
|
|||
|
||||
public void testPEMFile() {
|
||||
Environment env = randomBoolean() ? null :
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
MockSecureSettings secureSettings = new MockSecureSettings();
|
||||
secureSettings.setString("secure_key_passphrase", "testnode");
|
||||
Settings settings = Settings.builder()
|
||||
|
@ -315,7 +316,7 @@ public class SSLConfigurationTests extends ESTestCase {
|
|||
|
||||
public void testPEMFileBackcompat() {
|
||||
Environment env = randomBoolean() ? null :
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Settings settings = Settings.builder()
|
||||
.put("key",
|
||||
getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
|
||||
|
@ -336,7 +337,7 @@ public class SSLConfigurationTests extends ESTestCase {
|
|||
|
||||
public void testPEMKeyAndTrustFiles() {
|
||||
Environment env = randomBoolean() ? null :
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
MockSecureSettings secureSettings = new MockSecureSettings();
|
||||
secureSettings.setString("secure_key_passphrase", "testnode");
|
||||
Settings settings = Settings.builder()
|
||||
|
@ -361,7 +362,7 @@ public class SSLConfigurationTests extends ESTestCase {
|
|||
|
||||
public void testPEMKeyAndTrustFilesBackcompat() {
|
||||
Environment env = randomBoolean() ? null :
|
||||
new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Settings settings = Settings.builder()
|
||||
.put("key", getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
|
||||
.put("key_passphrase", "testnode")
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.common.settings.MockSecureSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
|
@ -110,7 +110,7 @@ public class SSLReloadIntegTests extends SecurityIntegTestCase {
|
|||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
String node = randomFrom(internalCluster().getNodeNames());
|
||||
SSLService sslService = new SSLService(settings, new Environment(settings));
|
||||
SSLService sslService = new SSLService(settings, TestEnvironment.newEnvironment(settings));
|
||||
SSLSocketFactory sslSocketFactory = sslService.sslSocketFactory(settings);
|
||||
TransportAddress address = internalCluster()
|
||||
.getInstance(Transport.class, node).boundAddress().publishAddress();
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
import org.elasticsearch.xpack.XPackSettings;
|
||||
|
@ -81,7 +82,7 @@ public class SSLServiceTests extends ESTestCase {
|
|||
}
|
||||
logger.info("Using [{}] key/truststore [{}]", testnodeStoreType, testnodeStore);
|
||||
testclientStore = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.jks");
|
||||
env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
}
|
||||
|
||||
public void testThatCustomTruststoreCanBeSpecified() throws Exception {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
|
@ -188,7 +188,7 @@ public class SSLTrustRestrictionsTests extends SecurityIntegTestCase {
|
|||
.build();
|
||||
|
||||
String node = randomFrom(internalCluster().getNodeNames());
|
||||
SSLService sslService = new SSLService(settings, new Environment(settings));
|
||||
SSLService sslService = new SSLService(settings, TestEnvironment.newEnvironment(settings));
|
||||
SSLSocketFactory sslSocketFactory = sslService.sslSocketFactory(settings);
|
||||
TransportAddress address = internalCluster().getInstance(Transport.class, node).boundAddress().publishAddress();
|
||||
try (SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(address.getAddress(), address.getPort())) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.security.PrivateKey;
|
|||
|
||||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -34,7 +34,7 @@ public class StoreKeyConfigTests extends ESTestCase {
|
|||
final SecureString keyStorePassword = new SecureString("testnode".toCharArray());
|
||||
final StoreKeyConfig keyConfig = new StoreKeyConfig(path, type, keyStorePassword, keyStorePassword,
|
||||
KeyManagerFactory.getDefaultAlgorithm(), TrustManagerFactory.getDefaultAlgorithm());
|
||||
final X509ExtendedKeyManager keyManager = keyConfig.createKeyManager(new Environment(settings));
|
||||
final X509ExtendedKeyManager keyManager = keyConfig.createKeyManager(TestEnvironment.newEnvironment(settings));
|
||||
final PrivateKey key = keyManager.getPrivateKey("testnode");
|
||||
assertThat(key, notNullValue());
|
||||
assertThat(key.getAlgorithm(), equalTo("RSA"));
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.bootstrap.BootstrapContext;
|
|||
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class EncryptSensitiveDataBootstrapCheckTests extends ESTestCase {
|
|||
|
||||
public void testDefaultIsFalse() {
|
||||
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
EncryptSensitiveDataBootstrapCheck check = new EncryptSensitiveDataBootstrapCheck(env);
|
||||
assertFalse(check.check(new BootstrapContext(settings, null)).isFailure());
|
||||
assertTrue(check.alwaysEnforce());
|
||||
|
@ -27,7 +28,7 @@ public class EncryptSensitiveDataBootstrapCheckTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.put(Watcher.ENCRYPT_SENSITIVE_DATA_SETTING.getKey(), true)
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
EncryptSensitiveDataBootstrapCheck check = new EncryptSensitiveDataBootstrapCheck(env);
|
||||
assertTrue(check.check(new BootstrapContext(settings, null)).isFailure());
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ public class EncryptSensitiveDataBootstrapCheckTests extends ESTestCase {
|
|||
.put(Watcher.ENCRYPT_SENSITIVE_DATA_SETTING.getKey(), true)
|
||||
.setSecureSettings(secureSettings)
|
||||
.build();
|
||||
Environment env = new Environment(settings);
|
||||
Environment env = TestEnvironment.newEnvironment(settings);
|
||||
EncryptSensitiveDataBootstrapCheck check = new EncryptSensitiveDataBootstrapCheck(env);
|
||||
assertFalse(check.check(new BootstrapContext(settings, null)).isFailure());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.xpack.watcher;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.analysis.AnalysisRegistry;
|
||||
|
@ -65,8 +65,8 @@ public class WatcherPluginTests extends ESTestCase {
|
|||
|
||||
// ensure index module is not called, even if watches index is tried
|
||||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(Watch.INDEX, settings);
|
||||
AnalysisRegistry registry = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(),
|
||||
emptyMap(), emptyMap(), emptyMap(), emptyMap());
|
||||
AnalysisRegistry registry = new AnalysisRegistry(TestEnvironment.newEnvironment(settings), emptyMap(), emptyMap(), emptyMap(),
|
||||
emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap());
|
||||
IndexModule indexModule = new IndexModule(indexSettings, registry);
|
||||
// this will trip an assertion if the watcher indexing operation listener is null (which it is) but we try to add it
|
||||
watcher.onIndexModule(indexModule);
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.http.MockResponse;
|
||||
import org.elasticsearch.test.http.MockWebServer;
|
||||
|
@ -216,7 +217,7 @@ public class WebhookActionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatSelectingProxyWorks() throws Exception {
|
||||
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
|
||||
HttpClient httpClient = new HttpClient(Settings.EMPTY, authRegistry,
|
||||
new SSLService(environment.settings(), environment));
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
|
||||
import com.sun.jna.IntegerType;
|
||||
|
@ -275,7 +276,7 @@ public class NamedPipeHelperNoBootstrapTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testOpenForInput() throws IOException, InterruptedException {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
String pipeName = NAMED_PIPE_HELPER.getDefaultPipeDirectoryPrefix(env) + "inputPipe" + JvmInfo.jvmInfo().pid();
|
||||
|
||||
|
@ -306,7 +307,7 @@ public class NamedPipeHelperNoBootstrapTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testOpenForOutput() throws IOException, InterruptedException {
|
||||
Environment env = new Environment(
|
||||
Environment env = TestEnvironment.newEnvironment(
|
||||
Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build());
|
||||
String pipeName = NAMED_PIPE_HELPER.getDefaultPipeDirectoryPrefix(env) + "outputPipe" + JvmInfo.jvmInfo().pid();
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
|
@ -99,7 +100,7 @@ public class OpenLdapTests extends ESTestCase {
|
|||
builder.put("xpack.security.authc.realms.bar.ssl.verification_mode", VerificationMode.CERTIFICATE);
|
||||
}
|
||||
globalSettings = builder.setSecureSettings(mockSecureSettings).build();
|
||||
Environment environment = new Environment(globalSettings);
|
||||
Environment environment = TestEnvironment.newEnvironment(globalSettings);
|
||||
sslService = new SSLService(globalSettings, environment);
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,8 @@ public class OpenLdapTests extends ESTestCase {
|
|||
String groupSearchBase = "ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
|
||||
String userTemplate = "uid={0},ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
|
||||
RealmConfig config = new RealmConfig("oldap-test", buildLdapSettings(OPEN_LDAP_URL, userTemplate, groupSearchBase,
|
||||
LdapSearchScope.ONE_LEVEL), globalSettings, new Environment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
LdapSearchScope.ONE_LEVEL), globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
String[] users = new String[] { "blackwidow", "cap", "hawkeye", "hulk", "ironman", "thor" };
|
||||
|
@ -126,7 +128,7 @@ public class OpenLdapTests extends ESTestCase {
|
|||
String groupSearchBase = "cn=Avengers,ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
|
||||
String userTemplate = "uid={0},ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
|
||||
RealmConfig config = new RealmConfig("oldap-test", buildLdapSettings(OPEN_LDAP_URL, userTemplate, groupSearchBase,
|
||||
LdapSearchScope.BASE), globalSettings, new Environment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
LdapSearchScope.BASE), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
String[] users = new String[] { "blackwidow", "cap", "hawkeye", "hulk", "ironman", "thor" };
|
||||
|
@ -145,7 +147,7 @@ public class OpenLdapTests extends ESTestCase {
|
|||
.put("group_search.filter", "(&(objectclass=posixGroup)(memberUid={0}))")
|
||||
.put("group_search.user_attribute", "uid")
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -164,7 +166,7 @@ public class OpenLdapTests extends ESTestCase {
|
|||
.put("ssl.verification_mode", VerificationMode.CERTIFICATE)
|
||||
.put(SessionFactory.TIMEOUT_TCP_READ_SETTING, "1ms") //1 millisecond
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
@ -182,7 +184,7 @@ public class OpenLdapTests extends ESTestCase {
|
|||
.put("ssl.verification_mode", VerificationMode.FULL)
|
||||
.build();
|
||||
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, new Environment(globalSettings),
|
||||
RealmConfig config = new RealmConfig("oldap-test", settings, globalSettings, TestEnvironment.newEnvironment(globalSettings),
|
||||
new ThreadContext(Settings.EMPTY));
|
||||
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.common.settings.MockSecureSettings;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.OpenLdapTests;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
|
@ -29,7 +29,6 @@ import java.nio.file.Path;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.test.OpenLdapTests.LDAPTRUST_PATH;
|
||||
|
@ -75,12 +74,12 @@ public class OpenLdapUserSearchSessionFactoryTests extends ESTestCase {
|
|||
.put("bind_dn", "uid=blackwidow,ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com")
|
||||
.put("bind_password", OpenLdapTests.PASSWORD)
|
||||
.put("user_search.pool.enabled", randomBoolean())
|
||||
.build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings));
|
||||
.build(), globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
|
||||
Settings.Builder builder = Settings.builder()
|
||||
.put(globalSettings);
|
||||
builder.put(Settings.builder().put(config.settings()).normalizePrefix("xpack.security.authc.realms.ldap.").build());
|
||||
Settings settings = builder.build();
|
||||
SSLService sslService = new SSLService(settings, new Environment(settings));
|
||||
SSLService sslService = new SSLService(settings, TestEnvironment.newEnvironment(settings));
|
||||
|
||||
|
||||
String[] users = new String[] { "cap", "hawkeye", "hulk", "ironman", "thor" };
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.action.support.PlainActionFuture;
|
|||
import org.elasticsearch.common.settings.SecureString;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.AuthenticationResult;
|
||||
import org.elasticsearch.xpack.security.authc.RealmConfig;
|
||||
|
@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
public class CustomRealmTests extends ESTestCase {
|
||||
public void testAuthenticate() {
|
||||
Settings globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
CustomRealm realm = new CustomRealm(new RealmConfig("test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings)));
|
||||
CustomRealm realm = new CustomRealm(new RealmConfig("test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)));
|
||||
SecureString password = CustomRealm.KNOWN_PW.clone();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(CustomRealm.KNOWN_USER, password);
|
||||
PlainActionFuture<AuthenticationResult> plainActionFuture = new PlainActionFuture<>();
|
||||
|
@ -35,7 +35,7 @@ public class CustomRealmTests extends ESTestCase {
|
|||
|
||||
public void testAuthenticateBadUser() {
|
||||
Settings globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
CustomRealm realm = new CustomRealm(new RealmConfig("test", Settings.EMPTY, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings)));
|
||||
CustomRealm realm = new CustomRealm(new RealmConfig("test", Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)));
|
||||
SecureString password = CustomRealm.KNOWN_PW.clone();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(CustomRealm.KNOWN_USER + "1", password);
|
||||
PlainActionFuture<AuthenticationResult> plainActionFuture = new PlainActionFuture<>();
|
||||
|
|
Loading…
Reference in New Issue