1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/enterprise_install_attributes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace policy {
static const char kTestUser[] = "test@example.com";
static const char kTestDomain[] = "example.com";
static const char kTestDeviceId[] = "133750519";
static const char kAttrEnterpriseOwned[] = "enterprise.owned";
static const char kAttrEnterpriseUser[] = "enterprise.user";
class EnterpriseInstallAttributesTest : public testing::Test {
protected:
EnterpriseInstallAttributesTest()
: cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
install_attributes_(cryptohome_.get()) {}
scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
EnterpriseInstallAttributes install_attributes_;
};
TEST_F(EnterpriseInstallAttributesTest, Lock) {
EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
// Another user from the4 same domain should also succeed.
EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
"test1@example.com",
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
// But another domain should fail.
EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_USER,
install_attributes_.LockDevice(
"test@bluebears.com",
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
}
TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) {
EXPECT_FALSE(install_attributes_.IsEnterpriseDevice());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_TRUE(install_attributes_.IsEnterpriseDevice());
}
TEST_F(EnterpriseInstallAttributesTest, GetDomain) {
EXPECT_EQ(std::string(), install_attributes_.GetDomain());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
}
TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) {
EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
}
TEST_F(EnterpriseInstallAttributesTest, GetDeviceId) {
EXPECT_EQ(std::string(), install_attributes_.GetDeviceId());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_ENTERPRISE,
kTestDeviceId));
EXPECT_EQ(kTestDeviceId, install_attributes_.GetDeviceId());
}
TEST_F(EnterpriseInstallAttributesTest, GetMode) {
EXPECT_EQ(DEVICE_MODE_NOT_SET,
install_attributes_.GetMode());
ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
install_attributes_.LockDevice(
kTestUser,
DEVICE_MODE_KIOSK,
kTestDeviceId));
EXPECT_EQ(DEVICE_MODE_KIOSK,
install_attributes_.GetMode());
}
TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) {
EXPECT_EQ(DEVICE_MODE_NOT_SET,
install_attributes_.GetMode());
// Lock the attributes empty.
ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_CONSUMER,
install_attributes_.GetMode());
}
TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) {
EXPECT_EQ(DEVICE_MODE_NOT_SET,
install_attributes_.GetMode());
// Lock the attributes as if it was done from older Chrome version.
ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true"));
ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseUser,
kTestUser));
ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_ENTERPRISE,
install_attributes_.GetMode());
EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
EXPECT_EQ("", install_attributes_.GetDeviceId());
}
} // namespace policy
|