Skip to content

Commit 35b445e

Browse files
committed
Test new CSV routes
1 parent 3b96dd8 commit 35b445e

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

src/test/lrsql/admin/route_test.clj

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@
174174
(is-err-code (create-account nil req-body) 400))
175175
(testing "create accounts with invalid username and passwords"
176176
(are [input expected-status]
177-
(let [{:keys [status]} (create-account
178-
headers
179-
(u/write-json-str
180-
input)
181-
:throw false)]
182-
(= expected-status status))
177+
(let [{:keys [status]} (create-account
178+
headers
179+
(u/write-json-str
180+
input)
181+
:throw false)]
182+
(= expected-status status))
183183
;; both empty
184184
{"username" ""
185185
"password" ""} 400
@@ -309,33 +309,57 @@
309309
(= 400))))
310310
(testing "with an invalid password"
311311
(are [password expected-status]
312-
(-> (update-pass! {"old-password" new-pass
313-
"new-password" password})
314-
:status
315-
(= expected-status))
312+
(-> (update-pass! {"old-password" new-pass
313+
"new-password" password})
314+
:status
315+
(= expected-status))
316316
"" 400
317317
"password" 400))
318318
(testing "change it back"
319319
(is (-> (update-pass! {"old-password" new-pass
320320
"new-password" orig-pass})
321321
:status
322322
(= 200))))))
323-
(testing "download CSV data"
323+
(testing "authenticate and download CSV data"
324324
(let [property-paths-vec [["id"] ["actor" "mbox"]]
325325
property-paths-str (u/url-encode (str property-paths-vec))
326-
endpoint-url (format "http://0.0.0.0:8080/admin/csv?property-paths=%s&ascending=true"
327-
property-paths-str)
328-
{:keys [status body]} (curl/get endpoint-url
329-
{:headers headers
330-
:as :stream})
331-
csv-body (slurp body)]
326+
bad-prop-paths-vec ["zoo" "wee" "mama"]
327+
bad-prop-paths-str (u/url-encode (str bad-prop-paths-vec))
328+
auth-endpoint-url "http://0.0.0.0:8080/admin/csv/auth"
329+
{:keys [status body]}
330+
(curl/get auth-endpoint-url {:headers headers})
331+
{:keys [account-id json-web-token]}
332+
(u/parse-json body :keyword-keys? true)]
332333
(is (= 200 status))
333-
(is (= "id,actor_mbox\r\n" csv-body)))
334-
(let [bad-prop-path (->> ["zoo" "wee" "mama"] str u/url-encode)
335-
bad-url (format "http://0.0.0.0:8080/admin/csv?property-paths=%s"
336-
bad-prop-path)]
337-
(is-err-code (curl/get bad-url {:headers headers :as :stream})
338-
400)))
334+
(is (string? account-id))
335+
(is (string? json-web-token))
336+
(let [endpoint-url
337+
(format "http://0.0.0.0:8080/admin/csv?token=%s&property-paths=%s&ascending=true"
338+
json-web-token
339+
property-paths-str)
340+
bad-endpoint-url-1
341+
(format "http://0.0.0.0:8080/admin/csv?token=%s&property-paths=%s"
342+
seed-jwt
343+
property-paths-str)
344+
bad-endpoint-url-2
345+
(format "http://0.0.0.0:8080/admin/csv?token=%s&property-paths=%s"
346+
json-web-token
347+
bad-prop-paths-str)]
348+
(testing "- valid download"
349+
(let [{:keys [status body]}
350+
(curl/get endpoint-url {:headers headers :as :stream})
351+
csv-body (slurp body)]
352+
(is (= 200 status))
353+
(is (= "id,actor_mbox\r\n" csv-body))))
354+
(testing "- expired one-time token does not authenticate"
355+
(is-err-code (curl/get endpoint-url {:headers headers :as :stream})
356+
401))
357+
(testing "- account JWT does not authenticate"
358+
(is-err-code (curl/get bad-endpoint-url-1 {:headers headers :as :stream})
359+
401))
360+
(testing "- invalid property path"
361+
(is-err-code (curl/get bad-endpoint-url-2 {:headers headers :as :stream})
362+
400)))))
339363
(testing "delete the `myname` account using the seed account"
340364
(let [del-jwt (-> (login-account content-type req-body)
341365
:body

0 commit comments

Comments
 (0)