Skip to content

Commit

Permalink
[#9573] Fix some password saving bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Dec 11, 2019
1 parent 4a40b6f commit beed1a6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 7 additions & 2 deletions src/status_im/ui/screens/biometric/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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})]]}]))
75 changes: 75 additions & 0 deletions test/cljs/status_im/test/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
@@ -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]))))))
2 changes: 2 additions & 0 deletions test/cljs/status_im/test/runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down

0 comments on commit beed1a6

Please sign in to comment.