biscuit-haskell 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+52/−16 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- biscuit-haskell.cabal +1/−1
- src/Auth/Biscuit.hs +2/−2
- test/Spec/Roundtrip.hs +49/−13
biscuit-haskell.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0 name: biscuit-haskell-version: 0.1.0.0+version: 0.1.1.0 category: Security synopsis: Library support for the Biscuit security token description: Please see the README on GitHub at <https://github.com/divarvel/biscuit-haskell#readme>
src/Auth/Biscuit.hs view
@@ -182,9 +182,9 @@ -- | Serialize a biscuit to URL-compatible base 64, as recommended by the spec serializeB64 :: Biscuit -> ByteString-serializeB64 = Hex.encode . serialize+serializeB64 = B64.encodeBase64' . serialize -- | Serialize a biscuit to a hex (base 16) string. Be advised that the specs -- recommends base 64 instead. serializeHex :: Biscuit -> ByteString-serializeHex = B64.encodeBase64' . serialize+serializeHex = Hex.encode . serialize
test/Spec/Roundtrip.hs view
@@ -5,7 +5,7 @@ ( specs ) where --- import qualified Data.ByteString as ByteString+import Data.ByteString (ByteString) import Data.List.NonEmpty (NonEmpty ((:|))) import Test.Tasty import Test.Tasty.HUnit@@ -15,34 +15,51 @@ specs :: TestTree specs = testGroup "Serde roundtrips"- [ singleBlock- , multipleBlocks+ [ testGroup "Raw serde"+ [ singleBlock (serialize, parse)+ , multipleBlocks (serialize, parse)+ ]+ , testGroup "B64 serde"+ [ singleBlock (serializeB64, parseB64)+ , multipleBlocks (serializeB64, parseB64)+ ]+ , testGroup "Hex serde"+ [ singleBlock (serializeHex, parseHex)+ , multipleBlocks (serializeHex, parseHex)+ ]+ , testGroup "Keys serde"+ [ private+ , public+ ] ] -roundtrip :: NonEmpty Block+type Roundtrip = (Biscuit -> ByteString, ByteString -> Either ParseError Biscuit)++roundtrip :: Roundtrip+ -> NonEmpty Block -> Assertion-roundtrip i@(authority' :| blocks') = do+roundtrip (s,p) i@(authority' :| blocks') = do let addBlocks bs biscuit = case bs of (b:rest) -> addBlocks rest =<< addBlock b biscuit [] -> pure biscuit keypair <- newKeypair init' <- mkBiscuit keypair authority' final <- addBlocks blocks' init'- let serialized = serialize final- parsed = parse serialized+ let serialized = s final+ parsed = p serialized getBlocks Biscuit{..} = snd (snd authority) :| (snd . snd <$> blocks) getBlocks <$> parsed @?= Right i -singleBlock :: TestTree-singleBlock = testCase "Single block" $ roundtrip $ pure+singleBlock :: Roundtrip -> TestTree+singleBlock r = testCase "Single block" $ roundtrip r $ pure [block| right(#authority, "file1", #read); right(#authority, "file2", #read); right(#authority, "file1", #write); |] -multipleBlocks :: TestTree-multipleBlocks = testCase "Multiple block" $ roundtrip $+multipleBlocks :: Roundtrip -> TestTree+multipleBlocks r = testCase "Multiple block" $ roundtrip r $ [block| right(#authority, "file1", #read); right(#authority, "file2", #read);@@ -53,7 +70,6 @@ valid_date($1) <- time(#ambient, $0), resource(#ambient, $1), $0 <= 1999-12-31T12:59:59+00:00, !["file1"].contains($1); check if valid_date($0), resource(#ambient, $0); |]- ] {- , [block| check if true; check if !false;@@ -96,4 +112,24 @@ check if resource(#ambient, "file1"); check if time(#ambient, $date), $date <= 2018-12-20T00:00:00+00:00; |]- ]-}+ ]++private :: TestTree+private = testGroup "Private key serde"+ [ testCase "Raw bytes" $ do+ pk <- privateKey <$> newKeypair+ parsePrivateKey (serializePrivateKey pk) @?= Just pk+ , testCase "Hex encoding" $ do+ pk <- privateKey <$> newKeypair+ parsePrivateKeyHex (serializePrivateKeyHex pk) @?= Just pk+ ]++public :: TestTree+public = testGroup "Public key serde"+ [ testCase "Raw bytes" $ do+ pk <- publicKey <$> newKeypair+ parsePublicKey (serializePublicKey pk) @?= Just pk+ , testCase "Hex encoding" $ do+ pk <- publicKey <$> newKeypair+ parsePublicKeyHex (serializePublicKeyHex pk) @?= Just pk+ ]