From bb7afbbe8abf50749e7fe64c23d4e73dc102bf7c Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Sat, 23 Apr 2022 01:00:47 -0500 Subject: [PATCH] Update security policy for testing feature flags Signed-off-by: Nicholas Walter Knize --- .../org/opensearch/bootstrap/security.policy | 3 +++ .../common/util/FeatureFlagTests.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/server/src/main/resources/org/opensearch/bootstrap/security.policy b/server/src/main/resources/org/opensearch/bootstrap/security.policy index 97b73aedf24bb..d0ca6a269b0ae 100644 --- a/server/src/main/resources/org/opensearch/bootstrap/security.policy +++ b/server/src/main/resources/org/opensearch/bootstrap/security.policy @@ -120,6 +120,9 @@ grant { // TODO: set this with gradle or some other way that repros with seed? permission java.util.PropertyPermission "processors.override", "write"; + // needed for feature flags + permission java.util.PropertyPermission "opensearch.experimental.feature.*", "write"; + // TODO: these simply trigger a noisy warning if its unable to clear the properties // fix that in randomizedtesting permission java.util.PropertyPermission "junit4.childvm.count", "write"; diff --git a/server/src/test/java/org/opensearch/common/util/FeatureFlagTests.java b/server/src/test/java/org/opensearch/common/util/FeatureFlagTests.java index 7f416c233080e..1084f9c658db4 100644 --- a/server/src/test/java/org/opensearch/common/util/FeatureFlagTests.java +++ b/server/src/test/java/org/opensearch/common/util/FeatureFlagTests.java @@ -8,10 +8,27 @@ package org.opensearch.common.util; +import org.junit.BeforeClass; +import org.opensearch.common.SuppressForbidden; import org.opensearch.test.OpenSearchTestCase; +import java.security.AccessController; +import java.security.PrivilegedAction; + public class FeatureFlagTests extends OpenSearchTestCase { + @SuppressForbidden(reason = "sets the feature flag") + @BeforeClass + public static void enableFeature() { + AccessController.doPrivileged((PrivilegedAction) () -> System.setProperty(FeatureFlags.REPLICATION_TYPE, "true")); + } + + public void testReplicationTypeFeatureFlag() { + String replicationTypeFlag = FeatureFlags.REPLICATION_TYPE; + assertNotNull(System.getProperty(replicationTypeFlag)); + assertTrue(FeatureFlags.isEnabled(replicationTypeFlag)); + } + public void testMissingFeatureFlag() { String testFlag = "missingFeatureFlag"; assertNull(System.getProperty(testFlag));