|
34 | 34 | :let [resp (http/get url)]] |
35 | 35 | (is (http/success? resp)) |
36 | 36 | (is (= (page-bodies uri) (:body resp)))) |
37 | | - |
| 37 | + |
38 | 38 | (let [api-resp (http/get (url "/free-api") {:as :json})] |
39 | 39 | (is (http/success? api-resp)) |
40 | 40 | (is (= {:data 99} (:body api-resp))))) |
|
69 | 69 | ; clj-http *should* redirect us, but isn't yet; working on it: |
70 | 70 | ; https://github.com/dakrone/clj-http/issues/57 |
71 | 71 | (is (http/redirect? resp)) |
72 | | - (is (= (url "/user/account?query-string=test") (-> resp :headers (get "location"))))) |
| 72 | + (is (= "/user/account?query-string=test" |
| 73 | + (-> resp :headers (get "location"))))) |
73 | 74 | (check-user-role-access) |
74 | 75 | (is (= {:roles ["test-friend.mock-app/user"]} (:body (http/get (url "/echo-roles") {:as :json})))) |
75 | | - |
| 76 | + |
76 | 77 | ; deny on admin role |
77 | 78 | (try+ |
78 | 79 | (http/get (url "/admin")) |
79 | 80 | (assert false) ; should never get here |
80 | 81 | (catch [:status 403] _ |
81 | 82 | (is true))) |
82 | | - |
| 83 | + |
83 | 84 | (testing "logout blocks access to privileged routes" |
84 | 85 | (is (= (page-bodies "/") (:body (http/get (url "/logout"))))) |
85 | 86 | (is (= (page-bodies "/login") (:body (http/get (url "/user/account")))))))) |
|
100 | 101 | (is (= "auth-data" (post-session-data "auth-data"))) |
101 | 102 | (is (= "auth-data" (get-session-data))) |
102 | 103 | (check-user-role-access) |
103 | | - |
| 104 | + |
104 | 105 | (http/get (url "/logout")) |
105 | 106 | (let [should-be-login-redirect (http/get (url "/user/account") |
106 | 107 | {:follow-redirects false})] |
107 | 108 | (is (= 302 (:status should-be-login-redirect))) |
108 | | - (is (re-matches #"http://localhost:\d+/login" |
109 | | - (-> should-be-login-redirect :headers (get "location"))))) |
| 109 | + (is (= "/login" (-> should-be-login-redirect :headers (get "location"))))) |
110 | 110 | ; TODO should logout blow away the session completely? |
111 | 111 | (is (= "auth-data" (get-session-data))))))) |
112 | 112 |
|
|
118 | 118 | (assert false) ; should never get here |
119 | 119 | (catch [:status 403] resp |
120 | 120 | (is (= "Sorry, you do not have access to this resource." (:body resp))))) |
121 | | - |
| 121 | + |
122 | 122 | (http/post (url "/login") {:form-params {:username "root" :password "admin_password"}}) |
123 | 123 | (is (= (page-bodies "/hook-admin") (:body (http/get (url "/hook-admin"))))))) |
124 | 124 |
|
|
135 | 135 | (deftest admin-login |
136 | 136 | (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)] |
137 | 137 | (is (= (page-bodies "/login") (:body (http/get (url "/admin"))))) |
138 | | - |
| 138 | + |
139 | 139 | (http/post (url "/login") {:form-params {:username "root" :password "admin_password"}}) |
140 | 140 | (is (= (page-bodies "/admin") (:body (http/get (url "/admin"))))) |
141 | 141 | (check-user-role-access) |
|
151 | 151 | (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)] |
152 | 152 | (is (= (page-bodies "/login") (:body (http/get (url "/admin"))))) |
153 | 153 | (http/post (url "/login") {:form-params {:username "root" :password "admin_password"}}) |
154 | | - |
| 154 | + |
155 | 155 | (try+ |
156 | 156 | (http/get (url "/wat")) |
157 | 157 | (assert false) |
158 | 158 | (catch [:status 404] e)) |
159 | 159 | (is (= (page-bodies "/admin") (:body (http/get (url "/admin"))))) |
160 | | - |
| 160 | + |
161 | 161 | (is (= (page-bodies "/") (:body (http/get (url "/logout"))))) |
162 | 162 | (is (= (page-bodies "/login") (:body (http/get (url "/admin"))))))) |
163 | 163 |
|
|
0 commit comments