Skip to content

Handle lookup returning empty array of users. #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export const FIREBASE_AUTH_GET_ACCOUNT_INFO = new ApiSettings('/accounts:lookup'
})
// Set response validator.
.setResponseValidator((response: any) => {
if (!response.users) {
if (!response.users || !response.users.length) {
throw new FirebaseAuthError(AuthClientErrorCode.USER_NOT_FOUND);
}
});
Expand Down
10 changes: 8 additions & 2 deletions test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,23 @@ describe('FIREBASE_AUTH_GET_ACCOUNT_INFO', () => {
describe('responseValidator', () => {
const responseValidator = FIREBASE_AUTH_GET_ACCOUNT_INFO.getResponseValidator();
it('should succeed with users returned', () => {
const validResponse: object = { users: [] };
const validResponse: object = { users: [{ localId: 'foo' }] };
expect(() => {
return responseValidator(validResponse);
}).not.to.throw();
});
it('should fail when users is not returned', () => {
it('should fail when the response object is empty', () => {
const invalidResponse = {};
expect(() => {
responseValidator(invalidResponse);
}).to.throw();
});
it('should fail when the response object has an empty list of users', () => {
const invalidResponse = { users: [] };
expect(() => {
responseValidator(invalidResponse);
}).to.throw();
});
});
});

Expand Down