-
Notifications
You must be signed in to change notification settings - Fork 332
[FS-705] Fix Repeated MLS Public Keys #2501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1987fae
cb4d3e5
7ca1ecf
608e018
5ea0d01
244d467
2e9a4ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix all clients having the same MLS public key |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ tests _cl _at opts p db b c g = | |
| test p "put /clients/:client - 200" $ testUpdateClient opts b, | ||
| test p "put /clients/:client - 200 (mls keys)" $ testMLSPublicKeyUpdate b, | ||
| test p "get /clients/:client - 404" $ testMissingClient b, | ||
| test p "get /clients/:client - 200" $ testMLSClient b, | ||
| test p "post /clients - 200 multiple temporary" $ testAddMultipleTemporary b g, | ||
| test p "client/prekeys/race" $ testPreKeyRace b | ||
| ] | ||
|
|
@@ -308,10 +309,15 @@ testListClients brig = do | |
| let (pk1, lk1) = (somePrekeys !! 0, (someLastPrekeys !! 0)) | ||
| let (pk2, lk2) = (somePrekeys !! 1, (someLastPrekeys !! 1)) | ||
| let (pk3, lk3) = (somePrekeys !! 2, (someLastPrekeys !! 2)) | ||
| c1 <- responseJsonMaybe <$> addClient brig uid (defNewClient PermanentClientType [pk1] lk1) | ||
| c2 <- responseJsonMaybe <$> addClient brig uid (defNewClient PermanentClientType [pk2] lk2) | ||
| c3 <- responseJsonMaybe <$> addClient brig uid (defNewClient TemporaryClientType [pk3] lk3) | ||
| let cs = sortBy (compare `on` clientId) $ catMaybes [c1, c2, c3] | ||
| c1 <- responseJsonError =<< addClient brig uid (defNewClient PermanentClientType [pk1] lk1) | ||
| c2 <- responseJsonError =<< addClient brig uid (defNewClient PermanentClientType [pk2] lk2) | ||
| c3 <- responseJsonError =<< addClient brig uid (defNewClient TemporaryClientType [pk3] lk3) | ||
|
|
||
| let pks = Map.fromList [(Ed25519, "random")] | ||
| void $ putClient brig uid (clientId c1) pks | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify this for me? From what I understood, this test checks that listing the clients work, but here we're updating something.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. An error is in fetching the list of clients, where we would accidentally associate an MLS public key from one client with the rest of clients, potentially non-MLS clients. This test sets an MLS public key for one of the three clients and asserts that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I thought that was what the new test did, but this one as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test |
||
| let c1' = c1 {clientMLSPublicKeys = pks} | ||
| let cs = sortBy (compare `on` clientId) [c1', c2, c3] | ||
|
|
||
| get | ||
| ( brig | ||
| . path "clients" | ||
|
|
@@ -321,6 +327,25 @@ testListClients brig = do | |
| const 200 === statusCode | ||
| const (Just cs) === responseJsonMaybe | ||
|
|
||
| testMLSClient :: Brig -> Http () | ||
| testMLSClient brig = do | ||
| uid <- userId <$> randomUser brig | ||
| let (pk1, lk1) = (somePrekeys !! 0, (someLastPrekeys !! 0)) | ||
| let (pk2, lk2) = (somePrekeys !! 1, (someLastPrekeys !! 1)) | ||
| -- An MLS client | ||
| c1 <- responseJsonError =<< addClient brig uid (defNewClient PermanentClientType [pk1] lk1) | ||
| -- Non-MLS client | ||
| c2 <- responseJsonError =<< addClient brig uid (defNewClient PermanentClientType [pk2] lk2) | ||
|
|
||
| let pks = Map.fromList [(Ed25519, "random")] | ||
| void $ putClient brig uid (clientId c1) pks | ||
|
|
||
| -- Assert that adding MLS public keys to one client does not affect the other | ||
| -- client | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
| getClient brig uid (clientId c2) !!! do | ||
| const 200 === statusCode | ||
| const (Just c2) === responseJsonMaybe | ||
|
|
||
| testListClientsBulk :: Opt.Opts -> Brig -> Http () | ||
| testListClientsBulk opts brig = do | ||
| uid1 <- userId <$> randomUser brig | ||
|
|
@@ -840,25 +865,11 @@ testMLSPublicKeyUpdate brig = do | |
| } | ||
| c <- responseJsonError =<< addClient brig uid clt | ||
| let keys = Map.fromList [(Ed25519, "aGVsbG8gd29ybGQ=")] | ||
| put | ||
| ( brig | ||
| . paths ["clients", toByteString' (clientId c)] | ||
| . zUser uid | ||
| . contentJson | ||
| . json (UpdateClient [] Nothing Nothing Nothing keys) | ||
| ) | ||
| !!! const 200 === statusCode | ||
| putClient brig uid (clientId c) keys !!! const 200 === statusCode | ||
| c' <- responseJsonError =<< getClient brig uid (clientId c) <!! const 200 === statusCode | ||
| liftIO $ clientMLSPublicKeys c' @?= keys | ||
| -- adding the key again should fail | ||
| put | ||
| ( brig | ||
| . paths ["clients", toByteString' (clientId c)] | ||
| . zUser uid | ||
| . contentJson | ||
| . json (UpdateClient [] Nothing Nothing Nothing keys) | ||
| ) | ||
| !!! const 400 === statusCode | ||
| putClient brig uid (clientId c) keys !!! const 400 === statusCode | ||
|
|
||
| testMissingClient :: Brig -> Http () | ||
| testMissingClient brig = do | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hlint will soon complain about not using
headhere. Whilst the consistent argument is a solid one, I don't think we want to disable the rule globally. I know this was already here, but just something to consider.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of not applying that hlint rule in tests. In tests we don't have to strive to have total functions and
headinstead of(!!).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I'll look into disabling the rule for test targets. 👍