Skip to content
Browse files

update auth test to cleanup launched servers

  • Loading branch information...
1 parent d6374fe commit 61f08d681dead891621a1e4f465a33eb659b3297 @nathanmarz nathanmarz committed Mar 11, 2013
Showing with 93 additions and 87 deletions.
  1. +93 −87 test/clj/backtype/storm/security/auth/auth_test.clj
View
180 test/clj/backtype/storm/security/auth/auth_test.clj
@@ -113,103 +113,109 @@
server (ThriftServer. conf (Nimbus$Processor. service-handler) (int (conf NIMBUS-THRIFT-PORT)))]
(.addShutdownHook (Runtime/getRuntime) (Thread. (fn [] (.stop server))))
(.start (Thread. #(.serve server)))
- (wait-for-condition #(.isServing server))))
+ (wait-for-condition #(.isServing server))
+ server ))
+
+(defmacro with-server [args & body]
+ `(let [server# (launch-server ~@args)]
+ ~@body
+ (.stop server#)
+ ))
(deftest Simple-authentication-test
- (launch-server 6627 nil nil "backtype.storm.security.auth.SimpleTransportPlugin")
-
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
- client (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout)
- nimbus_client (.getClient client)]
- (.activate nimbus_client "security_auth_test_topology")
- (.close client))
-
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})]
- (testing "(Negative authentication) Server: Simple vs. Client: Digest"
- (is (thrown-cause? java.net.SocketTimeoutException
- (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout))))))
+ (with-server [6627 nil nil "backtype.storm.security.auth.SimpleTransportPlugin"]
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
+ client (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout)
+ nimbus_client (.getClient client)]
+ (.activate nimbus_client "security_auth_test_topology")
+ (.close client))
+
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})]
+ (testing "(Negative authentication) Server: Simple vs. Client: Digest"
+ (is (thrown-cause? java.net.SocketTimeoutException
+ (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout)))))))
(deftest positive-authorization-test
- (launch-server 6628 nil
- "backtype.storm.security.auth.authorizer.NoopAuthorizer"
- "backtype.storm.security.auth.SimpleTransportPlugin")
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
- client (NimbusClient. storm-conf "localhost" 6628 nimbus-timeout)
- nimbus_client (.getClient client)]
- (testing "(Positive authorization) Authorization plugin should accept client request"
- (.activate nimbus_client "security_auth_test_topology"))
- (.close client)))
+ (with-server [6627 nil
+ "backtype.storm.security.auth.authorizer.NoopAuthorizer"
+ "backtype.storm.security.auth.SimpleTransportPlugin"]
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
+ client (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout)
+ nimbus_client (.getClient client)]
+ (testing "(Positive authorization) Authorization plugin should accept client request"
+ (.activate nimbus_client "security_auth_test_topology"))
+ (.close client))))
(deftest deny-authorization-test
- (launch-server 6629 nil
- "backtype.storm.security.auth.authorizer.DenyAuthorizer"
- "backtype.storm.security.auth.SimpleTransportPlugin")
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"
- Config/NIMBUS_HOST "localhost"
- Config/NIMBUS_THRIFT_PORT 6629
- Config/NIMBUS_TASK_TIMEOUT_SECS nimbus-timeout})
- client (NimbusClient/getConfiguredClient storm-conf)
- nimbus_client (.getClient client)]
- (testing "(Negative authorization) Authorization plugin should reject client request"
- (is (thrown? TTransportException
- (.activate nimbus_client "security_auth_test_topology"))))
- (.close client)))
+ (with-server [6627 nil
+ "backtype.storm.security.auth.authorizer.DenyAuthorizer"
+ "backtype.storm.security.auth.SimpleTransportPlugin"]
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"
+ Config/NIMBUS_HOST "localhost"
+ Config/NIMBUS_THRIFT_PORT 6627
+ Config/NIMBUS_TASK_TIMEOUT_SECS nimbus-timeout})
+ client (NimbusClient/getConfiguredClient storm-conf)
+ nimbus_client (.getClient client)]
+ (testing "(Negative authorization) Authorization plugin should reject client request"
+ (is (thrown? TTransportException
+ (.activate nimbus_client "security_auth_test_topology"))))
+ (.close client))))
(deftest digest-authentication-test
- (launch-server 6630
- "test/clj/backtype/storm/security/auth/jaas_digest.conf"
- nil
- "backtype.storm.security.auth.digest.DigestSaslTransportPlugin")
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})
- client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
- nimbus_client (.getClient client)]
- (testing "(Positive authentication) valid digest authentication"
- (.activate nimbus_client "security_auth_test_topology"))
- (.close client))
-
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
- client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
- nimbus_client (.getClient client)]
- (testing "(Negative authentication) Server: Digest vs. Client: Simple"
- (is (thrown-cause? java.net.SocketTimeoutException
- (.activate nimbus_client "security_auth_test_topology"))))
- (.close client))
+ (with-server [6630
+ "test/clj/backtype/storm/security/auth/jaas_digest.conf"
+ nil
+ "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"]
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})
+ client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
+ nimbus_client (.getClient client)]
+ (testing "(Positive authentication) valid digest authentication"
+ (.activate nimbus_client "security_auth_test_topology"))
+ (.close client))
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_bad_password.conf"})]
- (testing "(Negative authentication) Invalid password"
- (is (thrown? TTransportException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.SimpleTransportPlugin"})
+ client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
+ nimbus_client (.getClient client)]
+ (testing "(Negative authentication) Server: Digest vs. Client: Simple"
+ (is (thrown-cause? java.net.SocketTimeoutException
+ (.activate nimbus_client "security_auth_test_topology"))))
+ (.close client))
+
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_bad_password.conf"})]
+ (testing "(Negative authentication) Invalid password"
+ (is (thrown? TTransportException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
+
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_unknown_user.conf"})]
+ (testing "(Negative authentication) Unknown user"
+ (is (thrown? TTransportException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
+
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/nonexistent.conf"})]
+ (testing "(Negative authentication) nonexistent configuration file"
+ (is (thrown? RuntimeException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_unknown_user.conf"})]
- (testing "(Negative authentication) Unknown user"
- (is (thrown? TTransportException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
-
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/nonexistent.conf"})]
- (testing "(Negative authentication) nonexistent configuration file"
- (is (thrown? RuntimeException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
-
- (let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_missing_client.conf"})]
- (testing "(Negative authentication) Missing client"
- (is (thrown-cause? java.io.IOException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout))))))
+ (let [storm-conf (merge (read-storm-config)
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_missing_client.conf"})]
+ (testing "(Negative authentication) Missing client"
+ (is (thrown-cause? java.io.IOException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))))
(deftest test-GetTransportPlugin-throws-RuntimeException

0 comments on commit 61f08d6

Please sign in to comment.
Something went wrong with that request. Please try again.