| Index: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc
|
| index f0694a06c989f73f6621f8b39088f02cc16ed066..97a58a1f046201ec50b9634e5f3f632a2e713158 100644
|
| --- a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc
|
| +++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api_unittest.cc
|
| @@ -20,6 +20,8 @@
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/browser_with_test_window_test.h"
|
| +#include "chrome/test/base/testing_browser_process.h"
|
| +#include "chrome/test/base/testing_profile_manager.h"
|
| #include "chromeos/attestation/attestation_constants.h"
|
| #include "chromeos/attestation/mock_attestation_flow.h"
|
| #include "chromeos/cryptohome/async_method_caller.h"
|
| @@ -72,7 +74,7 @@ class FakeBoolDBusMethod {
|
|
|
| void RegisterKeyCallbackTrue(
|
| chromeos::attestation::AttestationKeyType key_type,
|
| - const std::string& user_id,
|
| + const cryptohome::Identification& user_id,
|
| const std::string& key_name,
|
| const cryptohome::AsyncMethodCaller::Callback& callback) {
|
| base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| @@ -81,7 +83,7 @@ void RegisterKeyCallbackTrue(
|
|
|
| void RegisterKeyCallbackFalse(
|
| chromeos::attestation::AttestationKeyType key_type,
|
| - const std::string& user_id,
|
| + const cryptohome::Identification& user_id,
|
| const std::string& key_name,
|
| const cryptohome::AsyncMethodCaller::Callback& callback) {
|
| base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| @@ -90,7 +92,7 @@ void RegisterKeyCallbackFalse(
|
|
|
| void SignChallengeCallbackTrue(
|
| chromeos::attestation::AttestationKeyType key_type,
|
| - const std::string& user_id,
|
| + const cryptohome::Identification& user_id,
|
| const std::string& key_name,
|
| const std::string& domain,
|
| const std::string& device_id,
|
| @@ -103,7 +105,7 @@ void SignChallengeCallbackTrue(
|
|
|
| void SignChallengeCallbackFalse(
|
| chromeos::attestation::AttestationKeyType key_type,
|
| - const std::string& user_id,
|
| + const cryptohome::Identification& user_id,
|
| const std::string& key_name,
|
| const std::string& domain,
|
| const std::string& device_id,
|
| @@ -116,7 +118,7 @@ void SignChallengeCallbackFalse(
|
|
|
| void GetCertificateCallbackTrue(
|
| chromeos::attestation::AttestationCertificateProfile certificate_profile,
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| const std::string& request_origin,
|
| bool force_new_key,
|
| const chromeos::attestation::AttestationFlow::CertificateCallback&
|
| @@ -127,7 +129,7 @@ void GetCertificateCallbackTrue(
|
|
|
| void GetCertificateCallbackFalse(
|
| chromeos::attestation::AttestationCertificateProfile certificate_profile,
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| const std::string& request_origin,
|
| bool force_new_key,
|
| const chromeos::attestation::AttestationFlow::CertificateCallback&
|
| @@ -141,6 +143,7 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
| EPKChallengeKeyTestBase()
|
| : settings_helper_(false),
|
| extension_(test_util::CreateEmptyExtension()),
|
| + profile_manager_(TestingBrowserProcess::GetGlobal()),
|
| fake_user_manager_(new chromeos::FakeChromeUserManager),
|
| user_manager_enabler_(fake_user_manager_) {
|
| // Set up the default behavior of mocks.
|
| @@ -169,6 +172,8 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
| }
|
|
|
| void SetUp() override {
|
| + ASSERT_TRUE(profile_manager_.SetUp());
|
| +
|
| BrowserWithTestWindowTest::SetUp();
|
|
|
| // Set the user preferences.
|
| @@ -178,8 +183,19 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
| prefs_->Set(prefs::kAttestationExtensionWhitelist, whitelist);
|
|
|
| SetAuthenticatedUser();
|
| + }
|
| +
|
| + // This will be called by BrowserWithTestWindowTest::SetUp();
|
| + TestingProfile* CreateProfile() override {
|
| fake_user_manager_->AddUserWithAffiliation(
|
| AccountId::FromUserEmail(kUserEmail), true);
|
| + return profile_manager_.CreateTestingProfile(kUserEmail);
|
| + }
|
| +
|
| + void DestroyProfile(TestingProfile* profile) override {
|
| + profile_manager_.DeleteTestingProfile(profile->GetProfileUserName());
|
| + // Profile itself will be destroyed later in
|
| + // ProfileManager::ProfileInfo::~ProfileInfo() .
|
| }
|
|
|
| // Derived classes can override this method to set the required authenticated
|
| @@ -228,9 +244,11 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
| chromeos::ScopedCrosSettingsTestHelper settings_helper_;
|
| scoped_refptr<extensions::Extension> extension_;
|
| policy::StubEnterpriseInstallAttributes stub_install_attributes_;
|
| - PrefService* prefs_;
|
| + TestingProfileManager profile_manager_;
|
| + // fake_user_manager_ is owned by user_manager_enabler_.
|
| chromeos::FakeChromeUserManager* fake_user_manager_;
|
| chromeos::ScopedUserManagerEnabler user_manager_enabler_;
|
| + PrefService* prefs_ = nullptr;
|
| };
|
|
|
| class EPKChallengeMachineKeyTest : public EPKChallengeKeyTestBase {
|
| @@ -328,10 +346,11 @@ TEST_F(EPKChallengeMachineKeyTest, Success) {
|
| _, _, _, _))
|
| .Times(1);
|
| // SignEnterpriseChallenge must be called exactly once.
|
| - EXPECT_CALL(mock_async_method_caller_,
|
| - TpmAttestationSignEnterpriseChallenge(
|
| - chromeos::attestation::KEY_DEVICE, "", "attest-ent-machine",
|
| - "google.com", "device_id", _, "challenge", _))
|
| + EXPECT_CALL(
|
| + mock_async_method_caller_,
|
| + TpmAttestationSignEnterpriseChallenge(
|
| + chromeos::attestation::KEY_DEVICE, cryptohome::Identification(),
|
| + "attest-ent-machine", "google.com", "device_id", _, "challenge", _))
|
| .Times(1);
|
|
|
| scoped_ptr<base::Value> value(
|
| @@ -492,17 +511,19 @@ TEST_F(EPKChallengeUserKeyTest, Success) {
|
| GetCertificate(chromeos::attestation::PROFILE_ENTERPRISE_USER_CERTIFICATE,
|
| _, _, _, _))
|
| .Times(1);
|
| + const cryptohome::Identification cryptohome_id(
|
| + AccountId::FromUserEmail(kUserEmail));
|
| // SignEnterpriseChallenge must be called exactly once.
|
| EXPECT_CALL(
|
| mock_async_method_caller_,
|
| TpmAttestationSignEnterpriseChallenge(
|
| - chromeos::attestation::KEY_USER, kUserEmail, "attest-ent-user",
|
| + chromeos::attestation::KEY_USER, cryptohome_id, "attest-ent-user",
|
| kUserEmail, "device_id", _, "challenge", _))
|
| .Times(1);
|
| // RegisterKey must be called exactly once.
|
| EXPECT_CALL(mock_async_method_caller_,
|
| TpmAttestationRegisterKey(chromeos::attestation::KEY_USER,
|
| - kUserEmail, "attest-ent-user", _))
|
| + cryptohome_id, "attest-ent-user", _))
|
| .Times(1);
|
|
|
| scoped_ptr<base::Value> value(
|
| @@ -537,8 +558,19 @@ class EPKChallengeMachineKeyUnmanagedUserTest
|
| protected:
|
| void SetAuthenticatedUser() override {
|
| SigninManagerFactory::GetForProfile(browser()->profile())
|
| - ->SetAuthenticatedAccountInfo("12345", "test@chromium.com");
|
| + ->SetAuthenticatedAccountInfo(account_id_.GetGaiaId(),
|
| + account_id_.GetUserEmail());
|
| + }
|
| +
|
| + TestingProfile* CreateProfile() override {
|
| + fake_user_manager_->AddUser(account_id_);
|
| + TestingProfile* profile =
|
| + profile_manager_.CreateTestingProfile(account_id_.GetUserEmail());
|
| + return profile;
|
| }
|
| +
|
| + const AccountId account_id_ =
|
| + AccountId::FromUserEmailGaiaId("test@chromium.com", "12345");
|
| };
|
|
|
| TEST_F(EPKChallengeMachineKeyUnmanagedUserTest, UserNotManaged) {
|
| @@ -550,8 +582,19 @@ class EPKChallengeUserKeyUnmanagedUserTest : public EPKChallengeUserKeyTest {
|
| protected:
|
| void SetAuthenticatedUser() override {
|
| SigninManagerFactory::GetForProfile(browser()->profile())
|
| - ->SetAuthenticatedAccountInfo("12345", "test@chromium.com");
|
| + ->SetAuthenticatedAccountInfo(account_id_.GetGaiaId(),
|
| + account_id_.GetUserEmail());
|
| }
|
| +
|
| + TestingProfile* CreateProfile() override {
|
| + fake_user_manager_->AddUser(account_id_);
|
| + TestingProfile* profile =
|
| + profile_manager_.CreateTestingProfile(account_id_.GetUserEmail());
|
| + return profile;
|
| + }
|
| +
|
| + const AccountId account_id_ =
|
| + AccountId::FromUserEmailGaiaId("test@chromium.com", "12345");
|
| };
|
|
|
| TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) {
|
|
|