From 44cd14d5f1e8f4968e888c359f82a45e4ab562b6 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 23 Sep 2015 13:34:23 -0400 Subject: [PATCH] test: cleanup usages of node builder where we actually need Shield loaded Some tests are still using a node builder for nodes that need to load Shield, which is not currently supported by elasticsearch. This changes some to use a MockNode and awaits fix a tribe test that was previously testing nothing. Original commit: elastic/x-pack-elasticsearch@57d0c902b61c03babfaab4ef5d44d6e20150396e --- .../ldap/LdapUserSearchSessionFactoryTests.java | 2 -- .../ServerTransportFilterIntegrationTests.java | 4 ++-- .../shield/tribe/TribeShieldLoadedTests.java | 14 +++++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactoryTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactoryTests.java index 3718f8b17a6..b1850fa10bd 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactoryTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactoryTests.java @@ -17,7 +17,6 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.shield.ShieldPlugin; import org.elasticsearch.shield.authc.RealmConfig; import org.elasticsearch.shield.authc.activedirectory.ActiveDirectorySessionFactoryTests; @@ -36,7 +35,6 @@ import java.nio.file.Path; import java.text.MessageFormat; import java.util.*; -import static org.elasticsearch.common.settings.Settings.builder; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException; import static org.hamcrest.Matchers.*; diff --git a/shield/src/test/java/org/elasticsearch/shield/transport/ServerTransportFilterIntegrationTests.java b/shield/src/test/java/org/elasticsearch/shield/transport/ServerTransportFilterIntegrationTests.java index f528f83c587..1f17e56b209 100644 --- a/shield/src/test/java/org/elasticsearch/shield/transport/ServerTransportFilterIntegrationTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/transport/ServerTransportFilterIntegrationTests.java @@ -30,7 +30,6 @@ import java.nio.file.Path; import java.util.Arrays; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.elasticsearch.shield.test.ShieldTestUtils.createFolder; import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile; import static org.hamcrest.CoreMatchers.instanceOf; @@ -139,8 +138,9 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase { .put(InternalCryptoService.FILE_SETTING, systemKeyFile) .put("discovery.initial_state_timeout", "2s") .put("path.home", createTempDir()) + .put("node.client", true) .build(); - try (Node node = nodeBuilder().client(true).settings(nodeSettings).build()) { + try (Node node = new MockNode(nodeSettings, Version.CURRENT, Arrays.asList(ShieldPlugin.class, licensePluginClass()))) { node.start(); // assert that node is not connected by waiting for the timeout diff --git a/shield/src/test/java/org/elasticsearch/shield/tribe/TribeShieldLoadedTests.java b/shield/src/test/java/org/elasticsearch/shield/tribe/TribeShieldLoadedTests.java index d984f64d6bc..a8c52b324f6 100644 --- a/shield/src/test/java/org/elasticsearch/shield/tribe/TribeShieldLoadedTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/tribe/TribeShieldLoadedTests.java @@ -6,8 +6,10 @@ package org.elasticsearch.shield.tribe; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.plugin.LicensePlugin; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.plugins.PluginsService; @@ -15,6 +17,8 @@ import org.elasticsearch.shield.ShieldPlugin; import org.elasticsearch.test.ESTestCase; import org.junit.Test; +import java.util.Arrays; + import static org.hamcrest.CoreMatchers.containsString; /** @@ -25,11 +29,13 @@ import static org.hamcrest.CoreMatchers.containsString; public class TribeShieldLoadedTests extends ESTestCase { @Test + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/13212") + // we really need to support loading plugins at the node level this way which should flow the plugins down to the tribe service, right now it doesnt! public void testShieldLoadedOnBothTribeNodeAndClients() { //all good if the plugin is loaded on both tribe node and tribe clients, no matter how it gets loaded (manually or from classpath) Settings.Builder builder = defaultSettings(); - try (Node node = NodeBuilder.nodeBuilder().settings(builder.build()).build()) { + try (Node node = new MockNode(builder.build(), Version.CURRENT, Arrays.asList(ShieldPlugin.class, LicensePlugin.class))) { node.start(); } } @@ -66,13 +72,15 @@ public class TribeShieldLoadedTests extends ESTestCase { private static Settings.Builder defaultSettings() { return addTribeSettings(Settings.builder() .put("node.name", "tribe_node") - .put("path.home", createTempDir()), "t1"); + .put("path.home", createTempDir()) + .putArray("plugin.mandatory", ShieldPlugin.NAME, LicensePlugin.NAME), "t1"); } private static Settings.Builder addTribeSettings(Settings.Builder settingsBuilder, String tribe) { String tribePrefix = "tribe." + tribe + "."; return settingsBuilder.put(tribePrefix + "cluster.name", "non_existing_cluster") .put(tribePrefix + "discovery.type", "local") - .put(tribePrefix + "discovery.initial_state_timeout", 0); + .put(tribePrefix + "discovery.initial_state_timeout", 0) + .putArray(tribePrefix + "plugin.mandatory", ShieldPlugin.NAME, LicensePlugin.NAME); } }