Skip to content

Commit ef3bc75

Browse files
committed
Add tests for x-header response functions
1 parent eadd493 commit ef3bc75

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/ring/middleware/x_headers_test.clj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
(let [handler (wrap-frame-options (constantly nil) :deny)]
4242
(is (nil? (handler (request :get "/"))))))))
4343

44+
(deftest test-frame-options-response
45+
(testing "deny"
46+
(is (= (frame-options-response (response "hello") :deny)
47+
{:status 200, :headers {"X-Frame-Options" "DENY"}, :body "hello"})))
48+
49+
(testing "nil response"
50+
(is (nil? (frame-options-response nil :deny)))))
51+
4452
(deftest test-wrap-frame-options-cps
4553
(testing "deny"
4654
(let [handler (-> (fn [_ respond _] (respond (response "hello")))
@@ -77,6 +85,19 @@
7785
(let [handler (wrap-content-type-options (constantly nil) :nosniff)]
7886
(is (nil? (handler (request :get "/"))))))))
7987

88+
(deftest test-content-type-options-response
89+
(testing "nosniff"
90+
(is (= (content-type-options-response
91+
(-> (response "hello") (content-type "text/plain"))
92+
:nosniff)
93+
{:status 200
94+
:headers {"X-Content-Type-Options" "nosniff"
95+
"Content-Type" "text/plain"}
96+
:body "hello"})))
97+
98+
(testing "nil response"
99+
(is (nil? (content-type-options-response nil :nosniff)))))
100+
80101
(deftest test-wrap-content-type-options-cps
81102
(testing "nosniff"
82103
(let [handler (-> (fn [_ respond _]
@@ -131,6 +152,14 @@
131152
(let [handler (wrap-xss-protection (constantly nil) true)]
132153
(is (nil? (handler (request :get "/"))))))))
133154

155+
(deftest test-xss-protection-response
156+
(testing "enable"
157+
(is (= (xss-protection-response (response "hello") :deny)
158+
{:status 200, :headers {"X-XSS-Protection" "1"}, :body "hello"})))
159+
160+
(testing "nil response"
161+
(is (nil? (frame-options-response nil :deny)))))
162+
134163
(deftest test-wrap-xss-protection-cps
135164
(testing "nosniff"
136165
(let [handler (-> (fn [_ respond _] (respond (response "hello")))

0 commit comments

Comments
 (0)