2020-02-04 10:05:51 -05:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2022-09-20 16:23:22 -05:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2020-02-04 10:05:51 -05:00
|
|
|
|
2022-11-08 04:40:19 -05:00
|
|
|
(ns backend-tests.rpc-profile-test
|
2020-02-04 10:05:51 -05:00
|
|
|
(:require
|
2021-11-12 07:54:26 -05:00
|
|
|
[app.common.uuid :as uuid]
|
2022-03-10 06:37:55 -05:00
|
|
|
[app.config :as cf]
|
2021-05-28 06:50:42 -05:00
|
|
|
[app.db :as db]
|
2023-01-14 06:11:45 -05:00
|
|
|
[app.rpc :as-alias rpc]
|
2022-06-30 08:11:41 -05:00
|
|
|
[app.rpc.commands.auth :as cauth]
|
2022-08-30 07:26:54 -05:00
|
|
|
[app.tokens :as tokens]
|
2021-06-07 09:51:09 -05:00
|
|
|
[app.util.time :as dt]
|
2023-01-14 06:11:45 -05:00
|
|
|
[backend-tests.helpers :as th]
|
2020-02-04 10:05:51 -05:00
|
|
|
[clojure.java.io :as io]
|
2021-05-28 06:50:42 -05:00
|
|
|
[clojure.test :as t]
|
2020-02-04 10:05:51 -05:00
|
|
|
[cuerdas.core :as str]
|
|
|
|
[datoteka.core :as fs]
|
2021-05-28 06:50:42 -05:00
|
|
|
[mockery.core :refer [with-mocks]]))
|
2020-02-04 10:05:51 -05:00
|
|
|
|
2021-02-11 11:57:41 -05:00
|
|
|
;; TODO: profile deletion with teams
|
|
|
|
;; TODO: profile deletion with owner teams
|
|
|
|
|
2020-02-04 10:05:51 -05:00
|
|
|
(t/use-fixtures :once th/state-init)
|
|
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
|
2021-01-31 11:02:10 -05:00
|
|
|
;; Test with wrong credentials
|
|
|
|
(t/deftest profile-login-failed-1
|
|
|
|
(let [profile (th/create-profile* 1)
|
2022-06-30 08:11:41 -05:00
|
|
|
data {::th/type :login-with-password
|
2021-01-31 11:02:10 -05:00
|
|
|
:email "profile1.test@nodomain.com"
|
2022-06-30 08:11:41 -05:00
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)]
|
2021-01-31 11:02:10 -05:00
|
|
|
|
|
|
|
#_(th/print-result! out)
|
|
|
|
(let [error (:error out)]
|
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :wrong-credentials)))))
|
|
|
|
|
|
|
|
;; Test with good credentials but profile not activated.
|
|
|
|
(t/deftest profile-login-failed-2
|
|
|
|
(let [profile (th/create-profile* 1)
|
2022-06-30 08:11:41 -05:00
|
|
|
data {::th/type :login-with-password
|
2021-01-31 11:02:10 -05:00
|
|
|
:email "profile1.test@nodomain.com"
|
2022-06-30 08:11:41 -05:00
|
|
|
:password "123123"}
|
|
|
|
out (th/command! data)]
|
2021-01-31 11:02:10 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(let [error (:error out)]
|
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :wrong-credentials)))))
|
|
|
|
|
|
|
|
;; Test with good credentials but profile already activated
|
|
|
|
(t/deftest profile-login-success
|
|
|
|
(let [profile (th/create-profile* 1 {:is-active true})
|
2022-11-28 10:48:30 -05:00
|
|
|
data {::th/type :login-with-password
|
2021-01-31 11:02:10 -05:00
|
|
|
:email "profile1.test@nodomain.com"
|
2022-06-30 08:11:41 -05:00
|
|
|
:password "123123"}
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)]
|
2021-01-31 11:02:10 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(t/is (= (:id profile) (get-in out [:result :id])))))
|
2020-02-17 03:49:04 -05:00
|
|
|
|
|
|
|
(t/deftest profile-query-and-manipulation
|
2021-01-31 11:02:10 -05:00
|
|
|
(let [profile (th/create-profile* 1)]
|
2020-02-17 03:49:04 -05:00
|
|
|
(t/testing "query profile"
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [data {::th/type :get-profile
|
|
|
|
::rpc/profile-id (:id profile)}
|
|
|
|
out (th/command! data)]
|
2020-02-17 03:49:04 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
|
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (= "Profile 1" (:fullname result)))
|
|
|
|
(t/is (= "profile1.test@nodomain.com" (:email result)))
|
|
|
|
(t/is (not (contains? result :password))))))
|
|
|
|
|
|
|
|
(t/testing "update profile"
|
|
|
|
(let [data (assoc profile
|
2020-12-24 08:32:19 -05:00
|
|
|
::th/type :update-profile
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2020-02-17 03:49:04 -05:00
|
|
|
:fullname "Full Name"
|
2020-04-08 03:57:29 -05:00
|
|
|
:lang "en"
|
|
|
|
:theme "dark")
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2020-02-17 03:49:04 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
2021-10-07 09:23:19 -05:00
|
|
|
(t/is (map? (:result out)))))
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2020-05-14 06:49:11 -05:00
|
|
|
(t/testing "query profile after update"
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [data {::th/type :get-profile
|
|
|
|
::rpc/profile-id (:id profile)}
|
|
|
|
out (th/command! data)]
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2022-09-20 07:13:19 -05:00
|
|
|
#_(th/print-result! out)
|
2020-02-17 03:49:04 -05:00
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
|
|
|
|
(let [result (:result out)]
|
2020-05-14 06:49:11 -05:00
|
|
|
(t/is (= "Full Name" (:fullname result)))
|
|
|
|
(t/is (= "en" (:lang result)))
|
|
|
|
(t/is (= "dark" (:theme result))))))
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2020-08-07 07:55:22 -05:00
|
|
|
(t/testing "update photo"
|
2020-12-24 08:32:19 -05:00
|
|
|
(let [data {::th/type :update-profile-photo
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2020-08-07 07:55:22 -05:00
|
|
|
:file {:filename "sample.jpg"
|
|
|
|
:size 123123
|
2022-11-08 04:40:19 -05:00
|
|
|
:path (th/tempfile "backend_tests/test_files/sample.jpg")
|
2022-03-04 12:00:16 -05:00
|
|
|
:mtype "image/jpeg"}}
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2020-08-07 07:55:22 -05:00
|
|
|
;; (th/print-result! out)
|
2020-12-24 08:32:19 -05:00
|
|
|
(t/is (nil? (:error out)))))
|
|
|
|
))
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2021-01-31 11:02:10 -05:00
|
|
|
(t/deftest profile-deletion-simple
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [prof (th/create-profile* 1)
|
2021-01-31 11:02:10 -05:00
|
|
|
file (th/create-file* 1 {:profile-id (:id prof)
|
|
|
|
:project-id (:default-project-id prof)
|
|
|
|
:is-shared false})]
|
|
|
|
|
|
|
|
;; profile is not deleted because it does not meet all
|
|
|
|
;; conditions to be deleted.
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [result (th/run-task! :objects-gc {:min-age (dt/duration 0)})]
|
2022-08-12 01:34:23 -05:00
|
|
|
(t/is (= 0 (:processed result))))
|
2021-01-31 11:02:10 -05:00
|
|
|
|
|
|
|
;; Request profile to be deleted
|
2021-06-07 09:51:09 -05:00
|
|
|
(let [params {::th/type :delete-profile
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id prof)}
|
|
|
|
out (th/command! params)]
|
2021-06-07 09:51:09 -05:00
|
|
|
(t/is (nil? (:error out))))
|
2021-01-31 11:02:10 -05:00
|
|
|
|
|
|
|
;; query files after profile soft deletion
|
2023-01-16 10:50:42 -05:00
|
|
|
(let [params {::th/type :get-project-files
|
|
|
|
::rpc/profile-id (:id prof)
|
|
|
|
:project-id (:default-project-id prof)}
|
|
|
|
out (th/command! params)]
|
2021-01-31 11:02:10 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(t/is (= 1 (count (:result out)))))
|
|
|
|
|
|
|
|
;; execute permanent deletion task
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [result (th/run-task! :objects-gc {:min-age (dt/duration "-1m")})]
|
2022-12-21 05:53:56 -05:00
|
|
|
(t/is (= 2 (:processed result))))
|
|
|
|
|
|
|
|
(let [row (th/db-get :team
|
|
|
|
{:id (:default-team-id prof)}
|
2023-01-02 16:56:24 -05:00
|
|
|
{::db/remove-deleted? false})]
|
2022-12-21 05:53:56 -05:00
|
|
|
(t/is (dt/instant? (:deleted-at row))))
|
2021-01-31 11:02:10 -05:00
|
|
|
|
|
|
|
;; query profile after delete
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [params {::th/type :get-profile
|
|
|
|
::rpc/profile-id (:id prof)}
|
|
|
|
out (th/command! params)]
|
2021-01-31 11:02:10 -05:00
|
|
|
;; (th/print-result! out)
|
2021-11-12 07:54:26 -05:00
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (= uuid/zero (:id result)))))))
|
2020-04-08 03:57:29 -05:00
|
|
|
|
2021-01-31 11:02:10 -05:00
|
|
|
(t/deftest registration-domain-whitelist
|
2021-05-25 14:19:13 -05:00
|
|
|
(let [whitelist #{"gmail.com" "hey.com" "ya.ru"}]
|
2021-01-31 11:02:10 -05:00
|
|
|
(t/testing "allowed email domain"
|
2022-06-30 08:11:41 -05:00
|
|
|
(t/is (true? (cauth/email-domain-in-whitelist? whitelist "username@ya.ru")))
|
|
|
|
(t/is (true? (cauth/email-domain-in-whitelist? #{} "username@somedomain.com"))))
|
2020-02-17 03:49:04 -05:00
|
|
|
|
2021-01-31 11:02:10 -05:00
|
|
|
(t/testing "not allowed email domain"
|
2022-06-30 08:11:41 -05:00
|
|
|
(t/is (false? (cauth/email-domain-in-whitelist? whitelist "username@somedomain.com"))))))
|
2020-03-16 10:55:44 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest prepare-register-and-register-profile-1
|
2021-06-15 10:24:00 -05:00
|
|
|
(let [data {::th/type :prepare-register-profile
|
2021-03-02 05:48:51 -05:00
|
|
|
:email "user@example.com"
|
2021-06-15 10:24:00 -05:00
|
|
|
:password "foobar"}
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)
|
2021-06-15 10:24:00 -05:00
|
|
|
token (get-in out [:result :token])]
|
|
|
|
(t/is (string? token))
|
|
|
|
|
|
|
|
|
|
|
|
;; try register without token
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true}
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2021-06-15 10:24:00 -05:00
|
|
|
(let [error (:error out)]
|
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :spec-validation))))
|
|
|
|
|
|
|
|
;; try correct register
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:token token
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true
|
|
|
|
:accept-newsletter-subscription true}]
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [{:keys [result error]} (th/command! data)]
|
2021-10-05 08:58:45 -05:00
|
|
|
(t/is (nil? error))))
|
2021-06-15 10:24:00 -05:00
|
|
|
))
|
2021-03-02 05:48:51 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest prepare-register-and-register-profile-1
|
|
|
|
(let [data {::th/type :prepare-register-profile
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "foobar"}
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)
|
2022-09-21 07:20:26 -05:00
|
|
|
token (get-in out [:result :token])]
|
|
|
|
(t/is (string? token))
|
|
|
|
|
|
|
|
|
|
|
|
;; try register without token
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true}
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)]
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [error (:error out)]
|
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :spec-validation))))
|
|
|
|
|
|
|
|
;; try correct register
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:token token
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true
|
|
|
|
:accept-newsletter-subscription true}]
|
2022-11-28 10:48:30 -05:00
|
|
|
(let [{:keys [result error] :as out} (th/command! data)]
|
|
|
|
;; (th/print-result! out)
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (nil? error))))
|
|
|
|
))
|
|
|
|
|
|
|
|
(t/deftest prepare-register-and-register-profile-2
|
|
|
|
(with-redefs [app.rpc.commands.auth/register-retry-threshold (dt/duration 500)]
|
|
|
|
(with-mocks [mock {:target 'app.emails/send! :return nil}]
|
|
|
|
(let [current-token (atom nil)]
|
|
|
|
|
|
|
|
;; PREPARE REGISTER
|
|
|
|
(let [data {::th/type :prepare-register-profile
|
|
|
|
:email "hello@example.com"
|
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)
|
|
|
|
token (get-in out [:result :token])]
|
|
|
|
(t/is (string? token))
|
|
|
|
(reset! current-token token))
|
|
|
|
|
|
|
|
;; DO REGISTRATION: try correct register attempt 1
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:token @current-token
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true
|
|
|
|
:accept-newsletter-subscription true}
|
|
|
|
out (th/command! data)]
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(t/is (= 1 (:call-count @mock))))
|
|
|
|
|
|
|
|
(th/reset-mock! mock)
|
|
|
|
|
|
|
|
;; PREPARE REGISTER without waiting for threshold
|
|
|
|
(let [data {::th/type :prepare-register-profile
|
|
|
|
:email "hello@example.com"
|
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)]
|
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(t/is (= :validation (-> out :error th/ex-type)))
|
|
|
|
(t/is (= :email-already-exists (-> out :error th/ex-code))))
|
|
|
|
|
|
|
|
(th/sleep {:millis 500})
|
|
|
|
(th/reset-mock! mock)
|
|
|
|
|
|
|
|
;; PREPARE REGISTER waiting the threshold
|
|
|
|
(let [data {::th/type :prepare-register-profile
|
|
|
|
:email "hello@example.com"
|
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)]
|
|
|
|
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(t/is (= 0 (:call-count @mock)))
|
|
|
|
|
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (contains? result :token))
|
|
|
|
(reset! current-token (:token result))))
|
|
|
|
|
|
|
|
;; DO REGISTRATION: try correct register attempt 1
|
|
|
|
(let [data {::th/type :register-profile
|
|
|
|
:token @current-token
|
|
|
|
:fullname "foobar"
|
|
|
|
:accept-terms-and-privacy true
|
|
|
|
:accept-newsletter-subscription true}
|
|
|
|
out (th/command! data)]
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(t/is (= 1 (:call-count @mock))))
|
|
|
|
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2022-03-10 06:37:55 -05:00
|
|
|
(t/deftest prepare-and-register-with-invitation-and-disabled-registration-1
|
|
|
|
(with-redefs [app.config/flags [:disable-registration]]
|
2022-08-30 07:26:54 -05:00
|
|
|
(let [sprops (:app.setup/props th/*system*)
|
|
|
|
itoken (tokens/generate sprops
|
|
|
|
{:iss :team-invitation
|
|
|
|
:exp (dt/in-future "48h")
|
|
|
|
:role :editor
|
|
|
|
:team-id uuid/zero
|
|
|
|
:member-email "user@example.com"})
|
2022-03-10 06:37:55 -05:00
|
|
|
data {::th/type :prepare-register-profile
|
|
|
|
:invitation-token itoken
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "foobar"}
|
|
|
|
|
2022-11-28 10:48:30 -05:00
|
|
|
{:keys [result error] :as out} (th/command! data)]
|
2022-03-10 06:37:55 -05:00
|
|
|
(t/is (nil? error))
|
|
|
|
(t/is (map? result))
|
|
|
|
(t/is (string? (:token result)))
|
|
|
|
|
|
|
|
(let [rtoken (:token result)
|
|
|
|
data {::th/type :register-profile
|
|
|
|
:token rtoken
|
|
|
|
:fullname "foobar"}
|
|
|
|
|
2022-11-28 10:48:30 -05:00
|
|
|
{:keys [result error] :as out} (th/command! data)]
|
2022-03-10 06:37:55 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? error))
|
|
|
|
(t/is (map? result))
|
|
|
|
(t/is (string? (:invitation-token result)))))))
|
|
|
|
|
|
|
|
(t/deftest prepare-and-register-with-invitation-and-disabled-registration-2
|
|
|
|
(with-redefs [app.config/flags [:disable-registration]]
|
2022-08-30 07:26:54 -05:00
|
|
|
(let [sprops (:app.setup/props th/*system*)
|
|
|
|
itoken (tokens/generate sprops
|
|
|
|
{:iss :team-invitation
|
|
|
|
:exp (dt/in-future "48h")
|
|
|
|
:role :editor
|
|
|
|
:team-id uuid/zero
|
|
|
|
:member-email "user2@example.com"})
|
2022-03-10 06:37:55 -05:00
|
|
|
|
|
|
|
data {::th/type :prepare-register-profile
|
|
|
|
:invitation-token itoken
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "foobar"}
|
2022-09-21 07:20:26 -05:00
|
|
|
out (th/command! data)]
|
2022-03-10 06:37:55 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :restriction (:type edata)))
|
|
|
|
(t/is (= :email-does-not-match-invitation (:code edata))))
|
|
|
|
)))
|
2022-03-10 06:37:55 -05:00
|
|
|
|
2021-06-15 10:24:00 -05:00
|
|
|
(t/deftest prepare-register-with-registration-disabled
|
2022-09-21 07:20:26 -05:00
|
|
|
(with-redefs [app.config/flags #{}]
|
2021-06-15 10:24:00 -05:00
|
|
|
(let [data {::th/type :prepare-register-profile
|
2021-02-11 07:36:46 -05:00
|
|
|
:email "user@example.com"
|
2022-09-21 07:20:26 -05:00
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)]
|
|
|
|
|
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :restriction (:type edata)))
|
|
|
|
(t/is (= :registration-disabled (:code edata)))))))
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2021-06-15 10:24:00 -05:00
|
|
|
(t/deftest prepare-register-with-existing-user
|
2021-02-11 07:36:46 -05:00
|
|
|
(let [profile (th/create-profile* 1)
|
2021-06-15 10:24:00 -05:00
|
|
|
data {::th/type :prepare-register-profile
|
2021-02-11 07:36:46 -05:00
|
|
|
:email (:email profile)
|
2022-09-21 07:20:26 -05:00
|
|
|
:password "foobar"}
|
|
|
|
out (th/command! data)]
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
|
|
|
(t/is (= :email-already-exists (:code edata))))))
|
|
|
|
|
|
|
|
(t/deftest register-profile-with-bounced-email
|
2021-06-15 10:24:00 -05:00
|
|
|
(let [pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :prepare-register-profile
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "foobar"}]
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2021-06-15 10:24:00 -05:00
|
|
|
(th/create-global-complaint-for pool {:type :bounce :email "user@example.com"})
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [out (th/command! data)]
|
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
|
|
|
(t/is (= :email-has-permanent-bounces (:code edata)))))))
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest register-profile-with-complained-email
|
2021-06-15 10:24:00 -05:00
|
|
|
(let [pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :prepare-register-profile
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "foobar"}]
|
2021-02-11 07:36:46 -05:00
|
|
|
|
2021-06-15 10:24:00 -05:00
|
|
|
(th/create-global-complaint-for pool {:type :complaint :email "user@example.com"})
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [out (th/command! data)]
|
|
|
|
(t/is (th/success? out))
|
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (contains? result :token))))))
|
2022-02-04 03:28:23 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest register-profile-with-email-as-password
|
|
|
|
(let [data {::th/type :prepare-register-profile
|
|
|
|
:email "user@example.com"
|
|
|
|
:password "USER@example.com"}
|
|
|
|
out (th/command! data)]
|
2022-02-04 03:28:23 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (not (th/success? out)))
|
|
|
|
(let [edata (-> out :error ex-data)]
|
|
|
|
(t/is (= :validation (:type edata)))
|
|
|
|
(t/is (= :email-as-password (:code edata))))))
|
|
|
|
|
|
|
|
(t/deftest email-change-request
|
|
|
|
(with-mocks [mock {:target 'app.emails/send! :return nil}]
|
2021-02-11 11:57:41 -05:00
|
|
|
(let [profile (th/create-profile* 1)
|
2021-02-24 05:51:57 -05:00
|
|
|
pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :request-email-change
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2021-02-24 05:51:57 -05:00
|
|
|
:email "user1@example.com"}]
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; without complaints
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:result out)))
|
2022-09-21 07:20:26 -05:00
|
|
|
(let [mock @mock]
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (= 1 (:call-count mock)))
|
|
|
|
(t/is (true? (:called? mock)))))
|
|
|
|
|
|
|
|
;; with complaints
|
|
|
|
(th/create-global-complaint-for pool {:type :complaint :email (:email data)})
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:result out)))
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 2 (:call-count @mock))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; with bounces
|
|
|
|
(th/create-global-complaint-for pool {:type :bounce :email (:email data)})
|
2023-01-14 06:11:45 -05:00
|
|
|
(let [out (th/command! data)
|
2021-02-11 11:57:41 -05:00
|
|
|
error (:error out)]
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :email-has-permanent-bounces))
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 2 (:call-count @mock)))))))
|
2021-02-24 05:51:57 -05:00
|
|
|
|
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest email-change-request-without-smtp
|
|
|
|
(with-mocks [mock {:target 'app.emails/send! :return nil}]
|
2022-09-20 07:13:19 -05:00
|
|
|
(with-redefs [app.config/flags #{}]
|
|
|
|
(let [profile (th/create-profile* 1)
|
|
|
|
pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :request-email-change
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2022-09-21 07:20:26 -05:00
|
|
|
:email "user1@example.com"}
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2022-09-20 07:13:19 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (false? (:called? @mock)))
|
|
|
|
(let [res (:result out)]
|
|
|
|
(t/is (= {:changed true} res)))))))
|
2021-02-24 05:51:57 -05:00
|
|
|
|
2021-02-11 11:57:41 -05:00
|
|
|
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/deftest request-profile-recovery
|
2021-02-11 11:57:41 -05:00
|
|
|
(with-mocks [mock {:target 'app.emails/send! :return nil}]
|
|
|
|
(let [profile1 (th/create-profile* 1)
|
|
|
|
profile2 (th/create-profile* 2 {:is-active true})
|
|
|
|
pool (:app.db/pool th/*system*)
|
|
|
|
data {::th/type :request-profile-recovery}]
|
|
|
|
|
|
|
|
;; with invalid email
|
|
|
|
(let [data (assoc data :email "foo@bar.com")
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (nil? (:result out)))
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 0 (:call-count @mock))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; with valid email inactive user
|
|
|
|
(let [data (assoc data :email (:email profile1))
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)
|
2021-02-11 11:57:41 -05:00
|
|
|
error (:error out)]
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 0 (:call-count @mock)))
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :profile-not-verified)))
|
|
|
|
|
|
|
|
;; with valid email and active user
|
|
|
|
(let [data (assoc data :email (:email profile2))
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:result out)))
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 1 (:call-count @mock))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; with valid email and active user with global complaints
|
|
|
|
(th/create-global-complaint-for pool {:type :complaint :email (:email profile2)})
|
|
|
|
(let [data (assoc data :email (:email profile2))
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)]
|
2021-02-11 11:57:41 -05:00
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:result out)))
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 2 (:call-count @mock))))
|
2021-02-11 11:57:41 -05:00
|
|
|
|
|
|
|
;; with valid email and active user with global bounce
|
|
|
|
(th/create-global-complaint-for pool {:type :bounce :email (:email profile2)})
|
|
|
|
(let [data (assoc data :email (:email profile2))
|
2022-11-28 10:48:30 -05:00
|
|
|
out (th/command! data)
|
2021-02-11 11:57:41 -05:00
|
|
|
error (:error out)]
|
|
|
|
;; (th/print-result! out)
|
2022-09-21 07:20:26 -05:00
|
|
|
(t/is (= 2 (:call-count @mock)))
|
2021-02-11 11:57:41 -05:00
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :email-has-permanent-bounces)))
|
|
|
|
|
|
|
|
)))
|
2022-02-04 03:28:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
(t/deftest update-profile-password
|
|
|
|
(let [profile (th/create-profile* 1)
|
|
|
|
data {::th/type :update-profile-password
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2022-02-04 03:28:23 -05:00
|
|
|
:old-password "123123"
|
|
|
|
:password "foobarfoobar"}
|
2023-01-14 06:11:45 -05:00
|
|
|
out (th/command! data)]
|
2022-02-04 03:28:23 -05:00
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(t/is (nil? (:result out)))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
(t/deftest update-profile-password-bad-old-password
|
|
|
|
(let [profile (th/create-profile* 1)
|
|
|
|
data {::th/type :update-profile-password
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2022-02-04 03:28:23 -05:00
|
|
|
:old-password "badpassword"
|
|
|
|
:password "foobarfoobar"}
|
2023-01-14 06:11:45 -05:00
|
|
|
{:keys [result error] :as out} (th/command! data)]
|
2022-02-04 03:28:23 -05:00
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :old-password-not-match))))
|
|
|
|
|
|
|
|
|
|
|
|
(t/deftest update-profile-password-email-as-password
|
|
|
|
(let [profile (th/create-profile* 1)
|
|
|
|
data {::th/type :update-profile-password
|
2023-01-14 06:11:45 -05:00
|
|
|
::rpc/profile-id (:id profile)
|
2022-02-04 03:28:23 -05:00
|
|
|
:old-password "123123"
|
|
|
|
:password "profile1.test@nodomain.com"}
|
2023-01-14 06:11:45 -05:00
|
|
|
{:keys [result error] :as out} (th/command! data)]
|
2022-02-04 03:28:23 -05:00
|
|
|
(t/is (th/ex-info? error))
|
|
|
|
(t/is (th/ex-of-type? error :validation))
|
|
|
|
(t/is (th/ex-of-code? error :email-as-password))))
|