From d258da466353780d917dfe47045cfc914f70538b Mon Sep 17 00:00:00 2001 From: mansisampat Date: Thu, 3 Jul 2025 12:22:44 +0530 Subject: [PATCH 1/5] Increase unit test coverage for oauth.ts to 100% --- .../auth/src/core/providers/oauth.test.ts | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/packages/auth/src/core/providers/oauth.test.ts b/packages/auth/src/core/providers/oauth.test.ts index 09acbc5b095..f8cfa89bd5f 100644 --- a/packages/auth/src/core/providers/oauth.test.ts +++ b/packages/auth/src/core/providers/oauth.test.ts @@ -26,8 +26,17 @@ import { AuthErrorCode } from '../errors'; import { UserCredentialImpl } from '../user/user_credential_impl'; import { _createError } from '../util/assert'; import { OAuthProvider } from './oauth'; +import { OAuthCredential } from '../credentials/oauth'; +import sinon from 'sinon'; describe('core/providers/oauth', () => { + + const callMethod = (tokenResponse: any) => { + return (OAuthProvider as any).oauthCredentialFromTaggedObject({ + _tokenResponse: tokenResponse + }); + }; + it('generates the correct type of oauth credential', () => { const cred = new OAuthProvider('google.com').credential({ idToken: 'id-token', @@ -125,4 +134,96 @@ describe('core/providers/oauth', () => { expect(cred.signInMethod).to.eq('foo.test'); expect((cred.toJSON() as { nonce: string }).nonce).to.eq('i-am-a-nonce'); }); + + it('creates OAuthCredential from valid object input', () => { + const input = { + providerId: 'google.com', + signInMethod: 'google.com', + idToken: 'id-token', + accessToken: 'access-token' + }; + + const credential = OAuthProvider.credentialFromJSON(input); + expect(credential).to.be.instanceOf(OAuthCredential); + expect(credential.providerId).to.equal('google.com'); + expect(credential.signInMethod).to.equal('google.com'); + expect(credential.idToken).to.equal('id-token'); + expect(credential.accessToken).to.equal('access-token'); + }); + + it('creates OAuthCredential from valid JSON string input', () => { + const input = JSON.stringify({ + providerId: 'providerid', + signInMethod: 'providerid', + accessToken: 'access-token' + }); + + const credential = OAuthProvider.credentialFromJSON(input); + expect(credential).to.be.instanceOf(OAuthCredential); + expect(credential.providerId).to.equal('providerid'); + expect(credential.signInMethod).to.equal('providerid'); + expect(credential.accessToken).to.equal('access-token'); + }); + + it('throws an error if providerId or signInMethod is missing', () => { + const input = { + idToken: 'missing-provider-id' + }; + + expect(() => { + OAuthProvider.credentialFromJSON(input); + }).to.throw(AuthErrorCode.ARGUMENT_ERROR); + }); + + it('throws an error if JSON string is invalid', () => { + const invalidJson = '{ not valid json }'; + + expect(() => { + OAuthProvider.credentialFromJSON(invalidJson); + }).to.throw(SyntaxError); + }); + + it('returns null if tokenResponse is missing', () => { + const result = callMethod(undefined); + expect(result).to.be.null; + }); + + it('returns null if all tokens (idToken, accessToken, tokenSecret, pendingToken) are missing', () => { + const result = callMethod({ + providerId: 'google.com' + // all token fields missing + }); + expect(result).to.be.null; + }); + + it('returns null if providerId is missing', () => { + const result = callMethod({ + oauthIdToken: 'id-token', + oauthAccessToken: 'access-token', + // providerId is missing + }); + expect(result).to.be.null; + }); + + it('returns null if OAuthProvider._credential throws', () => { + const proto = OAuthProvider.prototype as any; + const original = proto._credential; + + // Temporarily replace _credential to throw an error + proto._credential = () => { + throw new Error('Simulated error'); + }; + + const result = (OAuthProvider as any).oauthCredentialFromTaggedObject({ + _tokenResponse: { + providerId: 'google.com', + oauthIdToken: 'id-token' + } + }); + + expect(result).to.be.null; + + // Restore original method + proto._credential = original; + }); }); From b54a402414b197f14d8fabc9afcdc61a67ee33ed Mon Sep 17 00:00:00 2001 From: mansisampat Date: Thu, 3 Jul 2025 12:29:48 +0530 Subject: [PATCH 2/5] fix lint errors --- packages/auth/src/core/providers/oauth.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/auth/src/core/providers/oauth.test.ts b/packages/auth/src/core/providers/oauth.test.ts index f8cfa89bd5f..0a944f2d2e1 100644 --- a/packages/auth/src/core/providers/oauth.test.ts +++ b/packages/auth/src/core/providers/oauth.test.ts @@ -30,7 +30,6 @@ import { OAuthCredential } from '../credentials/oauth'; import sinon from 'sinon'; describe('core/providers/oauth', () => { - const callMethod = (tokenResponse: any) => { return (OAuthProvider as any).oauthCredentialFromTaggedObject({ _tokenResponse: tokenResponse @@ -199,7 +198,7 @@ describe('core/providers/oauth', () => { it('returns null if providerId is missing', () => { const result = callMethod({ oauthIdToken: 'id-token', - oauthAccessToken: 'access-token', + oauthAccessToken: 'access-token' // providerId is missing }); expect(result).to.be.null; From 4d4c23a3091ae5e48c24185e35b75c7ace006f10 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Thu, 3 Jul 2025 12:32:33 +0530 Subject: [PATCH 3/5] fix lint errors --- packages/auth/src/core/providers/oauth.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/auth/src/core/providers/oauth.test.ts b/packages/auth/src/core/providers/oauth.test.ts index 0a944f2d2e1..4607c56e045 100644 --- a/packages/auth/src/core/providers/oauth.test.ts +++ b/packages/auth/src/core/providers/oauth.test.ts @@ -27,7 +27,6 @@ import { UserCredentialImpl } from '../user/user_credential_impl'; import { _createError } from '../util/assert'; import { OAuthProvider } from './oauth'; import { OAuthCredential } from '../credentials/oauth'; -import sinon from 'sinon'; describe('core/providers/oauth', () => { const callMethod = (tokenResponse: any) => { From 7ece3cfbf0f0126ed993fffbbe6f9076966c27df Mon Sep 17 00:00:00 2001 From: mansisampat Date: Thu, 3 Jul 2025 12:39:49 +0530 Subject: [PATCH 4/5] fix lint errors --- packages/auth/src/core/providers/oauth.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/src/core/providers/oauth.test.ts b/packages/auth/src/core/providers/oauth.test.ts index 4607c56e045..2c8554aec1d 100644 --- a/packages/auth/src/core/providers/oauth.test.ts +++ b/packages/auth/src/core/providers/oauth.test.ts @@ -29,7 +29,7 @@ import { OAuthProvider } from './oauth'; import { OAuthCredential } from '../credentials/oauth'; describe('core/providers/oauth', () => { - const callMethod = (tokenResponse: any) => { + const callMethod = (tokenResponse: any): OAuthCredential => { return (OAuthProvider as any).oauthCredentialFromTaggedObject({ _tokenResponse: tokenResponse }); From aa83460ace469bbfe9a986763c0a8e0a16059cc6 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Thu, 3 Jul 2025 12:46:25 +0530 Subject: [PATCH 5/5] Updating the chrom version in test-changed-auth.yaml --- .github/workflows/test-changed-auth.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-changed-auth.yml b/.github/workflows/test-changed-auth.yml index b72c7cd9e2d..84b0ef4adda 100644 --- a/.github/workflows/test-changed-auth.yml +++ b/.github/workflows/test-changed-auth.yml @@ -23,7 +23,7 @@ env: # the behavior to use the new URLs. CHROMEDRIVER_CDNURL: https://googlechromelabs.github.io/ CHROMEDRIVER_CDNBINARIESURL: https://storage.googleapis.com/chrome-for-testing-public - CHROME_VALIDATED_VERSION: linux-120.0.6099.71 + CHROME_VALIDATED_VERSION: linux-137.0.7151.119 # Bump Node memory limit NODE_OPTIONS: "--max_old_space_size=4096" @@ -119,4 +119,4 @@ jobs: - name: Run tests on changed packages run: yarn test:changed auth env: - BROWSERS: 'WebkitHeadless' \ No newline at end of file + BROWSERS: 'WebkitHeadless'