Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL-163 localhost-friendly CORS defaults #268

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/lrsql/system/webserver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
;; default ports
allowed-list
(or allowed-origins
(cond-> [(format "http://%s:%s" http-host http-port)
(cond-> [(format "http://localhost:%s" http-port)
(format "https://localhost:%s" ssl-port)
kelvinqian00 marked this conversation as resolved.
Show resolved Hide resolved
(format "http://%s:%s" http-host http-port)
(format "https://%s:%s" http-host ssl-port)]
(= http-port 80) (conj (format "http://%s" http-host))
(= ssl-port 443) (conj (format "https://%s" http-host))))]
Expand Down
8 changes: 4 additions & 4 deletions src/test/lrsql/admin/cors_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

(defn- login-account
[headers body]
(curl/post "http://0.0.0.0:8080/admin/account/login"
(curl/post "http://localhost:8080/admin/account/login"
{:headers headers
:body body}))

(defn- create-account
[headers body]
(curl/post "http://0.0.0.0:8080/admin/account/create"
(curl/post "http://localhost:8080/admin/account/create"
{:headers headers
:body body}))

Expand Down Expand Up @@ -72,7 +72,7 @@
(is-err-code (create-account bad-cors-headers req-body) 403)))
(testing "create account with default CORS check success"
(let [good-cors-headers
(merge headers {"Origin" "http://0.0.0.0:8080"})
(merge headers {"Origin" "http://localhost:8080"})
kelvinqian00 marked this conversation as resolved.
Show resolved Hide resolved
{:keys [status body]}
(create-account good-cors-headers req-body)
edn-body (u/parse-json body)]
Expand Down Expand Up @@ -106,7 +106,7 @@
(is (some? seed-jwt)))
(testing "create account with custom CORS check failure"
(let [bad-cors-headers
(merge headers {"Origin" "http://0.0.0.0:8080"})]
(merge headers {"Origin" "http://localhost:8080"})]
(is-err-code (create-account bad-cors-headers req-body) 403)))
(testing "create account with custom CORS check success"
(let [good-cors-headers
Expand Down