|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + * |
| 8 | + * Modifications Copyright OpenSearch Contributors. See |
| 9 | + * GitHub history for details. |
| 10 | + */ |
| 11 | + |
| 12 | +package org.opensearch.security.privileges.int_tests; |
| 13 | + |
| 14 | +import java.util.Map; |
| 15 | +import java.util.function.Function; |
| 16 | +import java.util.function.Supplier; |
| 17 | + |
| 18 | +import org.opensearch.test.framework.cluster.LocalCluster; |
| 19 | + |
| 20 | +/** |
| 21 | + * This is one of the test parameter dimensions used by the *Authorization*IntTests test suites. |
| 22 | + * The test suites run on different cluster configurations; the possible cluster configurations are defined here. |
| 23 | + */ |
| 24 | +public enum ClusterConfig { |
| 25 | + LEGACY_PRIVILEGES_EVALUATION( |
| 26 | + "legacy", |
| 27 | + c -> c.doNotFailOnForbidden(true).nodeSettings(Map.of("plugins.security.system_indices.enabled", true)), |
| 28 | + true, |
| 29 | + false, |
| 30 | + false |
| 31 | + ), |
| 32 | + LEGACY_PRIVILEGES_EVALUATION_SYSTEM_INDEX_PERMISSION( |
| 33 | + "legacy_system_index_perm", |
| 34 | + c -> c.doNotFailOnForbidden(true) |
| 35 | + .nodeSettings( |
| 36 | + Map.of("plugins.security.system_indices.enabled", true, "plugins.security.system_indices.permission.enabled", true) |
| 37 | + ), |
| 38 | + true, |
| 39 | + true, |
| 40 | + false |
| 41 | + ); |
| 42 | + |
| 43 | + final String name; |
| 44 | + final Function<LocalCluster.Builder, LocalCluster.Builder> clusterConfiguration; |
| 45 | + final boolean legacyPrivilegeEvaluation; |
| 46 | + final boolean systemIndexPrivilegeEnabled; |
| 47 | + final boolean allowsEmptyResultSets; |
| 48 | + |
| 49 | + private LocalCluster cluster; |
| 50 | + |
| 51 | + ClusterConfig( |
| 52 | + String name, |
| 53 | + Function<LocalCluster.Builder, LocalCluster.Builder> clusterConfiguration, |
| 54 | + boolean legacyPrivilegeEvaluation, |
| 55 | + boolean systemIndexPrivilegeEnabled, |
| 56 | + boolean allowsEmptyResultSets |
| 57 | + ) { |
| 58 | + this.name = name; |
| 59 | + this.clusterConfiguration = clusterConfiguration; |
| 60 | + this.legacyPrivilegeEvaluation = legacyPrivilegeEvaluation; |
| 61 | + this.systemIndexPrivilegeEnabled = systemIndexPrivilegeEnabled; |
| 62 | + this.allowsEmptyResultSets = allowsEmptyResultSets; |
| 63 | + } |
| 64 | + |
| 65 | + LocalCluster cluster(Supplier<LocalCluster.Builder> clusterBuilder) { |
| 66 | + if (cluster == null) { |
| 67 | + cluster = this.clusterConfiguration.apply(clusterBuilder.get()).build(); |
| 68 | + cluster.before(); |
| 69 | + } |
| 70 | + return cluster; |
| 71 | + } |
| 72 | + |
| 73 | + void shutdown() { |
| 74 | + if (cluster != null) { |
| 75 | + try { |
| 76 | + cluster.close(); |
| 77 | + } catch (Exception e) {} |
| 78 | + cluster = null; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String toString() { |
| 84 | + return name; |
| 85 | + } |
| 86 | +} |
0 commit comments