File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,16 @@ export class Storage implements StorageInterface {
4949 }
5050
5151 if ( ! process . env . STORAGE_EMULATOR_HOST && process . env . FIREBASE_STORAGE_EMULATOR_HOST ) {
52- process . env . STORAGE_EMULATOR_HOST = process . env . FIREBASE_STORAGE_EMULATOR_HOST ;
52+ const firebaseStorageEmulatorHost = process . env . FIREBASE_STORAGE_EMULATOR_HOST ;
53+
54+ if ( firebaseStorageEmulatorHost . match ( / h t t p s ? : \/ \/ / ) ) {
55+ throw new FirebaseError ( {
56+ code : 'storage/invalid-emulator-host' ,
57+ message : 'FIREBASE_STORAGE_EMULATOR_HOST should not contain a protocol (http or https).' ,
58+ } ) ;
59+ }
60+
61+ process . env . STORAGE_EMULATOR_HOST = `http://${ process . env . FIREBASE_STORAGE_EMULATOR_HOST } ` ;
5362 }
5463
5564 let storage : typeof StorageClient ;
Original file line number Diff line number Diff line change @@ -114,18 +114,27 @@ describe('Storage', () => {
114114 } ) ;
115115 } ) ;
116116
117- describe ( 'Emulator mode' , ( ) => {
118- const EMULATOR_HOST = 'http://localhost:9199' ;
117+ describe . only ( 'Emulator mode' , ( ) => {
118+ const VALID_EMULATOR_HOST = 'localhost:9199' ;
119+ const INVALID_EMULATOR_HOST = 'https://localhost:9199' ;
119120
120- before ( ( ) => {
121+ beforeEach ( ( ) => {
121122 delete process . env . STORAGE_EMULATOR_HOST ;
122- process . env . FIREBASE_STORAGE_EMULATOR_HOST = EMULATOR_HOST ;
123+ delete process . env . FIREBASE_STORAGE_EMULATOR_HOST ;
123124 } ) ;
124125
125126 it ( 'sets STORAGE_EMULATOR_HOST if FIREBASE_STORAGE_EMULATOR_HOST is set' , ( ) => {
126- new Storage ( mockApp ) ;
127-
128- expect ( process . env . STORAGE_EMULATOR_HOST ) . to . equal ( EMULATOR_HOST ) ;
127+ process . env . FIREBASE_STORAGE_EMULATOR_HOST = VALID_EMULATOR_HOST ;
128+
129+ new Storage ( mockApp )
130+ expect ( process . env . STORAGE_EMULATOR_HOST ) . to . equal ( `http://${ VALID_EMULATOR_HOST } ` ) ;
131+ } ) ;
132+
133+ it ( 'throws if FIREBASE_STORAGE_EMULATOR_HOST has a protocol' , ( ) => {
134+ process . env . FIREBASE_STORAGE_EMULATOR_HOST = INVALID_EMULATOR_HOST ;
135+
136+ expect ( ( ) => new Storage ( mockApp ) ) . to . throw (
137+ 'FIREBASE_STORAGE_EMULATOR_HOST should not contain a protocol' ) ;
129138 } ) ;
130139
131140 after ( ( ) => {
You can’t perform that action at this time.
0 commit comments