OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_policy_cros_browser_test.h" | 5 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
6 | 6 |
7 #include <string> | |
8 #include <vector> | 7 #include <vector> |
9 | 8 |
10 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
12 #include "base/path_service.h" | 11 #include "base/path_service.h" |
13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
14 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 13 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
16 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
17 #include "chromeos/chromeos_paths.h" | 16 #include "chromeos/chromeos_paths.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/dbus/fake_session_manager_client.h" | 18 #include "chromeos/dbus/fake_session_manager_client.h" |
20 #include "crypto/rsa_private_key.h" | 19 #include "crypto/rsa_private_key.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 using ::testing::_; | 23 using ::testing::_; |
25 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
26 using ::testing::Return; | 25 using ::testing::Return; |
27 | 26 |
28 namespace policy { | 27 namespace policy { |
29 | 28 |
30 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} | 29 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} |
31 | 30 |
32 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} | 31 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} |
33 | 32 |
34 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { | 33 // static |
| 34 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( |
| 35 const std::string& user_name) { |
35 OverridePaths(); | 36 OverridePaths(); |
36 | 37 |
37 const std::string install_attrs_blob( | 38 const std::string install_attrs_blob( |
38 EnterpriseInstallAttributes:: | 39 EnterpriseInstallAttributes:: |
39 GetEnterpriseOwnedInstallAttributesBlobForTesting( | 40 GetEnterpriseOwnedInstallAttributesBlobForTesting(user_name)); |
40 device_policy_.policy_data().username())); | |
41 | 41 |
42 base::FilePath install_attrs_file; | 42 base::FilePath install_attrs_file; |
43 ASSERT_TRUE( | 43 ASSERT_TRUE( |
44 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); | 44 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); |
45 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), | 45 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), |
46 base::WriteFile(install_attrs_file, | 46 base::WriteFile(install_attrs_file, |
47 install_attrs_blob.c_str(), | 47 install_attrs_blob.c_str(), |
48 install_attrs_blob.size())); | 48 install_attrs_blob.size())); |
49 } | 49 } |
50 | 50 |
| 51 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { |
| 52 MarkAsEnterpriseOwnedBy(device_policy_.policy_data().username()); |
| 53 } |
| 54 |
51 void DevicePolicyCrosTestHelper::InstallOwnerKey() { | 55 void DevicePolicyCrosTestHelper::InstallOwnerKey() { |
52 OverridePaths(); | 56 OverridePaths(); |
53 | 57 |
54 base::FilePath owner_key_file; | 58 base::FilePath owner_key_file; |
55 ASSERT_TRUE(PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_file)); | 59 ASSERT_TRUE(PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_file)); |
56 std::vector<uint8> owner_key_bits; | 60 std::vector<uint8> owner_key_bits; |
57 ASSERT_TRUE( | 61 ASSERT_TRUE( |
58 device_policy()->GetSigningKey()->ExportPublicKey(&owner_key_bits)); | 62 device_policy()->GetSigningKey()->ExportPublicKey(&owner_key_bits)); |
59 ASSERT_EQ(base::WriteFile( | 63 ASSERT_EQ(base::WriteFile( |
60 owner_key_file, | 64 owner_key_file, |
61 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), | 65 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), |
62 owner_key_bits.size()), | 66 owner_key_bits.size()), |
63 static_cast<int>(owner_key_bits.size())); | 67 static_cast<int>(owner_key_bits.size())); |
64 } | 68 } |
65 | 69 |
| 70 // static |
66 void DevicePolicyCrosTestHelper::OverridePaths() { | 71 void DevicePolicyCrosTestHelper::OverridePaths() { |
67 // This is usually done by ChromeBrowserMainChromeOS, but some tests | 72 // This is usually done by ChromeBrowserMainChromeOS, but some tests |
68 // use the overridden paths before ChromeBrowserMain starts. Make sure that | 73 // use the overridden paths before ChromeBrowserMain starts. Make sure that |
69 // the paths are overridden before using them. | 74 // the paths are overridden before using them. |
70 base::FilePath user_data_dir; | 75 base::FilePath user_data_dir; |
71 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 76 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
72 chromeos::RegisterStubPathOverrides(user_data_dir); | 77 chromeos::RegisterStubPathOverrides(user_data_dir); |
73 } | 78 } |
74 | 79 |
75 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() | 80 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() |
(...skipping 24 matching lines...) Expand all Loading... |
100 | 105 |
101 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { | 106 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { |
102 // Reset the key to its original state. | 107 // Reset the key to its original state. |
103 device_policy()->SetDefaultSigningKey(); | 108 device_policy()->SetDefaultSigningKey(); |
104 device_policy()->Build(); | 109 device_policy()->Build(); |
105 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 110 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
106 session_manager_client()->OnPropertyChangeComplete(true); | 111 session_manager_client()->OnPropertyChangeComplete(true); |
107 } | 112 } |
108 | 113 |
109 } // namespace policy | 114 } // namespace policy |
OLD | NEW |