Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/policy/enterprise_install_attributes.h" | 5 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace em = enterprise_management; | |
| 11 | |
| 10 namespace policy { | 12 namespace policy { |
| 11 | 13 |
| 12 static const char kTestUser[] = "test@example.com"; | 14 static const char kTestUser[] = "test@example.com"; |
| 15 static const char kTestDomain[] = "example.com"; | |
| 16 static const char kTestDeviceId[] = "133750519"; | |
| 17 | |
| 18 static const char kAttrEnterpriseOwned[] = "enterprise.owned"; | |
| 19 static const char kAttrEnterpriseUser[] = "enterprise.user"; | |
| 13 | 20 |
| 14 class EnterpriseInstallAttributesTest : public testing::Test { | 21 class EnterpriseInstallAttributesTest : public testing::Test { |
| 15 protected: | 22 protected: |
| 16 EnterpriseInstallAttributesTest() | 23 EnterpriseInstallAttributesTest() |
| 17 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), | 24 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), |
| 18 install_attributes_(cryptohome_.get()) {} | 25 install_attributes_(cryptohome_.get()) {} |
| 19 | 26 |
| 20 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; | 27 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; |
| 21 EnterpriseInstallAttributes install_attributes_; | 28 EnterpriseInstallAttributes install_attributes_; |
| 22 }; | 29 }; |
| 23 | 30 |
| 24 TEST_F(EnterpriseInstallAttributesTest, Lock) { | 31 TEST_F(EnterpriseInstallAttributesTest, Lock) { |
| 25 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 32 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 26 install_attributes_.LockDevice(kTestUser)); | 33 install_attributes_.LockDevice( |
| 34 kTestUser, | |
| 35 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 36 kTestDeviceId)); | |
| 27 | 37 |
| 28 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 38 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 29 install_attributes_.LockDevice(kTestUser)); | 39 install_attributes_.LockDevice( |
| 40 kTestUser, | |
| 41 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 42 kTestDeviceId)); | |
| 30 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_USER, | 43 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_USER, |
| 31 install_attributes_.LockDevice("test1@example.com")); | 44 install_attributes_.LockDevice( |
| 45 "test1@example.com", | |
| 46 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 47 kTestDeviceId)); | |
| 32 } | 48 } |
| 33 | 49 |
| 34 TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) { | 50 TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) { |
| 35 EXPECT_FALSE(install_attributes_.IsEnterpriseDevice()); | 51 EXPECT_FALSE(install_attributes_.IsEnterpriseDevice()); |
| 36 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 52 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 37 install_attributes_.LockDevice(kTestUser)); | 53 install_attributes_.LockDevice( |
| 54 kTestUser, | |
| 55 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 56 kTestDeviceId)); | |
| 38 EXPECT_TRUE(install_attributes_.IsEnterpriseDevice()); | 57 EXPECT_TRUE(install_attributes_.IsEnterpriseDevice()); |
| 39 } | 58 } |
| 40 | 59 |
| 41 TEST_F(EnterpriseInstallAttributesTest, GetDomain) { | 60 TEST_F(EnterpriseInstallAttributesTest, GetDomain) { |
| 42 EXPECT_EQ(std::string(), install_attributes_.GetDomain()); | 61 EXPECT_EQ(std::string(), install_attributes_.GetDomain()); |
| 43 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 62 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 44 install_attributes_.LockDevice(kTestUser)); | 63 install_attributes_.LockDevice( |
| 45 EXPECT_EQ("example.com", install_attributes_.GetDomain()); | 64 kTestUser, |
| 65 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 66 kTestDeviceId)); | |
| 67 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain()); | |
| 46 } | 68 } |
| 47 | 69 |
| 48 TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) { | 70 TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) { |
| 49 EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser()); | 71 EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser()); |
| 50 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 72 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 51 install_attributes_.LockDevice(kTestUser)); | 73 install_attributes_.LockDevice( |
| 74 kTestUser, | |
| 75 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 76 kTestDeviceId)); | |
| 52 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser()); | 77 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser()); |
| 53 } | 78 } |
| 54 | 79 |
| 80 TEST_F(EnterpriseInstallAttributesTest, GetDeviceId) { | |
| 81 EXPECT_EQ(std::string(), install_attributes_.GetDeviceId()); | |
| 82 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | |
| 83 install_attributes_.LockDevice( | |
| 84 kTestUser, | |
| 85 EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 86 kTestDeviceId)); | |
| 87 EXPECT_EQ(kTestDeviceId, install_attributes_.GetDeviceId()); | |
| 88 } | |
| 89 | |
| 90 TEST_F(EnterpriseInstallAttributesTest, GetMode) { | |
| 91 EXPECT_EQ(EnterpriseInstallAttributes::UNKNOWN_DEVICE, | |
| 92 install_attributes_.GetMode()); | |
| 93 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | |
| 94 install_attributes_.LockDevice( | |
| 95 kTestUser, | |
| 96 EnterpriseInstallAttributes::KIOSK_DEVICE, | |
| 97 kTestDeviceId)); | |
| 98 EXPECT_EQ(EnterpriseInstallAttributes::KIOSK_DEVICE, | |
| 99 install_attributes_.GetMode()); | |
| 100 } | |
| 101 | |
| 102 TEST_F(EnterpriseInstallAttributesTest, EndUserDevice) { | |
|
Mattias Nissler (ping if slow)
2012/02/16 10:36:27
consumer
pastarmovj
2012/02/17 13:59:47
Done.
| |
| 103 EXPECT_EQ(EnterpriseInstallAttributes::UNKNOWN_DEVICE, | |
| 104 install_attributes_.GetMode()); | |
| 105 // Lock the attributes empty. | |
| 106 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize()); | |
| 107 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall()); | |
| 108 EXPECT_EQ(EnterpriseInstallAttributes::END_USER_DEVICE, | |
| 109 install_attributes_.GetMode()); | |
| 110 } | |
| 111 | |
| 112 TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) { | |
| 113 EXPECT_EQ(EnterpriseInstallAttributes::UNKNOWN_DEVICE, | |
| 114 install_attributes_.GetMode()); | |
| 115 // Lock the attributes as if it was done from older Chrome version. | |
| 116 ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true")); | |
| 117 ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, | |
| 118 kTestUser)); | |
| 119 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize()); | |
| 120 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall()); | |
| 121 EXPECT_EQ(EnterpriseInstallAttributes::ENTERPRISE_DEVICE, | |
| 122 install_attributes_.GetMode()); | |
| 123 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain()); | |
| 124 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser()); | |
| 125 EXPECT_EQ("", install_attributes_.GetDeviceId()); | |
| 126 } | |
| 127 | |
| 55 } // namespace policy | 128 } // namespace policy |
| OLD | NEW |