diff --git a/auth/integration_test/src/integration_test.cc b/auth/integration_test/src/integration_test.cc index 597919f6bf..eef1301adc 100644 --- a/auth/integration_test/src/integration_test.cc +++ b/auth/integration_test/src/integration_test.cc @@ -649,6 +649,38 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) { auth_->CreateUserWithEmailAndPassword(email.c_str(), kTestPassword); WaitForCompletion(create_user, "CreateUserWithEmailAndPassword"); EXPECT_TRUE(auth_->current_user().is_valid()); + + // Set some user profile properties. + firebase::auth::User user = create_user.result()->user; + const char kDisplayName[] = "Hello World"; + const char kPhotoUrl[] = "http://example.com/image.jpg"; + firebase::auth::User::UserProfile user_profile; + user_profile.display_name = kDisplayName; + user_profile.photo_url = kPhotoUrl; + firebase::Future update_profile = user.UpdateUserProfile(user_profile); + WaitForCompletion(update_profile, "UpdateUserProfile"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), kDisplayName); + EXPECT_EQ(user.photo_url(), kPhotoUrl); + + // Validate that the new properties are present after signing out and in. + SignOut(); + WaitForCompletion( + auth_->SignInWithEmailAndPassword(email.c_str(), kTestPassword), + "SignInWithEmailAndPassword"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), kDisplayName); + EXPECT_EQ(user.photo_url(), kPhotoUrl); + DeleteUser(); +} + +TEST_F(FirebaseAuthTest, TestUpdateUserProfileNull) { + std::string email = GenerateEmailAddress(); + firebase::Future create_user = + auth_->CreateUserWithEmailAndPassword(email.c_str(), kTestPassword); + WaitForCompletion(create_user, "CreateUserWithEmailAndPassword"); + EXPECT_TRUE(auth_->current_user().is_valid()); + // Set some user profile properties. firebase::auth::User user = create_user.result()->user; const char kDisplayName[] = "Hello World"; @@ -661,6 +693,19 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) { user = auth_->current_user(); EXPECT_EQ(user.display_name(), kDisplayName); EXPECT_EQ(user.photo_url(), kPhotoUrl); + + // Setting the entries to null should leave the old values + firebase::auth::User::UserProfile user_profile_null; + user_profile_null.display_name = nullptr; + user_profile_null.photo_url = nullptr; + firebase::Future update_profile_null = + user.UpdateUserProfile(user_profile_null); + WaitForCompletion(update_profile_null, "UpdateUserProfileNull"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), kDisplayName); + EXPECT_EQ(user.photo_url(), kPhotoUrl); + + // Validate that the new properties are present after signing out and in. SignOut(); WaitForCompletion( auth_->SignInWithEmailAndPassword(email.c_str(), kTestPassword), @@ -671,6 +716,48 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfile) { DeleteUser(); } +TEST_F(FirebaseAuthTest, TestUpdateUserProfileEmpty) { + std::string email = GenerateEmailAddress(); + firebase::Future create_user = + auth_->CreateUserWithEmailAndPassword(email.c_str(), kTestPassword); + WaitForCompletion(create_user, "CreateUserWithEmailAndPassword"); + EXPECT_TRUE(auth_->current_user().is_valid()); + + // Set some user profile properties. + firebase::auth::User user = create_user.result()->user; + const char kDisplayName[] = "Hello World"; + const char kPhotoUrl[] = "http://example.com/image.jpg"; + firebase::auth::User::UserProfile user_profile; + user_profile.display_name = kDisplayName; + user_profile.photo_url = kPhotoUrl; + firebase::Future update_profile = user.UpdateUserProfile(user_profile); + WaitForCompletion(update_profile, "UpdateUserProfile"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), kDisplayName); + EXPECT_EQ(user.photo_url(), kPhotoUrl); + + // Setting the fields to empty should clear it. + firebase::auth::User::UserProfile user_profile_empty; + user_profile_empty.display_name = ""; + user_profile_empty.photo_url = ""; + firebase::Future update_profile_empty = + user.UpdateUserProfile(user_profile_empty); + WaitForCompletion(update_profile_empty, "UpdateUserProfileEmpty"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), ""); + EXPECT_EQ(user.photo_url(), ""); + + // Validate that the properties are cleared out after signing out and in. + SignOut(); + WaitForCompletion( + auth_->SignInWithEmailAndPassword(email.c_str(), kTestPassword), + "SignInWithEmailAndPassword"); + user = auth_->current_user(); + EXPECT_EQ(user.display_name(), ""); + EXPECT_EQ(user.photo_url(), ""); + DeleteUser(); +} + TEST_F(FirebaseAuthTest, TestUpdateEmailAndPassword) { std::string email = GenerateEmailAddress(); WaitForCompletion( diff --git a/auth/src/android/user_android.cc b/auth/src/android/user_android.cc index 7fd679e8b1..4e638a85db 100644 --- a/auth/src/android/user_android.cc +++ b/auth/src/android/user_android.cc @@ -425,7 +425,10 @@ Future User::UpdateUserProfile(const UserProfile& profile) { // Extra painfully call UserProfileChangeRequest.Builder.setPhotoUri. if (error == kAuthErrorNone && profile.photo_url != nullptr) { - jobject j_uri = CharsToJniUri(env, profile.photo_url); + jobject j_uri = nullptr; + if (strlen(profile.photo_url) > 0) { + j_uri = CharsToJniUri(env, profile.photo_url); + } jobject j_builder_discard = env->CallObjectMethod( j_user_profile_builder, userprofilebuilder::GetMethodId(userprofilebuilder::kSetPhotoUri), @@ -434,7 +437,9 @@ Future User::UpdateUserProfile(const UserProfile& profile) { if (j_builder_discard) { env->DeleteLocalRef(j_builder_discard); } - env->DeleteLocalRef(j_uri); + if (j_uri) { + env->DeleteLocalRef(j_uri); + } } jobject j_user_profile_request = nullptr; diff --git a/release_build_files/readme.md b/release_build_files/readme.md index e66d896e9e..9ddcdec602 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -631,6 +631,11 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### Upcoming Release +- Changes + - Auth (Android): Setting photo_url to empty string with UpdateUserProfile + clears the field, making it consistent with the other platforms. + ### 12.3.0 - Changes - General (iOS): Update to Firebase Cocoapods version 11.2.0.