-
Notifications
You must be signed in to change notification settings - Fork 333
Do not fail user deletion when a remote notification fails #1912
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3de6374
Refactor: withMockedFederatorAndGalley
smatting 3072d15
brig: ignore when remote notifications fail
smatting 848bf17
extend test case with a domain that is unvailable
smatting 3efc96d
Remove FUTUREWORK, done in #1891
smatting 6991453
Add changelog entry
smatting d92e7fa
Refactor: Changes from review
smatting File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog.d/6-federation/dont-fail-user-deletion-unavailble-remotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Do not fail user deletion when a remote notification fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,7 @@ tests _ at opts p b c ch g aws = | |
| test' aws p "delete /i/users/:uid - 202" $ testDeleteInternal b c aws, | ||
| test' aws p "delete with profile pic" $ testDeleteWithProfilePic b ch, | ||
| test' aws p "delete with connected remote users" $ testDeleteWithRemotes opts b, | ||
| test' aws p "delete with connected remote users and failed remote notifcations" $ testDeleteWithRemotesAndFailedNotifications opts b c, | ||
| test' aws p "put /i/users/:uid/sso-id" $ testUpdateSSOId b g, | ||
| testGroup | ||
| "temporary customer extensions" | ||
|
|
@@ -1224,7 +1225,7 @@ testDeleteWithRemotes opts brig = do | |
| sendConnectionAction brig opts (userId localUser) remote2UserBlocked (Just FedBrig.RemoteConnect) Accepted | ||
| void $ putConnectionQualified brig (userId localUser) remote2UserBlocked Blocked | ||
|
|
||
| let fedMockResponse = OutwardResponseBody (cs $ Aeson.encode EmptyResponse) | ||
| let fedMockResponse = const (OutwardResponseBody (cs $ Aeson.encode EmptyResponse)) | ||
| let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response | ||
| galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = | ||
| case (requestMethod, requestPath) of | ||
|
|
@@ -1257,6 +1258,56 @@ testDeleteWithRemotes opts brig = do | |
| (eitherDecode . cs) (F.body r) | ||
| Nothing -> Left "No request" | ||
|
|
||
| testDeleteWithRemotesAndFailedNotifications :: Opt.Opts -> Brig -> Cannon -> Http () | ||
| testDeleteWithRemotesAndFailedNotifications opts brig cannon = do | ||
| alice <- randomUser brig | ||
| alex <- randomUser brig | ||
| let localDomain = qDomain (userQualifiedId alice) | ||
|
|
||
| let bDomain = Domain "b.example.com" | ||
| cDomain = Domain "c.example.com" | ||
| bob <- Qualified <$> randomId <*> pure bDomain | ||
| carl <- Qualified <$> randomId <*> pure cDomain | ||
|
|
||
| postConnection brig (userId alice) (userId alex) !!! const 201 === statusCode | ||
| putConnection brig (userId alex) (userId alice) Accepted !!! const 200 === statusCode | ||
| sendConnectionAction brig opts (userId alice) bob (Just FedBrig.RemoteConnect) Accepted | ||
| sendConnectionAction brig opts (userId alice) carl (Just FedBrig.RemoteConnect) Accepted | ||
|
|
||
| let fedMockResponse req = | ||
| if Domain (F.domain req) == bDomain | ||
| then F.OutwardResponseError (F.OutwardError F.ConnectionRefused "mocked connection problem with b domain") | ||
| else OutwardResponseBody (cs $ Aeson.encode EmptyResponse) | ||
|
|
||
| let galleyHandler :: ReceivedRequest -> MockT IO Wai.Response | ||
| galleyHandler (ReceivedRequest requestMethod requestPath _requestBody) = | ||
| case (requestMethod, requestPath) of | ||
| (_methodDelete, ["i", "user"]) -> do | ||
| let response = Wai.responseLBS Http.status200 [(Http.hContentType, "application/json")] (cs $ Aeson.encode EmptyResponse) | ||
| pure response | ||
| _ -> error "not mocked" | ||
|
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. There's no need to pattern match on
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. Yes, you're right. I changed this to a proper pattern match in d92e7fa |
||
|
|
||
| (_, rpcCalls, _galleyCalls) <- WS.bracketR cannon (userId alex) $ \wsAlex -> do | ||
| let action = withMockedFederatorAndGalley opts localDomain fedMockResponse galleyHandler $ do | ||
| deleteUser (userId alice) (Just defPassword) brig !!! do | ||
| const 200 === statusCode | ||
| liftIO action <* do | ||
| void . liftIO . WS.assertMatch (5 # Second) wsAlex $ matchDeleteUserNotification (userQualifiedId alice) | ||
|
|
||
| liftIO $ do | ||
| rRpc <- assertOne $ filter (\c -> F.domain c == domainText cDomain) rpcCalls | ||
| cUdn <- assertRight $ parseFedRequest rRpc | ||
| udcnUser cUdn @?= userId alice | ||
| sort (fromRange (udcnConnections cUdn)) | ||
| @?= sort (map qUnqualified [carl]) | ||
| where | ||
| parseFedRequest :: FromJSON a => F.FederatedRequest -> Either String a | ||
| parseFedRequest fr = | ||
| case F.request fr of | ||
| Just r -> | ||
| (eitherDecode . cs) (F.body r) | ||
| Nothing -> Left "No request" | ||
|
|
||
| testUpdateSSOId :: Brig -> Galley -> Http () | ||
| testUpdateSSOId brig galley = do | ||
| noSuchUserId <- Id <$> liftIO UUID.nextRandom | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A pattern like this is encapsulated by
whenLeft :: Applicative m => Either a b -> (a -> m ()) -> m ().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.
Ah nice, done.