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