Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests and lint
  • Loading branch information
brettwillis committed Mar 8, 2023
commit dc1055dd45e0df4bbecd8211e47a4d83fa7e281a
1 change: 1 addition & 0 deletions etc/firebase-admin.auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export interface UpdateProjectConfigRequest {

// @public
export interface UpdateRequest {
customUserClaims?: object | null;
disabled?: boolean;
displayName?: string | null;
email?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,8 @@ export abstract class AbstractAuthRequestHandler {
'providersToUnlink of properties argument must be an array of strings.');
}
});
} else if ((typeof properties.customUserClaims !== 'undefined') && !validator.isObject(properties.customUserClaims)) {
} else if ((typeof properties.customUserClaims !== 'undefined')
&& !validator.isObject(properties.customUserClaims)) {
return Promise.reject(
new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
Expand Down
3 changes: 2 additions & 1 deletion src/auth/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export interface UpdateRequest {

/**
* If provided, sets additional developer claims on the user's token, overwriting
* any existing claims. If not provided or `undefined`, then existing claims will remain unchanged.
* any existing claims. Providing `null` will clear any existing custom claims.
* If not provided or `undefined`, then existing claims will remain unchanged.
*/
customUserClaims?: object | null;
}
Expand Down
23 changes: 13 additions & 10 deletions test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,8 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
password: 'password',
phoneNumber: '+11234567890',
customUserClaims: {
claim1: true,
admin: true,
groupId: '123',
},
multiFactor: {
enrolledFactors: [
Expand Down Expand Up @@ -2079,7 +2080,7 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
photoUrl: 'http://localhost/1234/photo.png',
password: 'password',
phoneNumber: '+11234567890',
customAttributes: '{"claim1":true}',
customAttributes: JSON.stringify({ admin: true, groupId: '123' }),
mfa: {
enrollments: [
{
Expand Down Expand Up @@ -2110,6 +2111,7 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
disableUser: false,
password: 'password',
phoneNumber: '+11234567890',
customAttributes: JSON.stringify({ admin: true, groupId: '123' }),
deleteAttribute: ['DISPLAY_NAME', 'PHOTO_URL'],
};
// Valid request to delete phoneNumber.
Expand All @@ -2124,12 +2126,13 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
disableUser: false,
photoUrl: 'http://localhost/1234/photo.png',
password: 'password',
customAttributes: JSON.stringify({ admin: true, groupId: '123' }),
deleteProvider: ['phone'],
};
// Valid request to delete custom claims.
const validDeleteCustomClaimsData = deepCopy(validData);
validDeleteCustomClaimsData.customUserClaims = null;
delete validDeletePhoneNumberData.multiFactor;
delete validDeleteCustomClaimsData.multiFactor;
const expectedValidDeleteCustomClaimsData = {
localId: uid,
displayName: 'John Doe',
Expand All @@ -2138,7 +2141,8 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
disableUser: false,
photoUrl: 'http://localhost/1234/photo.png',
password: 'password',
customAttributes: '{}',
phoneNumber: '+11234567890',
customAttributes: JSON.stringify({}),
};
// Valid request to leave custom claims unchanged.
const validUnchangedCustomClaimsData = deepCopy(validData);
Expand All @@ -2152,6 +2156,7 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
disableUser: false,
photoUrl: 'http://localhost/1234/photo.png',
password: 'password',
phoneNumber: '+11234567890',
};
// Valid request to delete all second factors.
const expectedValidDeleteMfaData = {
Expand Down Expand Up @@ -2265,13 +2270,12 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
stubs.push(stub);

const requestHandler = handler.init(mockApp);
// Send update request to delete phone number.
// Send update request to delete custom claims.
return requestHandler.updateExistingAccount(uid, validDeleteCustomClaimsData)
.then((returnedUid: string) => {
// uid should be returned.
expect(returnedUid).to.be.equal(uid);
// Confirm expected rpc request parameters sent. In this case, phoneNumber
// removed from request and deleteProvider added.
// Confirm expected rpc request parameters sent. In this case, customAttributes added.
expect(stub).to.have.been.calledOnce.and.calledWith(
callParams(path, method, expectedValidDeleteCustomClaimsData));
});
Expand All @@ -2288,13 +2292,12 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
stubs.push(stub);

const requestHandler = handler.init(mockApp);
// Send update request to delete phone number.
// Send update request to update account excluding custom claims.
return requestHandler.updateExistingAccount(uid, validUnchangedCustomClaimsData)
.then((returnedUid: string) => {
// uid should be returned.
expect(returnedUid).to.be.equal(uid);
// Confirm expected rpc request parameters sent. In this case, phoneNumber
// removed from request and deleteProvider added.
// Confirm expected rpc request parameters sent. In this case, customAttributes removed.
expect(stub).to.have.been.calledOnce.and.calledWith(
callParams(path, method, expectedValidUnchangedCustomClaimsData));
});
Expand Down