diff --git a/firebase_admin/_user_mgt.py b/firebase_admin/_user_mgt.py index c77c4d40d..782e82809 100644 --- a/firebase_admin/_user_mgt.py +++ b/firebase_admin/_user_mgt.py @@ -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, @@ -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 = {} diff --git a/tests/test_user_mgt.py b/tests/test_user_mgt.py index b590cca05..b67c47502 100644 --- a/tests/test_user_mgt.py +++ b/tests/test_user_mgt.py @@ -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): @@ -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])