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

Side by Side Diff: chromeos/dbus/fake_auth_policy_client.cc

Issue 2673813003: Emulate StartAuthPolicyService from FakeUpstartClient (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 4
5 #include "chromeos/dbus/fake_auth_policy_client.h" 5 #include "chromeos/dbus/fake_auth_policy_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 FakeAuthPolicyClient::FakeAuthPolicyClient() {} 69 FakeAuthPolicyClient::FakeAuthPolicyClient() {}
70 70
71 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} 71 FakeAuthPolicyClient::~FakeAuthPolicyClient() {}
72 72
73 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} 73 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {}
74 74
75 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, 75 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name,
76 const std::string& user_principal_name, 76 const std::string& user_principal_name,
77 int password_fd, 77 int password_fd,
78 const JoinCallback& callback) { 78 const JoinCallback& callback) {
79 if (!started) {
80 LOG(ERROR) << "authpolicyd not started";
81 callback.Run(authpolicy::ERROR_DBUS_FAILURE);
82 return;
83 }
79 if (machine_name.size() > kMaxMachineNameLength) { 84 if (machine_name.size() > kMaxMachineNameLength) {
80 callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG); 85 callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG);
81 return; 86 return;
82 } 87 }
83 88
84 if (machine_name.empty() || 89 if (machine_name.empty() ||
85 machine_name.find_first_of(kInvalidMachineNameCharacters) != 90 machine_name.find_first_of(kInvalidMachineNameCharacters) !=
86 std::string::npos) { 91 std::string::npos) {
87 callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME); 92 callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME);
88 return; 93 return;
89 } 94 }
90 95
91 std::vector<std::string> parts = base::SplitString( 96 std::vector<std::string> parts = base::SplitString(
92 user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 97 user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
93 if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) { 98 if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
94 callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED); 99 callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED);
95 return; 100 return;
96 } 101 }
97 102
98 callback.Run(authpolicy::ERROR_NONE); 103 callback.Run(authpolicy::ERROR_NONE);
99 } 104 }
100 105
101 void FakeAuthPolicyClient::AuthenticateUser( 106 void FakeAuthPolicyClient::AuthenticateUser(
102 const std::string& user_principal_name, 107 const std::string& user_principal_name,
103 int password_fd, 108 int password_fd,
104 const AuthCallback& callback) { 109 const AuthCallback& callback) {
110 if (!started) {
111 LOG(ERROR) << "authpolicyd not started";
112 callback.Run(authpolicy::ERROR_DBUS_FAILURE, std::string());
113 return;
114 }
105 callback.Run(authpolicy::ERROR_NONE, base::MD5String(user_principal_name)); 115 callback.Run(authpolicy::ERROR_NONE, base::MD5String(user_principal_name));
106 } 116 }
107 117
108 void FakeAuthPolicyClient::RefreshDevicePolicy( 118 void FakeAuthPolicyClient::RefreshDevicePolicy(
109 const RefreshPolicyCallback& callback) { 119 const RefreshPolicyCallback& callback) {
120 if (!started) {
121 LOG(ERROR) << "authpolicyd not started";
122 callback.Run(false);
123 return;
124 }
110 base::FilePath policy_path; 125 base::FilePath policy_path;
111 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) { 126 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) {
112 callback.Run(false); 127 callback.Run(false);
113 return; 128 return;
114 } 129 }
115 policy_path = policy_path.DirName().AppendASCII("stub_device_policy"); 130 policy_path = policy_path.DirName().AppendASCII("stub_device_policy");
116 131
117 em::ChromeDeviceSettingsProto policy; 132 em::ChromeDeviceSettingsProto policy;
118 std::string payload; 133 std::string payload;
119 CHECK(policy.SerializeToString(&payload)); 134 CHECK(policy.SerializeToString(&payload));
120 135
121 // Drop file for SessionManagerClientStubImpl to read. 136 // Drop file for SessionManagerClientStubImpl to read.
122 base::PostTaskWithTraitsAndReplyWithResult( 137 base::PostTaskWithTraitsAndReplyWithResult(
123 FROM_HERE, base::TaskTraits() 138 FROM_HERE, base::TaskTraits()
124 .WithShutdownBehavior( 139 .WithShutdownBehavior(
125 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 140 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
126 .WithPriority(base::TaskPriority::BACKGROUND) 141 .WithPriority(base::TaskPriority::BACKGROUND)
127 .MayBlock(), 142 .MayBlock(),
128 Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"), 143 Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"),
129 callback); 144 callback);
130 } 145 }
131 146
132 void FakeAuthPolicyClient::RefreshUserPolicy( 147 void FakeAuthPolicyClient::RefreshUserPolicy(
133 const AccountId& account_id, 148 const AccountId& account_id,
134 const RefreshPolicyCallback& callback) { 149 const RefreshPolicyCallback& callback) {
150 if (!started) {
151 LOG(ERROR) << "authpolicyd not started";
152 callback.Run(false);
153 return;
154 }
135 base::FilePath policy_path; 155 base::FilePath policy_path;
136 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) { 156 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) {
137 callback.Run(false); 157 callback.Run(false);
138 return; 158 return;
139 } 159 }
140 const cryptohome::Identification cryptohome_identification(account_id); 160 const cryptohome::Identification cryptohome_identification(account_id);
141 const std::string sanitized_username = 161 const std::string sanitized_username =
142 chromeos::CryptohomeClient::GetStubSanitizedUsername( 162 chromeos::CryptohomeClient::GetStubSanitizedUsername(
143 cryptohome_identification); 163 cryptohome_identification);
144 policy_path = policy_path.AppendASCII(sanitized_username); 164 policy_path = policy_path.AppendASCII(sanitized_username);
145 policy_path = policy_path.AppendASCII("stub_policy"); 165 policy_path = policy_path.AppendASCII("stub_policy");
146 166
147 em::CloudPolicySettings policy; 167 em::CloudPolicySettings policy;
148 std::string payload; 168 std::string payload;
149 CHECK(policy.SerializeToString(&payload)); 169 CHECK(policy.SerializeToString(&payload));
150 170
151 // Drop file for SessionManagerClientStubImpl to read. 171 // Drop file for SessionManagerClientStubImpl to read.
152 base::PostTaskWithTraitsAndReplyWithResult( 172 base::PostTaskWithTraitsAndReplyWithResult(
153 FROM_HERE, base::TaskTraits() 173 FROM_HERE, base::TaskTraits()
154 .WithShutdownBehavior( 174 .WithShutdownBehavior(
155 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 175 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
156 .WithPriority(base::TaskPriority::BACKGROUND) 176 .WithPriority(base::TaskPriority::BACKGROUND)
157 .MayBlock(), 177 .MayBlock(),
158 base::Bind(&WritePolicyFile, policy_path, payload, 178 base::Bind(&WritePolicyFile, policy_path, payload,
159 "google/chromeos/user"), 179 "google/chromeos/user"),
160 callback); 180 callback);
161 } 181 }
162 182
163 } // namespace chromeos 183 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698