[#9573] Fix some password saving bugs

This commit is contained in:
Roman Volosovskyi 2019-12-10 12:07:38 +02:00
parent 4a40b6f033
commit beed1a60ee
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 98 additions and 4 deletions

View File

@ -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"]]

View File

@ -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?)

View File

@ -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]

View File

@ -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})]]}]))

View File

@ -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]))))))

View File

@ -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

View File

@ -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 ",