@@ -111,12 +111,6 @@ static bool WaitForSignInFuture(Future<User*> sign_in_future, const char* fn,
111
111
static_cast <int >(reinterpret_cast <intptr_t >(auth_user)));
112
112
}
113
113
114
- const bool should_be_null = expected_error != kAuthErrorNone ;
115
- const bool is_null = sign_in_user == nullptr ;
116
- if (should_be_null != is_null) {
117
- LogMessage (" ERROR: user pointer (%x) is incorrect" ,
118
- static_cast <int >(reinterpret_cast <intptr_t >(auth_user)));
119
- }
120
114
return false ;
121
115
}
122
116
@@ -326,7 +320,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
326
320
auth->SignOut ();
327
321
if (auth->current_user () != nullptr ) {
328
322
LogMessage (
329
- " ERROR: current_user() returning %x instead of NULL after "
323
+ " ERROR: current_user() returning %x instead of nullptr after "
330
324
" SignOut()" ,
331
325
auth->current_user ());
332
326
}
@@ -373,12 +367,15 @@ extern "C" int common_main(int argc, const char* argv[]) {
373
367
Future<User*> sign_in_future = auth->SignInAnonymously ();
374
368
WaitForSignInFuture (sign_in_future, " Auth::SignInAnonymously()" ,
375
369
kAuthErrorNone , auth);
370
+ ExpectTrue (" SignInAnonymouslyLastResult matches returned Future" ,
371
+ sign_in_future == auth->SignInAnonymouslyLastResult ());
372
+
376
373
// Test SignOut() after signed in anonymously.
377
374
if (sign_in_future.status () == ::firebase::kFutureStatusComplete ) {
378
375
auth->SignOut ();
379
376
if (auth->current_user () != nullptr ) {
380
377
LogMessage (
381
- " ERROR: current_user() returning %x instead of NULL after "
378
+ " ERROR: current_user() returning %x instead of nullptr after "
382
379
" SignOut()" ,
383
380
auth->current_user ());
384
381
}
@@ -391,6 +388,10 @@ extern "C" int common_main(int argc, const char* argv[]) {
391
388
auth->FetchProvidersForEmail (user_login.email ());
392
389
WaitForFuture (providers_future, " Auth::FetchProvidersForEmail()" ,
393
390
kAuthErrorNone );
391
+ ExpectTrue (
392
+ " FetchProvidersForEmailLastResult matches returned Future" ,
393
+ providers_future == auth->FetchProvidersForEmailLastResult ());
394
+
394
395
const Auth::FetchProvidersResult* pro = providers_future.result ();
395
396
if (pro) {
396
397
LogMessage (" email %s, num providers %d" , user_login.email (),
@@ -411,12 +412,16 @@ extern "C" int common_main(int argc, const char* argv[]) {
411
412
sign_in_future,
412
413
" Auth::SignInWithEmailAndPassword() existing email and password" ,
413
414
kAuthErrorNone , auth);
415
+ ExpectTrue (
416
+ " SignInWithEmailAndPasswordLastResult matches returned Future" ,
417
+ sign_in_future == auth->SignInWithEmailAndPasswordLastResult ());
418
+
414
419
// Test SignOut() after signed in with email and password.
415
420
if (sign_in_future.status () == ::firebase::kFutureStatusComplete ) {
416
421
auth->SignOut ();
417
422
if (auth->current_user () != nullptr ) {
418
423
LogMessage (
419
- " ERROR: current_user() returning %x instead of NULL after "
424
+ " ERROR: current_user() returning %x instead of nullptr after "
420
425
" SignOut()" ,
421
426
auth->current_user ());
422
427
}
@@ -450,6 +455,10 @@ extern "C" int common_main(int argc, const char* argv[]) {
450
455
create_future_bad,
451
456
" Auth::CreateUserWithEmailAndPassword() existing email" ,
452
457
kAuthErrorFailure , auth);
458
+ ExpectTrue (
459
+ " CreateUserWithEmailAndPasswordLastResult matches returned Future" ,
460
+ create_future_bad ==
461
+ auth->CreateUserWithEmailAndPasswordLastResult ());
453
462
}
454
463
455
464
// Test Auth::SignInWithCredential() using email&password.
@@ -462,6 +471,8 @@ extern "C" int common_main(int argc, const char* argv[]) {
462
471
WaitForSignInFuture (sign_in_cred_ok,
463
472
" Auth::SignInWithCredential() existing email" ,
464
473
kAuthErrorNone , auth);
474
+ ExpectTrue (" SignInWithCredentialLastResult matches returned Future" ,
475
+ sign_in_cred_ok == auth->SignInWithCredentialLastResult ());
465
476
}
466
477
467
478
// Use bad Facebook credentials. Should fail.
@@ -516,6 +527,9 @@ extern "C" int common_main(int argc, const char* argv[]) {
516
527
WaitForFuture (send_password_reset_ok,
517
528
" Auth::SendPasswordResetEmail() existing email" ,
518
529
kAuthErrorNone );
530
+ ExpectTrue (
531
+ " SendPasswordResetEmailLastResult matches returned Future" ,
532
+ send_password_reset_ok == auth->SendPasswordResetEmailLastResult ());
519
533
}
520
534
521
535
// Use bad email. Should fail.
@@ -554,14 +568,42 @@ extern "C" int common_main(int argc, const char* argv[]) {
554
568
ExpectFalse (" Email email is_email_verified()" ,
555
569
anonymous_user->is_email_verified ());
556
570
557
- // Test User::LinkWithCredential().
571
+ // Test User::LinkWithCredential(), linking with email & password .
558
572
const std::string newer_email = CreateNewEmail ();
559
573
Credential user_cred = EmailAuthProvider::GetCredential (
560
574
newer_email.c_str (), kTestPassword );
561
- Future<User*> link_future =
562
- anonymous_user->LinkWithCredential (user_cred);
563
- WaitForSignInFuture (link_future, " User::LinkWithCredential()" ,
564
- kAuthErrorNone , auth);
575
+ {
576
+ Future<User*> link_future =
577
+ anonymous_user->LinkWithCredential (user_cred);
578
+ WaitForSignInFuture (link_future, " User::LinkWithCredential()" ,
579
+ kAuthErrorNone , auth);
580
+ }
581
+
582
+ // Test User::LinkWithCredential(), linking with same email & password.
583
+ {
584
+ Future<User*> link_future =
585
+ anonymous_user->LinkWithCredential (user_cred);
586
+ WaitForSignInFuture (link_future, " User::LinkWithCredential() again" ,
587
+ kAuthErrorNone , auth);
588
+ }
589
+
590
+ // Test User::LinkWithCredential(), linking with bad credential.
591
+ // Call should fail and Auth's current user should be maintained.
592
+ {
593
+ const User* pre_link_user = auth->current_user ();
594
+ ExpectTrue (" Test precondition requires active user" ,
595
+ pre_link_user != nullptr );
596
+
597
+ Credential twitter_cred_bad = TwitterAuthProvider::GetCredential (
598
+ kTestIdTokenBad , kTestAccessTokenBad );
599
+ Future<User*> link_bad_future =
600
+ anonymous_user->LinkWithCredential (twitter_cred_bad);
601
+ WaitForFuture (link_bad_future,
602
+ " User::LinkWithCredential() with bad credential" ,
603
+ kAuthErrorFailure );
604
+ ExpectTrue (" Linking maintains user" ,
605
+ auth->current_user () == pre_link_user);
606
+ }
565
607
566
608
UserLogin user_login (auth);
567
609
user_login.Register ();
0 commit comments