Skip to content

Commit

Permalink
add golden 1
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 23, 2024
1 parent 08911d1 commit 781f2d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ module Cardano.Wallet.Api.Http.Shelley.Server
, rndStateChange
, withWorkerCtx
, getCurrentEpoch
, toMetadataEncrypted

-- * Workers
, manageRewardBalance
Expand Down Expand Up @@ -3159,7 +3160,7 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
-- (b) encrypt the 'msg' values if present, if there is no 'msg' value emit error
-- (c) update value of `msg` with the encrypted initial value(s) encoded in base64
-- [TxMetaText base64_1, TxMetaText base64_2, ..., TxMetaText base64_n]
-- (d) add `enc` field with encryption method value 'base'
-- (d) add `enc` field with encryption method value 'basic'
toMetadataEncrypted
:: ApiEncryptMetadata
-> TxMetadataWithSchema
Expand Down Expand Up @@ -3206,7 +3207,7 @@ toMetadataEncrypted apiEncrypt payload = do
Cardano.metadataValueToJsonNoSchema metaValue
encMethodEntry =
( Cardano.TxMetaText "enc"
, Cardano.TxMetaText "base"
, Cardano.TxMetaText "basic"
)
toPair enc =
[ ( Cardano.TxMetaText metaField
Expand Down
32 changes: 25 additions & 7 deletions lib/unit/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ import Cardano.Wallet.Address.Keys.WalletKey
import Cardano.Wallet.Api
( Api
)
import Cardano.Wallet.Api.Http.Shelley.Server
( toMetadataEncrypted
)
import Cardano.Wallet.Api.Types
( AccountPostData (..)
, AddressAmount (..)
Expand Down Expand Up @@ -1174,13 +1177,28 @@ spec = do
parseUrlPiece "patate"
`shouldBe` (Left @Text @(ApiT AddressState) msg)

describe "Api Errors" $ do
it "Every ApiErrorInfo constructor has a corresponding schema type" $
let res = fromJSON @SchemaApiErrorInfo specification
errStr = case res of
Error s -> s
_ -> ""
in counterexample errStr $ res == Success SchemaApiErrorInfo
describe "toMetadataEncrypted openssl goldens" $ do
-- $ echo -n '"secret data"' | openssl enc -e -aes-256-cbc -pbkdf2 -iter 10000 -a -k "cardano" -nosalt
-- vBSywXY+WGcrckHUCyjJcQ==
it "msg is 0-level deep short - no salt" $ do
let apiEncrypt = ApiEncryptMetadata
{ passphrase = ApiT $ Passphrase "cardano"
, enc = Nothing
}
schemaBefore = TxMetadataWithSchema TxMetadataNoSchema $ Cardano.TxMetadata $ Map.fromList
[( 0, Cardano.TxMetaMap
[ (Cardano.TxMetaText "field", Cardano.TxMetaNumber 123)
, (Cardano.TxMetaText "msg", Cardano.TxMetaText "secret data")
])
]
schemaAfter = Cardano.TxMetadata $ Map.fromList $
[ (0, Cardano.TxMetaMap
[ (Cardano.TxMetaText "field", Cardano.TxMetaNumber 123)
, (Cardano.TxMetaText "msg", Cardano.TxMetaList [Cardano.TxMetaText "vBSywXY+WGcrckHUCyjJcQ=="])
, (Cardano.TxMetaText "enc", Cardano.TxMetaText "basic")
])
]
toMetadataEncrypted apiEncrypt schemaBefore `shouldBe` Right schemaAfter

{-------------------------------------------------------------------------------
Error type encoding
Expand Down

0 comments on commit 781f2d7

Please sign in to comment.