Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit b7f1e5d

Browse files
committed
[CBR-437] Add emptyPassphrase check
When the password is updated we should check if it is the `emptyPassphrase` and, if so, update `HdRoot` to have no spending password. This commit also adds a test property that ensures the hdRoot has no spending password afterwards, and modifies the existing property to only test updates with non-empty passwords, where we expect the new hdRoot to *have* a spending password.
1 parent 74a19e5 commit b7f1e5d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

wallet-new/src/Cardano/Wallet/Kernel/Wallets.hs

+9-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,15 @@ updatePassword pw hdRootId oldPassword newPassword = do
384384
-- was set.
385385
-- Fix this properly as part of [CBR-404].
386386
lastUpdateNow <- InDb <$> getCurrentTimestamp
387-
let hasSpendingPassword = HD.HasSpendingPassword lastUpdateNow
387+
388+
-- There is no such thing as "removing" the spending password.
389+
-- However, it can be set to the empty string. We check for that
390+
-- here and update 'hasSpendingPassword' on 'HdRoot' accordingly.
391+
let hasSpendingPassword =
392+
if newPassword == emptyPassphrase
393+
then HD.NoSpendingPassword
394+
else HD.HasSpendingPassword lastUpdateNow
395+
388396
res <- update' (pw ^. wallets)
389397
(UpdateHdRootPassword hdRootId hasSpendingPassword)
390398
case res of

wallet-new/test/unit/Test/Spec/Wallets.hs

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE TypeApplications #-}
34
module Test.Spec.Wallets (
45
spec
@@ -23,6 +24,7 @@ import qualified Cardano.Wallet.Kernel.BIP39 as BIP39
2324
import Cardano.Wallet.Kernel.DB.HdWallet (AssuranceLevel (..),
2425
HdRootId (..), UnknownHdRoot (..), WalletName (..),
2526
hdRootId)
27+
import qualified Cardano.Wallet.Kernel.DB.HdWallet as HD
2628
import Cardano.Wallet.Kernel.DB.HdWallet.Create
2729
(CreateHdRootError (..))
2830
import Cardano.Wallet.Kernel.DB.InDb (InDb (..))
@@ -327,6 +329,24 @@ spec = describe "Wallets" $ do
327329
newKey `shouldSatisfy` isJust
328330
(fmap hash newKey) `shouldSatisfy` (not . (==) (fmap hash oldKey))
329331

332+
prop "correctly updates hdRootHasPassword" $ do
333+
monadicIO $ do
334+
newPwd <- pick arbitrary
335+
withNewWalletFixture $ \ _ _ wallet Fixture{..} -> do
336+
res <- Kernel.updatePassword wallet
337+
fixtureHdRootId
338+
(unV1 fixtureSpendingPassword)
339+
newPwd
340+
let passphraseIsEmpty = newPwd == emptyPassphrase
341+
let satisfied = \case
342+
HD.NoSpendingPassword -> passphraseIsEmpty
343+
HD.HasSpendingPassword _ -> not passphraseIsEmpty
344+
case res of
345+
Left e -> fail (show e)
346+
Right (_, newRoot) -> do
347+
(newRoot ^. HD.hdRootHasPassword) `shouldSatisfy` satisfied
348+
349+
330350
describe "Wallet update password (Servant)" $ do
331351
prop "works as expected in the happy path scenario" $ withMaxSuccess 50 $ do
332352
monadicIO $ do

0 commit comments

Comments
 (0)