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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_browsertest.cc

Issue 2621413007: Revert of Re-enable fetching component policies for login screen apps (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <memory> 5 #include <memory>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/dir_reader_posix.h" 8 #include "base/files/dir_reader_posix.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); 79 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer());
80 } 80 }
81 81
82 // This class is the base class for the tests of the behavior regarding 82 // This class is the base class for the tests of the behavior regarding
83 // extensions installed on the signin screen (which is generally possible only 83 // extensions installed on the signin screen (which is generally possible only
84 // through an admin policy, but the tests may install the extensions directly 84 // through an admin policy, but the tests may install the extensions directly
85 // for the test purposes). 85 // for the test purposes).
86 class SigninExtensionsDeviceCloudPolicyBrowserTestBase 86 class SigninExtensionsDeviceCloudPolicyBrowserTestBase
87 : public DevicePolicyCrosBrowserTest { 87 : public DevicePolicyCrosBrowserTest {
88 protected: 88 protected:
89 static constexpr const char* kTestExtensionId = 89 constexpr static const char* kTestExtensionId =
90 "baogpbmpccplckhhehfipokjaflkmbno"; 90 "baogpbmpccplckhhehfipokjaflkmbno";
91 static constexpr const char* kTestExtensionSourceDir = 91 constexpr static const char* kTestExtensionSourceDir =
92 "extensions/signin_screen_managed_storage"; 92 "extensions/signin_screen_managed_storage";
93 static constexpr const char* kTestExtensionVersion = "1.0"; 93 constexpr static const char* kTestExtensionVersion = "1.0";
94 static constexpr const char* kTestExtensionTestPage = "test.html"; 94 constexpr static const char* kTestExtensionTestPage = "test.html";
95 static constexpr const char* kFakePolicyUrl = 95 constexpr static const char* kFakePolicyUrl =
96 "http://example.org/test-policy.json"; 96 "http://example.org/test-policy.json";
97 static constexpr const char* kFakePolicy = 97 constexpr static const char* kFakePolicy =
98 "{\"string-policy\": {\"Value\": \"value\"}}"; 98 "{\"string-policy\": {\"Value\": \"value\"}}";
99 static constexpr int kFakePolicyPublicKeyVersion = 1; 99 constexpr static const char* kPolicyProtoCacheKey = "signinextension-policy";
100 static constexpr const char* kPolicyProtoCacheKey = "signinextension-policy"; 100 constexpr static const char* kPolicyDataCacheKey =
101 static constexpr const char* kPolicyDataCacheKey =
102 "signinextension-policy-data"; 101 "signinextension-policy-data";
103 102
104 SigninExtensionsDeviceCloudPolicyBrowserTestBase() {} 103 SigninExtensionsDeviceCloudPolicyBrowserTestBase() {}
105 104
106 void SetUpCommandLine(base::CommandLine* command_line) override { 105 void SetUpCommandLine(base::CommandLine* command_line) override {
107 DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line); 106 DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
108 command_line->AppendSwitch(chromeos::switches::kLoginManager); 107 command_line->AppendSwitch(chromeos::switches::kLoginManager);
109 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); 108 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
110 // This flag is required for the successful installation of the test 109 // This flag is required for the successful installation of the test
111 // extension into the signin profile, due to some checks in 110 // extension into the signin profile, due to some checks in
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 148
150 static const extensions::Extension* GetTestExtension() { 149 static const extensions::Extension* GetTestExtension() {
151 extensions::ExtensionRegistry* registry = 150 extensions::ExtensionRegistry* registry =
152 extensions::ExtensionRegistry::Get(GetSigninProfile()); 151 extensions::ExtensionRegistry::Get(GetSigninProfile());
153 const extensions::Extension* extension = 152 const extensions::Extension* extension =
154 registry->enabled_extensions().GetByID(kTestExtensionId); 153 registry->enabled_extensions().GetByID(kTestExtensionId);
155 EXPECT_TRUE(extension); 154 EXPECT_TRUE(extension);
156 return extension; 155 return extension;
157 } 156 }
158 157
159 static enterprise_management::PolicyFetchResponse BuildTestComponentPolicy() { 158 enterprise_management::PolicyFetchResponse BuildTestComponentPolicy() {
160 ComponentPolicyBuilder builder; 159 ComponentPolicyBuilder builder;
161 MakeTestComponentPolicyBuilder(&builder); 160 MakeTestComponentPolicyBuilder(&builder);
162 return builder.policy(); 161 return builder.policy();
163 } 162 }
164 163
165 static enterprise_management::ExternalPolicyData 164 enterprise_management::ExternalPolicyData BuildTestComponentPolicyPayload() {
166 BuildTestComponentPolicyPayload() {
167 ComponentPolicyBuilder builder; 165 ComponentPolicyBuilder builder;
168 MakeTestComponentPolicyBuilder(&builder); 166 MakeTestComponentPolicyBuilder(&builder);
169 return builder.payload(); 167 return builder.payload();
170 } 168 }
171 169
172 private: 170 private:
173 void SetFakeDevicePolicy() { 171 void SetFakeDevicePolicy() {
174 device_policy()->policy_data().set_username(PolicyBuilder::kFakeUsername); 172 device_policy()->policy_data().set_username(PolicyBuilder::kFakeUsername);
175 device_policy()->policy_data().set_public_key_version( 173 device_policy()->SetDefaultSigningKey();
176 kFakePolicyPublicKeyVersion);
177 device_policy()->Build(); 174 device_policy()->Build();
178 session_manager_client()->set_device_policy(device_policy()->GetBlob()); 175 session_manager_client()->set_device_policy(device_policy()->GetBlob());
179 } 176 }
180 177
181 static void MakeTestComponentPolicyBuilder(ComponentPolicyBuilder* builder) { 178 void MakeTestComponentPolicyBuilder(ComponentPolicyBuilder* builder) {
182 builder->policy_data().set_policy_type( 179 builder->policy_data().set_policy_type(
183 dm_protocol::kChromeSigninExtensionPolicyType); 180 dm_protocol::kChromeSigninExtensionPolicyType);
184 builder->policy_data().set_username(PolicyBuilder::kFakeUsername); 181 builder->policy_data().set_username(
182 device_policy()->policy_data().username());
185 builder->policy_data().set_settings_entity_id(kTestExtensionId); 183 builder->policy_data().set_settings_entity_id(kTestExtensionId);
186 builder->policy_data().set_public_key_version(kFakePolicyPublicKeyVersion); 184 builder->policy_data().set_public_key_version(1);
187 builder->payload().set_download_url(kFakePolicyUrl); 185 builder->payload().set_download_url(kFakePolicyUrl);
188 builder->payload().set_secure_hash(crypto::SHA256HashString(kFakePolicy)); 186 builder->payload().set_secure_hash(crypto::SHA256HashString(kFakePolicy));
187 builder->SetDefaultSigningKey();
189 builder->Build(); 188 builder->Build();
190 } 189 }
191 190
192 DISALLOW_COPY_AND_ASSIGN(SigninExtensionsDeviceCloudPolicyBrowserTestBase); 191 DISALLOW_COPY_AND_ASSIGN(SigninExtensionsDeviceCloudPolicyBrowserTestBase);
193 }; 192 };
194 193
195 // This class tests whether the component policy is successfully processed and 194 // This class tests whether the component policy is successfully processed and
196 // passed to the extension that is installed into the signin profile after the 195 // passed to the extension that is installed into the signin profile after the
197 // initialization finishes. 196 // initialization finishes.
198 // 197 //
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 net::URLRequestStatus::SUCCESS); 271 net::URLRequestStatus::SUCCESS);
273 } 272 }
274 273
275 LocalPolicyTestServer policy_test_server_; 274 LocalPolicyTestServer policy_test_server_;
276 net::URLFetcherImplFactory fetcher_impl_factory_; 275 net::URLFetcherImplFactory fetcher_impl_factory_;
277 net::FakeURLFetcherFactory fetcher_factory_; 276 net::FakeURLFetcherFactory fetcher_factory_;
278 base::FilePath component_policy_cache_dir_; 277 base::FilePath component_policy_cache_dir_;
279 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_; 278 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_;
280 }; 279 };
281 280
281 // DISABLED: see crbug.com/666720, crbug.com/644304. TODO(emaxx): Enable the
282 // test back.
282 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, 283 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest,
283 InstallAndRunInWindow) { 284 DISABLED_InstallAndRunInWindow) {
284 const extensions::Extension* extension = InstallAndLoadTestExtension(); 285 const extensions::Extension* extension = InstallAndLoadTestExtension();
285 ASSERT_TRUE(extension); 286 ASSERT_TRUE(extension);
286 Browser* browser = CreateBrowser(GetSigninProfile()); 287 Browser* browser = CreateBrowser(GetSigninProfile());
287 extensions::ResultCatcher result_catcher; 288 extensions::ResultCatcher result_catcher;
288 ui_test_utils::NavigateToURL( 289 ui_test_utils::NavigateToURL(
289 browser, extension->GetResourceURL(kTestExtensionTestPage)); 290 browser, extension->GetResourceURL(kTestExtensionTestPage));
290 EXPECT_TRUE(result_catcher.GetNextResult()); 291 EXPECT_TRUE(result_catcher.GetNextResult());
291 CloseBrowserSynchronously(browser); 292 CloseBrowserSynchronously(browser);
292 } 293 }
293 294
294 // This class tests that the cached component policy is successfully loaded and 295 // This class tests that the cached component policy is successfully loaded and
295 // passed to the extension that is already installed into the signin profile. 296 // passed to the extension that is already installed into the signin profile.
296 // 297 //
297 // To accomplish this, the class prefills the signin profile with, first, the 298 // To accomplish this, the class prefills the signin profile with, first, the
298 // installed test extension, and, second, with the cached component policy. 299 // installed test extension, and, second, with the cached component policy.
299 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest 300 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest
300 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { 301 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase {
301 protected: 302 protected:
302 static constexpr const char* kFakeProfileSourceDir = 303 constexpr static const char* kFakeProfileSourceDir =
303 "extensions/profiles/signin_screen_managed_storage"; 304 "extensions/profiles/signin_screen_managed_storage";
304 305
306 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_;
307
305 bool SetUpUserDataDirectory() override { 308 bool SetUpUserDataDirectory() override {
306 PrefillSigninProfile(); 309 PrefillSigninProfile();
307 PrefillComponentPolicyCache(); 310 PrefillComponentPolicyCache();
308 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); 311 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory();
309 } 312 }
310 313
311 void SetUpInProcessBrowserTestFixture() override { 314 void SetUpInProcessBrowserTestFixture() override {
312 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: 315 SigninExtensionsDeviceCloudPolicyBrowserTestBase::
313 SetUpInProcessBrowserTestFixture(); 316 SetUpInProcessBrowserTestFixture();
314 signin_policy_provided_disabler_ = 317 signin_policy_provided_disabler_ =
315 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting(); 318 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting();
316 } 319 }
317 320
318 private:
319 static void PrefillSigninProfile() { 321 static void PrefillSigninProfile() {
320 base::FilePath profile_source_path; 322 base::FilePath profile_source_path;
321 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); 323 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path));
322 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) 324 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir)
323 .AppendASCII(chrome::kInitialProfile); 325 .AppendASCII(chrome::kInitialProfile);
324 326
325 base::FilePath profile_target_path; 327 base::FilePath profile_target_path;
326 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); 328 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path));
327 329
328 EXPECT_TRUE( 330 EXPECT_TRUE(
(...skipping 16 matching lines...) Expand all
345 base::FilePath cache_dir; 347 base::FilePath cache_dir;
346 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, 348 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY,
347 &cache_dir)); 349 &cache_dir));
348 350
349 ResourceCache cache(cache_dir, new base::NullTaskRunner); 351 ResourceCache cache(cache_dir, new base::NullTaskRunner);
350 EXPECT_TRUE(cache.Store(kPolicyProtoCacheKey, kTestExtensionId, 352 EXPECT_TRUE(cache.Store(kPolicyProtoCacheKey, kTestExtensionId,
351 BuildTestComponentPolicy().SerializeAsString())); 353 BuildTestComponentPolicy().SerializeAsString()));
352 EXPECT_TRUE( 354 EXPECT_TRUE(
353 cache.Store(kPolicyDataCacheKey, kTestExtensionId, kFakePolicy)); 355 cache.Store(kPolicyDataCacheKey, kTestExtensionId, kFakePolicy));
354 } 356 }
355
356 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_;
357 }; 357 };
358 358
359 // DISABLED: see crbug.com/666720, crbug.com/644304. TODO(emaxx): Enable the
360 // test back.
359 IN_PROC_BROWSER_TEST_F(PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest, 361 IN_PROC_BROWSER_TEST_F(PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest,
360 OfflineStart) { 362 DISABLED_OfflineStart) {
361 const extensions::Extension* extension = GetTestExtension(); 363 const extensions::Extension* extension = GetTestExtension();
362 ASSERT_TRUE(extension); 364 ASSERT_TRUE(extension);
363 Browser* browser = CreateBrowser(GetSigninProfile()); 365 Browser* browser = CreateBrowser(GetSigninProfile());
364 extensions::ResultCatcher result_catcher; 366 extensions::ResultCatcher result_catcher;
365 ui_test_utils::NavigateToURL( 367 ui_test_utils::NavigateToURL(
366 browser, extension->GetResourceURL(kTestExtensionTestPage)); 368 browser, extension->GetResourceURL(kTestExtensionTestPage));
367 EXPECT_TRUE(result_catcher.GetNextResult()); 369 EXPECT_TRUE(result_catcher.GetNextResult());
368 CloseBrowserSynchronously(browser); 370 CloseBrowserSynchronously(browser);
369 } 371 }
370 372
371 } // namespace policy 373 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698