Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix tests

  • Loading branch information...
commit f8e43ef21938e398b01b42dc8af87fa6d4cf401d 1 parent 487bb96
@lancepantz lancepantz authored
Showing with 25 additions and 40 deletions.
  1. +25 −40 test/ring/middleware/test/cors.clj
View
65 test/ring/middleware/test/cors.clj
@@ -2,46 +2,31 @@
(:use ring.middleware.cors
clojure.test))
-(comment
- (deftest test-allow-request?
- (testing "with empty vector"
- (is (not (allow-request? {:headers {"origin" "http://eample.com"}} {:access-control-allow-origin []}))))
- (testing "with one regular expressions"
- (are [origin expected]
- (is (= expected (allow-request? {:headers {"origin" origin}} {:access-control-allow-origin #"http://(.*\.)?burningswell.com"})))
- nil false
- "" false
- "http://example.com" false
- "http://burningswell.com" true))
- (testing "with multiple regular expressions"
- (are [origin expected]
- (is (= expected (allow-request? {:headers {"origin" origin}} {:access-control-allow-origin [#"http://(.*\.)?burningswell.com" #"http://example.com"]})))
- nil false
- "" false
- "http://example.com" true
- "http://burningswell.com" true
- "http://api.burningswell.com" true
- "http://dev.burningswell.com" true)))
-
- (deftest test-header-name
- (are [header expected]
- (is (= expected (header-name header)))
- nil nil
- :access-control-allow-origin "Access-Control-Allow-Origin"
- "Access-Control-Allow-Origin" "Access-Control-Allow-Origin"))
-
- (deftest test-normalize-headers
- (are [headers expected]
- (is (= expected (normalize-headers headers)))
- nil {}
- {:access-control-allow-origin "*"} {"Access-Control-Allow-Origin" "*"}
- {"Access-Control-Allow-Origin" "*"} {"Access-Control-Allow-Origin" "*"}))
-
- (deftest test-add-access-control
- (let [origin "http://example.com"]
- (is (= {} (add-access-control {} {} {})))
- (is (= {:headers {"Access-Control-Allow-Origin" "http://example.com"}}
- (add-access-control {:headers {"origin" origin}} {} {:access-control-allow-origin #".*\.example.com"}))))))
+(deftest test-allow-request?
+ (testing "with empty vector"
+ (is (not (allow-request? {:headers {"origin" "http://eample.com"}} {:access-control-allow-origin []}))))
+ (testing "with one regular expressions"
+ (are [origin expected]
+ (is (= expected (allow-request? {:headers {"origin" origin}
+ :request-method :get}
+ {:access-control-allow-origin [#"http://(.*\.)?burningswell.com"]
+ :access-control-allow-methods #{:get :put :post}})))
+ nil false
+ "" false
+ "http://example.com" false
+ "http://burningswell.com" true))
+ (testing "with multiple regular expressions"
+ (are [origin expected]
+ (is (= expected (allow-request? {:headers {"origin" origin}
+ :request-method :get}
+ {:access-control-allow-origin [#"http://(.*\.)?burningswell.com" #"http://example.com"]
+ :access-control-allow-methods #{:get :put :post}})))
+ nil false
+ "" false
+ "http://example.com" true
+ "http://burningswell.com" true
+ "http://api.burningswell.com" true
+ "http://dev.burningswell.com" true)))
(defn handler [request]
((wrap-cors (fn [_] {})
Please sign in to comment.
Something went wrong with that request. Please try again.