Skip to content

Commit

Permalink
Merge pull request #267 from input-output-hk/KtorZ/265/fix-inconsiten…
Browse files Browse the repository at this point in the history
…t-response-code-wallet-update

Fix inconsitent response code wallet update
  • Loading branch information
piotr-iohk committed May 15, 2019
2 parents aecc07f + 22a9ecb commit 95bc4e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -30,6 +30,7 @@ module Cardano.Wallet
, ErrUpdatePassphrase (..)
, ErrWalletAlreadyExists (..)
, ErrWithRootKey (..)
, ErrWrongPassphrase(..)

-- * Construction
, newWalletLayer
Expand Down
11 changes: 9 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -24,6 +24,8 @@ import Cardano.Wallet
, ErrSubmitTx (..)
, ErrUpdatePassphrase (..)
, ErrWalletAlreadyExists (..)
, ErrWithRootKey (..)
, ErrWrongPassphrase (..)
, WalletLayer
)
import Cardano.Wallet.Api
Expand Down Expand Up @@ -267,6 +269,11 @@ instance LiftHandler ErrWalletAlreadyExists where
handler = \case
ErrWalletAlreadyExists _ -> err409

instance LiftHandler ErrWithRootKey where
handler = \case
ErrWithRootKeyNoRootKey _ -> err404
ErrWithRootKeyWrongPassphrase ErrWrongPassphrase -> err403

instance LiftHandler ErrCreateUnsignedTx where
handler = \case
ErrCreateUnsignedTxNoSuchWallet _ -> err404
Expand All @@ -277,12 +284,12 @@ instance LiftHandler ErrSignTx where
handler = \case
ErrSignTx _ -> err500
ErrSignTxNoSuchWallet _ -> err410
ErrSignTxWithRootKey _ -> err403
ErrSignTxWithRootKey e -> handler e

instance LiftHandler ErrSubmitTx where
handler _ = err500

instance LiftHandler ErrUpdatePassphrase where
handler = \case
ErrUpdatePassphraseNoSuchWallet _ -> err404
ErrUpdatePassphraseWithRootKey _ -> err403
ErrUpdatePassphraseWithRootKey e -> handler e
Expand Up @@ -1207,20 +1207,16 @@ spec = do
let payload = updatePassPayload "Secure passphrase" "Secure passphrase2"
let delEndp = "v2/wallets" </> (getFromResponse walletId r)
_ <- request @ApiWallet ctx ("DELETE", delEndp) Default Empty

let updEndp = delEndp </> ("passphrase" :: Text)
rup <- request @ApiWallet ctx ("PUT", updEndp) Default payload
expectResponseCode @IO HTTP.status403 rup
expectResponseCode @IO HTTP.status404 rup

describe "WALLETS_UPDATE_PASS_04 - non-existing wallets" $ do
forM_ falseWalletIds $ \(title, walId) -> it title $ \ctx -> do
let payload = updatePassPayload "Secure passphrase" "Secure passphrase2"
let endpoint = "v2/wallets" </> T.pack walId </> ("passphrase" :: Text)
rup <- request @ApiWallet ctx ("PUT", endpoint) Default payload
if (title == "40 chars hex") then
expectResponseCode @IO HTTP.status403 rup
else
expectResponseCode @IO HTTP.status404 rup
expectResponseCode @IO HTTP.status404 rup

it "WALLETS_UPDATE_PASS_04 - 'almost' valid walletId" $ \ctx -> do
r <- request @ApiWallet ctx ("POST", "v2/wallets") Default simplePayload
Expand Down

0 comments on commit 95bc4e2

Please sign in to comment.