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

Side by Side Diff: chrome/browser/chromeos/policy/affiliation_test_helper.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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "chrome/browser/chromeos/policy/affiliation_test_helper.h" 4 #include "chrome/browser/chromeos/policy/affiliation_test_helper.h"
5 5
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 26 matching lines...) Expand all
37 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 38
39 namespace policy { 39 namespace policy {
40 40
41 namespace affiliation_test_helper { 41 namespace affiliation_test_helper {
42 42
43 const char kFakeRefreshToken[] = "fake-refresh-token"; 43 const char kFakeRefreshToken[] = "fake-refresh-token";
44 const char kEnterpriseUser[] = "testuser@example.com"; 44 const char kEnterpriseUser[] = "testuser@example.com";
45 45
46 void SetUserKeys(policy::UserPolicyBuilder* user_policy) { 46 void SetUserKeys(policy::UserPolicyBuilder* user_policy) {
47 std::string username = user_policy->policy_data().username(); 47 const AccountId account_id =
48 AccountId::FromUserEmail(user_policy->policy_data().username());
48 base::FilePath user_keys_dir; 49 base::FilePath user_keys_dir;
49 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &user_keys_dir)); 50 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &user_keys_dir));
50 const std::string sanitized_username = 51 const std::string sanitized_username =
51 chromeos::CryptohomeClient::GetStubSanitizedUsername(username); 52 chromeos::CryptohomeClient::GetStubSanitizedUsername(
53 cryptohome::Identification(account_id));
52 const base::FilePath user_key_file = 54 const base::FilePath user_key_file =
53 user_keys_dir.AppendASCII(sanitized_username).AppendASCII("policy.pub"); 55 user_keys_dir.AppendASCII(sanitized_username).AppendASCII("policy.pub");
54 std::vector<uint8_t> user_key_bits; 56 std::vector<uint8_t> user_key_bits;
55 ASSERT_TRUE(user_policy->GetSigningKey()->ExportPublicKey(&user_key_bits)); 57 ASSERT_TRUE(user_policy->GetSigningKey()->ExportPublicKey(&user_key_bits));
56 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName())); 58 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName()));
57 ASSERT_EQ(base::WriteFile(user_key_file, 59 ASSERT_EQ(base::WriteFile(user_key_file,
58 reinterpret_cast<const char*>(user_key_bits.data()), 60 reinterpret_cast<const char*>(user_key_bits.data()),
59 user_key_bits.size()), 61 user_key_bits.size()),
60 static_cast<int>(user_key_bits.size())); 62 static_cast<int>(user_key_bits.size()));
61 } 63 }
(...skipping 15 matching lines...) Expand all
77 79
78 fake_session_manager_client->set_device_policy(device_policy->GetBlob()); 80 fake_session_manager_client->set_device_policy(device_policy->GetBlob());
79 fake_session_manager_client->OnPropertyChangeComplete(true); 81 fake_session_manager_client->OnPropertyChangeComplete(true);
80 } 82 }
81 83
82 void SetUserAffiliationIDs( 84 void SetUserAffiliationIDs(
83 policy::UserPolicyBuilder* user_policy, 85 policy::UserPolicyBuilder* user_policy,
84 chromeos::FakeSessionManagerClient* fake_session_manager_client, 86 chromeos::FakeSessionManagerClient* fake_session_manager_client,
85 const std::string& user_email, 87 const std::string& user_email,
86 const std::set<std::string>& user_affiliation_ids) { 88 const std::set<std::string>& user_affiliation_ids) {
89 const AccountId account_id = AccountId::FromUserEmail(user_email);
87 user_policy->policy_data().set_username(user_email); 90 user_policy->policy_data().set_username(user_email);
88 SetUserKeys(user_policy); 91 SetUserKeys(user_policy);
89 for (const auto& user_affiliation_id : user_affiliation_ids) { 92 for (const auto& user_affiliation_id : user_affiliation_ids) {
90 user_policy->policy_data().add_user_affiliation_ids(user_affiliation_id); 93 user_policy->policy_data().add_user_affiliation_ids(user_affiliation_id);
91 } 94 }
92 user_policy->Build(); 95 user_policy->Build();
93 fake_session_manager_client->set_user_policy(user_email, 96 fake_session_manager_client->set_user_policy(
94 user_policy->GetBlob()); 97 cryptohome::Identification(account_id), user_policy->GetBlob());
95 } 98 }
96 99
97 void PreLoginUser(const std::string& user_id) { 100 void PreLoginUser(const std::string& user_id) {
98 ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers"); 101 ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers");
99 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); 102 users_pref->AppendIfNotPresent(new base::StringValue(user_id));
100 chromeos::StartupUtils::MarkOobeCompleted(); 103 chromeos::StartupUtils::MarkOobeCompleted();
101 } 104 }
102 105
103 void LoginUser(const std::string& user_id) { 106 void LoginUser(const std::string& user_id) {
104 chromeos::test::UserSessionManagerTestApi session_manager_test_api( 107 chromeos::test::UserSessionManagerTestApi session_manager_test_api(
105 chromeos::UserSessionManager::GetInstance()); 108 chromeos::UserSessionManager::GetInstance());
106 session_manager_test_api.SetShouldObtainTokenHandleInTests(false); 109 session_manager_test_api.SetShouldObtainTokenHandleInTests(false);
107 110
108 chromeos::UserContext user_context(AccountId::FromUserEmail(user_id)); 111 chromeos::UserContext user_context(
109 user_context.SetGaiaID("gaia-id-" + user_id); 112 AccountId::FromUserEmailGaiaId(user_id, "gaia-id-" + user_id));
110 user_context.SetKey(chromeos::Key("password")); 113 user_context.SetKey(chromeos::Key("password"));
111 if (user_id == kEnterpriseUser) { 114 if (user_id == kEnterpriseUser) {
112 user_context.SetRefreshToken(kFakeRefreshToken); 115 user_context.SetRefreshToken(kFakeRefreshToken);
113 } 116 }
114 chromeos::ExistingUserController* controller = 117 chromeos::ExistingUserController* controller =
115 chromeos::ExistingUserController::current_controller(); 118 chromeos::ExistingUserController::current_controller();
116 CHECK(controller); 119 CHECK(controller);
117 content::WindowedNotificationObserver observer( 120 content::WindowedNotificationObserver observer(
118 chrome::NOTIFICATION_SESSION_STARTED, 121 chrome::NOTIFICATION_SESSION_STARTED,
119 content::NotificationService::AllSources()); 122 content::NotificationService::AllSources());
(...skipping 16 matching lines...) Expand all
136 // LoginManager tests typically don't stand up a policy test server but 139 // LoginManager tests typically don't stand up a policy test server but
137 // instead inject policies directly through a SessionManagerClient. So allow 140 // instead inject policies directly through a SessionManagerClient. So allow
138 // policy fetches to fail - this is expected. 141 // policy fetches to fail - this is expected.
139 command_line->AppendSwitch( 142 command_line->AppendSwitch(
140 chromeos::switches::kAllowFailedPolicyFetchForTest); 143 chromeos::switches::kAllowFailedPolicyFetchForTest);
141 } 144 }
142 145
143 } // namespace affiliation_test_helper 146 } // namespace affiliation_test_helper
144 147
145 } // namespace policy 148 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698