Skip to content

Commit

Permalink
More tests for OTR messages using protobuf (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiago-loureiro authored May 15, 2020
1 parent 800cd74 commit 62fcb81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ postCryptoMessage5 = do
conv <- decodeConvId <$> postConv alice [bob, eve] (Just "gossip") [] Nothing Nothing
-- Missing eve
let m = [(bob, bc, "hello bob")]
let m' = otrRecipients [(bob, [(bc, encodeCiphertext "hello bob")])]
-- These three are equivalent (i.e. report all missing clients)
postOtrMessage id alice ac conv m
!!! const 412 === statusCode
Expand All @@ -341,8 +342,18 @@ postCryptoMessage5 = do
-- Report missing clients of a specific user only
postOtrMessage (queryItem "report_missing" (toByteString' bob)) alice ac conv m
!!! const 201 === statusCode
-- Let's make sure that the same logic using protobuf in the body works too
postProtoOtrMessage' Nothing (queryItem "report_missing" (toByteString' bob)) alice ac conv m'
!!! const 201 === statusCode
-- Body takes precedence
postOtrMessage' (Just [makeIdOpaque bob]) (queryItem "report_missing" (toByteString' eve)) alice ac conv m
!!! const 201 === statusCode
-- Set it only in the body of the message
postOtrMessage' (Just [makeIdOpaque bob]) id alice ac conv m
!!! const 201 === statusCode
-- Let's make sure that protobuf works too, when specified in the body only
postProtoOtrMessage' (Just [makeIdOpaque bob]) id alice ac conv m'
!!! const 201 === statusCode
_rs <-
postOtrMessage (queryItem "report_missing" (toByteString' eve)) alice ac conv []
<!! const 412 === statusCode
Expand Down
8 changes: 6 additions & 2 deletions services/galley/test/integration/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,15 @@ mkOtrMessage (usr, clt, m) = (fn usr, HashMap.singleton (fn clt) m)
fn = fromJust . fromByteString . toByteString'

postProtoOtrMessage :: UserId -> ClientId -> ConvId -> OtrRecipients -> TestM ResponseLBS
postProtoOtrMessage u d c rec = do
postProtoOtrMessage = postProtoOtrMessage' Nothing id

postProtoOtrMessage' :: Maybe [OpaqueUserId] -> (Request -> Request) -> UserId -> ClientId -> ConvId -> OtrRecipients -> TestM ResponseLBS
postProtoOtrMessage' reportMissing modif u d c rec = do
g <- view tsGalley
let m = runPut (encodeMessage $ mkOtrProtoMessage d rec Nothing)
let m = runPut (encodeMessage $ mkOtrProtoMessage d rec reportMissing)
in post $
g
. modif
. paths ["conversations", toByteString' c, "otr", "messages"]
. zUser u
. zConn "conn"
Expand Down

0 comments on commit 62fcb81

Please sign in to comment.