Skip to content

Commit 0fd6f7b

Browse files
authored
Android Auth Google I/O rework (#1245)
Removes the need for User objects to be stored in AuthData, unlocking ability for there to be more than one User object at a time. Continues to store a User in Auth, though, to maintain the implementation of the newly deprecated methods which return a User*. Added a RetainUser integration test.
1 parent c208b23 commit 0fd6f7b

17 files changed

+1501
-659
lines changed

auth/integration_test/src/integration_test.cc

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class FirebaseAuthTest : public FirebaseTest {
9999
void SignOut();
100100

101101
// Delete the current user if it's currently signed in.
102-
void DeleteUser();
102+
void DeleteUser(firebase::auth::User* user = nullptr);
103103

104104
// Passthrough method to the base class's WaitForCompletion.
105105
bool WaitForCompletion(firebase::Future<std::string> future, const char* fn,
@@ -261,11 +261,15 @@ void FirebaseAuthTest::SignOut() {
261261
EXPECT_EQ(auth_->current_user_DEPRECATED(), nullptr);
262262
}
263263

264-
void FirebaseAuthTest::DeleteUser() {
265-
if (auth_ != nullptr && auth_->current_user_DEPRECATED() != nullptr) {
266-
FirebaseTest::WaitForCompletion(auth_->current_user_DEPRECATED()->Delete(),
267-
"Delete User");
268-
ProcessEvents(100);
264+
void FirebaseAuthTest::DeleteUser(firebase::auth::User* user) {
265+
if (auth_ != nullptr) {
266+
if (user == nullptr) {
267+
user = auth_->current_user_DEPRECATED();
268+
}
269+
if (user != nullptr) {
270+
FirebaseTest::WaitForCompletion(user->Delete(), "Delete User");
271+
ProcessEvents(100);
272+
}
269273
}
270274
}
271275

@@ -454,6 +458,37 @@ TEST_F(FirebaseAuthTest, TestEmailAndPasswordSignin) {
454458
EXPECT_EQ(auth_->current_user_DEPRECATED(), nullptr);
455459
}
456460

461+
TEST_F(FirebaseAuthTest, TestRetainUser) {
462+
WaitForCompletion(auth_->SignInAnonymously_DEPRECATED(), "SignInAnonymously");
463+
ASSERT_NE(auth_->current_user_DEPRECATED(), nullptr);
464+
firebase::auth::User anonymous_user = *auth_->current_user_DEPRECATED();
465+
EXPECT_EQ(anonymous_user.is_anonymous(), true);
466+
EXPECT_EQ(anonymous_user.email().size(), 0);
467+
468+
SignOut();
469+
470+
std::string email = GenerateEmailAddress();
471+
// Register a random email and password. This signs us in as that user.
472+
std::string password = kTestPassword;
473+
firebase::Future<firebase::auth::User*> create_user_future =
474+
auth_->CreateUserWithEmailAndPassword_DEPRECATED(email.c_str(),
475+
password.c_str());
476+
WaitForCompletion(create_user_future,
477+
"CreateUserWithEmailAndPassword_DEPRECATED");
478+
EXPECT_NE(auth_->current_user_DEPRECATED(), nullptr);
479+
firebase::auth::User* email_user = auth_->current_user_DEPRECATED();
480+
481+
// Ensure the users are distinct objects.
482+
EXPECT_EQ(anonymous_user.is_anonymous(), true);
483+
EXPECT_EQ(email_user->is_anonymous(), false);
484+
485+
EXPECT_EQ(anonymous_user.email().size(), 0);
486+
EXPECT_NE(email_user->email().size(), 0);
487+
488+
DeleteUser();
489+
DeleteUser(&anonymous_user);
490+
}
491+
457492
TEST_F(FirebaseAuthTest, TestUpdateUserProfile) {
458493
std::string email = GenerateEmailAddress();
459494
firebase::Future<firebase::auth::User*> create_user =

0 commit comments

Comments
 (0)