@@ -24,7 +24,8 @@ import {
24
24
AngularFireAuth ,
25
25
AuthMethods ,
26
26
firebaseAuthConfig ,
27
- AuthProviders
27
+ AuthProviders ,
28
+ WindowLocation
28
29
} from '../angularfire2' ;
29
30
import { COMMON_CONFIG } from '../test-config' ;
30
31
@@ -99,20 +100,37 @@ describe('FirebaseAuth', () => {
99
100
let backend : AuthBackend ;
100
101
let afAuth : AngularFireAuth ;
101
102
let authSpy : jasmine . Spy ;
102
- var fbAuthObserver : Observer < firebase . User > ;
103
-
104
- beforeEachProviders ( ( ) => [
105
- FIREBASE_PROVIDERS ,
106
- defaultFirebase ( COMMON_CONFIG ) ,
107
- provide ( FirebaseApp , {
108
- useFactory : ( config : FirebaseAppConfig ) => {
109
- var app = initializeApp ( config ) ;
110
- ( < any > app ) . auth = ( ) => authSpy ;
111
- return app ;
112
- } ,
113
- deps : [ FirebaseConfig ]
114
- } )
115
- ] ) ;
103
+ let fbAuthObserver : Observer < firebase . User > ;
104
+ let windowLocation : any ;
105
+
106
+ beforeEachProviders ( ( ) => {
107
+ windowLocation = {
108
+ hash : '' ,
109
+ search : '' ,
110
+ pathname :'/' ,
111
+ port : '' ,
112
+ hostname :'localhost' ,
113
+ host :'localhost' ,
114
+ protocol :'https:' ,
115
+ origin :'localhost' ,
116
+ href :'https://localhost/'
117
+ } ;
118
+ return [
119
+ FIREBASE_PROVIDERS ,
120
+ defaultFirebase ( COMMON_CONFIG ) ,
121
+ provide ( FirebaseApp , {
122
+ useFactory : ( config : FirebaseAppConfig ) => {
123
+ var app = initializeApp ( config ) ;
124
+ ( < any > app ) . auth = ( ) => authSpy ;
125
+ return app ;
126
+ } ,
127
+ deps : [ FirebaseConfig ]
128
+ } ) ,
129
+ provide ( WindowLocation , {
130
+ useValue : windowLocation
131
+ } )
132
+ ]
133
+ } ) ;
116
134
117
135
beforeEach ( ( ) => {
118
136
authSpy = jasmine . createSpyObj ( 'auth' , authMethods ) ;
@@ -202,7 +220,7 @@ describe('FirebaseAuth', () => {
202
220
let config = {
203
221
method : AuthMethods . Anonymous
204
222
} ;
205
- afAuth = new AngularFireAuth ( backend , config ) ;
223
+ afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
206
224
afAuth . login ( ) ;
207
225
expect ( app . auth ( ) . signInAnonymously ) . toHaveBeenCalled ( ) ;
208
226
} ) ;
@@ -211,7 +229,7 @@ describe('FirebaseAuth', () => {
211
229
let config = {
212
230
method : AuthMethods . Anonymous
213
231
} ;
214
- afAuth = new AngularFireAuth ( backend , config ) ;
232
+ afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
215
233
afAuth . login ( {
216
234
method : AuthMethods . Popup ,
217
235
provider : AuthProviders . Google
@@ -227,7 +245,7 @@ describe('FirebaseAuth', () => {
227
245
provider : AuthProviders . Google ,
228
246
scope : [ 'email' ]
229
247
} ;
230
- afAuth = new AngularFireAuth ( backend , config ) ;
248
+ afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
231
249
afAuth . login ( {
232
250
provider : AuthProviders . Github
233
251
} ) ;
@@ -252,7 +270,7 @@ describe('FirebaseAuth', () => {
252
270
let config = {
253
271
method : AuthMethods . Password
254
272
} ;
255
- let afAuth = new AngularFireAuth ( backend , config ) ;
273
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
256
274
afAuth . login ( )
257
275
. then ( done . fail , done ) ;
258
276
} ) ;
@@ -261,7 +279,7 @@ describe('FirebaseAuth', () => {
261
279
let config = {
262
280
method : AuthMethods . CustomToken
263
281
} ;
264
- let afAuth = new AngularFireAuth ( backend , config ) ;
282
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
265
283
afAuth . login ( )
266
284
. then ( done . fail , done ) ;
267
285
} ) ;
@@ -270,7 +288,7 @@ describe('FirebaseAuth', () => {
270
288
let config = {
271
289
method : AuthMethods . OAuthToken
272
290
} ;
273
- let afAuth = new AngularFireAuth ( backend , config ) ;
291
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
274
292
afAuth . login ( )
275
293
. then ( done . fail , done ) ;
276
294
} ) ;
@@ -279,7 +297,7 @@ describe('FirebaseAuth', () => {
279
297
let config = {
280
298
method : AuthMethods . Popup
281
299
} ;
282
- let afAuth = new AngularFireAuth ( backend , config ) ;
300
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
283
301
afAuth . login ( )
284
302
. then ( done . fail , done ) ;
285
303
} ) ;
@@ -288,7 +306,7 @@ describe('FirebaseAuth', () => {
288
306
let config = {
289
307
method : AuthMethods . Redirect
290
308
} ;
291
- let afAuth = new AngularFireAuth ( backend , config ) ;
309
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
292
310
afAuth . login ( )
293
311
. then ( done . fail , done ) ;
294
312
} ) ;
@@ -359,7 +377,7 @@ describe('FirebaseAuth', () => {
359
377
360
378
password : 'supersecretpassword'
361
379
} ;
362
- let afAuth = new AngularFireAuth ( backend , config ) ;
380
+ let afAuth = new AngularFireAuth ( backend , windowLocation , config ) ;
363
381
afAuth . login ( credentials ) ;
364
382
expect ( app . auth ( ) . signInWithEmailAndPassword ) . toHaveBeenCalledWith ( credentials . email , credentials . password ) ;
365
383
} ) ;
@@ -433,6 +451,18 @@ describe('FirebaseAuth', () => {
433
451
fbAuthObserver . next ( firebaseUser ) ;
434
452
} ) ;
435
453
} , 10 ) ;
454
+
455
+
456
+ it ( 'should not call getRedirectResult() if location.protocol is not http or https' , ( done ) => {
457
+ windowLocation . protocol = 'file:' ;
458
+ afAuth
459
+ . take ( 1 )
460
+ . do ( ( ) => {
461
+ expect ( authSpy [ 'getRedirectResult' ] ) . not . toHaveBeenCalled ( ) ;
462
+ } )
463
+ . subscribe ( done , done . fail ) ;
464
+ fbAuthObserver . next ( firebaseUser ) ;
465
+ } ) ;
436
466
} ) ;
437
467
438
468
describe ( 'authWithOAuthRedirect' , ( ) => {
0 commit comments