Repository navigation
QA environment: sign out when switching into or out of QA - #108234
eszlamczyk wants to merge 7 commits into
Conversation
JakubKorytko
left a comment
There was a problem hiding this comment.
mostly about the QA switch not always signing out (supportal, anonymous, cancelled SAML) and the global signOut guard
| const isCrossingQA = (currentServer === CONST.SERVER.QA) !== (server === CONST.SERVER.QA); | ||
| if (isCrossingQA) { | ||
| // Pinned to the server being left, because LogOut is sent after the Onyx.set below has stored the new one | ||
| signOutAndRedirectToSignIn(session, undefined, undefined, undefined, undefined, undefined, currentServer); |
There was a problem hiding this comment.
two cases where this doesn't sign out, if I read signOutAndRedirectToSignIn right:
- with a supportal session
isSupportalmakes it skipsignOutand restore the stashed session, so after the switch the old session is put back and its token goes to QA (plus it opens the OldDot supportal restore URL) - with an anonymous session it opens the sign in modal and returns early, so the token from the old server stays
did not test myself though. Maybe the QA switch wants its own small path that clears the session and stashed session without restoring anything? That would also get rid of the five undefineds here, which are easy to get wrong
There was a problem hiding this comment.
The switch now has its own signOutForServerSwitch: it never restores the stashed session (the clear drops it) and clears an anonymous session instead of opening the sign-in modal. Like a normal sign-out, it only sends LogOut for a signed-in session that isn't anonymous or support. This also got rid of the five undefineds. Done in 8ba6ce6
| signOutAndRedirectToSignIn(session, undefined, undefined, undefined, undefined, undefined, currentServer); | ||
| } | ||
|
|
||
| Onyx.set(ONYXKEYS.ACTIVE_SERVER, server); |
There was a problem hiding this comment.
hmmh, the new server is stored right away, before we know the sign out went through. For a SAML user who cancels the logout browser, callSAMLSignOut rejects with Logout cancelled, signOutAndRedirectToSignIn only logs it and the user stays signed in, but ACTIVE_SERVER is already QA. Could we keep the old server when the sign out is cancelled?
There was a problem hiding this comment.
Changed the order instead, the new server is now stored only once LogOut has its answer, right before the clear. So the app keeps talking to the old server while it's still signed in there (the SAML window can stay open a while), and if the sign-out fails or is cancelled the old server simply stays, with a Log.warn. Done in 8ba6ce6
| */ | ||
| async function signOut(params: {autoGeneratedLogin?: string; signedInWithSAML?: boolean; authToken?: string} = {}): Promise<void | Response<never>> { | ||
| async function signOut(params: {autoGeneratedLogin?: string; signedInWithSAML?: boolean; authToken?: string} = {}, server?: Server): Promise<void | Response<never>> { | ||
| if (!params.authToken) { |
There was a problem hiding this comment.
this changes signOut for every caller, not only the server switch. A session without authToken but with autoGeneratedLogin used to send LogOut with the partner credentials, which is what invalidates them, and now that and clearPrefetchOnAppStart are skipped. Not sure that state is reachable tho. Could we skip the call where the switch happens instead, so signOut keeps its old contract?
There was a problem hiding this comment.
Agreed, moved the check into the switch path, so signOut keeps its old contract for every caller. Done in 8ba6ce6
| @@ -299,11 +306,11 @@ async function signOut(params: {autoGeneratedLogin?: string; signedInWithSAML?: | |||
| }; | |||
|
|
|||
| if (params.signedInWithSAML && params.authToken) { | |||
There was a problem hiding this comment.
nit: with the early return above params.authToken is always set here, and the ?? null in logOutParams can't be hit either. Could drop both
There was a problem hiding this comment.
No longer applies, the early return is gone from signOut in 8ba6ce6
|
|
||
| /** | ||
| * Signs out, or switches back to a stashed session, then redirects to sign in. | ||
| * @param server the server the session belongs to, so LogOut reaches it even if the active server changes before it is sent |
There was a problem hiding this comment.
this @param server line is copied in signOut, callSAMLSignOut and here, and makeRequest, API/index and HttpUtils say the same thing in their own words. I'd keep the full reason in one place (e.g. on Request.server) and make the rest just say which server LogOut is sent to
There was a problem hiding this comment.
Done in 8ba6ce6, the full reason now lives on Request.server
| }); | ||
|
|
||
| test('hands the 407 back without reauthenticating a request pinned to a server other than the active one', () => { | ||
| // Given a request pinned to staging while the app is on production, like a LogOut sent after switching servers |
There was a problem hiding this comment.
the Given says the app is on production, but neither this test nor the next one sets the active server, they lean on the test env default. If that default changes, the second test stops covering the "pinned to active server" case without failing. Could we set ACTIVE_SERVER explicitly like ApiUtilsTest does?
There was a problem hiding this comment.
Removed together with the check in 8ba6ce6
| signOutAndRedirectToSignIn(await Onyx.get(ONYXKEYS.SESSION), undefined, undefined, undefined, undefined, undefined, CONST.SERVER.STAGING); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // Then the server reaches LogOut |
There was a problem hiding this comment.
this Then reads a bit off, I think it means LogOut is sent to the server passed in
There was a problem hiding this comment.
This test is gone, signOutAndRedirectToSignIn doesn't take a server anymore (8ba6ce6)
|
|
||
| // Then the pin reaches HttpUtils.xhr, which builds the URL from it, so a server switch made meanwhile doesn't redirect it | ||
| expect(xhr).toHaveBeenCalledTimes(1); | ||
| expect(xhr.mock.calls.at(0)?.at(5)).toBe(CONST.SERVER.QA); |
There was a problem hiding this comment.
nit: .at(5) depends on the position of server in the xhr args, and if a param is added before it the toBeUndefined one below still passes. toHaveBeenCalledWith(..., CONST.SERVER.QA) would be harder to break
| function setActiveServer(server: ValueOf<typeof CONST.SERVER>, session: OnyxEntry<Session>) { | ||
| const currentServer = getActiveServer(); | ||
| if (CONFIG.IS_HYBRID_APP) { | ||
| HybridAppModule.shouldUseStaging(server === CONST.SERVER.STAGING); |
There was a problem hiding this comment.
not sure if QA can be picked on HybridApp yet, but if it can, this flips the native staging flag before the sign out starts, and signOutAndRedirectToSignIn then calls startSignOut and signOutFromOldDot. The pin only covers the JS LogOut, so on a staging to QA switch the OldDot sign out might go to the new host. Did not check the native side tho. Moving this below the sign out would avoid the question, no?
There was a problem hiding this comment.
Moved in 8ba6ce6, shouldUseStaging now changes together with the stored server, after OldDot is signed out
|
|
||
| const saveAndGoBack = () => { | ||
| setActiveServer(selectedServer); | ||
| setActiveServer(selectedServer, session); |
There was a problem hiding this comment.
Save signs the user out right away with no warning. The feature/qa-env/web branch asks first (confirmServerChangeDescription with a Sign out button) when the switch crosses QA and the user is signed in. Without it a tester who taps Save loses the session and anything still waiting in the queue offline. Could we bring that prompt over here, or is it planned for a later PR?
There was a problem hiding this comment.
The confirmation is planned as a separate pr. I did not want to overcrowd this pr. The PR adds user-facing copy in all languages, which needs its own copy review
# Conflicts: # tests/unit/HttpUtilsTest.ts
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
# Conflicts: # tests/unit/ApiUtilsTest.ts
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@eszlamczyk could you sync with main to resolve the conflict? |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
Screen.Recording.2026-12-02.at.14.43.17.movTested with a SAML account. This is the observed behavior. However, SAML isn't working on staging, so we don't need to worry about this for now. |
Context
This PR is part of the web implementation of the QA environment. QA runs on its own server and database, behind Cloudflare Access, so every request the app sends to QA has to carry a Cloudflare token and renew it when it runs out. Earlier parts added the server selection (#99926, #100209) and the Cloudflare sign-in round trip (#100730). The remaining work lands as a series of small PRs.
Explanation of Change
Switching into or out of QA now signs the user out. QA has its own database, so the same email is a different account there, and a token from one side means nothing on the other. Production and staging share a database, so switching between them keeps the session, as before.
No change on production or staging. QA is only offered on builds with QA configured (
QA_EXPENSIFY_URL), and no production or staging build sets it yet, so the new sign-out can't be reached there. Every other sign-out works as before.How the switch signs out. It has its own
signOutForServerSwitch, becausesignOutAndRedirectToSignIndoesn't fit: for a support agent it restores the stashed session, whose token belongs to the server being left, and for an anonymous session it only opens the sign-in modal. The switch sign-out:LogOutonly for a signed-in session that isn't anonymous or a support session (the same sessions a normal sign-out logs out), and nothing when no one is signed in (the test tools can be opened from the sign-in page),redirectToSignIn, which also drops any stashed session, so nothing from the old server comes back,LogOuthas its answer, right before the clear. Until then the app is still signed in to the old server, so its requests keep going there; this matters for SAML, whose sign-out window can stay open a while,shouldUseStagingflag together with the stored server, after OldDot is signed out.Why
LogOutis pinned to a server. A request picks its server when it is sent, not when it is created. The active server is shared between tabs, so another tab can switch it whileLogOutwaits, and an unpinnedLogOutwould then reach a database that doesn't know the token.What changes
setActiveServer(server, currentServer, session)usessignOutForServerSwitchwhen moving into or out of QA, and stores the server right away otherwise.ServerSelectorpasses it the server it currently shows as active (fromuseActiveServer) and the session.Requestgets an optionalserverfield.prepareRequestandAPI.makeRequestWithSideEffectsaccept it, it is passed throughRequest.makeXHR,HttpUtils.xhrand the load-test duplicates, andgetApiRootuses it in place of the active server when it is set.signOutandcallSAMLSignOuttake an optionalserverand pinLogOutto it. Their behaviour is otherwise unchanged.LogOutreports OldDot cookies moves intoopenOldDotSignOut, shared by both sign-outs. No behaviour change forsignOutAndRedirectToSignIn.CONST.SIGN_OUT_REASON.SERVER_SWITCHfor the sign-out telemetry.Fixed Issues
$ #91419
PROPOSAL:
Tests
Note
I couldn't verify the SAML flow, but it follows the same request code line by line, so it shouldn't behave differently. Cancelling the SAML sign-out during a switch is covered by unit tests.
LogOutrequest is sent (Network tab) and you land on the sign-in page.LogOutis sent, and requests go to the selected server..env(QA_EXPENSIFY_URL,QA_CF_TEAM_DOMAIN,QA_CF_OAUTH_CLIENT_ID,QA_AUTH_CHECK_PATH), sign in on a dev build, open the test tools and switch to QA. Verify:LogOutrequest goes to the server you left, not to QA (Network tab)Logrequests sent after the switch go to the QA host (QA_EXPENSIFY_URL) and return 200 (Logshould be on a Cloudflare Access bypass path, so it needs no token)LogOutrequest is sent and the test tools show QA selected.Offline tests
QA Steps
Steps 1-3 of the tests, on staging. Steps 4-6 need a build with QA configured, which staging doesn't have yet.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
MacOS: Chrome / Safari
Screen.Recording.2026-11-30.at.12.17.02.mov
Probe still works as intended.