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

Side by Side Diff: client/site_tests/platform_ProcessPrivileges/platform_ProcessPrivileges.py

Issue 1534001: switch to autox.py and robustify login/logout code (Closed)
Patch Set: merge with head Created 10 years, 8 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
« no previous file with comments | « client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py ('k') | 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) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS 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 time 5 import time
6 from autotest_lib.client.bin import site_login, test, utils 6 from autotest_lib.client.bin import site_login, site_ui_test, utils
7 from autotest_lib.client.common_lib import error 7 from autotest_lib.client.common_lib import error
8 8
9 class platform_ProcessPrivileges(test.test): 9 class platform_ProcessPrivileges(site_ui_test.UITest):
10 version = 1 10 version = 1
11 11
12 def setup(self): 12 auto_login = False
13 site_login.setup_autox(self)
14
15 13
16 def run_once(self, process='X', user=None, run_as_root=False, 14 def run_once(self, process='X', user=None, run_as_root=False,
17 do_login=False, any=False): 15 do_login=False, any=False):
18 """Check if the process is running as the specified user / root. 16 """Check if the process is running as the specified user / root.
19 17
20 Args: 18 Args:
21 process: Process name to check. 19 process: Process name to check.
22 user: User process must run as; ignored if None. 20 user: User process must run as; ignored if None.
23 run_as_root: Is process allowed to run as root? 21 run_as_root: Is process allowed to run as root?
24 do_login: login before getting process information? 22 do_login: login before getting process information?
25 any: Test succeeds if any of processes satisfy the conditions. 23 any: Test succeeds if any of processes satisfy the conditions.
26 """ 24 """
27 logged_in = site_login.logged_in() 25 if do_login:
28 26 self.login()
29 if do_login and not logged_in:
30 # Test account information embedded into json file.
31 site_login.attempt_login(self, 'autox_script.json')
32 # Wait for processes for user-session are started. 27 # Wait for processes for user-session are started.
33 time.sleep(10) 28 time.sleep(10)
34 29
35 try: 30 # Get the process information
36 # Get the process information 31 pscmd = 'ps -o f,euser,ruser,suser,fuser,comm -C %s --no-headers'
37 pscmd = 'ps -o f,euser,ruser,suser,fuser,comm -C %s --no-headers' 32 ps = utils.system_output(pscmd % process, retain_output=True)
38 ps = utils.system_output(pscmd % process, retain_output=True)
39 33
40 pslines = ps.splitlines() 34 pslines = ps.splitlines()
41 35
42 # Fail if process is not running 36 # Fail if process is not running
43 if not len(pslines): 37 if not len(pslines):
44 raise error.TestFail('Process %s is not running' % process) 38 raise error.TestFail('Process %s is not running' % process)
45 39
46 # Check all instances of the process 40 # Check all instances of the process
47 for psline in pslines: 41 for psline in pslines:
48 ps = psline.split() 42 ps = psline.split()
49 43
50 # Assume process meets conditions until proven otherwise 44 # Assume process meets conditions until proven otherwise
51 user_satisfied = True 45 user_satisfied = True
52 run_as_root_satisfied = True 46 run_as_root_satisfied = True
53 47
54 # Fail if not running as the specified user 48 # Fail if not running as the specified user
55 if user is not None: 49 if user is not None:
56 for uid in ps[1:5]: 50 for uid in ps[1:5]:
57 if uid != user: 51 if uid != user:
58 if any: 52 if any:
59 user_satisfied = False 53 user_satisfied = False
60 break 54 break
61 raise error.TestFail( 55 raise error.TestFail(
62 'Process %s running as %s; expected %s' % 56 'Process %s running as %s; expected %s' %
63 (process, uid, user)) 57 (process, uid, user))
64 58
65 # Check if process has super-user privileges 59 # Check if process has super-user privileges
66 if not run_as_root: 60 if not run_as_root:
67 # TODO(yusukes): Uncomment this once issue 2253 is resolved 61 # TODO(yusukes): Uncomment this once issue 2253 is resolved
68 # if int(ps[0]) & 0x04: 62 # if int(ps[0]) & 0x04:
69 # raise error.TestFail( 63 # raise error.TestFail(
70 # 'Process %s running with super-user flag' % 64 # 'Process %s running with super-user flag' %
71 # process) 65 # process)
72 if 'root' in ps: 66 if 'root' in ps:
73 if any: 67 if any:
74 run_as_root_satisfied = False 68 run_as_root_satisfied = False
75 continue 69 continue
76 raise error.TestFail( 70 raise error.TestFail(
77 'Process %s running as root' % process) 71 'Process %s running as root' % process)
78 72
79 # Check if conditions are met for "any" mode. 73 # Check if conditions are met for "any" mode.
80 if any and user_satisfied and run_as_root_satisfied: 74 if any and user_satisfied and run_as_root_satisfied:
81 break 75 break
82 else: 76 else:
83 if any: 77 if any:
84 raise error.TestFail( 78 raise error.TestFail(
85 'Conditions are not met for any process %s' % process) 79 'Conditions are not met for any process %s' % process)
86
87 finally:
88 # If we started logged out, log back out.
89 if do_login and not logged_in:
90 site_login.attempt_logout()
OLDNEW
« no previous file with comments | « client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698