Skip to content
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

#678 fixed removing email from userRecord via update_user #744

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion firebase_admin/_user_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def update_user(self, uid, display_name=None, email=None, phone_number=None,
"""Updates an existing user account with the specified properties"""
payload = {
'localId': _auth_utils.validate_uid(uid, required=True),
'email': _auth_utils.validate_email(email),
'email': _auth_utils.validate_email(email) if email is not DELETE_ATTRIBUTE else None,
'password': _auth_utils.validate_password(password),
'validSince': _auth_utils.validate_timestamp(valid_since, 'valid_since'),
'emailVerified': bool(email_verified) if email_verified is not None else None,
Expand Down Expand Up @@ -720,6 +720,12 @@ def update_user(self, uid, display_name=None, email=None, phone_number=None,
else:
payload['phoneNumber'] = _auth_utils.validate_phone(phone_number)

if email is not None:
if email is DELETE_ATTRIBUTE:
remove_provider.append('email')
else:
payload['email'] = _auth_utils.validate_email(email)

if custom_claims is not None:
if custom_claims is DELETE_ATTRIBUTE:
custom_claims = {}
Expand Down
16 changes: 14 additions & 2 deletions tests/test_user_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,13 @@ def test_update_user_delete_fields(self, user_mgt_app):
'testuser',
display_name=auth.DELETE_ATTRIBUTE,
photo_url=auth.DELETE_ATTRIBUTE,
phone_number=auth.DELETE_ATTRIBUTE)
phone_number=auth.DELETE_ATTRIBUTE,
email=auth.DELETE_ATTRIBUTE)
request = json.loads(recorder[0].body.decode())
assert request == {
'localId' : 'testuser',
'deleteAttribute' : ['DISPLAY_NAME', 'PHOTO_URL'],
'deleteProvider' : ['phone'],
'deleteProvider' : ['phone', 'email'],
}

def test_update_user_error(self, user_mgt_app):
Expand Down Expand Up @@ -681,6 +682,17 @@ def test_update_user_delete_provider_and_phone(self, user_mgt_app, arg):
assert len(set(request['deleteProvider'])) == len(request['deleteProvider'])
assert set(arg) - set(request['deleteProvider']) == set()

@pytest.mark.parametrize('arg', [['email', 'phone', 'google.com']])
def test_update_user_delete_provider_and_email(self, user_mgt_app, arg):
user_mgt, recorder = _instrument_user_manager(user_mgt_app, 200, '{"localId":"testuser"}')
user_mgt.update_user('testuser',
email='yuvi@gmail.com',
providers_to_delete=arg)
request = json.loads(recorder[0].body.decode())
assert 'email' in request['deleteProvider']
assert len(set(request['deleteProvider'])) == len(request['deleteProvider'])
assert set(arg) - set(request['deleteProvider']) == set()

class TestSetCustomUserClaims:

@pytest.mark.parametrize('arg', INVALID_STRINGS + ['a'*129])
Expand Down