Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsitent response code wallet update #267

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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