Skip to content

Commit 1086515

Browse files
Adds validation for UserImportOptions. (#578)
* Adds validation for UserImportOptions. * Updates error message.
1 parent 843df12 commit 1086515

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/auth/user-import-builder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ export class UserImportBuilder {
298298
if (!requiresHashOptions) {
299299
return {};
300300
}
301+
if (!validator.isNonNullObject(options)) {
302+
throw new FirebaseAuthError(
303+
AuthClientErrorCode.INVALID_ARGUMENT,
304+
'"UserImportOptions" are required when importing users with passwords.',
305+
);
306+
}
301307
if (!validator.isNonNullObject(options.hash)) {
302308
throw new FirebaseAuthError(
303309
AuthClientErrorCode.MISSING_HASH_ALGORITHM,

test/unit/auth/user-import-builder.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ describe('UserImportBuilder', () => {
119119
'MD5', 'SHA1', 'SHA256', 'SHA512', 'PBKDF_SHA1', 'PBKDF2_SHA256',
120120
];
121121
describe('constructor', () => {
122+
const invalidUserImportOptions = [10, 'invalid', undefined, null, true, ['a']];
123+
invalidUserImportOptions.forEach((invalidOption) => {
124+
it(`should throw when non-object ${JSON.stringify(invalidOption)} UserImportOptions is provided`, () => {
125+
const expectedError = new FirebaseAuthError(
126+
AuthClientErrorCode.INVALID_ARGUMENT,
127+
'"UserImportOptions" are required when importing users with passwords.',
128+
);
129+
expect(() => {
130+
return new UserImportBuilder(users, invalidOption as any, userRequestValidator);
131+
}).to.throw(expectedError.message);
132+
});
133+
});
134+
122135
it('should throw when an empty hash algorithm is provided', () => {
123136
const expectedError = new FirebaseAuthError(
124137
AuthClientErrorCode.MISSING_HASH_ALGORITHM,

0 commit comments

Comments
 (0)