HomePhabricator
Diffusion Comm 477ec3ca967d

[lib] Dispatch SET_NEW_SESSION when session recovery fails

Description

[lib] Dispatch SET_NEW_SESSION when session recovery fails

Summary:
Prior to D10952, the code in call-single-keyserver-endpoint.js would handle dispatching SET_NEW_SESSION for a failed session recovery.

In that diff, I changed that behavior. The reason was that we can have multiple simultaneous callSingleKeyserverEndpoint calls. Even if they trigger only a single session recovery, when that session recovery fails it would result in multiple SET_NEW_SESSION actions, since they will be dispatched by multiple callSingleKeyserverEndpoint calls.

Now that callSingleKeyserverEndpoint isn't handling SET_NEW_SESSION for failed session recoveries, we need to handle it elsewhere. The KeyserverConnectionHandler is the right place, since it is where we handle the session recovery, and we are able to ensure that only a single session recovery is running for a particular keyserver at one time.

I considered leaving the setSessionRecoveryInProgressActionType calls there, but decided against it because it's bad Redux practice to dispatch two actions in a row, instead of having a single action handle everything. In order for the SET_NEW_SESSION call to handle flipping sessionRecoveryInProgress, I made some changes to D10949.

I decided to make this a separate diff (instead of including it in D10954) because there are some substantial changes here. I will annotate them inline.

Depends on D10954

Test Plan:

  1. Test successful session invalidation in single keyserver world
    1. I prevented the Socket from rendering by adding a return null line before the other returns in KeyserverConnectionHandler. This avoided the Socket triggering session recovery.
    2. I started the iOS simulator and logged in using a test user.
    3. I opened the Redux Dev Tools
    4. I deleted the test user's cookie from the MariaDB database: DELETE FROM cookies WHERE user = 6390578 AND platform = 'ios'
    5. I sent a message as the test user
    6. I confirmed that session recovery was triggered in the Redux dev tools (and through some console logs)
    7. I repeated the process above several times to make sure it consistently worked multiple times in a single run
    8. I confirmed that the message was delivered "transparently" (without any visible issues, or evidence of session invalidation)
  2. Test failed session invalidation in single keyserver world
    1. I ran through the above test, but I hacked legacy-recover-keyserver-session.js to use the wrong password so the session recovery would fail
    2. I confirmed that I was logged out, and that an alert appeared explaining that my session was invalidated
  3. Test logging out during session recovery
    1. I triggered an infinite loop of session recoveries by running through the above test, but swallowing the SET_NEW_SESSION
    2. I logged out of the app
    3. I confirmed that the session recovery loop stopped, and that I was logged out successfully

Reviewers: tomek, inka

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D10970

Details