def test_de_dups_duplicate_users(self, new_user): get_users_results = auth.get_users([ auth.UidIdentifier(new_user.uid), auth.UidIdentifier(new_user.uid)]) actual = [ self._map_user_record_to_uid_email_phones(user) for user in get_users_results.users] expected = [self._map_user_record_to_uid_email_phones(new_user)] assert actual == expected
def test_delete_multiple_users(self): uid1 = auth.create_user(disabled=True).uid uid2 = auth.create_user(disabled=False).uid uid3 = auth.create_user(disabled=True).uid delete_users_result = self._slow_delete_users(auth, [uid1, uid2, uid3]) assert delete_users_result.success_count == 3 assert delete_users_result.failure_count == 0 assert len(delete_users_result.errors) == 0 get_users_results = auth.get_users( [auth.UidIdentifier(uid1), auth.UidIdentifier(uid2), auth.UidIdentifier(uid3)]) assert len(get_users_results.users) == 0
def test_existing_and_non_existing_users(self, new_user_record_list): get_users_results = auth.get_users([ auth.UidIdentifier(new_user_record_list[0].uid), auth.UidIdentifier('uid_that_doesnt_exist'), auth.UidIdentifier(new_user_record_list[2].uid)]) actual = sorted([ self._map_user_record_to_uid_email_phones(user) for user in get_users_results.users ], key=lambda user: user['uid']) expected = sorted([ self._map_user_record_to_uid_email_phones(user) for user in [new_user_record_list[0], new_user_record_list[2]] ], key=lambda user: user['uid']) assert actual == expected
def verify_external_auth_associations_are_deleted(user_id: str) -> bool: """Returns true if and only if we have successfully verified that all external associations have been deleted. Args: user_id: str. The unique ID of the user whose associations should be checked. Returns: bool. True if and only if we have successfully verified that all external associations have been deleted. """ auth_id = get_auth_id_from_user_id(user_id, include_deleted=True) if auth_id is None: return True try: result = firebase_auth.get_users( [firebase_auth.UidIdentifier(auth_id)]) return len(result.users) == 0 except (firebase_exceptions.FirebaseError, ValueError): # NOTE: logging.exception appends the stack trace automatically. The # errors are not re-raised because wipeout_services, the user of this # function, will keep retrying the other "delete" family of functions # until this returns True (in 12h intervals). logging.exception('[WIPEOUT] Firebase Admin SDK failed! Stack trace:') return False
def bulk_get_users(): # [START bulk_get_users] from firebase_admin import auth result = auth.get_users([ auth.UidIdentifier('uid1'), auth.EmailIdentifier('*****@*****.**'), auth.PhoneIdentifier(+15555550003), auth.ProviderIdentifier('google.com', 'google_uid4') ]) print('Successfully fetched user data:') for user in result.users: print(user.uid) print('Unable to find users corresponding to these identifiers:') for uid in result.not_found: print(uid)
def test_multiple_uid_types(self, new_user_record_list, new_user_with_provider): get_users_results = auth.get_users([ auth.UidIdentifier(new_user_record_list[0].uid), auth.EmailIdentifier(new_user_record_list[1].email), auth.PhoneIdentifier(new_user_record_list[2].phone_number), auth.ProviderIdentifier( new_user_with_provider.provider_data[0].provider_id, new_user_with_provider.provider_data[0].uid, )]) actual = sorted([ self._map_user_record_to_uid_email_phones(user) for user in get_users_results.users ], key=lambda user: user['uid']) expected = sorted([ self._map_user_record_to_uid_email_phones(user) for user in new_user_record_list + [new_user_with_provider] ], key=lambda user: user['uid']) assert actual == expected
def test_non_existing_users(self): not_found_ids = [auth.UidIdentifier('non-existing user')] get_users_results = auth.get_users(not_found_ids) assert get_users_results.users == [] assert get_users_results.not_found == not_found_ids