@@ -393,8 +393,8 @@ describe('authentication/authentication-controller - performSignIn() with pairin
393
393
} ) ;
394
394
395
395
const controller = new AuthenticationController ( { messenger, metametrics } ) ;
396
- const requestCounter = jest . fn ( ) ;
397
- mockEndpoints . mockPairSocialIdentifierUrl . on ( 'request' , requestCounter )
396
+ const requestCounter = jest . fn ( ) ;
397
+ mockEndpoints . mockPairSocialIdentifierUrl . on ( 'request' , requestCounter ) ;
398
398
399
399
// Call performSignIn 10 times in parallel
400
400
const signInPromises = Array . from ( { length : 10 } , ( ) =>
@@ -448,6 +448,46 @@ describe('authentication/authentication-controller - performSignOut() tests', ()
448
448
expect ( controller . state . srpSessionData ) . toBeUndefined ( ) ;
449
449
expect ( controller . state . socialPairingDone ) . toBe ( false ) ;
450
450
} ) ;
451
+
452
+ it ( 'prevents race condition where async pairing could set socialPairingDone to true after sign-out' , async ( ) => {
453
+ const metametrics = createMockAuthMetaMetrics ( ) ;
454
+ const mockEndpoints = arrangeAuthAPIs ( ) ;
455
+ const { messenger, mockSeedlessOnboardingGetState } =
456
+ createMockAuthenticationMessenger ( ) ;
457
+
458
+ // Ensure social token is available for pairing
459
+ mockSeedlessOnboardingGetState . mockReturnValue ( {
460
+ accessToken : MOCK_SOCIAL_TOKEN ,
461
+ } ) ;
462
+
463
+ const controller = new AuthenticationController ( { messenger, metametrics } ) ;
464
+
465
+ // Start sign-in which triggers async pairing
466
+ await controller . performSignIn ( ) ;
467
+ // Immediately sign out before async pairing completes
468
+ controller . performSignOut ( ) ;
469
+
470
+ // Verify initial sign-out state
471
+ expect ( controller . state . isSignedIn ) . toBe ( false ) ;
472
+ expect ( controller . state . socialPairingDone ) . toBe ( false ) ;
473
+ expect ( controller . state . srpSessionData ) . toBeUndefined ( ) ;
474
+
475
+ // Wait a bit for the async pairing operation to complete
476
+ await waitFor ( ( ) => {
477
+ expect ( controller . state . pairingInProgress ) . toBe ( false ) ;
478
+ } ) ;
479
+
480
+ // Verify that socialPairingDone remains false after sign-out
481
+ expect ( controller . state . isSignedIn ) . toBe ( false ) ;
482
+ expect ( controller . state . socialPairingDone ) . toBe ( false ) ;
483
+ expect ( controller . state . srpSessionData ) . toBeUndefined ( ) ;
484
+ expect ( controller . state . pairingInProgress ) . toBe ( false ) ;
485
+
486
+ mockEndpoints . mockNonceUrl . done ( ) ;
487
+ mockEndpoints . mockSrpLoginUrl . done ( ) ;
488
+ mockEndpoints . mockOAuth2TokenUrl . done ( ) ;
489
+ mockEndpoints . mockPairSocialIdentifierUrl . done ( ) ;
490
+ } ) ;
451
491
} ) ;
452
492
453
493
describe ( 'authentication/authentication-controller - getBearerToken() tests' , ( ) => {
0 commit comments