Skip to content

Commit

Permalink
error testing
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 23, 2024
1 parent 65027a9 commit 1275c1f
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion lib/unit/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ import Cardano.Pool.Types
, PoolOwner (..)
, StakePoolTicker (..)
)
import Cardano.Wallet
( ErrConstructTx (..)
)
import Cardano.Wallet.Address.Derivation
( Depth (..)
, DerivationIndex (..)
Expand Down Expand Up @@ -1316,7 +1319,7 @@ spec = do
-- $ $ echo -n '["Invoice-No: 123456789","Order-No: 7654321","Email: john@doe.com"]' | openssl enc -e -aes-256-cbc -pbkdf2 -iter 10000 -a -k "cardano" -S 3030303030303030
-- U2FsdGVkX18wMDAwMDAwMFlOS4b0tXrZA7U5aQaHeI/sP74h84EPEjGv0wl4D8Do
-- +SIXXn04a9xkoFHk4ZH281nIfH5lpClsO16p2vRpSsdBDFO78aTPX3bsHsRE0L2A
it "cip msg - no salt" $ do
it "cip msg - salted" $ do
let apiEncrypt = ApiEncryptMetadata
{ passphrase = ApiT $ Passphrase "cardano"
, enc = Nothing
Expand Down Expand Up @@ -1344,6 +1347,42 @@ spec = do
toMetadataEncrypted apiEncrypt schemaBefore saltM
`shouldBe` Right schemaAfter

it "msg wrong label - no salt" $ do
let apiEncrypt = ApiEncryptMetadata
{ passphrase = ApiT $ Passphrase "cardano"
, enc = Nothing
}
schemaBefore = TxMetadataWithSchema TxMetadataNoSchema $ Cardano.TxMetadata $ Map.fromList
[( 675, Cardano.TxMetaMap
[ (Cardano.TxMetaText "field", Cardano.TxMetaNumber 123)
, (Cardano.TxMetaText "msg", Cardano.TxMetaList
[ Cardano.TxMetaText "Invoice-No: 123456789"
, Cardano.TxMetaText "Order-No: 7654321"
, Cardano.TxMetaText "Email: john@doe.com"
])
])
]
toMetadataEncrypted apiEncrypt schemaBefore Nothing
`shouldBe` Left ErrConstructTxIncorrectRawMetadata

it "msg without 'msg field' - no salt" $ do
let apiEncrypt = ApiEncryptMetadata
{ passphrase = ApiT $ Passphrase "cardano"
, enc = Nothing
}
schemaBefore = TxMetadataWithSchema TxMetadataNoSchema $ Cardano.TxMetadata $ Map.fromList
[( 674, Cardano.TxMetaMap
[ (Cardano.TxMetaText "field", Cardano.TxMetaNumber 123)
, (Cardano.TxMetaText "msgs", Cardano.TxMetaList
[ Cardano.TxMetaText "Invoice-No: 123456789"
, Cardano.TxMetaText "Order-No: 7654321"
, Cardano.TxMetaText "Email: john@doe.com"
])
])
]
toMetadataEncrypted apiEncrypt schemaBefore Nothing
`shouldBe` Left ErrConstructTxIncorrectRawMetadata

fromHexToM :: Text -> Maybe ByteString
fromHexToM = rightToMaybe . convertFromBase Base16 . T.encodeUtf8

Expand Down

0 comments on commit 1275c1f

Please sign in to comment.