Skip to content

Commit 8f9e559

Browse files
authored
Add assertion for emulator url scheme in auth (firebase#3942)
* Add assertion for emulator scheme * Formatting * PR feedback
1 parent 0322c1b commit 8f9e559

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,22 @@ describe('core/auth/auth_impl useEmulator', () => {
489489
expect(normalEndpoint.calls.length).to.eq(0);
490490
expect(emulatorEndpoint.calls.length).to.eq(1);
491491
});
492+
493+
it('checks the scheme properly', () => {
494+
expect(() => auth.useEmulator('http://localhost:2020')).not.to.throw;
495+
delete auth.config.emulator;
496+
expect(() => auth.useEmulator('https://localhost:2020')).not.to.throw;
497+
delete auth.config.emulator;
498+
expect(() => auth.useEmulator('ssh://localhost:2020')).to.throw(
499+
FirebaseError,
500+
'auth/invalid-emulator-scheme'
501+
);
502+
delete auth.config.emulator;
503+
expect(() => auth.useEmulator('localhost:2020')).to.throw(
504+
FirebaseError,
505+
'auth/invalid-emulator-scheme'
506+
);
507+
});
492508
});
493509

494510
context('toJSON', () => {

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ export class AuthImpl implements Auth, _FirebaseService {
203203
appName: this.name
204204
});
205205

206+
assert(/^https?:\/\//.test(url), AuthErrorCode.INVALID_EMULATOR_SCHEME, {
207+
appName: this.name
208+
});
209+
206210
this.config.emulator = { url };
207211
this.settings.appVerificationDisabledForTesting = true;
208212
}

packages-exp/auth-exp/src/core/errors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const enum AuthErrorCode {
5656
INVALID_CUSTOM_TOKEN = 'invalid-custom-token',
5757
INVALID_DYNAMIC_LINK_DOMAIN = 'invalid-dynamic-link-domain',
5858
INVALID_EMAIL = 'invalid-email',
59+
INVALID_EMULATOR_SCHEME = 'invalid-emulator-scheme',
5960
INVALID_IDP_RESPONSE = 'invalid-credential',
6061
INVALID_MESSAGE_PAYLOAD = 'invalid-message-payload',
6162
INVALID_MFA_SESSION = 'invalid-multi-factor-session',
@@ -189,6 +190,8 @@ const ERRORS: ErrorMap<AuthErrorCode> = {
189190
[AuthErrorCode.INVALID_DYNAMIC_LINK_DOMAIN]:
190191
'The provided dynamic link domain is not configured or authorized for the current project.',
191192
[AuthErrorCode.INVALID_EMAIL]: 'The email address is badly formatted.',
193+
[AuthErrorCode.INVALID_EMULATOR_SCHEME]:
194+
'Emulator URL must start with a valid scheme (http:// or https://).',
192195
[AuthErrorCode.INVALID_API_KEY]:
193196
'Your API key is invalid, please check you have copied it correctly.',
194197
[AuthErrorCode.INVALID_CERT_HASH]:

0 commit comments

Comments
 (0)