You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by jn...@apache.org on 2026/03/28 11:37:40 UTC
(storm) 01/01: Port Clojure tests to Java: metrics_test, nimbus_auth_test
This is an automated email from the ASF dual-hosted git repository.
jnioche pushed a commit to branch port/clojure-tests-phase5
in repository https://gitbox.apache.org/repos/asf/storm.git
commit 383ee5d9cc604927c957185c833da75a3df173be
Author: Julien Nioche <ju...@digitalpebble.com>
AuthorDate: Sat Mar 28 11:37:28 2026 +0000
Port Clojure tests to Java: metrics_test, nimbus_auth_test
Port 2 tests from storm-core/test/clj/org/apache/storm/metrics_test.clj to
storm-core/test/jvm/org/apache/storm/metric/MetricsIntegrationTest.java:
- testCustomMetric: CountMetric with FakeMetricConsumer, simulated time
- testCustomMetricWithMultiTasks: same with 2 tasks per bolt
Skipped 2 Python multilang metrics tests (require Python shell components)
and 1 spout multilang test.
Port 5 tests from storm-core/test/clj/org/apache/storm/security/auth/nimbus_auth_test.clj to
storm-server/src/test/java/org/apache/storm/security/auth/NimbusAuthTest.java:
- testSimpleAuthentication: SimpleTransportPlugin with no authorizer
- testNoopAuthorizationWithSimpleTransport: NoopAuthorizer, mocked cluster state
- testDenyAuthorizationWithSimpleTransport: DenyAuthorizer, 17 denied operations
- testNoopAuthorizationWithSaslDigest: DigestSaslTransportPlugin with JAAS
- testDenyAuthorizationWithSaslDigest: DenyAuthorizer with SASL, 17 denied ops
JAAS config file copied to storm-server test resources for classpath access.
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../storm/metric/MetricsIntegrationTest.java | 223 +++++++++++++
.../apache/storm/security/auth/NimbusAuthTest.java | 357 +++++++++++++++++++++
.../apache/storm/security/auth/jaas_digest.conf | 30 ++
3 files changed, 610 insertions(+)
diff --git a/storm-core/test/jvm/org/apache/storm/metric/MetricsIntegrationTest.java b/storm-core/test/jvm/org/apache/storm/metric/MetricsIntegrationTest.java
new file mode 100644
index 000000000..f7536eb8c
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/metric/MetricsIntegrationTest.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.metric;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.storm.Config;
+import org.apache.storm.LocalCluster;
+import org.apache.storm.Testing;
+import org.apache.storm.Thrift;
+import org.apache.storm.metric.api.CountMetric;
+import org.apache.storm.task.OutputCollector;
+import org.apache.storm.task.TopologyContext;
+import org.apache.storm.testing.FeederSpout;
+import org.apache.storm.topology.OutputFieldsDeclarer;
+import org.apache.storm.topology.base.BaseRichBolt;
+import org.apache.storm.tuple.Fields;
+import org.apache.storm.tuple.Tuple;
+import org.apache.storm.utils.Utils;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionTimeoutException;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Integration tests for custom metrics with FakeMetricConsumer.
+ *
+ * Ported from storm-core/test/clj/org/apache/storm/metrics_test.clj
+ */
+public class MetricsIntegrationTest {
+
+ /**
+ * Bolt that acks every tuple and increments a custom CountMetric.
+ */
+ static class CountAcksBolt extends BaseRichBolt {
+ private OutputCollector collector;
+ private CountMetric customMetric;
+
+ @Override
+ public void prepare(Map<String, Object> conf, TopologyContext context, OutputCollector collector) {
+ this.collector = collector;
+ this.customMetric = new CountMetric();
+ context.registerMetric("my-custom-metric", customMetric, 5);
+ }
+
+ @Override
+ public void execute(Tuple tuple) {
+ customMetric.incr();
+ collector.ack(tuple);
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ }
+ }
+
+ private static Map<String, Object> metricsConf() {
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.TOPOLOGY_METRICS_CONSUMER_REGISTER,
+ List.of(Map.of("class", "org.apache.storm.metric.FakeMetricConsumer")));
+ conf.put("storm.zookeeper.connection.timeout", 30000);
+ conf.put("storm.zookeeper.session.timeout", 60000);
+ return conf;
+ }
+
+ private static void waitForAtLeastNBuckets(int n, String compId, String metricName,
+ LocalCluster cluster) throws Exception {
+ Testing.whileTimeout(Testing.TEST_TIMEOUT_MS,
+ () -> {
+ Map<Integer, Collection<Object>> taskIdToBuckets =
+ FakeMetricConsumer.getTaskIdToBuckets(compId, metricName);
+ if (n != 0 && taskIdToBuckets == null) {
+ return true;
+ }
+ if (taskIdToBuckets == null) {
+ return false;
+ }
+ for (Collection<Object> buckets : taskIdToBuckets.values()) {
+ if (buckets.size() < n) {
+ return true;
+ }
+ }
+ return false;
+ },
+ () -> {
+ try {
+ cluster.advanceClusterTime(1);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ });
+ }
+
+ private static List<Object> lookupBuckets(String compId, String metricName) {
+ Map<Integer, Collection<Object>> taskIdToBuckets =
+ FakeMetricConsumer.getTaskIdToBuckets(compId, metricName);
+ if (taskIdToBuckets == null || taskIdToBuckets.isEmpty()) {
+ return List.of();
+ }
+ Collection<Object> buckets = taskIdToBuckets.values().iterator().next();
+ return List.copyOf(buckets);
+ }
+
+ private static void assertMetricRunningSum(String compId, String metricName,
+ long expected, int minBuckets,
+ LocalCluster cluster) throws Exception {
+ waitForAtLeastNBuckets(minBuckets, compId, metricName, cluster);
+ try {
+ Awaitility.with()
+ .pollInterval(10, TimeUnit.MILLISECONDS)
+ .conditionEvaluationListener(condition -> {
+ try {
+ cluster.advanceClusterTime(1);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ })
+ .atMost(Testing.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS)
+ .until((Callable<Long>) () -> {
+ List<Object> buckets = lookupBuckets(compId, metricName);
+ long sum = 0;
+ for (Object b : buckets) {
+ sum += ((Number) b).longValue();
+ }
+ return sum;
+ }, CoreMatchers.equalTo(expected));
+ } catch (ConditionTimeoutException e) {
+ throw new AssertionError(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCustomMetric() throws Exception {
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withSimulatedTime()
+ .withDaemonConf(metricsConf())
+ .build()) {
+
+ FeederSpout feeder = new FeederSpout(new Fields("field1"));
+ var topology = Thrift.buildTopology(
+ Map.of("1", Thrift.prepareSpoutDetails(feeder)),
+ Map.of("2", Thrift.prepareBoltDetails(
+ Map.of(Utils.getGlobalStreamId("1", null), Thrift.prepareGlobalGrouping()),
+ new CountAcksBolt())));
+
+ cluster.submitTopology("metrics-tester", Map.of(), topology);
+
+ feeder.feed(List.of("a"), 1);
+ cluster.advanceClusterTime(6);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 1, cluster);
+
+ cluster.advanceClusterTime(5);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 2, cluster);
+
+ cluster.advanceClusterTime(20);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 6, cluster);
+
+ feeder.feed(List.of("b"), 2);
+ feeder.feed(List.of("c"), 3);
+ cluster.advanceClusterTime(5);
+ assertMetricRunningSum("2", "my-custom-metric", 3, 7, cluster);
+ }
+ }
+
+ @Test
+ public void testCustomMetricWithMultiTasks() throws Exception {
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withSimulatedTime()
+ .withDaemonConf(metricsConf())
+ .build()) {
+
+ FeederSpout feeder = new FeederSpout(new Fields("field1"));
+ Map<String, Object> boltConf = new HashMap<>();
+ boltConf.put(Config.TOPOLOGY_TASKS, 2);
+
+ var topology = Thrift.buildTopology(
+ Map.of("1", Thrift.prepareSpoutDetails(feeder)),
+ Map.of("2", Thrift.prepareBoltDetails(
+ Map.of(Utils.getGlobalStreamId("1", null), Thrift.prepareAllGrouping()),
+ new CountAcksBolt(), 1, boltConf)));
+
+ cluster.submitTopology("metrics-tester-with-multitasks", Map.of(), topology);
+
+ feeder.feed(List.of("a"), 1);
+ cluster.advanceClusterTime(6);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 1, cluster);
+
+ cluster.advanceClusterTime(5);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 2, cluster);
+
+ cluster.advanceClusterTime(20);
+ assertMetricRunningSum("2", "my-custom-metric", 1, 6, cluster);
+
+ feeder.feed(List.of("b"), 2);
+ feeder.feed(List.of("c"), 3);
+ cluster.advanceClusterTime(5);
+ assertMetricRunningSum("2", "my-custom-metric", 3, 7, cluster);
+ }
+ }
+}
diff --git a/storm-server/src/test/java/org/apache/storm/security/auth/NimbusAuthTest.java b/storm-server/src/test/java/org/apache/storm/security/auth/NimbusAuthTest.java
new file mode 100644
index 000000000..f8826c694
--- /dev/null
+++ b/storm-server/src/test/java/org/apache/storm/security/auth/NimbusAuthTest.java
@@ -0,0 +1,357 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.security.auth;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.LocalCluster;
+import org.apache.storm.blobstore.BlobStore;
+import org.apache.storm.cluster.IStormClusterState;
+import org.apache.storm.daemon.nimbus.TopoCache;
+import org.apache.storm.generated.AuthorizationException;
+import org.apache.storm.generated.KillOptions;
+import org.apache.storm.generated.Nimbus;
+import org.apache.storm.generated.NotAliveException;
+import org.apache.storm.generated.SubmitOptions;
+import org.apache.storm.generated.TopologyInitialStatus;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.NimbusClient;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Tests for Nimbus authentication and authorization with various transport plugins.
+ *
+ * Ported from storm-core/test/clj/org/apache/storm/security/auth/nimbus_auth_test.clj
+ */
+public class NimbusAuthTest {
+
+ private static final int NIMBUS_TIMEOUT = 3000;
+ private static final String JAAS_CONF = jaasConfPath();
+
+ private static String jaasConfPath() {
+ java.net.URL url = NimbusAuthTest.class.getResource("/org/apache/storm/security/auth/jaas_digest.conf");
+ if (url == null) {
+ throw new RuntimeException("jaas_digest.conf not found on classpath");
+ }
+ return url.getPath();
+ }
+
+ /**
+ * Checks if the given exception or any of its causes is an instance of the expected class.
+ */
+ private static boolean hasCause(Throwable t, Class<? extends Throwable> expected) {
+ Throwable current = t;
+ while (current != null) {
+ if (expected.isInstance(current)) {
+ return true;
+ }
+ current = current.getCause();
+ }
+ return false;
+ }
+
+ @FunctionalInterface
+ private interface ThrowingRunnable {
+ void run() throws Exception;
+ }
+
+ private static void assertThrowsCause(Class<? extends Throwable> expectedCause,
+ ThrowingRunnable action) {
+ try {
+ action.run();
+ fail("Expected exception with cause " + expectedCause.getSimpleName() + " but no exception was thrown");
+ } catch (Exception e) {
+ assertTrue(hasCause(e, expectedCause),
+ "Expected cause " + expectedCause.getSimpleName() + " but got: " + e);
+ }
+ }
+
+ @Test
+ public void testSimpleAuthentication() throws Exception {
+ Map<String, Object> clusterConf = new HashMap<>();
+ clusterConf.put(DaemonConfig.NIMBUS_AUTHORIZER, null);
+ clusterConf.put(DaemonConfig.SUPERVISOR_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.NoopAuthorizer");
+ clusterConf.put(Config.NIMBUS_THRIFT_PORT, 0);
+ clusterConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withNimbusDaemon()
+ .withDaemonConf(clusterConf)
+ .withSupervisors(0)
+ .withPortsPerSupervisor(0)
+ .build()) {
+
+ Map<String, Object> clientConf = new HashMap<>(ConfigUtils.readStormConfig());
+ clientConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+ clientConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+
+ try (NimbusClient client = new NimbusClient(clientConf, "localhost",
+ cluster.getThriftServerPort(), NIMBUS_TIMEOUT)) {
+ Nimbus.Iface nimbusClient = client.getClient();
+ assertThrowsCause(NotAliveException.class, () -> nimbusClient.activate("topo-name"));
+ }
+ }
+ }
+
+ @Test
+ public void testNoopAuthorizationWithSimpleTransport() throws Exception {
+ IStormClusterState clusterState = Mockito.mock(IStormClusterState.class);
+ BlobStore blobStore = Mockito.mock(BlobStore.class);
+ TopoCache tc = Mockito.mock(TopoCache.class);
+ String topoName = "topo-name";
+
+ Mockito.when(clusterState.getTopoId(topoName)).thenReturn(Optional.empty());
+
+ Map<String, Object> clusterConf = new HashMap<>();
+ clusterConf.put(DaemonConfig.NIMBUS_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.NoopAuthorizer");
+ clusterConf.put(DaemonConfig.SUPERVISOR_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.NoopAuthorizer");
+ clusterConf.put(Config.NIMBUS_THRIFT_PORT, 0);
+ clusterConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withClusterState(clusterState)
+ .withBlobStore(blobStore)
+ .withTopoCache(tc)
+ .withNimbusDaemon()
+ .withDaemonConf(clusterConf)
+ .build()) {
+
+ Map<String, Object> clientConf = new HashMap<>(ConfigUtils.readStormConfig());
+ clientConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+ clientConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+
+ try (NimbusClient client = new NimbusClient(clientConf, "localhost",
+ cluster.getThriftServerPort(), NIMBUS_TIMEOUT)) {
+ Nimbus.Iface nimbusClient = client.getClient();
+ assertThrowsCause(NotAliveException.class, () -> nimbusClient.activate(topoName));
+ }
+ }
+ }
+
+ @Test
+ public void testDenyAuthorizationWithSimpleTransport() throws Exception {
+ IStormClusterState clusterState = Mockito.mock(IStormClusterState.class);
+ BlobStore blobStore = Mockito.mock(BlobStore.class);
+ TopoCache tc = Mockito.mock(TopoCache.class);
+ String topoName = "topo-name";
+ String topoId = "topo-name-1";
+
+ Mockito.when(clusterState.getTopoId(topoName)).thenReturn(Optional.of(topoId));
+ Mockito.when(tc.readTopoConf(Mockito.any(String.class), ArgumentMatchers.any()))
+ .thenReturn(Map.of());
+
+ Map<String, Object> clusterConf = new HashMap<>();
+ clusterConf.put(DaemonConfig.NIMBUS_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.DenyAuthorizer");
+ clusterConf.put(DaemonConfig.SUPERVISOR_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.DenyAuthorizer");
+ clusterConf.put(Config.NIMBUS_THRIFT_PORT, 0);
+ clusterConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withClusterState(clusterState)
+ .withBlobStore(blobStore)
+ .withTopoCache(tc)
+ .withNimbusDaemon()
+ .withDaemonConf(clusterConf)
+ .build()) {
+
+ Map<String, Object> clientConf = new HashMap<>(ConfigUtils.readStormConfig());
+ clientConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.SimpleTransportPlugin");
+ clientConf.put(Config.NIMBUS_THRIFT_PORT, cluster.getThriftServerPort());
+ clientConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+
+ try (NimbusClient client = new NimbusClient(clientConf, "localhost",
+ cluster.getThriftServerPort(), NIMBUS_TIMEOUT)) {
+ Nimbus.Iface nimbusClient = client.getClient();
+ SubmitOptions submitOptions = new SubmitOptions(TopologyInitialStatus.findByValue(2));
+
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.submitTopology(topoName, null, null, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.submitTopologyWithOpts(topoName, null, null, null, submitOptions));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.beginFileUpload());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.uploadChunk(null, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.finishFileUpload(null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.downloadChunk(null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getNimbusConf());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getClusterInfo());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.killTopology(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.killTopologyWithOpts(topoName, new KillOptions()));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.activate(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.deactivate(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.rebalance(topoName, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopologyConf(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopology(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getUserTopology(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopologyInfo(topoId));
+ }
+ }
+ }
+
+ @Test
+ public void testNoopAuthorizationWithSaslDigest() throws Exception {
+ Map<String, Object> clusterConf = new HashMap<>();
+ clusterConf.put(DaemonConfig.NIMBUS_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.NoopAuthorizer");
+ clusterConf.put(DaemonConfig.SUPERVISOR_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.NoopAuthorizer");
+ clusterConf.put(Config.NIMBUS_THRIFT_PORT, 0);
+ clusterConf.put("java.security.auth.login.config",
+ JAAS_CONF);
+ clusterConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.digest.DigestSaslTransportPlugin");
+
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withNimbusDaemon()
+ .withDaemonConf(clusterConf)
+ .withSupervisors(0)
+ .withPortsPerSupervisor(0)
+ .build()) {
+
+ Map<String, Object> clientConf = new HashMap<>(ConfigUtils.readStormConfig());
+ clientConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.digest.DigestSaslTransportPlugin");
+ clientConf.put("java.security.auth.login.config",
+ JAAS_CONF);
+ clientConf.put(Config.NIMBUS_THRIFT_PORT, cluster.getThriftServerPort());
+ clientConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+
+ try (NimbusClient client = new NimbusClient(clientConf, "localhost",
+ cluster.getThriftServerPort(), NIMBUS_TIMEOUT)) {
+ Nimbus.Iface nimbusClient = client.getClient();
+ assertThrowsCause(NotAliveException.class, () -> nimbusClient.activate("topo-name"));
+ }
+ }
+ }
+
+ @Test
+ public void testDenyAuthorizationWithSaslDigest() throws Exception {
+ IStormClusterState clusterState = Mockito.mock(IStormClusterState.class);
+ BlobStore blobStore = Mockito.mock(BlobStore.class);
+ TopoCache tc = Mockito.mock(TopoCache.class);
+ String topoName = "topo-name";
+ String topoId = "topo-name-1";
+
+ Mockito.when(clusterState.getTopoId(topoName)).thenReturn(Optional.of(topoId));
+ Mockito.when(tc.readTopoConf(Mockito.any(String.class), ArgumentMatchers.any()))
+ .thenReturn(Map.of());
+
+ Map<String, Object> clusterConf = new HashMap<>();
+ clusterConf.put(DaemonConfig.NIMBUS_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.DenyAuthorizer");
+ clusterConf.put(DaemonConfig.SUPERVISOR_AUTHORIZER,
+ "org.apache.storm.security.auth.authorizer.DenyAuthorizer");
+ clusterConf.put(Config.NIMBUS_THRIFT_PORT, 0);
+ clusterConf.put("java.security.auth.login.config",
+ JAAS_CONF);
+ clusterConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.digest.DigestSaslTransportPlugin");
+
+ try (LocalCluster cluster = new LocalCluster.Builder()
+ .withClusterState(clusterState)
+ .withBlobStore(blobStore)
+ .withTopoCache(tc)
+ .withNimbusDaemon()
+ .withDaemonConf(clusterConf)
+ .build()) {
+
+ Map<String, Object> clientConf = new HashMap<>(ConfigUtils.readStormConfig());
+ clientConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN,
+ "org.apache.storm.security.auth.digest.DigestSaslTransportPlugin");
+ clientConf.put("java.security.auth.login.config",
+ JAAS_CONF);
+ clientConf.put(Config.NIMBUS_THRIFT_PORT, cluster.getThriftServerPort());
+ clientConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+
+ try (NimbusClient client = new NimbusClient(clientConf, "localhost",
+ cluster.getThriftServerPort(), NIMBUS_TIMEOUT)) {
+ Nimbus.Iface nimbusClient = client.getClient();
+ SubmitOptions submitOptions = new SubmitOptions(TopologyInitialStatus.findByValue(2));
+
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.submitTopology(topoName, null, null, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.submitTopologyWithOpts(topoName, null, null, null, submitOptions));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.beginFileUpload());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.uploadChunk(null, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.finishFileUpload(null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.downloadChunk(null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getNimbusConf());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getClusterInfo());
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.killTopology(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.killTopologyWithOpts(topoName, new KillOptions()));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.activate(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.deactivate(topoName));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.rebalance(topoName, null));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopologyConf(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopology(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getUserTopology(topoId));
+ assertThrowsCause(AuthorizationException.class,
+ () -> nimbusClient.getTopologyInfo(topoId));
+ }
+ }
+ }
+}
diff --git a/storm-server/src/test/resources/org/apache/storm/security/auth/jaas_digest.conf b/storm-server/src/test/resources/org/apache/storm/security/auth/jaas_digest.conf
new file mode 100644
index 000000000..2a6d618ff
--- /dev/null
+++ b/storm-server/src/test/resources/org/apache/storm/security/auth/jaas_digest.conf
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This sample file illustrates how Digest authentication should be configured
+*/
+StormServer {
+ org.apache.zookeeper.server.auth.DigestLoginModule required
+ user_super="adminsecret"
+ user_bob="bobsecret";
+};
+StormClient {
+ org.apache.zookeeper.server.auth.DigestLoginModule required
+ username="bob"
+ password="bobsecret";
+};
\ No newline at end of file