@@ -22,7 +22,8 @@ import {
2222 ProviderId
2323} from '../../model/public_types' ;
2424import * as sinon from 'sinon' ;
25- import { _getInstance } from '../util/instantiator' ;
25+ import * as sinonChai from 'sinon-chai' ;
26+ import { _clearInstanceMap , _getInstance } from '../util/instantiator' ;
2627import {
2728 MockPersistenceLayer ,
2829 TestAuth ,
@@ -39,24 +40,24 @@ import {
3940 PopupRedirectResolverInternal
4041} from '../../model/popup_redirect' ;
4142import { BASE_AUTH_EVENT } from '../../../test/helpers/iframe_event' ;
42- import { PersistenceInternal } from '../persistence' ;
43- import { InMemoryPersistence } from '../persistence/in_memory' ;
4443import { UserCredentialImpl } from '../user/user_credential_impl' ;
4544import * as idpTasks from '../strategies/idp' ;
46- import { expect } from 'chai' ;
45+ import { expect , use } from 'chai' ;
4746import { AuthErrorCode } from '../errors' ;
47+ import { RedirectPersistence } from '../../../test/helpers/redirect_persistence' ;
48+
49+ use ( sinonChai ) ;
4850
4951const MATCHING_EVENT_ID = 'matching-event-id' ;
5052const OTHER_EVENT_ID = 'wrong-id' ;
5153
52- class RedirectPersistence extends InMemoryPersistence { }
53-
5454describe ( 'core/strategies/redirect' , ( ) => {
5555 let auth : AuthInternal ;
5656 let redirectAction : RedirectAction ;
5757 let eventManager : AuthEventManager ;
5858 let resolver : PopupRedirectResolver ;
5959 let idpStubs : sinon . SinonStubbedInstance < typeof idpTasks > ;
60+ let redirectPersistence : RedirectPersistence ;
6061
6162 beforeEach ( async ( ) => {
6263 eventManager = new AuthEventManager ( ( { } as unknown ) as TestAuth ) ;
@@ -67,11 +68,16 @@ describe('core/strategies/redirect', () => {
6768 ) . _redirectPersistence = RedirectPersistence ;
6869 auth = await testAuth ( ) ;
6970 redirectAction = new RedirectAction ( auth , _getInstance ( resolver ) , false ) ;
71+ redirectPersistence = _getInstance ( RedirectPersistence ) ;
72+
73+ // Default to has redirect for most test
74+ redirectPersistence . hasPendingRedirect = true ;
7075 } ) ;
7176
7277 afterEach ( ( ) => {
7378 sinon . restore ( ) ;
7479 _clearRedirectOutcomes ( ) ;
80+ _clearInstanceMap ( ) ;
7581 } ) ;
7682
7783 function iframeEvent ( event : Partial < AuthEvent > ) : void {
@@ -86,16 +92,11 @@ describe('core/strategies/redirect', () => {
8692 }
8793
8894 async function reInitAuthWithRedirectUser ( eventId : string ) : Promise < void > {
89- const redirectPersistence : PersistenceInternal = _getInstance (
90- RedirectPersistence
91- ) ;
9295 const mainPersistence = new MockPersistenceLayer ( ) ;
9396 const oldAuth = await testAuth ( ) ;
9497 const user = testUser ( oldAuth , 'uid' ) ;
9598 user . _redirectEventId = eventId ;
96- sinon
97- . stub ( redirectPersistence , '_get' )
98- . returns ( Promise . resolve ( user . toJSON ( ) ) ) ;
99+ redirectPersistence . redirectUser = user . toJSON ( ) ;
99100 sinon . stub ( mainPersistence , '_get' ) . returns ( Promise . resolve ( user . toJSON ( ) ) ) ;
100101
101102 auth = await testAuth ( resolver , mainPersistence ) ;
@@ -194,4 +195,18 @@ describe('core/strategies/redirect', () => {
194195 expect ( await promise ) . to . eq ( cred ) ;
195196 expect ( await redirectAction . execute ( ) ) . to . eq ( cred ) ;
196197 } ) ;
198+
199+ it ( 'bypasses initialization if no key set' , async ( ) => {
200+ await reInitAuthWithRedirectUser ( MATCHING_EVENT_ID ) ;
201+ const resolverInstance = _getInstance < PopupRedirectResolverInternal > (
202+ resolver
203+ ) ;
204+
205+ sinon . spy ( resolverInstance , '_initialize' ) ;
206+ redirectPersistence . hasPendingRedirect = false ;
207+
208+ expect ( await redirectAction . execute ( ) ) . to . eq ( null ) ;
209+ expect ( await redirectAction . execute ( ) ) . to . eq ( null ) ;
210+ expect ( resolverInstance . _initialize ) . not . to . have . been . called ;
211+ } ) ;
197212} ) ;
0 commit comments