|
174 | 174 | (is-err-code (create-account nil req-body) 400)) |
175 | 175 | (testing "create accounts with invalid username and passwords" |
176 | 176 | (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)) |
183 | 183 | ;; both empty |
184 | 184 | {"username" "" |
185 | 185 | "password" ""} 400 |
|
309 | 309 | (= 400)))) |
310 | 310 | (testing "with an invalid password" |
311 | 311 | (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)) |
316 | 316 | "" 400 |
317 | 317 | "password" 400)) |
318 | 318 | (testing "change it back" |
319 | 319 | (is (-> (update-pass! {"old-password" new-pass |
320 | 320 | "new-password" orig-pass}) |
321 | 321 | :status |
322 | 322 | (= 200)))))) |
323 | | - (testing "download CSV data" |
| 323 | + (testing "authenticate and download CSV data" |
324 | 324 | (let [property-paths-vec [["id"] ["actor" "mbox"]] |
325 | 325 | 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)] |
332 | 333 | (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))))) |
339 | 363 | (testing "delete the `myname` account using the seed account" |
340 | 364 | (let [del-jwt (-> (login-account content-type req-body) |
341 | 365 | :body |
|
0 commit comments