File tree 2 files changed +29
-2
lines changed
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,22 @@ describe('Database Tests', () => {
292
292
expect ( ( db as any ) . _delegate . _repo . repoInfo_ . isUsingEmulator ) . to . be . false ;
293
293
} ) ;
294
294
295
+ it ( 'uses ssl when useEmulator is called with https is specified' , ( ) => {
296
+ const db = firebase . database ( ) ;
297
+ db . useEmulator ( 'https://localhost' , 80 ) ;
298
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . isUsingEmulator ) . to . be . true ;
299
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . host ) . to . equal ( 'localhost:80' ) ;
300
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . secure ) . to . be . true ;
301
+ } ) ;
302
+
303
+ it ( 'uses ssl when useEmulator is called with wss is specified' , ( ) => {
304
+ const db = firebase . database ( ) ;
305
+ db . useEmulator ( 'wss://localhost' , 80 ) ;
306
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . isUsingEmulator ) . to . be . true ;
307
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . host ) . to . equal ( 'localhost:80' ) ;
308
+ expect ( ( db as any ) . _delegate . _repo . repoInfo_ . secure ) . to . be . true ;
309
+ } ) ;
310
+
295
311
it ( 'cannot call useEmulator after use' , ( ) => {
296
312
const db = ( firebase as any ) . database ( ) ;
297
313
Original file line number Diff line number Diff line change @@ -89,9 +89,19 @@ function repoManagerApplyEmulatorSettings(
89
89
emulatorOptions : RepoInfoEmulatorOptions ,
90
90
tokenProvider ?: AuthTokenProvider
91
91
) : void {
92
+ let ssl = false ;
93
+ let finalHost = hostAndPort ;
94
+ if ( / ^ h t t p s : \/ \/ / . test ( finalHost ) ) {
95
+ ssl = true ;
96
+ finalHost = finalHost . substring ( 8 ) ;
97
+ }
98
+ if ( / ^ w s s : \/ \/ / . test ( finalHost ) ) {
99
+ ssl = true ;
100
+ finalHost = finalHost . substring ( 6 ) ;
101
+ }
92
102
repo . repoInfo_ = new RepoInfo (
93
- hostAndPort ,
94
- /* secure= */ false ,
103
+ finalHost ,
104
+ /* secure= */ ssl ,
95
105
repo . repoInfo_ . namespace ,
96
106
repo . repoInfo_ . webSocketOnly ,
97
107
repo . repoInfo_ . nodeAdmin ,
@@ -352,6 +362,7 @@ export function connectDatabaseEmulator(
352
362
) : void {
353
363
db = getModularInstance ( db ) ;
354
364
db . _checkNotDeleted ( 'useEmulator' ) ;
365
+
355
366
const hostAndPort = `${ host } :${ port } ` ;
356
367
const repo = db . _repoInternal ;
357
368
if ( db . _instanceStarted ) {
You can’t perform that action at this time.
0 commit comments