Skip to content

Commit

Permalink
Add test for setting credentials via environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruedigergad committed Nov 2, 2024
1 parent ba54bf4 commit 37ee55a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@
:test
{:dependencies [[criterium "0.4.6"]]
:test-paths ["test" "benchmark"]}}
:plugins [[lein-cloverage "1.2.4"] [test2junit "1.4.2"] [lein-html5-docs "3.0.3"]]
:plugins [[lein-cloverage "1.2.4"] [lein-with-env-vars "0.2.0"] [test2junit "1.4.2"] [lein-html5-docs "3.0.3"]]
; Explicitly forcing TLSv1.2, for now, because of: https://bugs.openjdk.java.net/browse/JDK-8211426
;:jvm-opts ["-Dorg.slf4j.simpleLogger.defaultLogLevel=trace"]
;:jvm-opts ["-Djavax.net.debug=all" "-Djdk.tls.server.protocols=TLSv1.2" "-Djdk.tls.client.protocols=TLSv1.2"]
;:jvm-opts ["-Djavax.net.debug=all"]
:jvm-opts ["--add-opens" "java.base/sun.security.tools.keytool=ALL-UNNAMED"]
:env-vars {:BOWERICK_ADMIN_PASS "test_admin_pass"
:BOWERICK_WRITE_PASS "test_write_pass"
:BOWERICK_READ_PASS "test_read_pass"}
:hooks [leiningen.with-env-vars/auto-inject]
)
56 changes: 56 additions & 0 deletions test/bowerick/test/client_cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,62 @@
(println "Checking file exists:" f)
(test/is (.exists (io/file f))))))

(test/deftest simple-send-receive-with-cli-broker-with-permissions-test
(let [started-string "Broker started."
started-flag (utils/prepare-flag)
stopped-string "Broker stopped."
stopped-flag (utils/prepare-flag)
stop-wrtr (PipedWriter.)
stop-rdr (PipedReader. stop-wrtr)
main-thread (Thread. #(utils/with-out-str-cb
(fn [s]
(when (.contains s started-string)
(utils/println-err "Test broker started.")
(utils/set-flag started-flag))
(when (.contains s stopped-string)
(utils/println-err "Test broker stopped.")
(utils/set-flag stopped-flag)))
(binding [*in* (io/reader stop-rdr)]
(main/run-cli-app "-e" "-u" (str "\"" local-cli-jms-server "\"")))))
_ (.setDaemon main-thread true)
_ (.start main-thread)
_ (println "Waiting for test broker to start up...")
_ (utils/await-flag started-flag)
; When configuring permissions, the broker grants itself admin access.
; For the test, we need to unset this after the broker had startet because the client would also see
; the admin credentials the broker had configured for itself as they both run in the same JVM.
; So, for doing a realistic test, we need to unset the credentials to mimic a real case for which the client has not credentials.
_ (alter-var-root #'bowerick.jms/*user-name* (fn [_ x] x) nil)
_ (alter-var-root #'bowerick.jms/*user-password* (fn [_ x] x) nil)
test-cmd-input [
; Need to use admin credentials here because creating a topic requires admin privileges.
"set-user-name admin"
"set-user-password test_admin_pass"
(str "receive " local-cli-jms-server ":" test-topic)
(str "send " local-cli-jms-server ":" test-topic " \"test-data\"")
"_sleep 500"]
out-string (cli-tests/test-cli-stdout #(main/run-cli-app "-c" "-o") test-cmd-input)]
(test/is
(=
(cli-tests/expected-string
["\"admin\""
"\"test_admin_pass\""
(str "Set up consumer for: " local-cli-jms-server ":" test-topic)
(str "Sending: " local-cli-jms-server ":" test-topic " <-")
"\"test-data\""
(str "Received: " local-cli-jms-server ":" test-topic " ->")
"\"test-data\""
"Closing bowerick.jms.ProducerWrapper for tcp://127.0.0.1:53847:/topic/testtopic.foo ..."
"Closing bowerick.jms.ConsumerWrapper for tcp://127.0.0.1:53847:/topic/testtopic.foo ..."])
out-string))
(println "Stopping test broker...")
(.write stop-wrtr "q\r")
(println "Waiting for test broker to stop...")
(utils/await-flag stopped-flag)
; Reset credentials to default.
(alter-var-root #'bowerick.jms/*user-name* (fn [_ x] x) nil)
(alter-var-root #'bowerick.jms/*user-password* (fn [_ x] x) nil)))

(test/deftest simple-cli-broker-aframe-test
(let [started-string "Broker started."
started-flag (utils/prepare-flag)
Expand Down

0 comments on commit 37ee55a

Please sign in to comment.