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

Side by Side Diff: chrome/test/functional/chromeos_ephemeral.py

Issue 10832046: [chromeos] Simplify ephemeral users tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import logging 5 import logging
6 import os 6 import os
7 import sys 7 import sys
8 8
9 import pyauto_functional # Must come before pyauto (and thus, policy_base). 9 import pyauto_functional # Must come before pyauto (and thus, policy_base).
10 import policy_base 10 import policy_base
11 11
12 sys.path.append('/usr/local') # Required to import autotest libs. 12 sys.path.append('/usr/local') # Required to import autotest libs.
13 from autotest.cros import constants 13 from autotest.cros import constants
14 from autotest.cros import cryptohome 14 from autotest.cros import cryptohome
15 15
16 16
17 class ChromeosEphemeral(policy_base.PolicyTestBase): 17 class ChromeosEphemeral(policy_base.PolicyTestBase):
18 """Tests a policy that makes users ephemeral. 18 """Tests a policy that makes users ephemeral.
19 19
20 When this policy is enabled, no persistent information in the form of 20 When this policy is enabled, no persistent information in the form of
21 cryptohome shadow directories or local state prefs should be created for 21 cryptohome shadow directories or local state prefs should be created for
22 users. Additionally, any persistent information previously accumulated should 22 users. Additionally, any persistent information previously accumulated should
23 be cleared when a user first logs in after enabling the policy.""" 23 be cleared when a user first logs in after enabling the policy."""
24 24
25 _usernames = ('alice@example.com', 'bob@example.com')
26
25 def _SetEphemeralUsersEnabled(self, enabled): 27 def _SetEphemeralUsersEnabled(self, enabled):
26 """Sets the ephemeral users device policy. 28 """Sets the ephemeral users device policy.
27 29
28 TODO(bartfab): Ensure Login still works after crosbug.com/20709 is fixed.
29 The show_user_names policy is set to False to ensure that even if the local 30 The show_user_names policy is set to False to ensure that even if the local
30 state is not being automatically cleared, the login screen never shows user 31 state is not being automatically cleared, the login screen never shows user
31 pods. This is required by the Login browser automation call. 32 pods. This is required by the Login browser automation call.
32 """ 33 """
33 self.SetDevicePolicy({'ephemeral_users_enabled': enabled, 34 self.SetDevicePolicy({'ephemeral_users_enabled': enabled,
34 'show_user_names': False}) 35 'show_user_names': False})
35 36
36 def _DoesVaultDirectoryExist(self, user_index): 37 def _DoesVaultDirectoryExist(self, user_index):
37 user_hash = cryptohome.get_user_hash(self._usernames[user_index]) 38 user_hash = cryptohome.get_user_hash(self._usernames[user_index])
38 return os.path.exists(os.path.join(constants.SHADOW_ROOT, user_hash)) 39 return os.path.exists(os.path.join(constants.SHADOW_ROOT, user_hash))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 user=self._usernames[user_index], 76 user=self._usernames[user_index],
76 allow_fail=True), 77 allow_fail=True),
77 msg='Expected vault backed by %s to be mounted.' % 78 msg='Expected vault backed by %s to be mounted.' %
78 'tmpfs' if ephemeral else 'shadow directory') 79 'tmpfs' if ephemeral else 'shadow directory')
79 80
80 def _AssertNoVaultMounted(self): 81 def _AssertNoVaultMounted(self):
81 self.assertFalse(cryptohome.is_vault_mounted(allow_fail=True), 82 self.assertFalse(cryptohome.is_vault_mounted(allow_fail=True),
82 msg='Did not expect any vault to be mounted.') 83 msg='Did not expect any vault to be mounted.')
83 84
84 def Login(self, user_index): 85 def Login(self, user_index):
86 """Convenience method to login to the usr at the given index."""
85 self.assertFalse(self.GetLoginInfo()['is_logged_in'], 87 self.assertFalse(self.GetLoginInfo()['is_logged_in'],
86 msg='Expected to be logged out.') 88 msg='Expected to be logged out.')
87 policy_base.PolicyTestBase.Login(self, 89 policy_base.PolicyTestBase.Login(self,
88 self._usernames[user_index], 90 self._usernames[user_index],
89 'dummy_password') 91 'dummy_password')
90 self.assertTrue(self.GetLoginInfo()['is_logged_in'], 92 self.assertTrue(self.GetLoginInfo()['is_logged_in'],
91 msg='Expected to be logged in.') 93 msg='Expected to be logged in.')
92 94
93 def ExtraChromeFlags(self):
94 """Sets up Chrome to skip OOBE.
95
96 TODO(bartfab): Ensure OOBE is still skipped when crosbug.com/20709 is fixed.
97 Disabling automatic clearing of the local state has the curious side effect
98 of removing a flag that disables OOBE. This method adds back the flag.
99 """
100 flags = policy_base.PolicyTestBase.ExtraChromeFlags(self)
101 flags.append('--login-screen=login')
102 return flags
103
104 def setUp(self):
105 policy_base.PolicyTestBase.setUp(self)
106 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
107 # Try to disable automatic clearing of the local state.
108 self.TryToDisableLocalStateAutoClearingOnChromeOS()
109 self._local_state_auto_clearing = \
110 self.IsLocalStateAutoClearingEnabledOnChromeOS()
111 if not self._local_state_auto_clearing:
112 # Prevent the inherited Logout() method from cleaning up /home/chronos
113 # as this also clears the local state.
114 self.set_clear_profile(False)
bartfab (slow) 2012/07/27 08:11:22 Is this no longer needed either with the recent ch
Nirnimesh 2012/07/27 08:24:21 Logout() does not clear user profile (/home/chrono
bartfab (slow) 2012/07/27 08:28:39 There is a set_clear_profile()/get_clear_profile()
115
116 self._usernames = ('alice@example.com', 'bob@example.com')
117
118 def tearDown(self):
119 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
120 # Try to re-enable automatic clearing of the local state and /home/chronos.
121 if not self._local_state_auto_clearing:
122 self.TryToEnableLocalStateAutoClearingOnChromeOS()
123 self.set_clear_profile(True)
124 policy_base.PolicyTestBase.tearDown(self)
125
126 def testEnablingBeforeSession(self): 95 def testEnablingBeforeSession(self):
127 """Checks that a new session can be made ephemeral.""" 96 """Checks that a new session can be made ephemeral."""
128 self.PrepareToWaitForLoginFormReload() 97 self.PrepareToWaitForLoginFormReload()
129 self._SetEphemeralUsersEnabled(True) 98 self._SetEphemeralUsersEnabled(True)
130 self.WaitForLoginFormReload() 99 self.WaitForLoginFormReload()
131 100
132 self.Login(user_index=0) 101 self.Login(user_index=0)
133 self._AssertLocalStatePrefsEmpty() 102 self._AssertLocalStatePrefsEmpty()
134 self._AssertVaultMounted(user_index=0, ephemeral=True) 103 self._AssertVaultMounted(user_index=0, ephemeral=True)
135 self.Logout() 104 self.Logout()
(...skipping 20 matching lines...) Expand all
156 self._AssertNoVaultMounted() 125 self._AssertNoVaultMounted()
157 self._AssertVaultDirectoryDoesNotExist(user_index=0) 126 self._AssertVaultDirectoryDoesNotExist(user_index=0)
158 127
159 def testDisablingDuringSession(self): 128 def testDisablingDuringSession(self):
160 """Checks that an existing ephemeral session is not made non-ephemeral.""" 129 """Checks that an existing ephemeral session is not made non-ephemeral."""
161 self.PrepareToWaitForLoginFormReload() 130 self.PrepareToWaitForLoginFormReload()
162 self._SetEphemeralUsersEnabled(True) 131 self._SetEphemeralUsersEnabled(True)
163 self.WaitForLoginFormReload() 132 self.WaitForLoginFormReload()
164 133
165 self.Login(user_index=0) 134 self.Login(user_index=0)
166 # TODO(bartfab): Remove this when crosbug.com/20709 is fixed.
167 if self._local_state_auto_clearing:
168 self._AssertLocalStatePrefsEmpty()
169 self._AssertVaultMounted(user_index=0, ephemeral=True) 135 self._AssertVaultMounted(user_index=0, ephemeral=True)
170 self._SetEphemeralUsersEnabled(False) 136 self._SetEphemeralUsersEnabled(False)
171 self._AssertVaultMounted(user_index=0, ephemeral=True) 137 self._AssertVaultMounted(user_index=0, ephemeral=True)
172 self.Logout() 138 self.Logout()
173 139
174 # TODO(bartfab): Make this unconditional when crosbug.com/20709 is fixed. 140 self._AssertLocalStatePrefsEmpty()
175 if not self._local_state_auto_clearing:
176 self._AssertLocalStatePrefsEmpty()
177 self._AssertNoVaultMounted() 141 self._AssertNoVaultMounted()
178 self._AssertVaultDirectoryDoesNotExist(user_index=0) 142 self._AssertVaultDirectoryDoesNotExist(user_index=0)
179 143
180 def testEnablingEphemeralUsersCleansUp(self): 144 def testEnablingEphemeralUsersCleansUp(self):
181 """Checks that persistent information is cleared.""" 145 """Checks that persistent information is cleared."""
182 self.PrepareToWaitForLoginFormReload() 146 self.PrepareToWaitForLoginFormReload()
183 self._SetEphemeralUsersEnabled(False) 147 self._SetEphemeralUsersEnabled(False)
184 self.WaitForLoginFormReload() 148 self.WaitForLoginFormReload()
185 149
186 self.Login(user_index=0) 150 self.Login(user_index=0)
187 # TODO(bartfab): Remove this when crosbug.com/20709 is fixed.
188 if self._local_state_auto_clearing:
189 self._AssertLocalStatePrefsSet(user_indexes=[0])
190 self.Logout() 151 self.Logout()
191 # TODO(bartfab): Make this unconditional when crosbug.com/20709 is fixed. 152 self._AssertLocalStatePrefsSet(user_indexes=[0])
192 if not self._local_state_auto_clearing:
193 self._AssertLocalStatePrefsSet(user_indexes=[0])
194 153
195 self.Login(user_index=1) 154 self.Login(user_index=1)
196 # TODO(bartfab): Remove this when crosbug.com/20709 is fixed.
197 if self._local_state_auto_clearing:
198 self._AssertLocalStatePrefsSet(user_indexes=[1])
199 self.Logout() 155 self.Logout()
200 # TODO(bartfab): Make this unconditional when crosbug.com/20709 is fixed. 156 self._AssertLocalStatePrefsSet(user_indexes=[0, 1])
201 if not self._local_state_auto_clearing:
202 self._AssertLocalStatePrefsSet(user_indexes=[0, 1])
203 157
204 self._AssertVaultDirectoryExists(user_index=0) 158 self._AssertVaultDirectoryExists(user_index=0)
205 self._AssertVaultDirectoryExists(user_index=1) 159 self._AssertVaultDirectoryExists(user_index=1)
206 160
207 self._SetEphemeralUsersEnabled(True) 161 self._SetEphemeralUsersEnabled(True)
208 162
209 self.Login(user_index=0) 163 self.Login(user_index=0)
210 # TODO(bartfab): Remove this when crosbug.com/20709 is fixed.
211 if self._local_state_auto_clearing:
212 self._AssertLocalStatePrefsEmpty()
213 self._AssertVaultMounted(user_index=0, ephemeral=True) 164 self._AssertVaultMounted(user_index=0, ephemeral=True)
214 self.Logout() 165 self.Logout()
215 166
216 self._AssertVaultDirectoryDoesNotExist(user_index=0) 167 self._AssertVaultDirectoryDoesNotExist(user_index=0)
217 self._AssertVaultDirectoryDoesNotExist(user_index=1) 168 self._AssertVaultDirectoryDoesNotExist(user_index=1)
218 169
219 170
220 if __name__ == '__main__': 171 if __name__ == '__main__':
221 pyauto_functional.Main() 172 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698