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