| Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
|
| diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
|
| index ef61f0062e912d3edcdb05ed2aea1dd7af8be06c..7120dac2c16b645af91a115f0fad8dbf48ff7eea 100644
|
| --- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
|
| +++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
|
| @@ -202,8 +202,7 @@ class EasyUnlockTpmKeyManagerTest : public testing::Test {
|
|
|
| void SetUp() override {
|
| ASSERT_TRUE(profile_manager_.SetUp());
|
| - const user_manager::User* user =
|
| - user_manager_->AddUser(AccountId::FromUserEmail(kTestUserId));
|
| + const user_manager::User* user = user_manager_->AddUser(test_account_id_);
|
| username_hash_ = user->username_hash();
|
|
|
| signin_profile_ = profile_manager_.CreateTestingProfile(
|
| @@ -214,8 +213,9 @@ class EasyUnlockTpmKeyManagerTest : public testing::Test {
|
| TestingProfile::TestingFactories());
|
|
|
| user_profile_ = profile_manager_.CreateTestingProfile(
|
| - kTestUserId, scoped_ptr<syncable_prefs::TestingPrefServiceSyncable>(),
|
| - base::UTF8ToUTF16(kTestUserId), 0 /* avatar id */,
|
| + test_account_id_.GetUserEmail(),
|
| + scoped_ptr<syncable_prefs::TestingPrefServiceSyncable>(),
|
| + base::UTF8ToUTF16(test_account_id_.GetUserEmail()), 0 /* avatar id */,
|
| std::string() /* supervized user id */,
|
| TestingProfile::TestingFactories());
|
| }
|
| @@ -223,7 +223,7 @@ class EasyUnlockTpmKeyManagerTest : public testing::Test {
|
| void TearDown() override {
|
| if (test_nss_user_)
|
| ResetTestNssUser();
|
| - profile_manager_.DeleteTestingProfile(kTestUserId);
|
| + profile_manager_.DeleteTestingProfile(test_account_id_.GetUserEmail());
|
| profile_manager_.DeleteTestingProfile(chrome::kInitialProfile);
|
| }
|
|
|
| @@ -323,15 +323,18 @@ class EasyUnlockTpmKeyManagerTest : public testing::Test {
|
| }
|
|
|
| // Sets TPM public key pref in the test user's profile prefs.
|
| - void SetLocalStatePublicKey(const std::string& user_id,
|
| - const std::string& value) {
|
| + static void SetLocalStatePublicKey(const AccountId& account_id,
|
| + const std::string& value) {
|
| std::string encoded;
|
| base::Base64Encode(value, &encoded);
|
| DictionaryPrefUpdate update(g_browser_process->local_state(),
|
| prefs::kEasyUnlockLocalStateTpmKeys);
|
| - update->SetStringWithoutPathExpansion(kTestUserId, encoded);
|
| + update->SetStringWithoutPathExpansion(account_id.GetUserEmail(), encoded);
|
| }
|
|
|
| + protected:
|
| + const AccountId test_account_id_ = AccountId::FromUserEmail(kTestUserId);
|
| +
|
| private:
|
| content::TestBrowserThreadBundle thread_bundle_;
|
|
|
| @@ -359,20 +362,20 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPair) {
|
| ASSERT_TRUE(InitTestNssUser());
|
|
|
| base::RunLoop run_loop;
|
| - EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_TRUE(signin_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_TRUE(signin_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| ASSERT_FALSE(user_key_manager()->PrepareTpmKey(
|
| false /* check_private_key */,
|
| run_loop.QuitClosure()));
|
| - EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
|
|
| ASSERT_TRUE(SetUpTestSystemSlot());
|
| VerifyKeyGenerationNotStartedAndFinalizeTestNssUser();
|
| run_loop.Run();
|
|
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| - signin_key_manager()->GetPublicTpmKey(kTestUserId));
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| + signin_key_manager()->GetPublicTpmKey(test_account_id_));
|
|
|
| EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
|
| false /* check_private_key */,
|
| @@ -405,9 +408,9 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
|
| run_loop.Run();
|
|
|
| EXPECT_EQ(2, callback_count);
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| - signin_key_manager()->GetPublicTpmKey(kTestUserId));
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| + signin_key_manager()->GetPublicTpmKey(test_account_id_));
|
|
|
| EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
|
| false /* check_private_key */,
|
| @@ -416,24 +419,24 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) {
|
| SetLocalStatePublicKey(
|
| - kTestUserId, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| + test_account_id_, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
|
|
| EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
|
| false /* check_private_key */,
|
| base::Bind(&ExpectNotCalledCallback)));
|
|
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| - signin_key_manager()->GetPublicTpmKey(kTestUserId));
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| + signin_key_manager()->GetPublicTpmKey(test_account_id_));
|
| }
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey) {
|
| ASSERT_TRUE(InitTestNssUser());
|
|
|
| SetLocalStatePublicKey(
|
| - kTestUserId, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| + test_account_id_, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
|
|
| base::RunLoop run_loop;
|
| ASSERT_FALSE(user_key_manager()->PrepareTpmKey(
|
| @@ -444,11 +447,11 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey) {
|
| VerifyKeyGenerationNotStartedAndFinalizeTestNssUser();
|
| run_loop.Run();
|
|
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_NE(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_NE(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| - signin_key_manager()->GetPublicTpmKey(kTestUserId));
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| + signin_key_manager()->GetPublicTpmKey(test_account_id_));
|
| }
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
|
| @@ -457,7 +460,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
|
| VerifyKeyGenerationNotStartedAndFinalizeTestNssUser();
|
| ASSERT_TRUE(ImportPrivateKey(kTestPrivateKey, arraysize(kTestPrivateKey)));
|
| SetLocalStatePublicKey(
|
| - kTestUserId, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| + test_account_id_, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
|
|
| int callback_count = 0;
|
| base::RunLoop run_loop;
|
| @@ -472,11 +475,11 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
|
| run_loop.Run();
|
|
|
| EXPECT_EQ(1, callback_count);
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| - EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
|
| - signin_key_manager()->GetPublicTpmKey(kTestUserId));
|
| + EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
|
| + signin_key_manager()->GetPublicTpmKey(test_account_id_));
|
|
|
| EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
|
| true /* check_private_key */,
|
| @@ -500,7 +503,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutTriggers) {
|
|
|
| run_loop.Run();
|
|
|
| - EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| }
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutAfterSlotFetched) {
|
| @@ -519,7 +522,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutAfterSlotFetched) {
|
|
|
| run_loop.Run();
|
|
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| }
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotRetryAfterFailure) {
|
| @@ -535,7 +538,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotRetryAfterFailure) {
|
|
|
| run_loop.Run();
|
|
|
| - EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
|
|
| base::RunLoop run_loop_retry;
|
|
|
| @@ -548,20 +551,19 @@ TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotRetryAfterFailure) {
|
|
|
| run_loop_retry.Run();
|
|
|
| - EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
|
| + EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
|
| }
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, SignData) {
|
| ASSERT_TRUE(SetUpTestSystemSlot());
|
| ASSERT_TRUE(ImportPrivateKey(kTestPrivateKey, arraysize(kTestPrivateKey)));
|
| SetLocalStatePublicKey(
|
| - kTestUserId, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| + test_account_id_, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
|
|
| base::RunLoop loop;
|
| std::string signed_data;
|
| signin_key_manager()->SignUsingTpmKey(
|
| - kTestUserId,
|
| - "data",
|
| + test_account_id_, "data",
|
| base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
|
| loop.Run();
|
|
|
| @@ -572,8 +574,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignNoPublicKeySet) {
|
| base::RunLoop loop;
|
| std::string signed_data;
|
| signin_key_manager()->SignUsingTpmKey(
|
| - kTestUserId,
|
| - "data",
|
| + test_account_id_, "data",
|
| base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
|
| loop.Run();
|
|
|
| @@ -582,13 +583,12 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignNoPublicKeySet) {
|
|
|
| TEST_F(EasyUnlockTpmKeyManagerTest, SignDataNoPrivateKeyPresent) {
|
| SetLocalStatePublicKey(
|
| - kTestUserId, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
| + test_account_id_, std::string(kTestPublicKey, arraysize(kTestPublicKey)));
|
|
|
| base::RunLoop loop;
|
| std::string signed_data;
|
| signin_key_manager()->SignUsingTpmKey(
|
| - kTestUserId,
|
| - "data",
|
| + test_account_id_, "data",
|
| base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
|
|
|
| ASSERT_TRUE(SetUpTestSystemSlot());
|
|
|