module Signet.Unstable.Type.SymmetricSignatureTest where import qualified Crypto.Hash as Hash import qualified Data.ByteString as ByteString import qualified Data.ByteString.Char8 as Ascii import qualified Heck as Test import qualified Signet.Unstable.Exception.InvalidSymmetricSignature as InvalidSymmetricSignature import qualified Signet.Unstable.Type.SymmetricSignature as SymmetricSignature spec :: (Applicative io, Monad tree) => Test.Test io tree -> tree () spec :: forall (io :: * -> *) (tree :: * -> *). (Applicative io, Monad tree) => Test io tree -> tree () spec Test io tree test = Test io tree -> String -> tree () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> n () -> n () Test.describe Test io tree test String "Signet.Unstable.Type.SymmetricSignature" (tree () -> tree ()) -> tree () -> tree () forall a b. (a -> b) -> a -> b $ do Test io tree -> String -> tree () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> n () -> n () Test.describe Test io tree test String "parse" (tree () -> tree ()) -> tree () -> tree () forall a b. (a -> b) -> a -> b $ do Test io tree -> String -> io () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> m () -> n () Test.it Test io tree test String "fails with invalid symmetric signature" (io () -> tree ()) -> io () -> tree () forall a b. (a -> b) -> a -> b $ do let byteString :: ByteString byteString = String -> ByteString Ascii.pack String "invalid" let result :: Either InvalidSymmetricSignature SymmetricSignature result = ByteString -> Either InvalidSymmetricSignature SymmetricSignature SymmetricSignature.parse ByteString byteString Test io tree -> Either InvalidSymmetricSignature SymmetricSignature -> Either InvalidSymmetricSignature SymmetricSignature -> io () forall (m :: * -> *) a (n :: * -> *). (HasCallStack, Applicative m, Eq a, Show a) => Test m n -> a -> a -> m () Test.assertEq Test io tree test Either InvalidSymmetricSignature SymmetricSignature result (InvalidSymmetricSignature -> Either InvalidSymmetricSignature SymmetricSignature forall a b. a -> Either a b Left (ByteString -> InvalidSymmetricSignature InvalidSymmetricSignature.MkInvalidSymmetricSignature ByteString byteString)) Test io tree -> String -> io () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> m () -> n () Test.it Test io tree test String "succeeds with valid symmetric signature" (io () -> tree ()) -> io () -> tree () forall a b. (a -> b) -> a -> b $ do let byteString :: ByteString byteString = String -> ByteString Ascii.pack String "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=" let signature :: SymmetricSignature signature = Digest SHA256 -> SymmetricSignature SymmetricSignature.MkSymmetricSignature (Digest SHA256 -> SymmetricSignature) -> Digest SHA256 -> SymmetricSignature forall a b. (a -> b) -> a -> b $ ByteString -> Digest SHA256 forall ba a. (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a Hash.hash ByteString ByteString.empty Test io tree -> Either InvalidSymmetricSignature SymmetricSignature -> Either InvalidSymmetricSignature SymmetricSignature -> io () forall (m :: * -> *) a (n :: * -> *). (HasCallStack, Applicative m, Eq a, Show a) => Test m n -> a -> a -> m () Test.assertEq Test io tree test (ByteString -> Either InvalidSymmetricSignature SymmetricSignature SymmetricSignature.parse ByteString byteString) (SymmetricSignature -> Either InvalidSymmetricSignature SymmetricSignature forall a b. b -> Either a b Right SymmetricSignature signature) Test io tree -> String -> tree () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> n () -> n () Test.describe Test io tree test String "render" (tree () -> tree ()) -> tree () -> tree () forall a b. (a -> b) -> a -> b $ do Test io tree -> String -> io () -> tree () forall (m :: * -> *) (n :: * -> *). Test m n -> String -> m () -> n () Test.it Test io tree test String "renders symmetric signature correctly" (io () -> tree ()) -> io () -> tree () forall a b. (a -> b) -> a -> b $ do let signature :: SymmetricSignature signature = Digest SHA256 -> SymmetricSignature SymmetricSignature.MkSymmetricSignature (Digest SHA256 -> SymmetricSignature) -> Digest SHA256 -> SymmetricSignature forall a b. (a -> b) -> a -> b $ ByteString -> Digest SHA256 forall ba a. (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a Hash.hash ByteString ByteString.empty Test io tree -> ByteString -> ByteString -> io () forall (m :: * -> *) a (n :: * -> *). (HasCallStack, Applicative m, Eq a, Show a) => Test m n -> a -> a -> m () Test.assertEq Test io tree test (SymmetricSignature -> ByteString SymmetricSignature.render SymmetricSignature signature) (String -> ByteString Ascii.pack String "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")