You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by et...@apache.org on 2020/04/13 14:57:03 UTC
[storm] branch master updated: [STORM-1304] port
storm.submitter-test to java (#3234)
This is an automated email from the ASF dual-hosted git repository.
ethanli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git
The following commit(s) were added to refs/heads/master by this push:
new c122876 [STORM-1304] port storm.submitter-test to java (#3234)
c122876 is described below
commit c122876f1518f5e737ca0ea831e8c853af8d6a79
Author: nd368 <na...@hotmail.co.uk>
AuthorDate: Mon Apr 13 15:56:54 2020 +0100
[STORM-1304] port storm.submitter-test to java (#3234)
---
.../test/clj/org/apache/storm/submitter_test.clj | 75 ---------------
.../test/jvm/org/apache/storm/SubmitterTest.java | 107 +++++++++++++++++++++
2 files changed, 107 insertions(+), 75 deletions(-)
diff --git a/storm-core/test/clj/org/apache/storm/submitter_test.clj b/storm-core/test/clj/org/apache/storm/submitter_test.clj
deleted file mode 100644
index 7bdeb08..0000000
--- a/storm-core/test/clj/org/apache/storm/submitter_test.clj
+++ /dev/null
@@ -1,75 +0,0 @@
-;; 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.
-(ns org.apache.storm.submitter-test
- (:use [clojure test])
- (:use [org.apache.storm config])
- (:import [org.apache.storm StormSubmitter])
- )
-
-(deftest test-md5-digest-secret-generation
- (testing "No payload or scheme are generated when already present"
- (let [conf {STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD "foobar:12345"
- STORM-ZOOKEEPER-AUTH-SCHEME "anything"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (= "foobar:12345" actual-payload))
- (is (= "digest" actual-scheme))))
-
- (testing "Scheme is set to digest if not already."
- (let [conf {STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD "foobar:12345"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (= "foobar:12345" actual-payload))
- (is (= "digest" actual-scheme))))
-
- (testing "A payload is generated when no payload is present."
- (let [conf {STORM-ZOOKEEPER-AUTH-SCHEME "anything"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (not (clojure.string/blank? actual-payload)))
- (is (= "digest" actual-scheme))))
-
- (testing "A payload is generated when payload is not correctly formatted."
- (let [bogus-payload "not-a-valid-payload"
- conf {STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD bogus-payload
- STORM-ZOOKEEPER-AUTH-SCHEME "anything"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (not (StormSubmitter/validateZKDigestPayload bogus-payload))) ; Is this test correct?
- (is (not (clojure.string/blank? actual-payload)))
- (is (= "digest" actual-scheme))))
-
- (testing "A payload is generated when payload is null."
- (let [conf {STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD nil
- STORM-ZOOKEEPER-AUTH-SCHEME "anything"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (not (clojure.string/blank? actual-payload)))
- (is (= "digest" actual-scheme))))
-
- (testing "A payload is generated when payload is blank."
- (let [conf {STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD ""
- STORM-ZOOKEEPER-AUTH-SCHEME "anything"}
- result (StormSubmitter/prepareZookeeperAuthentication conf)
- actual-payload (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-PAYLOAD)
- actual-scheme (.get result STORM-ZOOKEEPER-TOPOLOGY-AUTH-SCHEME)]
- (is (not (clojure.string/blank? actual-payload)))
- (is (= "digest" actual-scheme)))))
diff --git a/storm-core/test/jvm/org/apache/storm/SubmitterTest.java b/storm-core/test/jvm/org/apache/storm/SubmitterTest.java
new file mode 100644
index 0000000..cd90381
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/SubmitterTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2018 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class SubmitterTest {
+
+ @Test
+ public void testMd5DigestSecretGeneration01() {
+ // No payload or scheme are generated when already present
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD, "foobar:12345");
+ conf.put(Config.STORM_ZOOKEEPER_AUTH_SCHEME, "anything");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertEquals("foobar:12345", actualPayload);
+ assertEquals("digest", actualScheme);
+ }
+
+ @Test
+ public void testMd5DigestSecretGeneration02() {
+ // Scheme is set to digest if not already.
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD, "foobar:12345");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertEquals("foobar:12345", actualPayload);
+ assertEquals("digest", actualScheme);
+ }
+
+ @Test
+ public void testMd5DigestSecretGeneration03() {
+ // A payload is generated when no payload is present.
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_AUTH_SCHEME, "anything");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertFalse(StringUtils.isBlank((String)actualPayload));
+ assertEquals("digest", actualScheme);
+ }
+
+ @Test
+ public void testMd5DigestSecretGeneration04() {
+ // A payload is generated when payload is not correctly formatted.
+ String bogusPayload = "not-a-valid-payload";
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD, bogusPayload);
+ conf.put(Config.STORM_ZOOKEEPER_AUTH_SCHEME, "anything");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertFalse(StormSubmitter.validateZKDigestPayload(bogusPayload));
+ assertFalse(StringUtils.isBlank((String)actualPayload));
+ assertEquals("digest", actualScheme);
+ }
+
+ @Test
+ public void testMd5DigestSecretGeneration05() {
+ // A payload is generated when payload is null.
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD, null);
+ conf.put(Config.STORM_ZOOKEEPER_AUTH_SCHEME, "anything");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertFalse(StringUtils.isBlank((String)actualPayload));
+ assertEquals("digest", actualScheme);
+ }
+
+ @Test
+ public void testMd5DigestSecretGeneration06() {
+ // A payload is generated when payload is blank.
+ Map<String, Object> conf = new HashMap<>();
+ conf.put(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD, "");
+ conf.put(Config.STORM_ZOOKEEPER_AUTH_SCHEME, "anything");
+ Map<String, Object> result = StormSubmitter.prepareZookeeperAuthentication(conf);
+ Object actualPayload = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD);
+ Object actualScheme = result.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME);
+ assertFalse(StringUtils.isBlank((String)actualPayload));
+ assertEquals("digest", actualScheme);
+ }
+}