Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 2488573003: Expose signing key from cloud policy stores (Closed)
Patch Set: Fix tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 dm_token_, 315 dm_token_,
316 client_id_, 316 client_id_,
317 profile_->GetRequestContext(), 317 profile_->GetRequestContext(),
318 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh, 318 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh,
319 base::Unretained(this))); 319 base::Unretained(this)));
320 320
321 Mock::VerifyAndClearExpectations(this); 321 Mock::VerifyAndClearExpectations(this);
322 ASSERT_TRUE(fetch_request); 322 ASSERT_TRUE(fetch_request);
323 323
324 // UserCloudPolicyManager should now be initialized. 324 // UserCloudPolicyManager should now be initialized.
325 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 325 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
326 ASSERT_TRUE(manager_->core()->service()); 326 ASSERT_TRUE(manager_->core()->service());
327 327
328 // Make the policy fetch succeed - this should result in a write to the 328 // Make the policy fetch succeed - this should result in a write to the
329 // store and ultimately result in a call to OnPolicyRefresh(). 329 // store and ultimately result in a call to OnPolicyRefresh().
330 EXPECT_CALL(*mock_store_, Store(_)); 330 EXPECT_CALL(*mock_store_, Store(_));
331 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1); 331 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1);
332 332
333 // Create a fake policy blob to deliver to the client. 333 // Create a fake policy blob to deliver to the client.
334 em::DeviceManagementResponse policy_blob; 334 em::DeviceManagementResponse policy_blob;
335 em::PolicyData policy_data; 335 em::PolicyData policy_data;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // No oauth access token yet, so client registration should be deferred. 417 // No oauth access token yet, so client registration should be deferred.
418 ASSERT_FALSE(IsRequestActive()); 418 ASSERT_FALSE(IsRequestActive());
419 419
420 // Make oauth token available. 420 // Make oauth token available.
421 GetTokenService()->UpdateCredentials( 421 GetTokenService()->UpdateCredentials(
422 SigninManagerFactory::GetForProfile(profile_.get()) 422 SigninManagerFactory::GetForProfile(profile_.get())
423 ->GetAuthenticatedAccountId(), 423 ->GetAuthenticatedAccountId(),
424 "oauth_login_refresh_token"); 424 "oauth_login_refresh_token");
425 425
426 // Client registration should be in progress since we now have an oauth token. 426 // Client registration should be in progress since we now have an oauth token.
427 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 427 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
428 ASSERT_TRUE(IsRequestActive()); 428 ASSERT_TRUE(IsRequestActive());
429 } 429 }
430 430
431 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { 431 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) {
432 // UserCloudPolicyManager should be initialized. 432 // UserCloudPolicyManager should be initialized.
433 ASSERT_TRUE(manager_->core()->service()); 433 ASSERT_TRUE(manager_->core()->service());
434 434
435 // Complete initialization of the store. 435 // Complete initialization of the store.
436 mock_store_->NotifyStoreLoaded(); 436 mock_store_->NotifyStoreLoaded();
437 437
(...skipping 28 matching lines...) Expand all
466 // Complete initialization of the store. 466 // Complete initialization of the store.
467 mock_store_->NotifyStoreLoaded(); 467 mock_store_->NotifyStoreLoaded();
468 468
469 // Make oauth token available. 469 // Make oauth token available.
470 GetTokenService()->UpdateCredentials( 470 GetTokenService()->UpdateCredentials(
471 SigninManagerFactory::GetForProfile(profile_.get()) 471 SigninManagerFactory::GetForProfile(profile_.get())
472 ->GetAuthenticatedAccountId(), 472 ->GetAuthenticatedAccountId(),
473 "oauth_login_refresh_token"); 473 "oauth_login_refresh_token");
474 474
475 // UserCloudPolicyManager should be initialized. 475 // UserCloudPolicyManager should be initialized.
476 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 476 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
477 ASSERT_TRUE(manager_->core()->service()); 477 ASSERT_TRUE(manager_->core()->service());
478 478
479 // Client registration should be in progress since we have an oauth token. 479 // Client registration should be in progress since we have an oauth token.
480 ASSERT_TRUE(IsRequestActive()); 480 ASSERT_TRUE(IsRequestActive());
481 } 481 }
482 482
483 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { 483 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
484 // UserCloudPolicyManager should not be initialized since there is no 484 // UserCloudPolicyManager should not be initialized since there is no
485 // signed-in user. 485 // signed-in user.
486 ASSERT_FALSE(manager_->core()->service()); 486 ASSERT_FALSE(manager_->core()->service());
(...skipping 27 matching lines...) Expand all
514 SigninManagerFactory::GetForProfile(profile_.get()) 514 SigninManagerFactory::GetForProfile(profile_.get())
515 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 515 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
516 516
517 // Make oauth token available. 517 // Make oauth token available.
518 GetTokenService()->UpdateCredentials( 518 GetTokenService()->UpdateCredentials(
519 SigninManagerFactory::GetForProfile(profile_.get()) 519 SigninManagerFactory::GetForProfile(profile_.get())
520 ->GetAuthenticatedAccountId(), 520 ->GetAuthenticatedAccountId(),
521 "oauth_login_refresh_token"); 521 "oauth_login_refresh_token");
522 522
523 // UserCloudPolicyManager should be initialized. 523 // UserCloudPolicyManager should be initialized.
524 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 524 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
525 ASSERT_TRUE(manager_->core()->service()); 525 ASSERT_TRUE(manager_->core()->service());
526 526
527 // Client registration should not be in progress since the store is not 527 // Client registration should not be in progress since the store is not
528 // yet initialized. 528 // yet initialized.
529 ASSERT_FALSE(IsRequestActive()); 529 ASSERT_FALSE(IsRequestActive());
530 530
531 // Complete initialization of the store with no policy (unregistered client). 531 // Complete initialization of the store with no policy (unregistered client).
532 mock_store_->NotifyStoreLoaded(); 532 mock_store_->NotifyStoreLoaded();
533 533
534 // Client registration should be in progress since we have an oauth token. 534 // Client registration should be in progress since we have an oauth token.
535 ASSERT_TRUE(IsRequestActive()); 535 ASSERT_TRUE(IsRequestActive());
536 } 536 }
537 537
538 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { 538 TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
539 // UserCloudPolicyManager should not be initialized since there is no 539 // UserCloudPolicyManager should not be initialized since there is no
540 // signed-in user. 540 // signed-in user.
541 ASSERT_FALSE(manager_->core()->service()); 541 ASSERT_FALSE(manager_->core()->service());
542 542
543 // Now sign in the user. 543 // Now sign in the user.
544 SigninManagerFactory::GetForProfile(profile_.get()) 544 SigninManagerFactory::GetForProfile(profile_.get())
545 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 545 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
546 546
547 // Make oauth token available. 547 // Make oauth token available.
548 GetTokenService()->UpdateCredentials( 548 GetTokenService()->UpdateCredentials(
549 SigninManagerFactory::GetForProfile(profile_.get()) 549 SigninManagerFactory::GetForProfile(profile_.get())
550 ->GetAuthenticatedAccountId(), 550 ->GetAuthenticatedAccountId(),
551 "oauth_login_refresh_token"); 551 "oauth_login_refresh_token");
552 552
553 // UserCloudPolicyManager should be initialized. 553 // UserCloudPolicyManager should be initialized.
554 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 554 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
555 ASSERT_TRUE(manager_->core()->service()); 555 ASSERT_TRUE(manager_->core()->service());
556 556
557 // Client registration should not be in progress since the store is not 557 // Client registration should not be in progress since the store is not
558 // yet initialized. 558 // yet initialized.
559 ASSERT_FALSE(manager_->IsClientRegistered()); 559 ASSERT_FALSE(manager_->IsClientRegistered());
560 ASSERT_FALSE(IsRequestActive()); 560 ASSERT_FALSE(IsRequestActive());
561 561
562 mock_store_->policy_.reset(new enterprise_management::PolicyData()); 562 mock_store_->policy_.reset(new enterprise_management::PolicyData());
563 mock_store_->policy_->set_request_token("fake token"); 563 mock_store_->policy_->set_request_token("fake token");
564 mock_store_->policy_->set_device_id("fake client id"); 564 mock_store_->policy_->set_device_id("fake client id");
565 565
566 // Complete initialization of the store. 566 // Complete initialization of the store.
567 mock_store_->NotifyStoreLoaded(); 567 mock_store_->NotifyStoreLoaded();
568 568
569 // Client registration should not be in progress since the client should be 569 // Client registration should not be in progress since the client should be
570 // already registered. 570 // already registered.
571 ASSERT_TRUE(manager_->IsClientRegistered()); 571 ASSERT_TRUE(manager_->IsClientRegistered());
572 ASSERT_FALSE(IsRequestActive()); 572 ASSERT_FALSE(IsRequestActive());
573 } 573 }
574 574
575 #endif // !defined(OS_ANDROID) 575 #endif // !defined(OS_ANDROID)
576 576
577 TEST_F(UserPolicySigninServiceSignedInTest, SignOutAfterInit) { 577 TEST_F(UserPolicySigninServiceSignedInTest, SignOutAfterInit) {
578 // UserCloudPolicyManager should be initialized. 578 // UserCloudPolicyManager should be initialized.
579 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 579 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
580 ASSERT_TRUE(manager_->core()->service()); 580 ASSERT_TRUE(manager_->core()->service());
581 581
582 // Signing out will clear the policy from the store. 582 // Signing out will clear the policy from the store.
583 EXPECT_CALL(*mock_store_, Clear()); 583 EXPECT_CALL(*mock_store_, Clear());
584 584
585 // Now sign out. 585 // Now sign out.
586 SigninManagerFactory::GetForProfile(profile_.get()) 586 SigninManagerFactory::GetForProfile(profile_.get())
587 ->SignOut(signin_metrics::SIGNOUT_TEST, 587 ->SignOut(signin_metrics::SIGNOUT_TEST,
588 signin_metrics::SignoutDelete::IGNORE_METRIC); 588 signin_metrics::SignoutDelete::IGNORE_METRIC);
589 589
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh, 745 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh,
746 base::Unretained(this))); 746 base::Unretained(this)));
747 ASSERT_TRUE(fetch_request); 747 ASSERT_TRUE(fetch_request);
748 748
749 // Make the policy fetch fail. 749 // Make the policy fetch fail.
750 EXPECT_CALL(*this, OnPolicyRefresh(false)).Times(1); 750 EXPECT_CALL(*this, OnPolicyRefresh(false)).Times(1);
751 fetch_request->SendResponse(DM_STATUS_REQUEST_FAILED, 751 fetch_request->SendResponse(DM_STATUS_REQUEST_FAILED,
752 em::DeviceManagementResponse()); 752 em::DeviceManagementResponse());
753 753
754 // UserCloudPolicyManager should be initialized. 754 // UserCloudPolicyManager should be initialized.
755 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 755 EXPECT_EQ(mock_store_->signin_username(), kTestUser);
756 ASSERT_TRUE(manager_->core()->service()); 756 ASSERT_TRUE(manager_->core()->service());
757 } 757 }
758 758
759 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) { 759 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) {
760 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin()); 760 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin());
761 } 761 }
762 762
763 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) { 763 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) {
764 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin()); 764 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin());
765 765
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 base::RunLoop().RunUntilIdle(); 821 base::RunLoop().RunUntilIdle();
822 EXPECT_FALSE(manager_->IsClientRegistered()); 822 EXPECT_FALSE(manager_->IsClientRegistered());
823 #if !defined(OS_ANDROID) 823 #if !defined(OS_ANDROID)
824 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 824 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
825 #endif 825 #endif
826 } 826 }
827 827
828 } // namespace 828 } // namespace
829 829
830 } // namespace policy 830 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698