Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions firebase_admin/_auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ def generate_password_reset_link(self, email, action_code_settings=None):

Raises:
ValueError: If the provided arguments are invalid
EmailNotFoundError: If no user exists by the specified email address.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason to use "by" here?

I'd expect "for" probably, here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching. I copied and pasted blindly. It is fixed now here and elsewhere.

FirebaseError: If an error occurs while generating the link
"""
return self._user_manager.generate_email_action_link(
Expand All @@ -464,6 +465,7 @@ def generate_email_verification_link(self, email, action_code_settings=None):

Raises:
ValueError: If the provided arguments are invalid
UserNotFoundError: If no user exists by the specified email address.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be EmailNotFoundError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is the problem. They throw different errors. For password reset, they throw EMAIL_NOT_FOUND. For email verification, they throw USER_NOT_FOUND.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fair enough 👍

FirebaseError: If an error occurs while generating the link
"""
return self._user_manager.generate_email_action_link(
Expand Down
10 changes: 10 additions & 0 deletions firebase_admin/_auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ def __init__(self, message, cause=None, http_response=None):
exceptions.NotFoundError.__init__(self, message, cause, http_response)


class EmailNotFoundError(exceptions.NotFoundError):
"""No user record found for the specified email."""

default_message = 'No user record found for the given email'

def __init__(self, message, cause=None, http_response=None):
exceptions.NotFoundError.__init__(self, message, cause, http_response)


class TenantNotFoundError(exceptions.NotFoundError):
"""No tenant found for the specified identifier."""

Expand Down Expand Up @@ -381,6 +390,7 @@ def __init__(self, message, cause=None, http_response=None):
'DUPLICATE_EMAIL': EmailAlreadyExistsError,
'DUPLICATE_LOCAL_ID': UidAlreadyExistsError,
'EMAIL_EXISTS': EmailAlreadyExistsError,
'EMAIL_NOT_FOUND': EmailNotFoundError,
'INSUFFICIENT_PERMISSION': InsufficientPermissionError,
'INVALID_DYNAMIC_LINK_DOMAIN': InvalidDynamicLinkDomainError,
'INVALID_ID_TOKEN': InvalidIdTokenError,
Expand Down
2 changes: 2 additions & 0 deletions firebase_admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'ConfigurationNotFoundError',
'DELETE_ATTRIBUTE',
'EmailAlreadyExistsError',
'EmailNotFoundError',
'ErrorInfo',
'ExpiredIdTokenError',
'ExpiredSessionCookieError',
Expand Down Expand Up @@ -112,6 +113,7 @@
DELETE_ATTRIBUTE = _user_mgt.DELETE_ATTRIBUTE
DeleteUsersResult = _user_mgt.DeleteUsersResult
EmailAlreadyExistsError = _auth_utils.EmailAlreadyExistsError
EmailNotFoundError = _auth_utils.EmailNotFoundError
ErrorInfo = _user_import.ErrorInfo
ExpiredIdTokenError = _token_gen.ExpiredIdTokenError
ExpiredSessionCookieError = _token_gen.ExpiredSessionCookieError
Expand Down
11 changes: 11 additions & 0 deletions tests/test_user_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,17 @@ def test_api_call_failure(self, user_mgt_app, func):
assert excinfo.value.http_response is not None
assert excinfo.value.cause is not None

def test_password_reset_non_existing(self, user_mgt_app):
_instrument_user_manager(user_mgt_app, 400, '{"error":{"message": "EMAIL_NOT_FOUND"}}')
with pytest.raises(auth.EmailNotFoundError) as excinfo:
auth.generate_password_reset_link(
'nonexistent@user', MOCK_ACTION_CODE_SETTINGS, app=user_mgt_app)
error_msg = 'No user record found for the given email (EMAIL_NOT_FOUND).'
assert excinfo.value.code == exceptions.NOT_FOUND
assert str(excinfo.value) == error_msg
assert excinfo.value.http_response is not None
assert excinfo.value.cause is not None

@pytest.mark.parametrize('func', [
auth.generate_sign_in_with_email_link,
auth.generate_email_verification_link,
Expand Down