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

Unified Diff: chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc
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 4867a5ef0919001ffa75a2c00688b5cf2fdd7c29..e52f893740f2ed6ee94ea1bed8aee9f5ef1a6388 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) {

Powered by Google App Engine
This is Rietveld 408576698