From ff242e826a2b49207cb6a7346703f0ce710891d8 Mon Sep 17 00:00:00 2001 From: Ioannis Kakavas Date: Thu, 6 Dec 2018 16:21:51 +0200 Subject: [PATCH] Fix FullClusterRestartIT --- .../xpack/restart/FullClusterRestartIT.java | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index f0c0d3af77519..84e99ecdc3e3d 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -96,8 +96,8 @@ public void testSingleDoc() throws IOException { @SuppressWarnings("unchecked") public void testSecurityNativeRealm() throws Exception { if (isRunningAgainstOldCluster()) { - createUser("preupgrade_user"); - createRole("preupgrade_role"); + createUser(true); + createRole(true); } else { waitForYellow(".security"); Response settingsResponse = client().performRequest(new Request("GET", "/.security/_settings/index.format")); @@ -126,7 +126,7 @@ public void testSecurityNativeRealm() throws Exception { logger.info("upgrading security index {}", concreteSecurityIndex); // without upgrade, an error should be thrown try { - createUser("postupgrade_user"); + createUser(false); fail("should not be able to add a user when upgrade hasn't taken place"); } catch (ResponseException e) { assertThat(e.getMessage(), containsString("Security index is not on the current version - " + @@ -139,16 +139,12 @@ public void testSecurityNativeRealm() throws Exception { } // create additional user and role - createUser("postupgrade_user"); - createRole("postupgrade_role"); + createUser(false); + createRole(false); } - assertUserInfo("preupgrade_user"); - assertRoleInfo("preupgrade_role"); - if (isRunningAgainstOldCluster() == false) { - assertUserInfo("postupgrade_user"); - assertRoleInfo("postupgrade_role"); - } + assertUserInfo(isRunningAgainstOldCluster()); + assertRoleInfo(isRunningAgainstOldCluster()); } public void testWatcher() throws Exception { @@ -578,8 +574,14 @@ static String toStr(Response response) throws IOException { return EntityUtils.toString(response.getEntity()); } - private void createUser(final String id) throws Exception { - Request request = new Request("PUT", "/_security/user/" + id); + private void createUser(final boolean oldCluster) throws Exception { + final String id = oldCluster ? "preupgrade_user" : "postupgrade_user"; + Request request; + if (oldCluster) { + request = new Request("PUT", "/_xpack/security/user/" + id); + } else { + request = new Request("PUT", "/_security/user/" + id); + } request.setJsonEntity( "{\n" + " \"password\" : \"j@rV1s\",\n" + @@ -591,8 +593,14 @@ private void createUser(final String id) throws Exception { client().performRequest(request); } - private void createRole(final String id) throws Exception { - Request request = new Request("PUT", "/_security/role/" + id); + private void createRole(final boolean oldCluster) throws Exception { + final String id = oldCluster ? "preupgrade_role" : "postupgrade_role"; + Request request; + if (oldCluster) { + request = new Request("PUT", "/_xpack/security/role/" + id); + } else { + request = new Request("PUT", "/_security/role/" + id); + } request.setJsonEntity( "{\n" + " \"run_as\": [ \"abc\" ],\n" + @@ -611,17 +619,22 @@ private void createRole(final String id) throws Exception { client().performRequest(request); } - private void assertUserInfo(final String user) throws Exception { - Map response = entityAsMap(client().performRequest(new Request("GET", "/_security/user/" + user))); + private void assertUserInfo(final boolean oldCluster) throws Exception { + final String user = oldCluster ? "preupgrade_user" : "postupgrade_user"; + Map response = oldCluster ? + entityAsMap(client().performRequest(new Request("GET", "/_xpack/security/user/" + user))) : + entityAsMap(client().performRequest(new Request("GET", "/_security/user/" + user))); @SuppressWarnings("unchecked") Map userInfo = (Map) response.get(user); assertEquals(user + "@example.com", userInfo.get("email")); assertNotNull(userInfo.get("full_name")); assertNotNull(userInfo.get("roles")); } - private void assertRoleInfo(final String role) throws Exception { - @SuppressWarnings("unchecked") Map response = (Map) - entityAsMap(client().performRequest(new Request("GET", "/_security/role/" + role))).get(role); + private void assertRoleInfo(final boolean oldCluster) throws Exception { + final String role = oldCluster ? "preupgrade_role" : "postupgrade_role"; + @SuppressWarnings("unchecked") Map response = oldCluster ? + (Map) entityAsMap(client().performRequest(new Request("GET", "/_xpack/security/role/" + role))).get(role) : + (Map) entityAsMap(client().performRequest(new Request("GET", "/_security/role/" + role))).get(role); assertNotNull(response.get("run_as")); assertNotNull(response.get("cluster")); assertNotNull(response.get("indices"));