Skip to content

Commit

Permalink
Fix parsing of legacy --allowed-origins option
Browse files Browse the repository at this point in the history
  • Loading branch information
wardle committed Jan 15, 2023
1 parent a064c18 commit 2acb3fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/com/eldrix/hermes/cmd/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
(if (str/blank? (:allowed-origins options))
parsed
(-> parsed
(update :options disj :allowed-origins)
(update :options dissoc :allowed-origins)
(update-in [:options :allowed-origin] #(apply conj % (str/split (:allowed-origins options) #","))))))

(defn parse-cli
Expand Down
19 changes: 14 additions & 5 deletions test/com/eldrix/hermes/cmd_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,39 @@
(is (= cmd "index"))
(is (= (:db options) "snomed.db"))
(is (= (:locale options) "en-GB,en-US")))}
{:s "Test status with missing database"
{:s "Test status with missing database"
:args ["status"]
:test (fn [{:keys [errors]}]
(is (seq errors)))}
{:s "Test status "
{:s "Test status "
:args ["status" "--db" "snomed.db"]
:test (fn [{:keys [cmd options errors]}]
(is (nil? errors))
(is (= cmd "status"))
(is (= (:db options) "snomed.db")))}
{:s "Run a server"
{:s "Run a server"
:args (str/split "--db snomed.db --port 8090 serve" #" ")
:test (fn [{:keys [cmd options errors]}]
(is (nil? errors))
(is (= "serve" cmd))
(is (= (:db options) "snomed.db"))
(is (= (:port options) 8090)))}])
(is (= (:port options) 8090)))}
{:s "Avoid extraneous options being included"
:args ["serve"]
:test (fn [{:keys [options]}]
(is (not (contains? options :dist)) "parse-cli mistakenly included :dist options key when not provided"))}])

(deftest test-parse-cli-options
(doseq [{:keys [s args test]} cli-tests]
(testing s
(test (cli/parse-cli args)))))


(deftest test-allowed-origins
(is (= (cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origins" "example.com,example.net"])
(cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origin" "example.com" "--allowed-origin" "example.net"])
(cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origins=example.com,example.net"])
(cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origin=example.com" "--allowed-origin=example.net"]))
"--allowed-origin and --allowed-origins are not parsed to be be equivalent"))

(comment
(cli/parse-cli ["download" "uk.nhs/sct-clinical" "api-key" "api-key.txt" "cache-dir" "/var/tmp"]))

0 comments on commit 2acb3fd

Please sign in to comment.