Skip to content

Commit ddfe166

Browse files
committed
fixup! Test
1 parent 4f7c377 commit ddfe166

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRoleMappingCleanupIT.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public void testCleanupDuplicateMappingsCreatedWithBug() throws Exception {
4444
assertAllRoleMappings(client(), "no_name_conflict", "operator_role_mapping_1");
4545
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
4646
waitForSecurityMigrationCompletion(adminClient(), 2);
47-
assertAllRoleMappings(client(), "no_name_conflict");
47+
assertRoleMappingsExistsInClusterState("operator_role_mapping_1", "operator_role_mapping_2");
48+
// In the old cluster we might have created these (depending on the node features), so make sure they were removed
4849
assertFalse(roleMappingExistsInSecurityIndex("operator_role_mapping_1"));
4950
assertFalse(roleMappingExistsInSecurityIndex("operator_role_mapping_2"));
5051
// Make sure we can create a conflicting role mapping again
@@ -63,15 +64,41 @@ public void testCleanupDuplicateMappingsCreatedBeforeBug() throws Exception {
6364
assertAllRoleMappings(client(), "no_name_conflict", "operator_role_mapping_1", "operator_role_mapping_2");
6465
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
6566
waitForSecurityMigrationCompletion(adminClient(), 2);
66-
// Make sure migrated mapping is only in cluster state
67+
assertRoleMappingsExistsInClusterState("operator_role_mapping_1", "operator_role_mapping_2");
68+
// In the old cluster we might have created these (depending on the version), so make sure they were removed
6769
assertFalse(roleMappingExistsInSecurityIndex("operator_role_mapping_1"));
6870
assertFalse(roleMappingExistsInSecurityIndex("operator_role_mapping_2"));
69-
// Make sure not migrated mapping is still in security index
70-
assertTrue(roleMappingExistsInSecurityIndex("no_name_conflict"));
7171
// Make sure we can create a conflicting role mapping
7272
createNativeRoleMapping("operator_role_mapping_1", Map.of("meta", "test"));
7373
}
7474
}
75+
@SuppressWarnings("unchecked")
76+
private void assertRoleMappingsExistsInClusterState(String... roleMappingNames) throws IOException {
77+
final Request request = new Request("GET", "_cluster/state/metadata/");
78+
Response response = adminClient().performRequest(request);
79+
assertOK(response);
80+
Map<String, Object> responseMap = responseAsMap(response);
81+
Map<String, Object> metadata = ((Map<String, Object>) responseMap.get("metadata"));
82+
assertNotNull(metadata);
83+
List<Map<String,Object>> clusterStateRoleMappings = (List<Map<String,Object>>) ((Map<String,Object>) metadata.get("role_mappings"))
84+
.get("role_mappings");
85+
86+
assertNotNull(clusterStateRoleMappings);
87+
assertEquals(clusterStateRoleMappings.size(), roleMappingNames.length);
88+
89+
List<String> roleMappingHandlers = (List<String>) ((Map<String, Object>)((Map<String, Object>)
90+
((Map<String, Object>)((Map<String, Object>) metadata
91+
.get("reserved_state"))
92+
.get("file_settings"))
93+
.get("handlers"))
94+
.get("role_mappings"))
95+
.get("keys");
96+
97+
assertNotNull(roleMappingHandlers);
98+
assertEquals(clusterStateRoleMappings.size(), roleMappingHandlers.size());
99+
assertThat(roleMappingHandlers, containsInAnyOrder(roleMappingNames));
100+
}
101+
75102

76103
@SuppressWarnings("unchecked")
77104
private boolean roleMappingExistsInSecurityIndex(String mappingName) throws IOException {

0 commit comments

Comments
 (0)