Commit a42f0327 authored by Lutz Justen's avatar Lutz Justen Committed by Commit Bot

Fix UserAvatarImage and WallpaperImage for Chromad

Both are 'external'-type policies, i.e. the images are not included in
the policy, but downloaded separately. However, the mechanisms to
download external user policies were not hooked up. This CL wires them
up. Interestingly, DeviceWallpaperImage works fine.

BUG=chromium:819561
TEST=out/Release/unit_tests --gtest_filter=ActiveDirectoryPolicyManagerTest.*
     Set UserAvatarImage and WallpaperImage on Windows Server and
     verified that it applies on a domain joined Chromebook.

Change-Id: I8670a3e1ba0edcee31ed5753be92b021e9553bb0
Reviewed-on: https://chromium-review.googlesource.com/952903
Commit-Queue: Lutz Justen <ljusten@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543084}
parent 596138ff
...@@ -268,10 +268,6 @@ ChromeUserManagerImpl::ChromeUserManagerImpl() ...@@ -268,10 +268,6 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
GetMinimumVersionPolicyHandler()->AddObserver(this); GetMinimumVersionPolicyHandler()->AddObserver(this);
} }
if (!device_local_account_policy_service) {
return;
}
avatar_policy_observer_ = avatar_policy_observer_ =
std::make_unique<policy::CloudExternalDataPolicyObserver>( std::make_unique<policy::CloudExternalDataPolicyObserver>(
cros_settings_, device_local_account_policy_service, cros_settings_, device_local_account_policy_service,
......
...@@ -9,11 +9,14 @@ ...@@ -9,11 +9,14 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/browser_process.h"
#include "chromeos/dbus/auth_policy_client.h" #include "chromeos/dbus/auth_policy_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "components/policy/core/common/cloud/cloud_external_data_manager.h"
#include "components/policy/core/common/policy_bundle.h" #include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "net/url_request/url_request_context_getter.h"
namespace { namespace {
...@@ -37,9 +40,9 @@ std::unique_ptr<ActiveDirectoryPolicyManager> ...@@ -37,9 +40,9 @@ std::unique_ptr<ActiveDirectoryPolicyManager>
ActiveDirectoryPolicyManager::CreateForDevicePolicy( ActiveDirectoryPolicyManager::CreateForDevicePolicy(
std::unique_ptr<CloudPolicyStore> store) { std::unique_ptr<CloudPolicyStore> store) {
// Can't use MakeUnique<> because the constructor is private. // Can't use MakeUnique<> because the constructor is private.
return base::WrapUnique( return base::WrapUnique(new ActiveDirectoryPolicyManager(
new ActiveDirectoryPolicyManager(EmptyAccountId(), base::TimeDelta(), EmptyAccountId(), base::TimeDelta(), base::OnceClosure(),
base::OnceClosure(), std::move(store))); std::move(store), nullptr /* external_data_manager */));
} }
// static // static
...@@ -48,11 +51,12 @@ ActiveDirectoryPolicyManager::CreateForUserPolicy( ...@@ -48,11 +51,12 @@ ActiveDirectoryPolicyManager::CreateForUserPolicy(
const AccountId& account_id, const AccountId& account_id,
base::TimeDelta initial_policy_fetch_timeout, base::TimeDelta initial_policy_fetch_timeout,
base::OnceClosure exit_session, base::OnceClosure exit_session,
std::unique_ptr<CloudPolicyStore> store) { std::unique_ptr<CloudPolicyStore> store,
std::unique_ptr<CloudExternalDataManager> external_data_manager) {
// Can't use MakeUnique<> because the constructor is private. // Can't use MakeUnique<> because the constructor is private.
return base::WrapUnique(new ActiveDirectoryPolicyManager( return base::WrapUnique(new ActiveDirectoryPolicyManager(
account_id, initial_policy_fetch_timeout, std::move(exit_session), account_id, initial_policy_fetch_timeout, std::move(exit_session),
std::move(store))); std::move(store), std::move(external_data_manager)));
} }
void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) { void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) {
...@@ -72,9 +76,20 @@ void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) { ...@@ -72,9 +76,20 @@ void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) {
base::BindRepeating(&ActiveDirectoryPolicyManager::OnPolicyFetched, base::BindRepeating(&ActiveDirectoryPolicyManager::OnPolicyFetched,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
kFetchInterval); kFetchInterval);
if (external_data_manager_) {
// Use the system request context here instead of a context derived from the
// Profile because Connect() is called before the profile is fully
// initialized (required so we can perform the initial policy load).
// Note: The request context can be null for tests and for device policy.
external_data_manager_->Connect(
g_browser_process->system_request_context());
}
} }
void ActiveDirectoryPolicyManager::Shutdown() { void ActiveDirectoryPolicyManager::Shutdown() {
if (external_data_manager_)
external_data_manager_->Disconnect();
store_->RemoveObserver(this); store_->RemoveObserver(this);
ConfigurationPolicyProvider::Shutdown(); ConfigurationPolicyProvider::Shutdown();
} }
...@@ -130,13 +145,15 @@ ActiveDirectoryPolicyManager::ActiveDirectoryPolicyManager( ...@@ -130,13 +145,15 @@ ActiveDirectoryPolicyManager::ActiveDirectoryPolicyManager(
const AccountId& account_id, const AccountId& account_id,
base::TimeDelta initial_policy_fetch_timeout, base::TimeDelta initial_policy_fetch_timeout,
base::OnceClosure exit_session, base::OnceClosure exit_session,
std::unique_ptr<CloudPolicyStore> store) std::unique_ptr<CloudPolicyStore> store,
std::unique_ptr<CloudExternalDataManager> external_data_manager)
: account_id_(account_id), : account_id_(account_id),
waiting_for_initial_policy_fetch_( waiting_for_initial_policy_fetch_(
!initial_policy_fetch_timeout.is_zero()), !initial_policy_fetch_timeout.is_zero()),
initial_policy_fetch_may_fail_(!initial_policy_fetch_timeout.is_max()), initial_policy_fetch_may_fail_(!initial_policy_fetch_timeout.is_max()),
exit_session_(std::move(exit_session)), exit_session_(std::move(exit_session)),
store_(std::move(store)) { store_(std::move(store)),
external_data_manager_(std::move(external_data_manager)) {
// Delaying initialization complete is intended for user policy only. // Delaying initialization complete is intended for user policy only.
DCHECK(account_id != EmptyAccountId() || !waiting_for_initial_policy_fetch_); DCHECK(account_id != EmptyAccountId() || !waiting_for_initial_policy_fetch_);
if (waiting_for_initial_policy_fetch_ && initial_policy_fetch_may_fail_) { if (waiting_for_initial_policy_fetch_ && initial_policy_fetch_may_fail_) {
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
namespace policy { namespace policy {
class CloudExternalDataManager;
// ConfigurationPolicyProvider for device or user policy from Active Directory. // ConfigurationPolicyProvider for device or user policy from Active Directory.
// The choice of constructor determines whether device or user policy is // The choice of constructor determines whether device or user policy is
// provided. // provided.
...@@ -40,7 +42,8 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider, ...@@ -40,7 +42,8 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider,
const AccountId& account_id, const AccountId& account_id,
base::TimeDelta initial_policy_fetch_timeout, base::TimeDelta initial_policy_fetch_timeout,
base::OnceClosure exit_session, base::OnceClosure exit_session,
std::unique_ptr<CloudPolicyStore> store); std::unique_ptr<CloudPolicyStore> store,
std::unique_ptr<CloudExternalDataManager> external_data_manager);
// ConfigurationPolicyProvider: // ConfigurationPolicyProvider:
void Init(SchemaRegistry* registry) override; void Init(SchemaRegistry* registry) override;
...@@ -71,10 +74,12 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider, ...@@ -71,10 +74,12 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider,
// enforce successful policy fetch. In case the conditions for signaling // enforce successful policy fetch. In case the conditions for signaling
// initialization complete are not met, the user session is aborted by calling // initialization complete are not met, the user session is aborted by calling
// |exit_session|. // |exit_session|.
ActiveDirectoryPolicyManager(const AccountId& account_id, ActiveDirectoryPolicyManager(
const AccountId& account_id,
base::TimeDelta initial_policy_fetch_timeout, base::TimeDelta initial_policy_fetch_timeout,
base::OnceClosure exit_session, base::OnceClosure exit_session,
std::unique_ptr<CloudPolicyStore> store); std::unique_ptr<CloudPolicyStore> store,
std::unique_ptr<CloudExternalDataManager> external_data_manager);
// Publish the policy that's currently cached in the store. // Publish the policy that's currently cached in the store.
void PublishPolicy(); void PublishPolicy();
...@@ -123,7 +128,12 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider, ...@@ -123,7 +128,12 @@ class ActiveDirectoryPolicyManager : public ConfigurationPolicyProvider,
// Callback to exit the session. // Callback to exit the session.
base::OnceClosure exit_session_; base::OnceClosure exit_session_;
// Store used to serialize policy, usually sends data to Session Manager.
std::unique_ptr<CloudPolicyStore> store_; std::unique_ptr<CloudPolicyStore> store_;
// Manages external data referenced by policies.
std::unique_ptr<CloudExternalDataManager> external_data_manager_;
std::unique_ptr<PolicyScheduler> scheduler_; std::unique_ptr<PolicyScheduler> scheduler_;
// Must be last member. // Must be last member.
......
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chromeos/dbus/auth_policy_client.h" #include "chromeos/dbus/auth_policy_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_store.h" #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
#include "components/policy/core/common/schema_registry.h" #include "components/policy/core/common/schema_registry.h"
#include "components/signin/core/account_id/account_id.h" #include "components/signin/core/account_id/account_id.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -94,10 +96,63 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test { ...@@ -94,10 +96,63 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test {
~ActiveDirectoryPolicyManagerTest() override { ~ActiveDirectoryPolicyManagerTest() override {
EXPECT_EQ(session_exit_expected_, session_exited_); EXPECT_EQ(session_exit_expected_, session_exited_);
if (mock_external_data_manager_)
EXPECT_CALL(*mock_external_data_manager_, Disconnect());
policy_manager_->Shutdown(); policy_manager_->Shutdown();
} }
protected: protected:
// Creates |mock_store_|, |mock_external_data_manager_| and |policy_manager_|
// with fake AD account id and |initial_policy_fetch_timeout| as timeout.
void CreateUserPolicyManager(base::TimeDelta initial_policy_fetch_timeout) {
auto account_id = AccountId::AdFromUserEmailObjGuid("bla", "ble");
auto mock_store_unique_ptr = std::make_unique<MockCloudPolicyStore>();
mock_store_ = mock_store_unique_ptr.get();
auto mock_external_data_manager_unique_ptr =
std::make_unique<MockCloudExternalDataManager>();
mock_external_data_manager_ = mock_external_data_manager_unique_ptr.get();
base::OnceClosure exit_session = base::BindOnce(
&ActiveDirectoryPolicyManagerTest::ExitSession, base::Unretained(this));
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy(
account_id, initial_policy_fetch_timeout, std::move(exit_session),
std::move(mock_store_unique_ptr),
std::move(mock_external_data_manager_unique_ptr));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(
policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
}
// Creates |mock_store_| and |policy_manager_|.
void CreateDevicePolicyManager() {
auto mock_store_unique_ptr = std::make_unique<MockCloudPolicyStore>();
mock_store_ = mock_store_unique_ptr.get();
policy_manager_ = ActiveDirectoryPolicyManager::CreateForDevicePolicy(
std::move(mock_store_unique_ptr));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(
policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
}
// Initializes the policy manager and verifies expectations on mock classes.
void InitPolicyManagerAndVerifyExpectations() {
EXPECT_CALL(*mock_store_, Load());
if (mock_external_data_manager_) {
EXPECT_CALL(*mock_external_data_manager_,
Connect(scoped_refptr<net::URLRequestContextGetter>()));
}
policy_manager_->Init(&schema_registry_);
testing::Mock::VerifyAndClearExpectations(mock_store_);
if (mock_external_data_manager_)
testing::Mock::VerifyAndClearExpectations(mock_external_data_manager_);
}
// Expect that session exit will be called below. (Must only be called once.) // Expect that session exit will be called below. (Must only be called once.)
void ExpectSessionExit() { void ExpectSessionExit() {
ASSERT_FALSE(session_exit_expected_); ASSERT_FALSE(session_exit_expected_);
...@@ -121,20 +176,12 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test { ...@@ -121,20 +176,12 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test {
bool session_exited_ = false; bool session_exited_ = false;
bool session_exit_expected_ = false; bool session_exit_expected_ = false;
// To be handed over to ActiveDirectoryPolicyManager. // Created by CreateUserPolicyManager().
base::OnceClosure exit_session_{ MockCloudPolicyStore* mock_store_ = nullptr;
base::BindOnce(&ActiveDirectoryPolicyManagerTest::ExitSession, MockCloudExternalDataManager* mock_external_data_manager_ = nullptr;
base::Unretained(this))};
// To be handed over to ActiveDirectoryPolicyManager ...
std::unique_ptr<MockCloudPolicyStore> mock_store_unique_ptr_{
std::make_unique<MockCloudPolicyStore>()};
// ... but keeping a non-owned pointer.
MockCloudPolicyStore* mock_store_{mock_store_unique_ptr_.get()};
// Owned by DBusThreadManager. // Owned by DBusThreadManager.
TestAuthPolicyClient* mock_client_; TestAuthPolicyClient* mock_client_ = nullptr;
SchemaRegistry schema_registry_; SchemaRegistry schema_registry_;
...@@ -146,18 +193,14 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test { ...@@ -146,18 +193,14 @@ class ActiveDirectoryPolicyManagerTest : public testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_; base::test::ScopedTaskEnvironment scoped_task_environment_;
}; };
TEST_F(ActiveDirectoryPolicyManagerTest, DontWait) { TEST_F(ActiveDirectoryPolicyManagerTest, UserManager_DontWait) {
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( CreateUserPolicyManager(base::TimeDelta());
AccountId::AdFromUserEmailObjGuid("bla", "ble"), base::TimeDelta(),
std::move(exit_session_), std::move(mock_store_unique_ptr_));
EXPECT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Simulate failed store load. Initialization is reported complete at this // Simulate failed store load. Initialization is reported complete at this
...@@ -166,6 +209,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, DontWait) { ...@@ -166,6 +209,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, DontWait) {
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -177,18 +221,14 @@ TEST_F(ActiveDirectoryPolicyManagerTest, DontWait) { ...@@ -177,18 +221,14 @@ TEST_F(ActiveDirectoryPolicyManagerTest, DontWait) {
// If the initial fetch timeout is infinite, initialization is only complete // If the initial fetch timeout is infinite, initialization is only complete
// after policy has been fetched and after that has been loaded. // after policy has been fetched and after that has been loaded.
TEST_F(ActiveDirectoryPolicyManagerTest, TEST_F(ActiveDirectoryPolicyManagerTest,
WaitInfinite_LoadSuccess_FetchSuccess) { UserManager_WaitInfinite_LoadSuccess_FetchSuccess) {
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( CreateUserPolicyManager(base::TimeDelta::Max());
AccountId::AdFromUserEmailObjGuid("bla", "ble"), base::TimeDelta::Max(),
std::move(exit_session_), std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to succeed. // Configure mock policy fetch to succeed.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_NONE); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_NONE);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate successful store load. // Simulate successful store load.
mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>(); mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>();
...@@ -196,6 +236,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, ...@@ -196,6 +236,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest,
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -207,18 +248,14 @@ TEST_F(ActiveDirectoryPolicyManagerTest, ...@@ -207,18 +248,14 @@ TEST_F(ActiveDirectoryPolicyManagerTest,
// If the initial fetch timeout is infinite, initialization does not complete if // If the initial fetch timeout is infinite, initialization does not complete if
// load after fetch fails. // load after fetch fails.
TEST_F(ActiveDirectoryPolicyManagerTest, TEST_F(ActiveDirectoryPolicyManagerTest,
WaitInfinite_LoadSuccess_FetchSuccess_LoadFail) { UserManager_WaitInfinite_LoadSuccess_FetchSuccess_LoadFail) {
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( CreateUserPolicyManager(base::TimeDelta::Max());
AccountId::AdFromUserEmailObjGuid("bla", "ble"), base::TimeDelta::Max(),
std::move(exit_session_), std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to succeed. // Configure mock policy fetch to succeed.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_NONE); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_NONE);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate successful store load. // Simulate successful store load.
mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>(); mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>();
...@@ -226,6 +263,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, ...@@ -226,6 +263,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest,
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -244,18 +282,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, ...@@ -244,18 +282,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest,
// If the initial fetch timeout is infinite, failure in policy fetch prevents // If the initial fetch timeout is infinite, failure in policy fetch prevents
// initialization from finishing, ever. // initialization from finishing, ever.
TEST_F(ActiveDirectoryPolicyManagerTest, WaitInfinite_LoadSuccess_FetchFail) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitInfinite_LoadSuccess_FetchFail) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), base::TimeDelta::Max(), CreateUserPolicyManager(base::TimeDelta::Max());
std::move(exit_session_), std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate successful store load. // Simulate successful store load.
mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>(); mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>();
...@@ -265,6 +300,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitInfinite_LoadSuccess_FetchFail) { ...@@ -265,6 +300,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitInfinite_LoadSuccess_FetchFail) {
ExpectSessionExit(); ExpectSessionExit();
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -278,19 +314,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitInfinite_LoadSuccess_FetchFail) { ...@@ -278,19 +314,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitInfinite_LoadSuccess_FetchFail) {
// If the initial fetch timeout is not infinite, we're in best-effort mode but // If the initial fetch timeout is not infinite, we're in best-effort mode but
// still require the policy load to succeed so that there's *some* policy // still require the policy load to succeed so that there's *some* policy
// present (though possibly outdated). // present (though possibly outdated).
TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchFail) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitFinite_LoadSuccess_FetchFail) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), CreateUserPolicyManager(base::TimeDelta::FromDays(365));
base::TimeDelta::FromDays(365), std::move(exit_session_),
std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate successful store load. // Simulate successful store load.
mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>(); mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>();
...@@ -300,6 +332,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchFail) { ...@@ -300,6 +332,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchFail) {
// Process reply for mock policy fetch. At this point initialization is // Process reply for mock policy fetch. At this point initialization is
// complete (we have waited for the fetch but now that we know it has failed // complete (we have waited for the fetch but now that we know it has failed
// we continue). // we continue).
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -312,21 +345,18 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchFail) { ...@@ -312,21 +345,18 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchFail) {
// still require the policy load to succeed so that there's *some* policy // still require the policy load to succeed so that there's *some* policy
// present (though possibly outdated). Here the sequence is inverted: Fetch // present (though possibly outdated). Here the sequence is inverted: Fetch
// returns before load. // returns before load.
TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_FetchFail_LoadSuccess) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitFinite_FetchFail_LoadSuccess) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), CreateUserPolicyManager(base::TimeDelta::FromDays(365));
base::TimeDelta::FromDays(365), std::move(exit_session_),
std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -338,19 +368,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_FetchFail_LoadSuccess) { ...@@ -338,19 +368,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_FetchFail_LoadSuccess) {
// If the initial fetch timeout is not infinite, we're in best-effort mode but // If the initial fetch timeout is not infinite, we're in best-effort mode but
// if we can't load existing policy from disk we have to give up. // if we can't load existing policy from disk we have to give up.
TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadFail_FetchFail) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitFinite_LoadFail_FetchFail) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), CreateUserPolicyManager(base::TimeDelta::FromDays(365));
base::TimeDelta::FromDays(365), std::move(exit_session_),
std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate failed store load. // Simulate failed store load.
mock_store_->NotifyStoreError(); mock_store_->NotifyStoreError();
...@@ -359,6 +385,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadFail_FetchFail) { ...@@ -359,6 +385,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadFail_FetchFail) {
ExpectSessionExit(); ExpectSessionExit();
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -373,19 +400,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadFail_FetchFail) { ...@@ -373,19 +400,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadFail_FetchFail) {
// If the initial fetch timeout is not infinite, we're in best-effort mode and // If the initial fetch timeout is not infinite, we're in best-effort mode and
// upon timeout initialization is complete if any policy could be loaded from // upon timeout initialization is complete if any policy could be loaded from
// disk. // disk.
TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchTimeout) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitFinite_LoadSuccess_FetchTimeout) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), CreateUserPolicyManager(base::TimeDelta::FromDays(365));
base::TimeDelta::FromDays(365), std::move(exit_session_),
std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
// Simulate successful store load. // Simulate successful store load.
mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>(); mock_store_->policy_ = std::make_unique<enterprise_management::PolicyData>();
...@@ -397,6 +420,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchTimeout) { ...@@ -397,6 +420,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchTimeout) {
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -407,19 +431,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchTimeout) { ...@@ -407,19 +431,15 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadSuccess_FetchTimeout) {
// If the initial fetch timeout is not infinite, we're in best-effort mode but // If the initial fetch timeout is not infinite, we're in best-effort mode but
// without a successful policy load we still can't continue. // without a successful policy load we still can't continue.
TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadTimeout_FetchTimeout) { TEST_F(ActiveDirectoryPolicyManagerTest,
policy_manager_ = ActiveDirectoryPolicyManager::CreateForUserPolicy( UserManager_WaitFinite_LoadTimeout_FetchTimeout) {
AccountId::AdFromUserEmailObjGuid("bla", "ble"), CreateUserPolicyManager(base::TimeDelta::FromDays(365));
base::TimeDelta::FromDays(365), std::move(exit_session_),
std::move(mock_store_unique_ptr_));
ASSERT_TRUE(policy_manager_);
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
// Configure mock policy fetch to fail. // Configure mock policy fetch to fail.
mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN); mock_client_->SetRefreshUserPolicyCallbackError(authpolicy::ERROR_UNKNOWN);
// Trigger mock policy fetch from authpolicyd. // Trigger mock policy fetch from authpolicyd.
policy_manager_->Init(&schema_registry_); InitPolicyManagerAndVerifyExpectations();
ExpectSessionExit(); ExpectSessionExit();
...@@ -430,6 +450,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadTimeout_FetchTimeout) { ...@@ -430,6 +450,7 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadTimeout_FetchTimeout) {
ExpectSessionExited(); ExpectSessionExited();
// Process reply for mock policy fetch. // Process reply for mock policy fetch.
EXPECT_CALL(*mock_store_, Load());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_FALSE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
...@@ -439,4 +460,9 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadTimeout_FetchTimeout) { ...@@ -439,4 +460,9 @@ TEST_F(ActiveDirectoryPolicyManagerTest, WaitFinite_LoadTimeout_FetchTimeout) {
EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); EXPECT_TRUE(policy_manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
} }
TEST_F(ActiveDirectoryPolicyManagerTest, DeviceManager_Initialization) {
CreateDevicePolicyManager();
InitPolicyManagerAndVerifyExpectations();
}
} // namespace policy } // namespace policy
...@@ -192,7 +192,7 @@ void CloudExternalDataPolicyObserver::OnPolicyUpdated( ...@@ -192,7 +192,7 @@ void CloudExternalDataPolicyObserver::OnPolicyUpdated(
} }
if (!device_local_account_policy_service_) { if (!device_local_account_policy_service_) {
NOTREACHED(); // May happen in tests.
return; return;
} }
DeviceLocalAccountPolicyBroker* broker = DeviceLocalAccountPolicyBroker* broker =
......
...@@ -57,6 +57,8 @@ class CloudExternalDataPolicyObserver ...@@ -57,6 +57,8 @@ class CloudExternalDataPolicyObserver
virtual ~Delegate(); virtual ~Delegate();
}; };
// |device_local_account_policy_service| may be nullptr if unavailable (e.g.
// Active Directory management mode).
CloudExternalDataPolicyObserver( CloudExternalDataPolicyObserver(
chromeos::CrosSettings* cros_settings, chromeos::CrosSettings* cros_settings,
DeviceLocalAccountPolicyService* device_local_account_policy_service, DeviceLocalAccountPolicyService* device_local_account_policy_service,
...@@ -98,7 +100,7 @@ class CloudExternalDataPolicyObserver ...@@ -98,7 +100,7 @@ class CloudExternalDataPolicyObserver
// A map from each logged-in user to the helper that observes |policy_| in the // A map from each logged-in user to the helper that observes |policy_| in the
// user's PolicyService. // user's PolicyService.
typedef std::map<std::string, linked_ptr<PolicyServiceObserver> > typedef std::map<std::string, linked_ptr<PolicyServiceObserver>>
LoggedInUserObserverMap; LoggedInUserObserverMap;
LoggedInUserObserverMap logged_in_user_observers_; LoggedInUserObserverMap logged_in_user_observers_;
...@@ -117,9 +119,8 @@ class CloudExternalDataPolicyObserver ...@@ -117,9 +119,8 @@ class CloudExternalDataPolicyObserver
// A map from user ID to a base::WeakPtr for each external data fetch // A map from user ID to a base::WeakPtr for each external data fetch
// currently in progress. This allows fetches to be effectively be canceled by // currently in progress. This allows fetches to be effectively be canceled by
// invalidating the pointers. // invalidating the pointers.
typedef base::WeakPtrFactory<CloudExternalDataPolicyObserver> using WeakPtrFactory = base::WeakPtrFactory<CloudExternalDataPolicyObserver>;
WeakPtrFactory; using FetchWeakPtrMap = std::map<std::string, linked_ptr<WeakPtrFactory>>;
typedef std::map<std::string, linked_ptr<WeakPtrFactory> > FetchWeakPtrMap;
FetchWeakPtrMap fetch_weak_ptrs_; FetchWeakPtrMap fetch_weak_ptrs_;
base::WeakPtrFactory<CloudExternalDataPolicyObserver> weak_factory_; base::WeakPtrFactory<CloudExternalDataPolicyObserver> weak_factory_;
......
...@@ -355,7 +355,8 @@ UserPolicyManagerFactoryChromeOS::CreateManagerForProfile( ...@@ -355,7 +355,8 @@ UserPolicyManagerFactoryChromeOS::CreateManagerForProfile(
std::unique_ptr<ActiveDirectoryPolicyManager> manager = std::unique_ptr<ActiveDirectoryPolicyManager> manager =
ActiveDirectoryPolicyManager::CreateForUserPolicy( ActiveDirectoryPolicyManager::CreateForUserPolicy(
account_id, policy_refresh_timeout, account_id, policy_refresh_timeout,
base::BindOnce(&chrome::AttemptUserExit), std::move(store)); base::BindOnce(&chrome::AttemptUserExit), std::move(store),
std::move(external_data_manager));
manager->Init( manager->Init(
SchemaRegistryServiceFactory::GetForContext(profile)->registry()); SchemaRegistryServiceFactory::GetForContext(profile)->registry());
......
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