File tree 2 files changed +26
-8
lines changed
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 {
49
49
}
50
50
51
51
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 } ` ;
53
62
}
54
63
55
64
let storage : typeof StorageClient ;
Original file line number Diff line number Diff line change @@ -114,18 +114,27 @@ describe('Storage', () => {
114
114
} ) ;
115
115
} ) ;
116
116
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' ;
119
120
120
- before ( ( ) => {
121
+ beforeEach ( ( ) => {
121
122
delete process . env . STORAGE_EMULATOR_HOST ;
122
- process . env . FIREBASE_STORAGE_EMULATOR_HOST = EMULATOR_HOST ;
123
+ delete process . env . FIREBASE_STORAGE_EMULATOR_HOST ;
123
124
} ) ;
124
125
125
126
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' ) ;
129
138
} ) ;
130
139
131
140
after ( ( ) => {
You can’t perform that action at this time.
0 commit comments