OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
19 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 19 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
20 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" | 22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
23 #include "chrome/browser/policy/external_data_fetcher.h" | 23 #include "chrome/browser/policy/external_data_fetcher.h" |
24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
26 #include "chrome/browser/prefs/browser_prefs.h" | 26 #include "chrome/browser/prefs/browser_prefs.h" |
27 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
28 #include "chromeos/cryptohome/cryptohome_library.h" | |
29 #include "chromeos/dbus/dbus_client_implementation_type.h" | 28 #include "chromeos/dbus/dbus_client_implementation_type.h" |
30 #include "chromeos/dbus/fake_cryptohome_client.h" | 29 #include "chromeos/dbus/fake_cryptohome_client.h" |
31 #include "google_apis/gaia/gaia_oauth_client.h" | 30 #include "google_apis/gaia/gaia_oauth_client.h" |
32 #include "net/url_request/test_url_fetcher_factory.h" | 31 #include "net/url_request/test_url_fetcher_factory.h" |
33 #include "net/url_request/url_request_test_util.h" | 32 #include "net/url_request/url_request_test_util.h" |
34 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
35 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
37 | 36 |
38 using testing::AnyNumber; | 37 using testing::AnyNumber; |
(...skipping 12 matching lines...) Expand all Loading... | |
51 EnterpriseInstallAttributes::LockResult* out, | 50 EnterpriseInstallAttributes::LockResult* out, |
52 EnterpriseInstallAttributes::LockResult result) { | 51 EnterpriseInstallAttributes::LockResult result) { |
53 *out = result; | 52 *out = result; |
54 loop->Quit(); | 53 loop->Quit(); |
55 } | 54 } |
56 | 55 |
57 class DeviceCloudPolicyManagerChromeOSTest | 56 class DeviceCloudPolicyManagerChromeOSTest |
58 : public chromeos::DeviceSettingsTestBase { | 57 : public chromeos::DeviceSettingsTestBase { |
59 protected: | 58 protected: |
60 DeviceCloudPolicyManagerChromeOSTest() | 59 DeviceCloudPolicyManagerChromeOSTest() |
61 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), | 60 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
62 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | 61 install_attributes_(fake_cryptohome_client_.get()), |
63 install_attributes_(cryptohome_library_.get(), | |
64 fake_cryptohome_client_.get()), | |
65 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 62 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
66 &install_attributes_)), | 63 &install_attributes_)), |
67 manager_(make_scoped_ptr(store_), | 64 manager_(make_scoped_ptr(store_), |
68 loop_.message_loop_proxy(), | 65 loop_.message_loop_proxy(), |
69 &install_attributes_) { | 66 &install_attributes_) { |
70 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); | 67 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); |
71 } | 68 } |
72 | 69 |
73 virtual void SetUp() OVERRIDE { | 70 virtual void SetUp() OVERRIDE { |
74 DeviceSettingsTestBase::SetUp(); | 71 DeviceSettingsTestBase::SetUp(); |
75 chrome::RegisterLocalState(local_state_.registry()); | 72 chrome::RegisterLocalState(local_state_.registry()); |
76 manager_.Init(); | 73 manager_.Init(); |
77 | 74 |
78 // DeviceOAuth2TokenService uses the system request context to fetch | 75 // DeviceOAuth2TokenService uses the system request context to fetch |
79 // OAuth tokens, then writes the token to local state, encrypting it | 76 // OAuth tokens, then writes the token to local state, encrypting it |
80 // first with methods in CryptohomeLibrary. | 77 // first with methods in CryptohomeLibrary. |
pneubeck (no reviews)
2013/09/27 08:59:25
stale comment?
satorux1
2013/10/01 05:24:03
Turned out the comment was correct. Encryption was
| |
81 request_context_getter_ = new net::TestURLRequestContextGetter( | 78 request_context_getter_ = new net::TestURLRequestContextGetter( |
82 loop_.message_loop_proxy()); | 79 loop_.message_loop_proxy()); |
83 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( | 80 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( |
84 request_context_getter_.get()); | 81 request_context_getter_.get()); |
85 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 82 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
86 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); | 83 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); |
87 chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get()); | |
satorux1
2013/10/01 05:24:03
This turned out to be necessary, as CryptohomeLibr
| |
88 url_fetcher_response_code_ = 200; | 84 url_fetcher_response_code_ = 200; |
89 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," | 85 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," |
90 "\"expires_in\":1234," | 86 "\"expires_in\":1234," |
91 "\"refresh_token\":\"refreshToken4Test\"}"; | 87 "\"refresh_token\":\"refreshToken4Test\"}"; |
92 } | 88 } |
93 | 89 |
94 virtual void TearDown() OVERRIDE { | 90 virtual void TearDown() OVERRIDE { |
95 manager_.Shutdown(); | 91 manager_.Shutdown(); |
96 DeviceSettingsTestBase::TearDown(); | 92 DeviceSettingsTestBase::TearDown(); |
97 | 93 |
98 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 94 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
99 chromeos::CryptohomeLibrary::SetForTest(NULL); | |
100 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 95 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
101 } | 96 } |
102 | 97 |
103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_; | |
104 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; | 98 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; |
105 EnterpriseInstallAttributes install_attributes_; | 99 EnterpriseInstallAttributes install_attributes_; |
106 | 100 |
107 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
108 net::TestURLFetcherFactory url_fetcher_factory_; | 102 net::TestURLFetcherFactory url_fetcher_factory_; |
109 int url_fetcher_response_code_; | 103 int url_fetcher_response_code_; |
110 string url_fetcher_response_string_; | 104 string url_fetcher_response_string_; |
111 TestingPrefServiceSimple local_state_; | 105 TestingPrefServiceSimple local_state_; |
112 MockDeviceManagementService device_management_service_; | 106 MockDeviceManagementService device_management_service_; |
113 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 107 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 484 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
491 loaded_blob_.clear(); | 485 loaded_blob_.clear(); |
492 RunTest(); | 486 RunTest(); |
493 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 487 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
494 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 488 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
495 status_.store_status()); | 489 status_.store_status()); |
496 } | 490 } |
497 | 491 |
498 } // namespace | 492 } // namespace |
499 } // namespace policy | 493 } // namespace policy |
OLD | NEW |