Skip to content

Commit

Permalink
Merge pull request #4069 from penpot/niwinz-main-bugfix-1
Browse files Browse the repository at this point in the history
🐛 Fix incorrect props handling on profile registration
  • Loading branch information
superalex committed Jan 29, 2024
2 parents 9474700 + 2fa06ba commit 0c302e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
4 changes: 3 additions & 1 deletion backend/src/app/rpc/commands/auth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@
(defn register-profile
[{:keys [::db/conn] :as cfg} {:keys [token fullname] :as params}]
(let [claims (tokens/verify (::main/props cfg) {:token token :iss :prepared-register})
params (assoc claims :fullname fullname)
params (-> claims
(into params)
(assoc :fullname fullname))

is-active (or (:is-active params)
(not (contains? cf/flags :email-verification)))
Expand Down
48 changes: 16 additions & 32 deletions backend/test/backend_tests/rpc_profile_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[app.db :as db]
[app.rpc :as-alias rpc]
[app.auth :as auth]
[app.rpc.commands.profile :as profile]
[app.tokens :as tokens]
[app.util.time :as dt]
[backend-tests.helpers :as th]
Expand Down Expand Up @@ -240,56 +241,39 @@
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}
out (th/command! data)]
;; (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 :spec-validation))))
(t/is (th/ex-of-code? error :params-validation))))

;; try correct register
(let [data {::th/type :register-profile
:token token
:fullname "foobar"
:utm_campaign "utma"
:mtm_campaign "mtma"
:accept-terms-and-privacy true
:accept-newsletter-subscription true}]
(let [{:keys [result error]} (th/command! data)]
(t/is (nil? error))))
))

(t/deftest prepare-register-and-register-profile-1
(let [data {::th/type :prepare-register-profile
:email "user@example.com"
:password "foobar"}
out (th/command! data)
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}
out (th/command! data)]
(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 :params-validation))))

;; try correct register
(let [data {::th/type :register-profile
:token token
:fullname "foobar"
:accept-terms-and-privacy true
:accept-newsletter-subscription true}]
(let [{:keys [result error] :as out} (th/command! data)]
;; (th/print-result! out)
(t/is (nil? error))))
))
(let [profile (some-> (th/db-get :profile {:email "user@example.com"})
(profile/decode-row))]
(t/is (= "penpot" (:auth-backend profile)))
(t/is (= "foobar" (:fullname profile)))
(t/is (false? (:is-active profile)))
(t/is (uuid? (:default-team-id profile)))
(t/is (uuid? (:default-project-id profile)))

(let [props (:props profile)]
(t/is (= "utma" (:penpot/utm-campaign props)))
(t/is (= "mtma" (:penpot/mtm-campaign props)))))))

(t/deftest prepare-register-and-register-profile-2
(with-redefs [app.rpc.commands.auth/register-retry-threshold (dt/duration 500)]
Expand Down

0 comments on commit 0c302e3

Please sign in to comment.