diff options
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 175 insertions, 75 deletions
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 f0694a0..97a58a1 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) { diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc index 2d95cd0a..b394488 100644 --- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc +++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc @@ -16,6 +16,7 @@ #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" +#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/extensions/chrome_extension_function_details.h" #include "chrome/browser/profiles/profile.h" @@ -25,6 +26,7 @@ #include "chromeos/attestation/attestation_constants.h" #include "chromeos/attestation/attestation_flow.h" #include "chromeos/cryptohome/async_method_caller.h" +#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -33,6 +35,7 @@ #include "components/prefs/pref_service.h" #include "components/signin/core/account_id/account_id.h" #include "components/signin/core/browser/signin_manager.h" +#include "components/user_manager/known_user.h" #include "components/user_manager/user.h" #include "components/user_manager/user_manager.h" #include "google_apis/gaia/gaia_auth_util.h" @@ -59,18 +62,17 @@ const char EPKPChallengeKeyBase::kUserNotManaged[] = EPKPChallengeKeyBase::PrepareKeyContext::PrepareKeyContext( chromeos::attestation::AttestationKeyType key_type, - const std::string& user_id, + const AccountId& account_id, const std::string& key_name, chromeos::attestation::AttestationCertificateProfile certificate_profile, bool require_user_consent, const base::Callback<void(PrepareKeyResult)>& callback) : key_type(key_type), - user_id(user_id), + account_id(account_id), key_name(key_name), certificate_profile(certificate_profile), require_user_consent(require_user_consent), - callback(callback) { -} + callback(callback) {} EPKPChallengeKeyBase::PrepareKeyContext::~PrepareKeyContext() { } @@ -141,16 +143,21 @@ bool EPKPChallengeKeyBase::IsExtensionWhitelisted() const { return list->Find(value) != list->end(); } -bool EPKPChallengeKeyBase::IsUserManaged() const { - std::string email = GetUserEmail(); +AccountId EPKPChallengeKeyBase::GetAccountId() const { + const user_manager::User* user = + chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); - if (email.empty()) { - return false; + // Signin profile doesn't have associated user. + if (!user) { + return EmptyAccountId(); } + return user->GetAccountId(); +} + +bool EPKPChallengeKeyBase::IsUserManaged() const { const user_manager::User* const user = - user_manager::UserManager::Get()->FindUser( - AccountId::FromUserEmail(email)); + user_manager::UserManager::Get()->FindUser(GetAccountId()); if (user) { return user->IsAffiliated(); @@ -164,13 +171,7 @@ std::string EPKPChallengeKeyBase::GetEnterpriseDomain() const { } std::string EPKPChallengeKeyBase::GetUserEmail() const { - SigninManagerBase* signin_manager = - SigninManagerFactory::GetForProfile(profile_); - if (!signin_manager) - return std::string(); - - return gaia::CanonicalizeEmail( - signin_manager->GetAuthenticatedAccountInfo().email); + return GetAccountId().GetUserEmail(); } std::string EPKPChallengeKeyBase::GetDeviceId() const { @@ -179,13 +180,13 @@ std::string EPKPChallengeKeyBase::GetDeviceId() const { void EPKPChallengeKeyBase::PrepareKey( chromeos::attestation::AttestationKeyType key_type, - const std::string& user_id, + const AccountId& account_id, const std::string& key_name, chromeos::attestation::AttestationCertificateProfile certificate_profile, bool require_user_consent, const base::Callback<void(PrepareKeyResult)>& callback) { const PrepareKeyContext context = PrepareKeyContext(key_type, - user_id, + account_id, key_name, certificate_profile, require_user_consent, @@ -209,7 +210,8 @@ void EPKPChallengeKeyBase::IsAttestationPreparedCallback( } // Attestation is available, see if the key we need already exists. cryptohome_client_->TpmAttestationDoesKeyExist( - context.key_type, context.user_id, context.key_name, + context.key_type, cryptohome::Identification(context.account_id), + context.key_name, base::Bind(&EPKPChallengeKeyBase::DoesKeyExistCallback, base::Unretained(this), context)); } @@ -259,7 +261,7 @@ void EPKPChallengeKeyBase::AskForUserConsentCallback( // Generate a new key and have it signed by PCA. attestation_flow_->GetCertificate( - context.certificate_profile, context.user_id, + context.certificate_profile, context.account_id, std::string(), // Not used. true, // Force a new key to be generated. base::Bind(&EPKPChallengeKeyBase::GetCertificateCallback, @@ -356,7 +358,7 @@ void EPKPChallengeMachineKey::GetDeviceAttestationEnabledCallback( } PrepareKey(chromeos::attestation::KEY_DEVICE, - std::string(), // Not used. + EmptyAccountId(), // Not used. kKeyName, chromeos::attestation::PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, false, // user consent is not required. @@ -375,7 +377,7 @@ void EPKPChallengeMachineKey::PrepareKeyCallback( // Everything is checked. Sign the challenge. async_caller_->TpmAttestationSignEnterpriseChallenge( chromeos::attestation::KEY_DEVICE, - std::string(), // Not used. + cryptohome::Identification(), // Not used. kKeyName, GetEnterpriseDomain(), GetDeviceId(), chromeos::attestation::CHALLENGE_OPTION_NONE, challenge, base::Bind(&EPKPChallengeMachineKey::SignChallengeCallback, @@ -489,7 +491,7 @@ void EPKPChallengeUserKey::GetDeviceAttestationEnabledCallback( return; } - PrepareKey(chromeos::attestation::KEY_USER, GetUserEmail(), kKeyName, + PrepareKey(chromeos::attestation::KEY_USER, GetAccountId(), kKeyName, chromeos::attestation::PROFILE_ENTERPRISE_USER_CERTIFICATE, require_user_consent, base::Bind(&EPKPChallengeUserKey::PrepareKeyCallback, @@ -507,7 +509,8 @@ void EPKPChallengeUserKey::PrepareKeyCallback(const std::string& challenge, // Everything is checked. Sign the challenge. async_caller_->TpmAttestationSignEnterpriseChallenge( - chromeos::attestation::KEY_USER, GetUserEmail(), kKeyName, GetUserEmail(), + chromeos::attestation::KEY_USER, + cryptohome::Identification(GetAccountId()), kKeyName, GetUserEmail(), GetDeviceId(), register_key ? chromeos::attestation::CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY : chromeos::attestation::CHALLENGE_OPTION_NONE, @@ -525,7 +528,8 @@ void EPKPChallengeUserKey::SignChallengeCallback(bool register_key, if (register_key) { async_caller_->TpmAttestationRegisterKey( - chromeos::attestation::KEY_USER, GetUserEmail(), kKeyName, + chromeos::attestation::KEY_USER, + cryptohome::Identification(GetAccountId()), kKeyName, base::Bind(&EPKPChallengeUserKey::RegisterKeyCallback, base::Unretained(this), response)); } else { diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.h b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.h index 19f201b..98bb8d2 100644 --- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.h +++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.h @@ -18,6 +18,7 @@ #include "chromeos/attestation/attestation_flow.h" #include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/dbus_method_call_status.h" +#include "components/signin/core/account_id/account_id.h" #include "extensions/browser/extension_function.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -94,6 +95,9 @@ class EPKPChallengeKeyBase { // Returns the user email. std::string GetUserEmail() const; + // Returns account id. + AccountId GetAccountId() const; + // Returns the enterprise virtual device ID. std::string GetDeviceId() const; @@ -103,7 +107,7 @@ class EPKPChallengeKeyBase { // user consent before calling GetCertificate(). void PrepareKey( chromeos::attestation::AttestationKeyType key_type, - const std::string& user_id, + const AccountId& account_id, const std::string& key_name, chromeos::attestation::AttestationCertificateProfile certificate_profile, bool require_user_consent, @@ -120,18 +124,17 @@ class EPKPChallengeKeyBase { private: // Holds the context of a PrepareKey() operation. struct PrepareKeyContext { - PrepareKeyContext( - chromeos::attestation::AttestationKeyType key_type, - const std::string& user_id, - const std::string& key_name, - chromeos::attestation::AttestationCertificateProfile - certificate_profile, - bool require_user_consent, - const base::Callback<void(PrepareKeyResult)>& callback); + PrepareKeyContext(chromeos::attestation::AttestationKeyType key_type, + const AccountId& account_id, + const std::string& key_name, + chromeos::attestation::AttestationCertificateProfile + certificate_profile, + bool require_user_consent, + const base::Callback<void(PrepareKeyResult)>& callback); ~PrepareKeyContext(); chromeos::attestation::AttestationKeyType key_type; - const std::string user_id; + const AccountId account_id; const std::string key_name; chromeos::attestation::AttestationCertificateProfile certificate_profile; bool require_user_consent; diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc index 4867a5e..e52f893 100644 --- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc +++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc @@ -20,9 +20,12 @@ #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" +#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/cryptohome/mock_async_method_caller.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/mock_cryptohome_client.h" @@ -74,7 +77,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( @@ -84,7 +87,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( @@ -94,7 +97,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, @@ -108,7 +111,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, @@ -122,7 +125,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& @@ -134,7 +137,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& @@ -147,9 +150,11 @@ void GetCertificateCallbackFalse( class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { protected: EPKPChallengeKeyTestBase() - : settings_helper_(false), extension_(test_util::CreateEmptyExtension()), + : settings_helper_(false), + extension_(test_util::CreateEmptyExtension()), + profile_manager_(TestingBrowserProcess::GetGlobal()), fake_user_manager_(new chromeos::FakeChromeUserManager), - user_manager_enabler_(fake_user_manager_){ + user_manager_enabler_(fake_user_manager_) { // Set up the default behavior of mocks. ON_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) .WillByDefault(WithArgs<3>(Invoke(FakeBoolDBusMethod( @@ -176,6 +181,8 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { } void SetUp() override { + ASSERT_TRUE(profile_manager_.SetUp()); + BrowserWithTestWindowTest::SetUp(); // Set the user preferences. @@ -185,8 +192,19 @@ class EPKPChallengeKeyTestBase : 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 @@ -202,9 +220,11 @@ class EPKPChallengeKeyTestBase : 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 EPKPChallengeMachineKeyTest : public EPKPChallengeKeyTestBase { @@ -308,10 +328,11 @@ TEST_F(EPKPChallengeMachineKeyTest, 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(utils::RunFunctionAndReturnSingleResult( @@ -470,17 +491,19 @@ TEST_F(EPKPChallengeUserKeyTest, Success) { chromeos::attestation::PROFILE_ENTERPRISE_USER_CERTIFICATE, _, _, _, _)) .Times(1); + const AccountId account_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", kUserEmail, "device_id", _, + chromeos::attestation::KEY_USER, + cryptohome::Identification(account_id), "attest-ent-user", + cryptohome::Identification(account_id).id(), "device_id", _, "challenge", _)) .Times(1); // RegisterKey must be called exactly once. EXPECT_CALL(mock_async_method_caller_, TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, - kUserEmail, + cryptohome::Identification(account_id), "attest-ent-user", _)) .Times(1); @@ -514,9 +537,20 @@ class EPKPChallengeMachineKeyUnmanagedUserTest : public EPKPChallengeMachineKeyTest { protected: void SetAuthenticatedUser() override { - SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedAccountInfo("12345", "test@chromium.com"); + SigninManagerFactory::GetForProfile(browser()->profile()) + ->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(EPKPChallengeMachineKeyUnmanagedUserTest, UserNotManaged) { @@ -527,9 +561,20 @@ TEST_F(EPKPChallengeMachineKeyUnmanagedUserTest, UserNotManaged) { class EPKPChallengeUserKeyUnmanagedUserTest : public EPKPChallengeUserKeyTest { protected: void SetAuthenticatedUser() override { - SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedAccountInfo("12345", "test@chromium.com"); + SigninManagerFactory::GetForProfile(browser()->profile()) + ->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(EPKPChallengeUserKeyUnmanagedUserTest, UserNotManaged) { diff --git a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc b/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc index f11313f..32709b6 100644 --- a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc +++ b/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc @@ -16,6 +16,7 @@ #include "chrome/browser/extensions/api/networking_private/networking_private_ui_delegate_chromeos.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chromeos/chromeos_switches.h" +#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_device_client.h" @@ -195,8 +196,11 @@ class NetworkingPrivateChromeOSApiTest : public ExtensionApiTest { // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI // uses the ProfileHelper to obtain the userhash crbug/238623. - const std::string login_user = chromeos::login::CanonicalizeUserID( - command_line->GetSwitchValueNative(chromeos::switches::kLoginUser)); + const cryptohome::Identification login_user = + cryptohome::Identification::FromString( + chromeos::login::CanonicalizeUserID( + command_line->GetSwitchValueNative( + chromeos::switches::kLoginUser))); const std::string sanitized_user = CryptohomeClient::GetStubSanitizedUsername(login_user); command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, @@ -209,7 +213,8 @@ class NetworkingPrivateChromeOSApiTest : public ExtensionApiTest { CHECK(user); std::string userhash; DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( - user->email(), base::Bind(&AssignString, &userhash_)); + cryptohome::Identification(user->GetAccountId()), + base::Bind(&AssignString, &userhash_)); content::RunAllPendingInMessageLoop(); CHECK(!userhash_.empty()); } diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index ace18cd..3476574 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -138,7 +138,7 @@ void ExtensionBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { // ExtensionService and then the real profile with one, as we do when // running on chromeos. command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, - "TestUser@gmail.com"); + "testuser@gmail.com"); command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); } #endif |
