From 0d91452641893f0f766de1b3a423cde6d1e93168 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Sat, 9 May 2020 23:43:39 +0200 Subject: [PATCH] add tests for serialising and deserialising messages --- Hash2Pub/src/Hash2Pub/ASN1Coding.hs | 6 +++--- Hash2Pub/test/FediChordSpec.hs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs index 1812d87..ec6aa46 100644 --- a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs +++ b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs @@ -71,11 +71,11 @@ chunkLength numParts totalSize = ceiling $ (realToFrac totalSize :: Double) / re -- The number of parts per message is limited to 150 for DOS protection reasons. -- The returned byte strings might exceed the desired maximum length, as only the payload (and not all of them) -- can be split into multiple parts. -serialiseMessage :: FediChordMessage -- mesage to be serialised in preparation for sending - -> Int -- maximum message size in bytes +serialiseMessage :: Int -- maximum message size in bytes + -> FediChordMessage -- mesage to be serialised in preparation for sending -> [BS.ByteString] -- list of ASN.1 DER encoded messages together representing -- the contents of the input message -serialiseMessage msg maxBytesLength = +serialiseMessage maxBytesLength msg = splitPayloadUntilSmallEnough 1 where splitPayloadUntilSmallEnough numParts diff --git a/Hash2Pub/test/FediChordSpec.hs b/Hash2Pub/test/FediChordSpec.hs index 30af766..a3bcd57 100644 --- a/Hash2Pub/test/FediChordSpec.hs +++ b/Hash2Pub/test/FediChordSpec.hs @@ -169,7 +169,7 @@ spec = do stabReqPayload = StabiliseRequestPayload pingReqPayload = PingRequestPayload qidResPayload1 = QueryIDResponsePayload { - queryResult = FOUND $ exampleNodeState + queryResult = FOUND exampleNodeState } qidResPayload2 = QueryIDResponsePayload { queryResult = FORWARD $ Set.fromList [ @@ -228,6 +228,8 @@ spec = do encodeDecodeAndCheck $ responseWith Leave lResPayload encodeDecodeAndCheck $ responseWith Stabilise stabResPayload encodeDecodeAndCheck $ responseWith Ping pingResPayload + it "messages are encoded and decoded to ASN.1 DER properly" $ do + deserialiseMessage (head $ serialiseMessage 652 $ responseWith Ping pingResPayload) `shouldBe` Right (responseWith Ping pingResPayload) -- some example data