Skip to content

Commit 0e7d7e8

Browse files
committed
add tests and fix errors
1 parent c09d197 commit 0e7d7e8

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/auth/auth-config.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -810,13 +810,11 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
810810
});
811811

812812
const idToken = options.responseType.idToken;
813-
if (typeof idToken !== 'undefined') {
814-
if (!validator.isBoolean(idToken)) {
815-
throw new FirebaseAuthError(
816-
AuthClientErrorCode.INVALID_ARGUMENT,
817-
'"OIDCAuthProviderConfig.responseType.idToken" must be a boolean.',
818-
);
819-
}
813+
if (typeof idToken !== 'undefined' && !validator.isBoolean(idToken)) {
814+
throw new FirebaseAuthError(
815+
AuthClientErrorCode.INVALID_ARGUMENT,
816+
'"OIDCAuthProviderConfig.responseType.idToken" must be a boolean.',
817+
);
820818
}
821819

822820
const code = options.responseType.code;
@@ -829,7 +827,7 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
829827
}
830828

831829
// If code flow is enabled, client secret must be provided.
832-
if (typeof options.clientSecret === 'undefined') {
830+
if (code === true && typeof options.clientSecret === 'undefined') {
833831
throw new FirebaseAuthError(
834832
AuthClientErrorCode.MISSING_OAUTH_CLIENT_SECRET,
835833
'The OAuth configuration client secret is required to enable OIDC code flow.',
@@ -897,8 +895,8 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
897895
providerId: this.providerId,
898896
issuer: this.issuer,
899897
clientId: this.clientId,
900-
clientSecret: this.clientSecret,
901-
responseType: this.responseType,
898+
clientSecret: deepCopy(this.clientSecret),
899+
responseType: deepCopy(this.responseType),
902900
};
903901
}
904902
}

test/unit/auth/auth-api-request.spec.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,12 +3503,20 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
35033503
enabled: true,
35043504
clientId: 'CLIENT_ID',
35053505
issuer: 'https://oidc.com/issuer',
3506+
clientSecret: 'CLIENT_SECRET',
3507+
responseType: {
3508+
code: true,
3509+
},
35063510
};
35073511
const expectedRequest = {
35083512
displayName: 'OIDC_DISPLAY_NAME',
35093513
enabled: true,
35103514
clientId: 'CLIENT_ID',
35113515
issuer: 'https://oidc.com/issuer',
3516+
clientSecret: 'CLIENT_SECRET',
3517+
responseType: {
3518+
code: true,
3519+
},
35123520
};
35133521
const expectedResult = utils.responseFrom(deepExtend({
35143522
name: `projects/project1/oauthIdpConfigs/${providerId}`,
@@ -3594,12 +3602,20 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
35943602
enabled: true,
35953603
clientId: 'CLIENT_ID',
35963604
issuer: 'https://oidc.com/issuer',
3605+
clientSecret: 'CLIENT_SECRET',
3606+
responseType: {
3607+
code: true,
3608+
},
35973609
};
35983610
const expectedRequest = {
35993611
displayName: 'OIDC_DISPLAY_NAME',
36003612
enabled: true,
36013613
clientId: 'CLIENT_ID',
36023614
issuer: 'https://oidc.com/issuer',
3615+
clientSecret: 'CLIENT_SECRET',
3616+
responseType: {
3617+
code: true,
3618+
},
36033619
};
36043620
const expectedResult = utils.responseFrom(deepExtend({
36053621
name: `projects/project_id/oauthIdpConfigs/${providerId}`,
@@ -3611,10 +3627,14 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
36113627
enabled: false,
36123628
clientId: 'NEW_CLIENT_ID',
36133629
issuer: 'https://oidc.com/issuer2',
3630+
clientSecret: 'CLIENT_SECRET',
3631+
responseType: {
3632+
code: true,
3633+
},
36143634
}));
36153635

36163636
it('should be fulfilled given full parameters', () => {
3617-
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId';
3637+
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId,clientSecret,responseType.code';
36183638
const stub = sinon.stub(HttpClient.prototype, 'send').resolves(expectedResult);
36193639
stubs.push(stub);
36203640

@@ -3708,7 +3728,7 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
37083728
});
37093729

37103730
it('should be rejected when the backend returns a response missing name', () => {
3711-
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId';
3731+
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId,clientSecret,responseType.code';
37123732
const expectedError = new FirebaseAuthError(
37133733
AuthClientErrorCode.INTERNAL_ERROR,
37143734
'INTERNAL ASSERT FAILED: Unable to update OIDC configuration',
@@ -3728,7 +3748,7 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
37283748
});
37293749

37303750
it('should be rejected when the backend returns an error', () => {
3731-
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId';
3751+
const expectedPath = path + '?updateMask=enabled,displayName,issuer,clientId,clientSecret,responseType.code';
37323752
const expectedServerError = utils.errorFrom({
37333753
error: {
37343754
message: 'INVALID_CONFIG',

test/unit/auth/auth-config.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,14 @@ describe('OIDCConfig', () => {
788788
});
789789

790790
it('should set readonly property expected responseType', () => {
791-
const expectedResponseType = {
792-
code: true,
793-
};
794-
expect(config.responseType).to.deep.equal(expectedResponseType);
791+
expect(config.responseType).to.deep.equal({ code: true });
792+
});
793+
794+
it('should not throw on no responseType and clientSecret', () => {
795+
const testResponse = deepCopy(serverResponse);
796+
delete testResponse.clientSecret;
797+
delete testResponse.responseType;
798+
expect(() => new OIDCConfig(testResponse)).not.to.throw();
795799
});
796800

797801
it('should throw on missing issuer', () => {

0 commit comments

Comments
 (0)