Commit 51accc46 authored by tnagel's avatar tnagel Committed by Commit bot

Add fake implementation for AuthPolicyClient::RefreshUserPolicy()

Also switch from std::string to AccountId argument for
RefreshUserPolicy().

BUG=655971

Review-Url: https://codereview.chromium.org/2607593002
Cr-Commit-Position: refs/heads/master@{#440845}
parent 68324d6b
...@@ -33,6 +33,7 @@ component("chromeos") { ...@@ -33,6 +33,7 @@ component("chromeos") {
"//chrome/browser/chromeos:device_policy_proto", "//chrome/browser/chromeos:device_policy_proto",
"//components/device_event_log", "//components/device_event_log",
"//components/onc", "//components/onc",
"//components/policy:cloud_policy_proto_generated_compile",
"//components/policy/proto", "//components/policy/proto",
"//components/pref_registry", "//components/pref_registry",
"//components/prefs", "//components/prefs",
......
// Copyright (c) 2016 The Chromium Authors. All rights reserved. // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/dbus/auth_policy_client.h" #include "chromeos/dbus/auth_policy_client.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/signin/core/account_id/account_id.h"
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/message.h" #include "dbus/message.h"
#include "dbus/object_proxy.h" #include "dbus/object_proxy.h"
...@@ -58,12 +59,12 @@ class AuthPolicyClientImpl : public AuthPolicyClient { ...@@ -58,12 +59,12 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), callback));
} }
void RefreshUserPolicy(const std::string& account_id, void RefreshUserPolicy(const AccountId& account_id,
const RefreshPolicyCallback& callback) override { const RefreshPolicyCallback& callback) override {
dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
authpolicy::kAuthPolicyRefreshUserPolicy); authpolicy::kAuthPolicyRefreshUserPolicy);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(account_id); writer.AppendString(account_id.GetObjGuid());
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback, base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback,
......
// Copyright (c) 2016 The Chromium Authors. All rights reserved. // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
class AccountId;
// TODO(rsorokin): Switch to service constants when it's landed. // TODO(rsorokin): Switch to service constants when it's landed.
// (see crbug.com/659732) // (see crbug.com/659732)
namespace authpolicy { namespace authpolicy {
...@@ -71,7 +73,7 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient { ...@@ -71,7 +73,7 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
// Calls RefreshUserPolicy - handle policy for the user specified by // Calls RefreshUserPolicy - handle policy for the user specified by
// |account_id|. Similar to RefreshDevicePolicy. // |account_id|. Similar to RefreshDevicePolicy.
virtual void RefreshUserPolicy(const std::string& account_id, virtual void RefreshUserPolicy(const AccountId& account_id,
const RefreshPolicyCallback& callback) = 0; const RefreshPolicyCallback& callback) = 0;
protected: protected:
......
// Copyright (c) 2016 The Chromium Authors. All rights reserved. // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -14,38 +14,38 @@ ...@@ -14,38 +14,38 @@
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chromeos/chromeos_paths.h" #include "chromeos/chromeos_paths.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "components/policy/proto/cloud_policy.pb.h"
#include "components/policy/proto/device_management_backend.pb.h" #include "components/policy/proto/device_management_backend.pb.h"
#include "components/signin/core/account_id/account_id.h"
namespace em = enterprise_management; namespace em = enterprise_management;
namespace { namespace {
// Create minimal stub device policy file and drop it at the place where // Drop stub policy file of |policy_type| at |policy_path| containing
// SessionManagerClientStubImpl is looking for it. // |serialized_payload|.
bool WriteDevicePolicyFile() { bool WritePolicyFile(const base::FilePath& policy_path,
em::ChromeDeviceSettingsProto policy; const std::string& serialized_payload,
const std::string& policy_type) {
em::PolicyData data; em::PolicyData data;
policy.SerializeToString(data.mutable_policy_value()); data.set_policy_value(serialized_payload);
data.set_policy_type("google/chromeos/device"); data.set_policy_type(policy_type);
em::PolicyFetchResponse response; em::PolicyFetchResponse response;
data.SerializeToString(response.mutable_policy_data()); CHECK(data.SerializeToString(response.mutable_policy_data()));
std::string serialized_response; std::string serialized_response;
response.SerializeToString(&serialized_response); CHECK(response.SerializeToString(&serialized_response));
base::FilePath owner_key_path; if (!base::CreateDirectory(policy_path.DirName()))
if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path))
return false; return false;
const base::FilePath device_policy_path =
owner_key_path.DirName().AppendASCII("stub_device_policy");
// Note that in theory there could be a short time window in which a // Note that in theory there could be a short time window in which a
// concurrent reader sees a partial (and thus invalid) file, but given the // concurrent reader sees a partial (and thus invalid) file, but given the
// small file size that seems very unlikely in practice. // small file size that seems very unlikely in practice.
const int bytes_written = const int bytes_written = base::WriteFile(
base::WriteFile(device_policy_path, serialized_response.c_str(), policy_path, serialized_response.c_str(), serialized_response.size());
serialized_response.size());
if (bytes_written < 0) if (bytes_written < 0)
return false; return false;
return bytes_written == static_cast<int>(serialized_response.size()); return bytes_written == static_cast<int>(serialized_response.size());
...@@ -78,17 +78,54 @@ void FakeAuthPolicyClient::AuthenticateUser( ...@@ -78,17 +78,54 @@ void FakeAuthPolicyClient::AuthenticateUser(
void FakeAuthPolicyClient::RefreshDevicePolicy( void FakeAuthPolicyClient::RefreshDevicePolicy(
const RefreshPolicyCallback& callback) { const RefreshPolicyCallback& callback) {
base::FilePath policy_path;
if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) {
callback.Run(false);
return;
}
policy_path = policy_path.DirName().AppendASCII("stub_device_policy");
em::ChromeDeviceSettingsProto policy;
std::string payload;
CHECK(policy.SerializeToString(&payload));
// Drop file for SessionManagerClientStubImpl to read.
if (!base::PostTaskAndReplyWithResult( if (!base::PostTaskAndReplyWithResult(
base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(),
FROM_HERE, base::Bind(&WriteDevicePolicyFile), callback)) { FROM_HERE, base::Bind(&WritePolicyFile, policy_path, payload,
"google/chromeos/device"),
callback)) {
callback.Run(false); callback.Run(false);
} }
} }
void FakeAuthPolicyClient::RefreshUserPolicy( void FakeAuthPolicyClient::RefreshUserPolicy(
const std::string& account_id, const AccountId& account_id,
const RefreshPolicyCallback& callback) { const RefreshPolicyCallback& callback) {
callback.Run(true); base::FilePath policy_path;
if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) {
callback.Run(false);
return;
}
const cryptohome::Identification cryptohome_identification(account_id);
const std::string sanitized_username =
chromeos::CryptohomeClient::GetStubSanitizedUsername(
cryptohome_identification);
policy_path = policy_path.AppendASCII(sanitized_username);
policy_path = policy_path.AppendASCII("stub_policy");
em::CloudPolicySettings policy;
std::string payload;
CHECK(policy.SerializeToString(&payload));
// Drop file for SessionManagerClientStubImpl to read.
if (!base::PostTaskAndReplyWithResult(
base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(),
FROM_HERE, base::Bind(&WritePolicyFile, policy_path, payload,
"google/chromeos/user"),
callback)) {
callback.Run(false);
}
} }
} // namespace chromeos } // namespace chromeos
// Copyright (c) 2016 The Chromium Authors. All rights reserved. // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "chromeos/dbus/auth_policy_client.h" #include "chromeos/dbus/auth_policy_client.h"
class AccountId;
namespace chromeos { namespace chromeos {
class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient { class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
...@@ -29,7 +31,7 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient { ...@@ -29,7 +31,7 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
int password_fd, int password_fd,
const AuthCallback& callback) override; const AuthCallback& callback) override;
void RefreshDevicePolicy(const RefreshPolicyCallback& calllback) override; void RefreshDevicePolicy(const RefreshPolicyCallback& calllback) override;
void RefreshUserPolicy(const std::string& account_id, void RefreshUserPolicy(const AccountId& account_id,
const RefreshPolicyCallback& callback) override; const RefreshPolicyCallback& callback) override;
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment