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