diff --git a/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java b/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java index 11cb934a94..90df8433aa 100644 --- a/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java +++ b/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java @@ -1961,9 +1961,10 @@ public void stop() {} } - public static void setClusterService (ClusterService clusterService) { + public static void setClusterService(ClusterService clusterService) { cs = clusterService; } + public static ClusterService getClusterNameString() { return cs; } diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java index b47f9cdd13..bce800c811 100644 --- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java +++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java @@ -83,12 +83,7 @@ public class DynamicConfigModelV7 extends DynamicConfigModel { private List> ipClientBlockRegistries; private Multimap> authBackendClientBlockRegistries; - public DynamicConfigModelV7( - ConfigV7 config, - Settings opensearchSettings, - Path configPath, - InternalAuthenticationBackend iab - ) { + public DynamicConfigModelV7(ConfigV7 config, Settings opensearchSettings, Path configPath, InternalAuthenticationBackend iab) { super(); this.config = config; this.opensearchSettings = opensearchSettings; diff --git a/src/test/java/org/opensearch/security/http/OnBehalfOfAuthenticatorTest.java b/src/test/java/org/opensearch/security/http/OnBehalfOfAuthenticatorTest.java index 7459d1ebbe..b3b1ef1a81 100644 --- a/src/test/java/org/opensearch/security/http/OnBehalfOfAuthenticatorTest.java +++ b/src/test/java/org/opensearch/security/http/OnBehalfOfAuthenticatorTest.java @@ -27,13 +27,21 @@ import io.jsonwebtoken.security.Keys; import org.apache.commons.lang3.RandomStringUtils; import org.apache.hc.core5.http.HttpHeaders; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opensearch.cluster.ClusterName; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; +import org.opensearch.security.OpenSearchSecurityPlugin; import org.opensearch.security.user.AuthCredentials; import org.opensearch.security.util.FakeRestRequest; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class OnBehalfOfAuthenticatorTest { final static String clusterNameString = "cluster_0"; final static String enableOBO = "true"; @@ -45,6 +53,20 @@ public class OnBehalfOfAuthenticatorTest { final static String signingKeyB64Encoded = BaseEncoding.base64().encode(signingKey.getBytes(StandardCharsets.UTF_8)); final static SecretKey secretKey = Keys.hmacShaKeyFor(signingKeyB64Encoded.getBytes(StandardCharsets.UTF_8)); + @Before + public void setupMocks() { + ClusterService mockedClusterService = mock(ClusterService.class); + ClusterName mockedClusterName = new ClusterName(clusterNameString); + when(mockedClusterService.getClusterName()).thenReturn(mockedClusterName); + + OpenSearchSecurityPlugin.setClusterService(mockedClusterService); + } + + @After + public void tearDown() { + OpenSearchSecurityPlugin.setClusterService(null); + } + @Test public void testNoKey() throws Exception {