From a6edd0cd36732ed370053da0a5b530277ffe1da7 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Mon, 5 May 2025 11:18:18 -0700 Subject: [PATCH 1/4] Fixed issue where port was set to null --- packages/auth/src/core/auth/emulator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/src/core/auth/emulator.ts b/packages/auth/src/core/auth/emulator.ts index 05f2e5e4bd5..8547f7bad6c 100644 --- a/packages/auth/src/core/auth/emulator.ts +++ b/packages/auth/src/core/auth/emulator.ts @@ -103,7 +103,7 @@ export function connectAuthEmulator( // Workaround to get cookies in Firebase Studio if (isCloudWorkstation(host)) { - void pingServer(`${protocol}//${host}:${port}`); + void pingServer(`${protocol}//${host}${portStr}`); } } From 486721c4ad845c97d834ed7c004a265ddedb04c4 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Mon, 5 May 2025 11:26:41 -0700 Subject: [PATCH 2/4] Added tests --- packages/auth/src/core/auth/emulator.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/auth/src/core/auth/emulator.test.ts b/packages/auth/src/core/auth/emulator.test.ts index 47c5d927c44..50b661521ce 100644 --- a/packages/auth/src/core/auth/emulator.test.ts +++ b/packages/auth/src/core/auth/emulator.test.ts @@ -29,6 +29,7 @@ import { Endpoint } from '../../api'; import { UserInternal } from '../../model/user'; import { _castAuth } from './auth_impl'; import { connectAuthEmulator } from './emulator'; +import * as Util from '@firebase/util'; use(sinonChai); use(chaiAsPromised); @@ -38,8 +39,10 @@ describe('core/auth/emulator', () => { let user: UserInternal; let normalEndpoint: fetch.Route; let emulatorEndpoint: fetch.Route; + let testStub: sinon.SinonStub; beforeEach(async () => { + testStub = sinon.stub(Util, 'pingServer'); auth = await testAuth(); user = testUser(_castAuth(auth), 'uid', 'email', true); fetch.setUp(); @@ -154,6 +157,19 @@ describe('core/auth/emulator', () => { ); } }); + it('calls pingServer with port if specified', () => { + connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev:2020'); + expect(testStub).to.have.been.calledWith( + 'https://abc.cloudworkstations.dev:2020' + ); + }); + + it('calls pingServer with no port if none specified', () => { + connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev'); + expect(testStub).to.have.been.calledWith( + 'https://abc.cloudworkstations.dev' + ); + }); it('logs out a warning to the console', () => { sinon.stub(console, 'info'); From 6507685a5c3974c5aa0c3862d836b2cc322375e0 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Mon, 5 May 2025 11:27:57 -0700 Subject: [PATCH 3/4] Updated formatting --- packages/auth/src/core/auth/emulator.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/auth/src/core/auth/emulator.test.ts b/packages/auth/src/core/auth/emulator.test.ts index 50b661521ce..5b3ba360c11 100644 --- a/packages/auth/src/core/auth/emulator.test.ts +++ b/packages/auth/src/core/auth/emulator.test.ts @@ -39,10 +39,10 @@ describe('core/auth/emulator', () => { let user: UserInternal; let normalEndpoint: fetch.Route; let emulatorEndpoint: fetch.Route; - let testStub: sinon.SinonStub; + let utilStub: sinon.SinonStub; beforeEach(async () => { - testStub = sinon.stub(Util, 'pingServer'); + utilStub = sinon.stub(Util, 'pingServer'); auth = await testAuth(); user = testUser(_castAuth(auth), 'uid', 'email', true); fetch.setUp(); @@ -159,14 +159,14 @@ describe('core/auth/emulator', () => { }); it('calls pingServer with port if specified', () => { connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev:2020'); - expect(testStub).to.have.been.calledWith( + expect(utilStub).to.have.been.calledWith( 'https://abc.cloudworkstations.dev:2020' ); }); it('calls pingServer with no port if none specified', () => { connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev'); - expect(testStub).to.have.been.calledWith( + expect(utilStub).to.have.been.calledWith( 'https://abc.cloudworkstations.dev' ); }); From 5bc5077c4a3b82bf906109f0aaa7da33a591e582 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Mon, 5 May 2025 11:28:26 -0700 Subject: [PATCH 4/4] Create lemon-tomatoes-breathe.md --- .changeset/lemon-tomatoes-breathe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lemon-tomatoes-breathe.md diff --git a/.changeset/lemon-tomatoes-breathe.md b/.changeset/lemon-tomatoes-breathe.md new file mode 100644 index 00000000000..0df04153d61 --- /dev/null +++ b/.changeset/lemon-tomatoes-breathe.md @@ -0,0 +1,5 @@ +--- +"@firebase/auth": patch +--- + +Fix issue where auth port wasn't properly set when setting up cookies in Firebase Studio.