Skip to content

Commit fc1e930

Browse files
authored
SQL-163 localhost-friendly CORS defaults (#268)
* SQL-163 allow CORS from localhost by default * SQL-163 update tests to use localhost
1 parent c6494cf commit fc1e930

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main/lrsql/system/webserver.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
;; default ports
6666
allowed-list
6767
(or allowed-origins
68-
(cond-> [(format "http://%s:%s" http-host http-port)
68+
(cond-> [(format "http://localhost:%s" http-port)
69+
(format "https://localhost:%s" ssl-port)
70+
(format "http://%s:%s" http-host http-port)
6971
(format "https://%s:%s" http-host ssl-port)]
7072
(= http-port 80) (conj (format "http://%s" http-host))
7173
(= ssl-port 443) (conj (format "https://%s" http-host))))]

src/test/lrsql/admin/cors_test.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
(defn- login-account
2525
[headers body]
26-
(curl/post "http://0.0.0.0:8080/admin/account/login"
26+
(curl/post "http://localhost:8080/admin/account/login"
2727
{:headers headers
2828
:body body}))
2929

3030
(defn- create-account
3131
[headers body]
32-
(curl/post "http://0.0.0.0:8080/admin/account/create"
32+
(curl/post "http://localhost:8080/admin/account/create"
3333
{:headers headers
3434
:body body}))
3535

@@ -72,7 +72,7 @@
7272
(is-err-code (create-account bad-cors-headers req-body) 403)))
7373
(testing "create account with default CORS check success"
7474
(let [good-cors-headers
75-
(merge headers {"Origin" "http://0.0.0.0:8080"})
75+
(merge headers {"Origin" "http://localhost:8080"})
7676
{:keys [status body]}
7777
(create-account good-cors-headers req-body)
7878
edn-body (u/parse-json body)]
@@ -106,7 +106,7 @@
106106
(is (some? seed-jwt)))
107107
(testing "create account with custom CORS check failure"
108108
(let [bad-cors-headers
109-
(merge headers {"Origin" "http://0.0.0.0:8080"})]
109+
(merge headers {"Origin" "http://localhost:8080"})]
110110
(is-err-code (create-account bad-cors-headers req-body) 403)))
111111
(testing "create account with custom CORS check success"
112112
(let [good-cors-headers

0 commit comments

Comments
 (0)