| 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/enterprise_install_attributes.h" | 5 #include "chrome/browser/chromeos/settings/install_attributes.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" | 16 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" |
| 16 #include "chromeos/chromeos_paths.h" | 17 #include "chromeos/chromeos_paths.h" |
| 17 #include "chromeos/cryptohome/cryptohome_util.h" | 18 #include "chromeos/cryptohome/cryptohome_util.h" |
| 18 #include "chromeos/dbus/cryptohome_client.h" | 19 #include "chromeos/dbus/cryptohome_client.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 namespace policy { | 24 namespace chromeos { |
| 24 | |
| 25 namespace cryptohome_util = chromeos::cryptohome_util; | |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 void CopyLockResult(base::RunLoop* loop, | 28 void CopyLockResult(base::RunLoop* loop, |
| 30 EnterpriseInstallAttributes::LockResult* out, | 29 InstallAttributes::LockResult* out, |
| 31 EnterpriseInstallAttributes::LockResult result) { | 30 InstallAttributes::LockResult result) { |
| 32 *out = result; | 31 *out = result; |
| 33 loop->Quit(); | 32 loop->Quit(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 static const char kTestUser[] = "test@example.com"; | 37 static const char kTestUser[] = "test@example.com"; |
| 39 static const char kTestUserCanonicalize[] = "UPPER.CASE@example.com"; | 38 static const char kTestUserCanonicalize[] = "UPPER.CASE@example.com"; |
| 40 static const char kTestDomain[] = "example.com"; | 39 static const char kTestDomain[] = "example.com"; |
| 41 static const char kTestDeviceId[] = "133750519"; | 40 static const char kTestDeviceId[] = "133750519"; |
| 42 | 41 |
| 43 class EnterpriseInstallAttributesTest : public testing::Test { | 42 class InstallAttributesTest : public testing::Test { |
| 44 protected: | 43 protected: |
| 45 EnterpriseInstallAttributesTest() {} | 44 InstallAttributesTest() {} |
| 46 | 45 |
| 47 void SetUp() override { | 46 void SetUp() override { |
| 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 49 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 48 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 50 chromeos::FILE_INSTALL_ATTRIBUTES, GetTempPath(), true, false)); | 49 FILE_INSTALL_ATTRIBUTES, GetTempPath(), true, false)); |
| 51 chromeos::DBusThreadManager::Initialize(); | 50 DBusThreadManager::Initialize(); |
| 52 install_attributes_.reset(new EnterpriseInstallAttributes( | 51 install_attributes_ = base::MakeUnique<InstallAttributes>( |
| 53 chromeos::DBusThreadManager::Get()->GetCryptohomeClient())); | 52 DBusThreadManager::Get()->GetCryptohomeClient()); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void TearDown() override { chromeos::DBusThreadManager::Shutdown(); } | 55 void TearDown() override { DBusThreadManager::Shutdown(); } |
| 57 | 56 |
| 58 base::FilePath GetTempPath() const { | 57 base::FilePath GetTempPath() const { |
| 59 base::FilePath temp_path = base::MakeAbsoluteFilePath(temp_dir_.GetPath()); | 58 base::FilePath temp_path = base::MakeAbsoluteFilePath(temp_dir_.GetPath()); |
| 60 return temp_path.Append("install_attrs_test"); | 59 return temp_path.Append("install_attrs_test"); |
| 61 } | 60 } |
| 62 | 61 |
| 63 void SetAttribute( | 62 void SetAttribute( |
| 64 cryptohome::SerializedInstallAttributes* install_attrs_proto, | 63 cryptohome::SerializedInstallAttributes* install_attrs_proto, |
| 65 const std::string& name, | 64 const std::string& name, |
| 66 const std::string& value) { | 65 const std::string& value) { |
| 67 cryptohome::SerializedInstallAttributes::Attribute* attribute; | 66 cryptohome::SerializedInstallAttributes::Attribute* attribute; |
| 68 attribute = install_attrs_proto->add_attributes(); | 67 attribute = install_attrs_proto->add_attributes(); |
| 69 attribute->set_name(name); | 68 attribute->set_name(name); |
| 70 attribute->set_value(value); | 69 attribute->set_value(value); |
| 71 } | 70 } |
| 72 | 71 |
| 73 base::MessageLoopForUI message_loop_; | 72 base::MessageLoopForUI message_loop_; |
| 74 base::ScopedTempDir temp_dir_; | 73 base::ScopedTempDir temp_dir_; |
| 75 std::unique_ptr<EnterpriseInstallAttributes> install_attributes_; | 74 std::unique_ptr<InstallAttributes> install_attributes_; |
| 76 | 75 |
| 77 EnterpriseInstallAttributes::LockResult LockDeviceAndWaitForResult( | 76 InstallAttributes::LockResult LockDeviceAndWaitForResult( |
| 78 const std::string& user, | 77 const std::string& user, |
| 79 DeviceMode device_mode, | 78 policy::DeviceMode device_mode, |
| 80 const std::string& device_id) { | 79 const std::string& device_id) { |
| 81 base::RunLoop loop; | 80 base::RunLoop loop; |
| 82 EnterpriseInstallAttributes::LockResult result; | 81 InstallAttributes::LockResult result; |
| 83 install_attributes_->LockDevice( | 82 install_attributes_->LockDevice( |
| 84 user, | 83 user, |
| 85 device_mode, | 84 device_mode, |
| 86 device_id, | 85 device_id, |
| 87 base::Bind(&CopyLockResult, &loop, &result)); | 86 base::Bind(&CopyLockResult, &loop, &result)); |
| 88 loop.Run(); | 87 loop.Run(); |
| 89 return result; | 88 return result; |
| 90 } | 89 } |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 TEST_F(EnterpriseInstallAttributesTest, Lock) { | 92 TEST_F(InstallAttributesTest, Lock) { |
| 94 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 93 EXPECT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 95 LockDeviceAndWaitForResult(kTestUser, DEVICE_MODE_ENTERPRISE, | 94 LockDeviceAndWaitForResult(kTestUser, |
| 95 policy::DEVICE_MODE_ENTERPRISE, |
| 96 kTestDeviceId)); | 96 kTestDeviceId)); |
| 97 | 97 |
| 98 // Locking an already locked device should succeed if the parameters match. | 98 // Locking an already locked device should succeed if the parameters match. |
| 99 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 99 EXPECT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 100 LockDeviceAndWaitForResult(kTestUser, DEVICE_MODE_ENTERPRISE, | 100 LockDeviceAndWaitForResult(kTestUser, |
| 101 policy::DEVICE_MODE_ENTERPRISE, |
| 101 kTestDeviceId)); | 102 kTestDeviceId)); |
| 102 | 103 |
| 103 // Another user from the same domain should also succeed. | 104 // Another user from the same domain should also succeed. |
| 104 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 105 EXPECT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 105 LockDeviceAndWaitForResult("test1@example.com", | 106 LockDeviceAndWaitForResult("test1@example.com", |
| 106 DEVICE_MODE_ENTERPRISE, kTestDeviceId)); | 107 policy::DEVICE_MODE_ENTERPRISE, |
| 108 kTestDeviceId)); |
| 107 | 109 |
| 108 // But another domain should fail. | 110 // But another domain should fail. |
| 109 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_DOMAIN, | 111 EXPECT_EQ(InstallAttributes::LOCK_WRONG_DOMAIN, |
| 110 LockDeviceAndWaitForResult("test@bluebears.com", | 112 LockDeviceAndWaitForResult("test@bluebears.com", |
| 111 DEVICE_MODE_ENTERPRISE, kTestDeviceId)); | 113 policy::DEVICE_MODE_ENTERPRISE, |
| 114 kTestDeviceId)); |
| 112 | 115 |
| 113 // A non-matching mode should fail as well. | 116 // A non-matching mode should fail as well. |
| 114 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_MODE, | 117 EXPECT_EQ(InstallAttributes::LOCK_WRONG_MODE, |
| 115 LockDeviceAndWaitForResult(kTestUser, DEVICE_MODE_CONSUMER, | 118 LockDeviceAndWaitForResult(kTestUser, policy::DEVICE_MODE_CONSUMER, |
| 116 kTestDeviceId)); | 119 kTestDeviceId)); |
| 117 } | 120 } |
| 118 | 121 |
| 119 TEST_F(EnterpriseInstallAttributesTest, LockCanonicalize) { | 122 TEST_F(InstallAttributesTest, LockCanonicalize) { |
| 120 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 123 EXPECT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 121 LockDeviceAndWaitForResult( | 124 LockDeviceAndWaitForResult( |
| 122 kTestUserCanonicalize, | 125 kTestUserCanonicalize, |
| 123 DEVICE_MODE_ENTERPRISE, | 126 policy::DEVICE_MODE_ENTERPRISE, |
| 124 kTestDeviceId)); | 127 kTestDeviceId)); |
| 125 EXPECT_EQ(gaia::CanonicalizeEmail(kTestUserCanonicalize), | 128 EXPECT_EQ(gaia::CanonicalizeEmail(kTestUserCanonicalize), |
| 126 install_attributes_->GetRegistrationUser()); | 129 install_attributes_->GetRegistrationUser()); |
| 127 } | 130 } |
| 128 | 131 |
| 129 TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) { | 132 TEST_F(InstallAttributesTest, IsEnterpriseDevice) { |
| 130 install_attributes_->Init(GetTempPath()); | 133 install_attributes_->Init(GetTempPath()); |
| 131 EXPECT_FALSE(install_attributes_->IsEnterpriseDevice()); | 134 EXPECT_FALSE(install_attributes_->IsEnterpriseDevice()); |
| 132 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 135 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 133 LockDeviceAndWaitForResult( | 136 LockDeviceAndWaitForResult( |
| 134 kTestUser, | 137 kTestUser, |
| 135 DEVICE_MODE_ENTERPRISE, | 138 policy::DEVICE_MODE_ENTERPRISE, |
| 136 kTestDeviceId)); | 139 kTestDeviceId)); |
| 137 EXPECT_TRUE(install_attributes_->IsEnterpriseDevice()); | 140 EXPECT_TRUE(install_attributes_->IsEnterpriseDevice()); |
| 138 } | 141 } |
| 139 | 142 |
| 140 TEST_F(EnterpriseInstallAttributesTest, GetDomain) { | 143 TEST_F(InstallAttributesTest, GetDomain) { |
| 141 install_attributes_->Init(GetTempPath()); | 144 install_attributes_->Init(GetTempPath()); |
| 142 EXPECT_EQ(std::string(), install_attributes_->GetDomain()); | 145 EXPECT_EQ(std::string(), install_attributes_->GetDomain()); |
| 143 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 146 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 144 LockDeviceAndWaitForResult( | 147 LockDeviceAndWaitForResult( |
| 145 kTestUser, | 148 kTestUser, |
| 146 DEVICE_MODE_ENTERPRISE, | 149 policy::DEVICE_MODE_ENTERPRISE, |
| 147 kTestDeviceId)); | 150 kTestDeviceId)); |
| 148 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); | 151 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); |
| 149 } | 152 } |
| 150 | 153 |
| 151 TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) { | 154 TEST_F(InstallAttributesTest, GetRegistrationUser) { |
| 152 install_attributes_->Init(GetTempPath()); | 155 install_attributes_->Init(GetTempPath()); |
| 153 EXPECT_EQ(std::string(), install_attributes_->GetRegistrationUser()); | 156 EXPECT_EQ(std::string(), install_attributes_->GetRegistrationUser()); |
| 154 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 157 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 155 LockDeviceAndWaitForResult( | 158 LockDeviceAndWaitForResult( |
| 156 kTestUser, | 159 kTestUser, |
| 157 DEVICE_MODE_ENTERPRISE, | 160 policy::DEVICE_MODE_ENTERPRISE, |
| 158 kTestDeviceId)); | 161 kTestDeviceId)); |
| 159 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); | 162 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); |
| 160 } | 163 } |
| 161 | 164 |
| 162 TEST_F(EnterpriseInstallAttributesTest, GetDeviceId) { | 165 TEST_F(InstallAttributesTest, GetDeviceId) { |
| 163 install_attributes_->Init(GetTempPath()); | 166 install_attributes_->Init(GetTempPath()); |
| 164 EXPECT_EQ(std::string(), install_attributes_->GetDeviceId()); | 167 EXPECT_EQ(std::string(), install_attributes_->GetDeviceId()); |
| 165 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 168 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 166 LockDeviceAndWaitForResult( | 169 LockDeviceAndWaitForResult( |
| 167 kTestUser, | 170 kTestUser, |
| 168 DEVICE_MODE_ENTERPRISE, | 171 policy::DEVICE_MODE_ENTERPRISE, |
| 169 kTestDeviceId)); | 172 kTestDeviceId)); |
| 170 EXPECT_EQ(kTestDeviceId, install_attributes_->GetDeviceId()); | 173 EXPECT_EQ(kTestDeviceId, install_attributes_->GetDeviceId()); |
| 171 } | 174 } |
| 172 | 175 |
| 173 TEST_F(EnterpriseInstallAttributesTest, GetMode) { | 176 TEST_F(InstallAttributesTest, GetMode) { |
| 174 install_attributes_->Init(GetTempPath()); | 177 install_attributes_->Init(GetTempPath()); |
| 175 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode()); | 178 EXPECT_EQ(policy::DEVICE_MODE_PENDING, install_attributes_->GetMode()); |
| 176 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 179 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 177 LockDeviceAndWaitForResult(kTestUser, DEVICE_MODE_ENTERPRISE, | 180 LockDeviceAndWaitForResult(kTestUser, |
| 181 policy::DEVICE_MODE_ENTERPRISE, |
| 178 kTestDeviceId)); | 182 kTestDeviceId)); |
| 179 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 183 EXPECT_EQ(policy::DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
| 180 } | 184 } |
| 181 | 185 |
| 182 TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) { | 186 TEST_F(InstallAttributesTest, ConsumerDevice) { |
| 183 install_attributes_->Init(GetTempPath()); | 187 install_attributes_->Init(GetTempPath()); |
| 184 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode()); | 188 EXPECT_EQ(policy::DEVICE_MODE_PENDING, install_attributes_->GetMode()); |
| 185 // Lock the attributes empty. | 189 // Lock the attributes empty. |
| 186 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); | 190 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); |
| 187 base::RunLoop loop; | 191 base::RunLoop loop; |
| 188 install_attributes_->ReadImmutableAttributes(loop.QuitClosure()); | 192 install_attributes_->ReadImmutableAttributes(loop.QuitClosure()); |
| 189 loop.Run(); | 193 loop.Run(); |
| 190 | 194 |
| 191 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); | 195 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); |
| 192 EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_->GetMode()); | 196 EXPECT_EQ(policy::DEVICE_MODE_CONSUMER, install_attributes_->GetMode()); |
| 193 } | 197 } |
| 194 | 198 |
| 195 TEST_F(EnterpriseInstallAttributesTest, ConsumerKioskDevice) { | 199 TEST_F(InstallAttributesTest, ConsumerKioskDevice) { |
| 196 install_attributes_->Init(GetTempPath()); | 200 install_attributes_->Init(GetTempPath()); |
| 197 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode()); | 201 EXPECT_EQ(policy::DEVICE_MODE_PENDING, install_attributes_->GetMode()); |
| 198 // Lock the attributes for consumer kiosk. | 202 // Lock the attributes for consumer kiosk. |
| 199 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 203 ASSERT_EQ(InstallAttributes::LOCK_SUCCESS, |
| 200 LockDeviceAndWaitForResult( | 204 LockDeviceAndWaitForResult( |
| 201 std::string(), | 205 std::string(), |
| 202 DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, | 206 policy::DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, |
| 203 std::string())); | 207 std::string())); |
| 204 | 208 |
| 205 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); | 209 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); |
| 206 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, | 210 EXPECT_EQ(policy::DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, |
| 207 install_attributes_->GetMode()); | 211 install_attributes_->GetMode()); |
| 208 ASSERT_TRUE(install_attributes_->IsConsumerKioskDeviceWithAutoLaunch()); | 212 ASSERT_TRUE(install_attributes_->IsConsumerKioskDeviceWithAutoLaunch()); |
| 209 } | 213 } |
| 210 | 214 |
| 211 TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) { | 215 TEST_F(InstallAttributesTest, DeviceLockedFromOlderVersion) { |
| 212 install_attributes_->Init(GetTempPath()); | 216 install_attributes_->Init(GetTempPath()); |
| 213 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_->GetMode()); | 217 EXPECT_EQ(policy::DEVICE_MODE_PENDING, install_attributes_->GetMode()); |
| 214 // Lock the attributes as if it was done from older Chrome version. | 218 // Lock the attributes as if it was done from older Chrome version. |
| 215 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( | 219 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( |
| 216 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true")); | 220 InstallAttributes::kAttrEnterpriseOwned, "true")); |
| 217 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( | 221 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( |
| 218 EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser)); | 222 InstallAttributes::kAttrEnterpriseUser, kTestUser)); |
| 219 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); | 223 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); |
| 220 base::RunLoop loop; | 224 base::RunLoop loop; |
| 221 install_attributes_->ReadImmutableAttributes(loop.QuitClosure()); | 225 install_attributes_->ReadImmutableAttributes(loop.QuitClosure()); |
| 222 loop.Run(); | 226 loop.Run(); |
| 223 | 227 |
| 224 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); | 228 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall()); |
| 225 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 229 EXPECT_EQ(policy::DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
| 226 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); | 230 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); |
| 227 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); | 231 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); |
| 228 EXPECT_EQ("", install_attributes_->GetDeviceId()); | 232 EXPECT_EQ("", install_attributes_->GetDeviceId()); |
| 229 } | 233 } |
| 230 | 234 |
| 231 TEST_F(EnterpriseInstallAttributesTest, Init) { | 235 TEST_F(InstallAttributesTest, Init) { |
| 232 cryptohome::SerializedInstallAttributes install_attrs_proto; | 236 cryptohome::SerializedInstallAttributes install_attrs_proto; |
| 233 SetAttribute(&install_attrs_proto, | 237 SetAttribute(&install_attrs_proto, |
| 234 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"); | 238 InstallAttributes::kAttrEnterpriseOwned, "true"); |
| 235 SetAttribute(&install_attrs_proto, | 239 SetAttribute(&install_attrs_proto, |
| 236 EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser); | 240 InstallAttributes::kAttrEnterpriseUser, kTestUser); |
| 237 const std::string blob(install_attrs_proto.SerializeAsString()); | 241 const std::string blob(install_attrs_proto.SerializeAsString()); |
| 238 ASSERT_EQ(static_cast<int>(blob.size()), | 242 ASSERT_EQ(static_cast<int>(blob.size()), |
| 239 base::WriteFile(GetTempPath(), blob.c_str(), blob.size())); | 243 base::WriteFile(GetTempPath(), blob.c_str(), blob.size())); |
| 240 install_attributes_->Init(GetTempPath()); | 244 install_attributes_->Init(GetTempPath()); |
| 241 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); | 245 EXPECT_EQ(policy::DEVICE_MODE_ENTERPRISE, install_attributes_->GetMode()); |
| 242 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); | 246 EXPECT_EQ(kTestDomain, install_attributes_->GetDomain()); |
| 243 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); | 247 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); |
| 244 EXPECT_EQ("", install_attributes_->GetDeviceId()); | 248 EXPECT_EQ("", install_attributes_->GetDeviceId()); |
| 245 } | 249 } |
| 246 | 250 |
| 247 TEST_F(EnterpriseInstallAttributesTest, InitForConsumerKiosk) { | 251 TEST_F(InstallAttributesTest, InitForConsumerKiosk) { |
| 248 cryptohome::SerializedInstallAttributes install_attrs_proto; | 252 cryptohome::SerializedInstallAttributes install_attrs_proto; |
| 249 SetAttribute(&install_attrs_proto, | 253 SetAttribute(&install_attrs_proto, |
| 250 EnterpriseInstallAttributes::kAttrConsumerKioskEnabled, "true"); | 254 InstallAttributes::kAttrConsumerKioskEnabled, "true"); |
| 251 const std::string blob(install_attrs_proto.SerializeAsString()); | 255 const std::string blob(install_attrs_proto.SerializeAsString()); |
| 252 ASSERT_EQ(static_cast<int>(blob.size()), | 256 ASSERT_EQ(static_cast<int>(blob.size()), |
| 253 base::WriteFile(GetTempPath(), blob.c_str(), blob.size())); | 257 base::WriteFile(GetTempPath(), blob.c_str(), blob.size())); |
| 254 install_attributes_->Init(GetTempPath()); | 258 install_attributes_->Init(GetTempPath()); |
| 255 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, | 259 EXPECT_EQ(policy::DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH, |
| 256 install_attributes_->GetMode()); | 260 install_attributes_->GetMode()); |
| 257 EXPECT_EQ("", install_attributes_->GetDomain()); | 261 EXPECT_EQ("", install_attributes_->GetDomain()); |
| 258 EXPECT_EQ("", install_attributes_->GetRegistrationUser()); | 262 EXPECT_EQ("", install_attributes_->GetRegistrationUser()); |
| 259 EXPECT_EQ("", install_attributes_->GetDeviceId()); | 263 EXPECT_EQ("", install_attributes_->GetDeviceId()); |
| 260 } | 264 } |
| 261 | 265 |
| 262 TEST_F(EnterpriseInstallAttributesTest, VerifyFakeInstallAttributesCache) { | 266 TEST_F(InstallAttributesTest, VerifyFakeInstallAttributesCache) { |
| 263 // This test verifies that FakeCryptohomeClient::InstallAttributesFinalize | 267 // This test verifies that FakeCryptohomeClient::InstallAttributesFinalize |
| 264 // writes a cache that EnterpriseInstallAttributes::Init accepts. | 268 // writes a cache that InstallAttributes::Init accepts. |
| 265 | 269 |
| 266 // Verify that no attributes are initially set. | 270 // Verify that no attributes are initially set. |
| 267 install_attributes_->Init(GetTempPath()); | 271 install_attributes_->Init(GetTempPath()); |
| 268 EXPECT_EQ("", install_attributes_->GetRegistrationUser()); | 272 EXPECT_EQ("", install_attributes_->GetRegistrationUser()); |
| 269 | 273 |
| 270 // Write test values. | 274 // Write test values. |
| 271 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( | 275 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( |
| 272 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true")); | 276 InstallAttributes::kAttrEnterpriseOwned, "true")); |
| 273 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( | 277 ASSERT_TRUE(cryptohome_util::InstallAttributesSet( |
| 274 EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser)); | 278 InstallAttributes::kAttrEnterpriseUser, kTestUser)); |
| 275 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); | 279 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize()); |
| 276 | 280 |
| 277 // Verify that EnterpriseInstallAttributes correctly decodes the stub | 281 // Verify that InstallAttributes correctly decodes the stub cache file. |
| 278 // cache file. | |
| 279 install_attributes_->Init(GetTempPath()); | 282 install_attributes_->Init(GetTempPath()); |
| 280 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); | 283 EXPECT_EQ(kTestUser, install_attributes_->GetRegistrationUser()); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace policy | 286 } // namespace chromeos |
| OLD | NEW |