From beed1a60ee1578306bde8834bbbcda770fcee4be Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 10 Dec 2019 12:07:38 +0200 Subject: [PATCH] [#9573] Fix some password saving bugs --- project.clj | 1 + src/status_im/multiaccounts/login/core.cljs | 5 +- src/status_im/subs.cljs | 7 ++ src/status_im/ui/screens/biometric/views.cljs | 9 ++- .../test/multiaccounts/login/core.cljs | 75 +++++++++++++++++++ test/cljs/status_im/test/runner.cljs | 2 + translations/en.json | 3 +- 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 test/cljs/status_im/test/multiaccounts/login/core.cljs diff --git a/project.clj b/project.clj index a5615245956..2e17cb071aa 100644 --- a/project.clj +++ b/project.clj @@ -46,6 +46,7 @@ ["with-profile" "prod" "cljsbuild" "once" "desktop"]] "figwheel-repl" ["with-profile" "+figwheel" "run" "-m" "clojure.main" "env/dev/run.clj"] "test-cljs" ["with-profile" "test" "doo" "node" "test" "once"] + "test-cljs-auto" ["with-profile" "test" "doo" "node" "test" "auto"] "test-protocol" ["with-profile" "test" "doo" "node" "protocol" "once"] "test-env-dev-utils" ["with-profile" "test" "doo" "node" "env-dev-utils" "once"]} :profiles {:dev {:dependencies [[cider/piggieback "0.4.0"]] diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 17bbae580a3..f017fbb7cf8 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -393,7 +393,10 @@ "previous-auth-method" previous-auth-method) (fx/merge cofx - {:db (cond-> (assoc db :auth-method keychain/auth-method-none) + {:db (cond-> db + (not= previous-auth-method + keychain/auth-method-biometric-prepare) + (assoc :auth-method keychain/auth-method-none) (or save-password? (not bioauth-supported?) (and (not save-password?) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index c80850db52d..37be0ba70d6 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -513,6 +513,13 @@ (fn [multiaccounts] (> (count multiaccounts) 1))) +(re-frame/reg-sub + :multiaccounts.login/keycard-account? + :<- [:multiaccounts/multiaccounts] + :<- [:multiaccounts/login] + (fn [[multiaccounts {:keys [key-uid]}]] + (get-in multiaccounts [key-uid :keycard-pairing]))) + (re-frame/reg-sub :accounts-without-watch-only :<- [:multiaccount] diff --git a/src/status_im/ui/screens/biometric/views.cljs b/src/status_im/ui/screens/biometric/views.cljs index 29f43793ec1..b4f6f29854a 100644 --- a/src/status_im/ui/screens/biometric/views.cljs +++ b/src/status_im/ui/screens/biometric/views.cljs @@ -69,12 +69,17 @@ :on-confirm :biometric-logout}]) (defn secure-with-biometric-popover [] - (let [bio-label-type (get-bio-type-label)] + (let [bio-label-type (get-bio-type-label) + keycard-account? @(re-frame/subscribe + [:multiaccounts.login/keycard-account?])] [biometric-popover {:title-label :t/biometric-secure-with :ok-button-label :t/biometric-enable-button :on-confirm :biometric/enable :description-text - [[{:style {:color colors/gray}} (i18n/label :t/biometric-enable)] + [[{:style {:color colors/gray}} + (if keycard-account? + (i18n/label :t/biometric-enable-keycard) + (i18n/label :t/biometric-enable))] [{} (i18n/label :t/biometric-sign-in {:bio-type-label bio-label-type})]]}])) diff --git a/test/cljs/status_im/test/multiaccounts/login/core.cljs b/test/cljs/status_im/test/multiaccounts/login/core.cljs new file mode 100644 index 00000000000..86a46edde76 --- /dev/null +++ b/test/cljs/status_im/test/multiaccounts/login/core.cljs @@ -0,0 +1,75 @@ +(ns status-im.test.multiaccounts.login.core + (:require [cljs.test :as test] + [status-im.multiaccounts.login.core :as login] + [status-im.multiaccounts.biometric.core :as biometric] + [status-im.utils.keychain.core :as keychain] + [status-im.utils.fx :as fx])) + +(test/deftest save-password-test + (test/testing "check save password, biometric unavailable" + (let [initial-cofx {:db {:auth-method keychain/auth-method-none + :supported-biometric-auth false}} + {:keys [db]} (login/save-password initial-cofx true)] + (test/is (= false (contains? db :popover/popover))) + (test/is (= true (get-in db [:multiaccounts/login :save-password?]))) + (test/testing "uncheck save password" + (let [{:keys [db]} (login/save-password {:db db} false)] + (test/is (= false (contains? db :popover/popover))) + (test/is (= false (get-in db [:multiaccounts/login :save-password?]))))))) + (test/testing "check save password, biometric available" + (let [initial-cofx {:db {:auth-method keychain/auth-method-none + :supported-biometric-auth true}} + {:keys [db]} (login/save-password initial-cofx true)] + (test/is (= :secure-with-biometric + (get-in db [:popover/popover :view]))) + (test/is (= true (get-in db [:multiaccounts/login :save-password?]))) + (test/testing "enable biometric auth" + (let [{:keys [db] :as res} (biometric/enable {:db db})] + (test/is (contains? res :biometric-auth/authenticate)) + (test/is (= false (contains? db :popover/popover))) + (test/testing "biometric auth successfully enabled" + (let [{:keys [db]} (biometric/setup-done + {:db db} + {:bioauth-success true + :bioauth-message nil + :bioauth-code nil})] + (test/is (= keychain/auth-method-biometric-prepare + (:auth-method db))))) + (test/testing "biometric auth canceled" + (let [{:keys [db]} (biometric/setup-done + {:db db} + {:bioauth-success false + :bioauth-message nil + :bioauth-code "USER_CANCELED"})] + (test/is (= nil db) "no db changes"))))))) + (test/testing (str "check save password, enable biometric auth," + "uncheck save password") + (let [initial-cofx {:db {:auth-method keychain/auth-method-none + :supported-biometric-auth true}} + {:keys [db]} (fx/merge + initial-cofx + (login/save-password true) + (biometric/enable) + (biometric/setup-done + {:bioauth-success true + :bioauth-message nil + :bioauth-code nil}) + (login/save-password false))] + (test/is (= true (get-in db [:multiaccounts/login :save-password?]))) + ;; case 2 from https://github.com/status-im/status-react/issues/9573 + (test/is (= keychain/auth-method-biometric-prepare (:auth-method db))) + (test/testing "disable biometric" + (let [{:keys [db]} (biometric/disable {:db db})] + (test/is (= false (get-in db [:multiaccounts/login :save-password?]))) + (test/is (= keychain/auth-method-none) (:auth-method db)))))) + (test/testing (str "check save password, skip biometric auth" + "uncheck save password, check again") + (let [initial-cofx {:db {:auth-method keychain/auth-method-none + :supported-biometric-auth true}} + {:keys [db]} (fx/merge + initial-cofx + (login/save-password true) + (login/save-password false) + (login/save-password false))] + ;; case 3 from https://github.com/status-im/status-react/issues/9573 + (test/is (= :secure-with-biometric (get-in db [:popover/popover :view])))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index ef71c28100d..7da973977b6 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -26,6 +26,7 @@ [status-im.test.mailserver.topics] [status-im.test.models.bootnode] [status-im.test.models.contact] + status-im.test.multiaccounts.login.core [status-im.test.multiaccounts.model] [status-im.test.multiaccounts.recover.core] [status-im.test.multiaccounts.update.core] @@ -98,6 +99,7 @@ 'status-im.test.mailserver.topics 'status-im.test.models.bootnode 'status-im.test.models.contact + 'status-im.test.multiaccounts.login.core 'status-im.test.multiaccounts.model 'status-im.test.multiaccounts.recover.core 'status-im.test.multiaccounts.update.core diff --git a/translations/en.json b/translations/en.json index dd39a731978..059e8c2c2fe 100644 --- a/translations/en.json +++ b/translations/en.json @@ -70,7 +70,8 @@ "biometric-auth-setting-label": "Use biometric authentication", "biometric-secure-with": "Secure with {{bio-type-label}}", "biometric-sign-in": "{{bio-type-label}} sign in", - "biometric-enable": "If you don't want to use your Keycard each time to access the app, enable ", + "biometric-enable-keycard": "If you don't want to use your Keycard each time to access the app, enable ", + "biometric-enable": "If you don't want to enter your password each time to access the app, enable ", "biometric-disable-bioauth": "disable {{bio-type-label}}", "biometric-disable-password-title": "Disable password saving", "biometric-disable-password-description": "If you disable this, you will also ",