OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 register_completed_ = true; | 130 register_completed_ = true; |
131 dm_token_ = dm_token; | 131 dm_token_ = dm_token; |
132 client_id_ = client_id; | 132 client_id_ = client_id; |
133 } | 133 } |
134 | 134 |
135 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { | 135 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { |
136 // Policy client registration on Android depends on Token Service having | 136 // Policy client registration on Android depends on Token Service having |
137 // a valid login token, while on other platforms, the login refresh token | 137 // a valid login token, while on other platforms, the login refresh token |
138 // is specified directly. | 138 // is specified directly. |
139 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
140 GetTokenService()->IssueRefreshTokenForUser( | 140 GetTokenService()->UpdateCredentials( |
141 AccountTrackerService::PickAccountIdForAccount( | 141 AccountTrackerService::PickAccountIdForAccount( |
142 profile_.get()->GetPrefs(), kTestGaiaId, kTestUser), | 142 profile_.get()->GetPrefs(), kTestGaiaId, kTestUser), |
143 "oauth2_login_refresh_token"); | 143 "oauth2_login_refresh_token"); |
144 #endif | 144 #endif |
145 service->RegisterForPolicy( | 145 service->RegisterForPolicy( |
146 kTestUser, | 146 kTestUser, |
147 #if !defined(OS_ANDROID) | 147 #if !defined(OS_ANDROID) |
148 "mock_oauth_token", | 148 "mock_oauth_token", |
149 #endif | 149 #endif |
150 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, | 150 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 // UserCloudPolicyManager should be initialized. | 423 // UserCloudPolicyManager should be initialized. |
424 ASSERT_TRUE(manager_->core()->service()); | 424 ASSERT_TRUE(manager_->core()->service()); |
425 | 425 |
426 // Complete initialization of the store. | 426 // Complete initialization of the store. |
427 mock_store_->NotifyStoreLoaded(); | 427 mock_store_->NotifyStoreLoaded(); |
428 | 428 |
429 // No oauth access token yet, so client registration should be deferred. | 429 // No oauth access token yet, so client registration should be deferred. |
430 ASSERT_FALSE(IsRequestActive()); | 430 ASSERT_FALSE(IsRequestActive()); |
431 | 431 |
432 // Make oauth token available. | 432 // Make oauth token available. |
433 GetTokenService()->IssueRefreshTokenForUser( | 433 GetTokenService()->UpdateCredentials( |
434 SigninManagerFactory::GetForProfile(profile_.get()) | 434 SigninManagerFactory::GetForProfile(profile_.get()) |
435 ->GetAuthenticatedAccountId(), | 435 ->GetAuthenticatedAccountId(), |
436 "oauth_login_refresh_token"); | 436 "oauth_login_refresh_token"); |
437 | 437 |
438 // Client registration should be in progress since we now have an oauth token. | 438 // Client registration should be in progress since we now have an oauth token. |
439 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 439 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
440 ASSERT_TRUE(IsRequestActive()); | 440 ASSERT_TRUE(IsRequestActive()); |
441 } | 441 } |
442 | 442 |
443 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { | 443 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { |
444 // UserCloudPolicyManager should be initialized. | 444 // UserCloudPolicyManager should be initialized. |
445 ASSERT_TRUE(manager_->core()->service()); | 445 ASSERT_TRUE(manager_->core()->service()); |
446 | 446 |
447 // Complete initialization of the store. | 447 // Complete initialization of the store. |
448 mock_store_->NotifyStoreLoaded(); | 448 mock_store_->NotifyStoreLoaded(); |
449 | 449 |
450 // No oauth access token yet, so client registration should be deferred. | 450 // No oauth access token yet, so client registration should be deferred. |
451 ASSERT_FALSE(IsRequestActive()); | 451 ASSERT_FALSE(IsRequestActive()); |
452 | 452 |
453 // Make oauth token available. | 453 // Make oauth token available. |
454 GetTokenService()->IssueRefreshTokenForUser( | 454 GetTokenService()->UpdateCredentials( |
455 SigninManagerFactory::GetForProfile(profile_.get()) | 455 SigninManagerFactory::GetForProfile(profile_.get()) |
456 ->GetAuthenticatedAccountId(), | 456 ->GetAuthenticatedAccountId(), |
457 "oauth_login_refresh_token"); | 457 "oauth_login_refresh_token"); |
458 | 458 |
459 // Client registration should be in progress since we now have an oauth token. | 459 // Client registration should be in progress since we now have an oauth token. |
460 ASSERT_TRUE(IsRequestActive()); | 460 ASSERT_TRUE(IsRequestActive()); |
461 | 461 |
462 // Now fail the access token fetch. | 462 // Now fail the access token fetch. |
463 GoogleServiceAuthError error( | 463 GoogleServiceAuthError error( |
464 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 464 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
465 GetTokenService()->IssueErrorForAllPendingRequests(error); | 465 GetTokenService()->IssueErrorForAllPendingRequests(error); |
466 ASSERT_FALSE(IsRequestActive()); | 466 ASSERT_FALSE(IsRequestActive()); |
467 } | 467 } |
468 | 468 |
469 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { | 469 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { |
470 // UserCloudPolicyManager should not be initialized since there is no | 470 // UserCloudPolicyManager should not be initialized since there is no |
471 // signed-in user. | 471 // signed-in user. |
472 ASSERT_FALSE(manager_->core()->service()); | 472 ASSERT_FALSE(manager_->core()->service()); |
473 | 473 |
474 // Now sign in the user. | 474 // Now sign in the user. |
475 SigninManagerFactory::GetForProfile(profile_.get()) | 475 SigninManagerFactory::GetForProfile(profile_.get()) |
476 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); | 476 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
477 | 477 |
478 // Complete initialization of the store. | 478 // Complete initialization of the store. |
479 mock_store_->NotifyStoreLoaded(); | 479 mock_store_->NotifyStoreLoaded(); |
480 | 480 |
481 // Make oauth token available. | 481 // Make oauth token available. |
482 GetTokenService()->IssueRefreshTokenForUser( | 482 GetTokenService()->UpdateCredentials( |
483 SigninManagerFactory::GetForProfile(profile_.get()) | 483 SigninManagerFactory::GetForProfile(profile_.get()) |
484 ->GetAuthenticatedAccountId(), | 484 ->GetAuthenticatedAccountId(), |
485 "oauth_login_refresh_token"); | 485 "oauth_login_refresh_token"); |
486 | 486 |
487 // UserCloudPolicyManager should be initialized. | 487 // UserCloudPolicyManager should be initialized. |
488 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 488 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
489 ASSERT_TRUE(manager_->core()->service()); | 489 ASSERT_TRUE(manager_->core()->service()); |
490 | 490 |
491 // Client registration should be in progress since we have an oauth token. | 491 // Client registration should be in progress since we have an oauth token. |
492 ASSERT_TRUE(IsRequestActive()); | 492 ASSERT_TRUE(IsRequestActive()); |
493 } | 493 } |
494 | 494 |
495 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { | 495 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { |
496 // UserCloudPolicyManager should not be initialized since there is no | 496 // UserCloudPolicyManager should not be initialized since there is no |
497 // signed-in user. | 497 // signed-in user. |
498 ASSERT_FALSE(manager_->core()->service()); | 498 ASSERT_FALSE(manager_->core()->service()); |
499 | 499 |
500 // Now sign in a non-enterprise user (blacklisted gmail.com domain). | 500 // Now sign in a non-enterprise user (blacklisted gmail.com domain). |
501 SigninManagerFactory::GetForProfile(profile_.get()) | 501 SigninManagerFactory::GetForProfile(profile_.get()) |
502 ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com", | 502 ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com", |
503 "non_enterprise_user@gmail.com"); | 503 "non_enterprise_user@gmail.com"); |
504 | 504 |
505 // Complete initialization of the store. | 505 // Complete initialization of the store. |
506 mock_store_->NotifyStoreLoaded(); | 506 mock_store_->NotifyStoreLoaded(); |
507 | 507 |
508 // Make oauth token available. | 508 // Make oauth token available. |
509 GetTokenService()->IssueRefreshTokenForUser( | 509 GetTokenService()->UpdateCredentials( |
510 SigninManagerFactory::GetForProfile(profile_.get()) | 510 SigninManagerFactory::GetForProfile(profile_.get()) |
511 ->GetAuthenticatedAccountId(), | 511 ->GetAuthenticatedAccountId(), |
512 "oauth_login_refresh_token"); | 512 "oauth_login_refresh_token"); |
513 | 513 |
514 // UserCloudPolicyManager should not be initialized and there should be no | 514 // UserCloudPolicyManager should not be initialized and there should be no |
515 // DMToken request active. | 515 // DMToken request active. |
516 ASSERT_TRUE(!manager_->core()->service()); | 516 ASSERT_TRUE(!manager_->core()->service()); |
517 ASSERT_FALSE(IsRequestActive()); | 517 ASSERT_FALSE(IsRequestActive()); |
518 } | 518 } |
519 | 519 |
520 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { | 520 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { |
521 // UserCloudPolicyManager should not be initialized since there is no | 521 // UserCloudPolicyManager should not be initialized since there is no |
522 // signed-in user. | 522 // signed-in user. |
523 ASSERT_FALSE(manager_->core()->service()); | 523 ASSERT_FALSE(manager_->core()->service()); |
524 | 524 |
525 // Now sign in the user. | 525 // Now sign in the user. |
526 SigninManagerFactory::GetForProfile(profile_.get()) | 526 SigninManagerFactory::GetForProfile(profile_.get()) |
527 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); | 527 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
528 | 528 |
529 // Make oauth token available. | 529 // Make oauth token available. |
530 GetTokenService()->IssueRefreshTokenForUser( | 530 GetTokenService()->UpdateCredentials( |
531 SigninManagerFactory::GetForProfile(profile_.get()) | 531 SigninManagerFactory::GetForProfile(profile_.get()) |
532 ->GetAuthenticatedAccountId(), | 532 ->GetAuthenticatedAccountId(), |
533 "oauth_login_refresh_token"); | 533 "oauth_login_refresh_token"); |
534 | 534 |
535 // UserCloudPolicyManager should be initialized. | 535 // UserCloudPolicyManager should be initialized. |
536 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 536 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
537 ASSERT_TRUE(manager_->core()->service()); | 537 ASSERT_TRUE(manager_->core()->service()); |
538 | 538 |
539 // Client registration should not be in progress since the store is not | 539 // Client registration should not be in progress since the store is not |
540 // yet initialized. | 540 // yet initialized. |
541 ASSERT_FALSE(IsRequestActive()); | 541 ASSERT_FALSE(IsRequestActive()); |
542 | 542 |
543 // Complete initialization of the store with no policy (unregistered client). | 543 // Complete initialization of the store with no policy (unregistered client). |
544 mock_store_->NotifyStoreLoaded(); | 544 mock_store_->NotifyStoreLoaded(); |
545 | 545 |
546 // Client registration should be in progress since we have an oauth token. | 546 // Client registration should be in progress since we have an oauth token. |
547 ASSERT_TRUE(IsRequestActive()); | 547 ASSERT_TRUE(IsRequestActive()); |
548 } | 548 } |
549 | 549 |
550 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { | 550 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { |
551 // UserCloudPolicyManager should not be initialized since there is no | 551 // UserCloudPolicyManager should not be initialized since there is no |
552 // signed-in user. | 552 // signed-in user. |
553 ASSERT_FALSE(manager_->core()->service()); | 553 ASSERT_FALSE(manager_->core()->service()); |
554 | 554 |
555 // Now sign in the user. | 555 // Now sign in the user. |
556 SigninManagerFactory::GetForProfile(profile_.get()) | 556 SigninManagerFactory::GetForProfile(profile_.get()) |
557 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); | 557 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
558 | 558 |
559 // Make oauth token available. | 559 // Make oauth token available. |
560 GetTokenService()->IssueRefreshTokenForUser( | 560 GetTokenService()->UpdateCredentials( |
561 SigninManagerFactory::GetForProfile(profile_.get()) | 561 SigninManagerFactory::GetForProfile(profile_.get()) |
562 ->GetAuthenticatedAccountId(), | 562 ->GetAuthenticatedAccountId(), |
563 "oauth_login_refresh_token"); | 563 "oauth_login_refresh_token"); |
564 | 564 |
565 // UserCloudPolicyManager should be initialized. | 565 // UserCloudPolicyManager should be initialized. |
566 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 566 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
567 ASSERT_TRUE(manager_->core()->service()); | 567 ASSERT_TRUE(manager_->core()->service()); |
568 | 568 |
569 // Client registration should not be in progress since the store is not | 569 // Client registration should not be in progress since the store is not |
570 // yet initialized. | 570 // yet initialized. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 base::RunLoop().RunUntilIdle(); | 832 base::RunLoop().RunUntilIdle(); |
833 EXPECT_FALSE(manager_->IsClientRegistered()); | 833 EXPECT_FALSE(manager_->IsClientRegistered()); |
834 #if !defined(OS_ANDROID) | 834 #if !defined(OS_ANDROID) |
835 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); | 835 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); |
836 #endif | 836 #endif |
837 } | 837 } |
838 | 838 |
839 } // namespace | 839 } // namespace |
840 | 840 |
841 } // namespace policy | 841 } // namespace policy |
OLD | NEW |