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

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

Issue 24869003: cryptohome: Move stateless wrapper functions out of CryptohomeLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h" 12 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h"
13 #include "chromeos/cryptohome/cryptohome_library.h" 13 #include "chromeos/cryptohome/cryptohome_library.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_cryptohome_client.h" 15 #include "chromeos/dbus/fake_cryptohome_client.h"
15 #include "google_apis/gaia/gaia_auth_util.h" 16 #include "google_apis/gaia/gaia_auth_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace policy { 19 namespace policy {
19 20
21 namespace cryptohome_util = chromeos::cryptohome_util;
22
20 namespace { 23 namespace {
21 24
22 void CopyLockResult(base::RunLoop* loop, 25 void CopyLockResult(base::RunLoop* loop,
23 EnterpriseInstallAttributes::LockResult* out, 26 EnterpriseInstallAttributes::LockResult* out,
24 EnterpriseInstallAttributes::LockResult result) { 27 EnterpriseInstallAttributes::LockResult result) {
25 *out = result; 28 *out = result;
26 loop->Quit(); 29 loop->Quit();
27 } 30 }
28 31
29 } // namespace 32 } // namespace
30 33
31 static const char kTestUser[] = "test@example.com"; 34 static const char kTestUser[] = "test@example.com";
32 static const char kTestUserCanonicalize[] = "UPPER.CASE@example.com"; 35 static const char kTestUserCanonicalize[] = "UPPER.CASE@example.com";
33 static const char kTestDomain[] = "example.com"; 36 static const char kTestDomain[] = "example.com";
34 static const char kTestDeviceId[] = "133750519"; 37 static const char kTestDeviceId[] = "133750519";
35 38
36 class EnterpriseInstallAttributesTest : public testing::Test { 39 class EnterpriseInstallAttributesTest : public testing::Test {
37 protected: 40 protected:
38 EnterpriseInstallAttributesTest() 41 EnterpriseInstallAttributesTest()
39 : cryptohome_(chromeos::CryptohomeLibrary::GetTestImpl()), 42 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
40 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), 43 install_attributes_(fake_cryptohome_client_.get()) {
41 install_attributes_(cryptohome_.get(), fake_cryptohome_client_.get()) {
42 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); 44 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
43 } 45 }
44 46
45 virtual void SetUp() OVERRIDE { 47 virtual void SetUp() OVERRIDE {
46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
49 chromeos::DBusThreadManager::InitializeWithStub();
50 }
51
52 virtual void TearDown() OVERRIDE {
53 chromeos::DBusThreadManager::Shutdown();
47 } 54 }
48 55
49 base::FilePath GetTempPath() const { 56 base::FilePath GetTempPath() const {
50 return temp_dir_.path().Append("install_attrs_test"); 57 return temp_dir_.path().Append("install_attrs_test");
51 } 58 }
52 59
53 void SetAttribute( 60 void SetAttribute(
54 cryptohome::SerializedInstallAttributes* install_attrs_proto, 61 cryptohome::SerializedInstallAttributes* install_attrs_proto,
55 const std::string& name, 62 const std::string& name,
56 const std::string& value) { 63 const std::string& value) {
57 cryptohome::SerializedInstallAttributes::Attribute* attribute; 64 cryptohome::SerializedInstallAttributes::Attribute* attribute;
58 attribute = install_attrs_proto->add_attributes(); 65 attribute = install_attrs_proto->add_attributes();
59 attribute->set_name(name); 66 attribute->set_name(name);
60 attribute->set_value(value); 67 attribute->set_value(value);
61 } 68 }
62 69
63 base::MessageLoopForUI message_loop_; 70 base::MessageLoopForUI message_loop_;
64 base::ScopedTempDir temp_dir_; 71 base::ScopedTempDir temp_dir_;
65 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
66 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; 72 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
67 EnterpriseInstallAttributes install_attributes_; 73 EnterpriseInstallAttributes install_attributes_;
68 74
69 EnterpriseInstallAttributes::LockResult LockDeviceAndWaitForResult( 75 EnterpriseInstallAttributes::LockResult LockDeviceAndWaitForResult(
70 const std::string& user, 76 const std::string& user,
71 DeviceMode device_mode, 77 DeviceMode device_mode,
72 const std::string& device_id) { 78 const std::string& device_id) {
73 base::RunLoop loop; 79 base::RunLoop loop;
74 EnterpriseInstallAttributes::LockResult result; 80 EnterpriseInstallAttributes::LockResult result;
75 install_attributes_.LockDevice(user, device_mode, device_id, 81 install_attributes_.LockDevice(user, device_mode, device_id,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 DEVICE_MODE_RETAIL_KIOSK, 174 DEVICE_MODE_RETAIL_KIOSK,
169 kTestDeviceId)); 175 kTestDeviceId));
170 EXPECT_EQ(DEVICE_MODE_RETAIL_KIOSK, 176 EXPECT_EQ(DEVICE_MODE_RETAIL_KIOSK,
171 install_attributes_.GetMode()); 177 install_attributes_.GetMode());
172 } 178 }
173 179
174 TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) { 180 TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) {
175 install_attributes_.ReadCacheFile(GetTempPath()); 181 install_attributes_.ReadCacheFile(GetTempPath());
176 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode()); 182 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
177 // Lock the attributes empty. 183 // Lock the attributes empty.
178 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize()); 184 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
179 base::RunLoop loop; 185 base::RunLoop loop;
180 install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure())); 186 install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
181 loop.Run(); 187 loop.Run();
182 188
183 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall()); 189 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
184 EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_.GetMode()); 190 EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_.GetMode());
185 } 191 }
186 192
187 TEST_F(EnterpriseInstallAttributesTest, ConsumerKioskDevice) { 193 TEST_F(EnterpriseInstallAttributesTest, ConsumerKioskDevice) {
188 install_attributes_.ReadCacheFile(GetTempPath()); 194 install_attributes_.ReadCacheFile(GetTempPath());
189 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode()); 195 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
190 // Lock the attributes for consumer kiosk. 196 // Lock the attributes for consumer kiosk.
191 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 197 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
192 LockDeviceAndWaitForResult( 198 LockDeviceAndWaitForResult(
193 std::string(), 199 std::string(),
194 DEVICE_MODE_CONSUMER_KIOSK, 200 DEVICE_MODE_CONSUMER_KIOSK,
195 std::string())); 201 std::string()));
196 202
197 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall()); 203 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
198 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK, install_attributes_.GetMode()); 204 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK, install_attributes_.GetMode());
199 ASSERT_TRUE(install_attributes_.IsConsumerKioskDevice()); 205 ASSERT_TRUE(install_attributes_.IsConsumerKioskDevice());
200 } 206 }
201 207
202 TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) { 208 TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) {
203 install_attributes_.ReadCacheFile(GetTempPath()); 209 install_attributes_.ReadCacheFile(GetTempPath());
204 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode()); 210 EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
205 // Lock the attributes as if it was done from older Chrome version. 211 // Lock the attributes as if it was done from older Chrome version.
206 ASSERT_TRUE(cryptohome_->InstallAttributesSet( 212 ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
207 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true")); 213 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"));
208 ASSERT_TRUE(cryptohome_->InstallAttributesSet( 214 ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
209 EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser)); 215 EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser));
210 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize()); 216 ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
211 base::RunLoop loop; 217 base::RunLoop loop;
212 install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure())); 218 install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
213 loop.Run(); 219 loop.Run();
214 220
215 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall()); 221 ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
216 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_.GetMode()); 222 EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_.GetMode());
217 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain()); 223 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
218 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser()); 224 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
219 EXPECT_EQ("", install_attributes_.GetDeviceId()); 225 EXPECT_EQ("", install_attributes_.GetDeviceId());
220 } 226 }
221 227
222 TEST_F(EnterpriseInstallAttributesTest, ReadCacheFile) { 228 TEST_F(EnterpriseInstallAttributesTest, ReadCacheFile) {
223 cryptohome::SerializedInstallAttributes install_attrs_proto; 229 cryptohome::SerializedInstallAttributes install_attrs_proto;
224 SetAttribute(&install_attrs_proto, 230 SetAttribute(&install_attrs_proto,
225 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"); 231 EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true");
(...skipping 17 matching lines...) Expand all
243 ASSERT_EQ(static_cast<int>(blob.size()), 249 ASSERT_EQ(static_cast<int>(blob.size()),
244 file_util::WriteFile(GetTempPath(), blob.c_str(), blob.size())); 250 file_util::WriteFile(GetTempPath(), blob.c_str(), blob.size()));
245 install_attributes_.ReadCacheFile(GetTempPath()); 251 install_attributes_.ReadCacheFile(GetTempPath());
246 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK, install_attributes_.GetMode()); 252 EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK, install_attributes_.GetMode());
247 EXPECT_EQ("", install_attributes_.GetDomain()); 253 EXPECT_EQ("", install_attributes_.GetDomain());
248 EXPECT_EQ("", install_attributes_.GetRegistrationUser()); 254 EXPECT_EQ("", install_attributes_.GetRegistrationUser());
249 EXPECT_EQ("", install_attributes_.GetDeviceId()); 255 EXPECT_EQ("", install_attributes_.GetDeviceId());
250 } 256 }
251 257
252 } // namespace policy 258 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698