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