8000 Add handling for InvalidHostingLinkDomainError · huwmartin/firebase-admin-python@bb1a986 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb1a986

Browse files
committed
Add handling for InvalidHostingLinkDomainError
1 parent 6e9058f commit bb1a986

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

firebase_admin/_auth_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ def __init__(self, message, cause, http_response):
328328
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)
329329

330330

331+
class InvalidHostingLinkDomainError(exceptions.InvalidArgumentError):
332+
"""Hosting link domain in ActionCodeSettings is not authorized."""
333+
334+
default_message = 'Hosting link domain specified in ActionCodeSettings is not authorized'
335+
336+
def __init__(self, message, cause, http_response):
337+
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)
338+
339+
331340
class InvalidIdTokenError(exceptions.InvalidArgumentError):
332341
"""The provided ID token is not a valid Firebase ID token."""
333342

@@ -427,6 +436,7 @@ def __init__(self, message, cause=None, http_response=None):
427436
'EMAIL_NOT_FOUND': EmailNotFoundError,
428437
'INSUFFICIENT_PERMISSION': InsufficientPermissionError,
429438
'INVALID_DYNAMIC_LINK_DOMAIN': InvalidDynamicLinkDomainError,
439+
'INVALID_HOSTING_LINK_DOMAIN': InvalidHostingLinkDomainError,
430440
'INVALID_ID_TOKEN': InvalidIdTokenError,
431441
'PHONE_NUMBER_EXISTS': PhoneNumberAlreadyExistsError,
432442
'TENANT_NOT_FOUND': TenantNotFoundError,

firebase_admin/auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'ImportUserRecord',
5050
'InsufficientPermissionError',
5151
'InvalidDynamicLinkDomainError',
52+
'InvalidHostingLinkDomainError',
5253
'InvalidIdTokenError',
5354
'InvalidSessionCookieError',
5455
'ListProviderConfigsPage',
@@ -125,6 +126,7 @@
125126
ImportUserRecord = _user_import.ImportUserRecord
126127
InsufficientPermissionError = _auth_utils.InsufficientPermissionError
127128
InvalidDynamicLinkDomainError = _auth_utils.InvalidDynamicLinkDomainError
129+
InvalidHostingLinkDomainError = _auth_utils.InvalidHostingLinkDomainError
128130
InvalidIdTokenError = _auth_utils.InvalidIdTokenError
129131
InvalidSessionCookieError = _token_gen.InvalidSessionCookieError
130132
ListProviderConfigsPage = _auth_providers.ListProviderConfigsPage

tests/test_user_mgt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,23 @@ def test_invalid_dynamic_link(self, user_mgt_app, func):
15001500
assert excinfo.value.http_response is not None
15011501
assert excinfo.value.cause is not None
15021502

1503+
@pytest.mark.parametrize('func', [
1504+
auth.generate_sign_in_with_email_link,
1505+
auth.generate_email_verification_link,
1506+
auth.generate_password_reset_link,
1507+
])
1508+
def test_invalid_hosting_link(self, user_mgt_app, func):
1509+
resp = '{"error":{"message": "INVALID_HOSTING_LINK_DOMAIN: Because of this reason."}}'
1510+
_instrument_user_manager(user_mgt_app, 500, resp)
1511+
with pytest.raises(auth.InvalidHostingLinkDomainError) as excinfo:
1512+
func('test@test.com', MOCK_ACTION_CODE_SETTINGS, app=user_mgt_app)
1513+
assert isinstance(excinfo.value, exceptions.InvalidArgumentError)
1514+
assert str(excinfo.value) == ('Hosting link domain specified in ActionCodeSettings is '
1515+
'not authorized (INVALID_HOSTING_LINK_DOMAIN). Because '
1516+
'of this reason.')
1517+
assert excinfo.value.http_response is not None
1518+
assert excinfo.value.cause is not None
1519+
15031520
@pytest.mark.parametrize('func', [
15041521
auth.generate_sign_in_with_email_link,
15051522
auth.generate_email_verification_link,

0 commit comments

Comments
 (0)
0