From b4d6181240a1540025461cb310b781ac58db1837 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 30 Jul 2020 09:39:07 +0000 Subject: [PATCH] Add test to confirm delay for unsuccessful authentications. Add integration test to confirm that an unsuccessful attempt to authenticate results in a delay of minimumAuthenticationFailureTime or longer. --- .../Integration/Scenario/API/Shelley/Wallets.hs | 17 +++++++++++++++++ lib/core/src/Cardano/Wallet.hs | 1 + 2 files changed, 18 insertions(+) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs index 40afe5ceb37..876e871b8ce 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs @@ -26,6 +26,8 @@ import Cardano.Mnemonic , genEntropy , mnemonicToText ) +import Cardano.Wallet + ( minimumExecutionTimeOnAuthFailure ) import Cardano.Wallet.Api.Types ( AddressAmount (..) , ApiByronWallet @@ -68,6 +70,8 @@ import Data.Text ( Text ) import Data.Text.Class ( toText ) +import Data.Time + ( diffUTCTime, getCurrentTime ) import Data.Word ( Word64 ) import Test.Hspec @@ -933,6 +937,19 @@ spec = do rup <- request @ApiWallet ctx endpoint headers payload verify rup expectations + it "WALLETS_UPDATE_PASS_08 - Delay on authentication failure" $ \ctx -> do + w <- emptyWalletWith ctx + ("Wallet to update pass", "cardano-passphrase", 20) + let payload = updatePassPayload "incorrect-passphrase" "whatever-pass" + startTime <- getCurrentTime + rup <- request @ApiWallet ctx + (Link.putWalletPassphrase @'Shelley w) Default payload + endTime <- getCurrentTime + let timeElapsed = endTime `diffUTCTime` startTime + timeElapsed `shouldSatisfy` (> minimumExecutionTimeOnAuthFailure) + expectResponseCode @IO HTTP.status403 rup + expectErrorMessage errMsg403WrongPass rup + it "WALLETS_COIN_SELECTION_01 - \ \A singleton payment is included in the coin selection output." $ \ctx -> do diff --git a/lib/core/src/Cardano/Wallet.hs b/lib/core/src/Cardano/Wallet.hs index fd67be5002d..0ab128bede1 100644 --- a/lib/core/src/Cardano/Wallet.hs +++ b/lib/core/src/Cardano/Wallet.hs @@ -164,6 +164,7 @@ module Cardano.Wallet , ErrStartTimeLaterThanEndTime (..) -- ** Root Key + , minimumExecutionTimeOnAuthFailure , withRootKey , ErrWithRootKey (..) , ErrWrongPassphrase (..)