Skip to content

Commit

Permalink
Update security policy for testing feature flags
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed Apr 23, 2022
1 parent 2001ed8 commit bb7afbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) () -> 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));
Expand Down

0 comments on commit bb7afbb

Please sign in to comment.