forked from bostonaholic/ring-okta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_test.clj
28 lines (23 loc) · 1.2 KB
/
session_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns ring.ring-okta.session-test
(:require [clojure.test :refer [deftest testing is]]
[ring.ring-okta.saml :as saml]
[ring.ring-okta.session :as session]))
(defn- stub-respond-to-okta-post [& args]
{:redirect-url "http://foo.bar.com"
:authenticated-user-email "foo@bar.com"})
(deftest test-login
(let [request {:params {} :okta-config-location "test-resources/okta-config.xml"}]
(with-redefs [saml/respond-to-okta-post stub-respond-to-okta-post]
(testing "user placed in session"
(is (= "foo@bar.com" (-> (session/login request) :session :okta/user))))
(testing "redirect after login"
(is (= 303 (-> (session/login request) :status)))
(is (= "http://foo.bar.com" (-> (session/login request) :headers (get "Location"))))))))
(deftest test-logout
(let [request {:params {:foo "foo"}
:session {:okta/user "foo@bar.com"
:bar "bar"}}]
(testing "logout removes only :okta/user from session"
(is (= {:bar "bar"} (-> (session/logout request) :session))))
(testing "logout does not clear other items in the request"
(is (= {:params {:foo "foo"} :session {:bar "bar"}} (session/logout request))))))