2012-06-30 16:43:44 +00:00
|
|
|
'''
|
|
|
|
tests for user state
|
|
|
|
user absent
|
|
|
|
user present
|
|
|
|
user present with custom homedir
|
|
|
|
'''
|
2012-06-30 23:51:11 +00:00
|
|
|
import os
|
2012-07-20 06:21:01 +00:00
|
|
|
from saltunittest import skipIf
|
2012-06-30 16:43:44 +00:00
|
|
|
import integration
|
2012-07-30 19:15:35 +00:00
|
|
|
import grp
|
2012-06-30 16:43:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserTest(integration.ModuleCase):
|
|
|
|
'''
|
|
|
|
test for user absent
|
|
|
|
'''
|
|
|
|
def test_user_absent(self):
|
|
|
|
ret = self.run_state('user.absent', name='unpossible')
|
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
self.assertTrue(result)
|
|
|
|
|
2012-06-30 23:51:11 +00:00
|
|
|
def test_user_if_present(self):
|
2012-07-20 06:21:01 +00:00
|
|
|
ret = self.run_state('user.present', name='nobody')
|
2012-06-30 23:51:11 +00:00
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
self.assertTrue(result)
|
2012-06-30 16:43:44 +00:00
|
|
|
|
2012-07-01 00:00:27 +00:00
|
|
|
@skipIf(not (os.geteuid()==0),'you must be this root to run this test')
|
2012-06-30 23:51:11 +00:00
|
|
|
def test_user_not_present(self):
|
|
|
|
"""
|
|
|
|
This is a DESTRUCTIVE TEST it creates a new user on the minion.
|
2012-07-01 00:28:48 +00:00
|
|
|
And then destroys that user.
|
2012-06-30 23:51:11 +00:00
|
|
|
Assume that it will break any system you run it on.
|
|
|
|
"""
|
2012-07-20 06:21:01 +00:00
|
|
|
ret = self.run_state('user.present', name='salt_test')
|
2012-06-30 23:51:11 +00:00
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
self.assertTrue(result)
|
2012-07-01 00:28:48 +00:00
|
|
|
ret = self.run_state('user.absent', name='salt_test')
|
2012-06-30 16:43:44 +00:00
|
|
|
|
2012-07-01 00:00:27 +00:00
|
|
|
@skipIf(not (os.geteuid()==0), 'you must be this root to run this test')
|
2012-06-30 23:51:11 +00:00
|
|
|
def test_user_present_nondefault(self):
|
|
|
|
"""
|
|
|
|
This is a DESTRUCTIVE TEST it creates a new user on the on the minion.
|
|
|
|
"""
|
|
|
|
ret = self.run_state('user.present', name='salt_test',
|
2012-07-20 06:21:01 +00:00
|
|
|
home='/var/lib/salt_test')
|
2012-06-30 23:51:11 +00:00
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
self.assertTrue(result)
|
2012-07-01 00:28:48 +00:00
|
|
|
self.assertTrue(os.stat('/var/lib/salt_test'))
|
|
|
|
ret = self.run_state('user.absent', name='salt_test')
|
|
|
|
|
2012-07-30 19:15:35 +00:00
|
|
|
@skipIf(not (os.geteuid()==0), 'you must be this root to run this test')
|
|
|
|
def test_user_present_gid_from_name_default(self):
|
|
|
|
"""
|
|
|
|
This is a DESTRUCTIVE TEST it creates a new user on the on the minion.
|
|
|
|
This is an integration test. Not all systems will automatically create
|
|
|
|
a group of the same name as the user, but I don't have access to any.
|
|
|
|
If you run the test and it fails, please fix the code it's testing to
|
|
|
|
work on your operating system.
|
|
|
|
"""
|
|
|
|
ret = self.run_state('user.present', name='salt_test',
|
|
|
|
gid_from_name=True, home='/var/lib/salt_test')
|
|
|
|
gid = self.run_function('user.info', ['salt_test'])['gid']
|
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
group_name = grp.getgrgid(gid).gr_name
|
|
|
|
self.assertTrue(result)
|
|
|
|
self.assertTrue(os.stat('/var/lib/salt_test'))
|
|
|
|
self.assertTrue(group_name == 'salt_test')
|
|
|
|
ret = self.run_state('user.absent', name='salt_test')
|
|
|
|
|
|
|
|
@skipIf(not (os.geteuid()==0), 'you must be this root to run this test')
|
|
|
|
def test_user_present_gid_from_name(self):
|
|
|
|
"""
|
|
|
|
This is a DESTRUCTIVE TEST it creates a new user on the on the minion.
|
|
|
|
This is a unit test, NOT an integration test. We create a group of the
|
|
|
|
same name as the user beforehand, so it should all run smoothly.
|
|
|
|
"""
|
|
|
|
ret = self.run_state('group.present', name='salt_test')
|
|
|
|
ret = self.run_state('user.present', name='salt_test',
|
|
|
|
gid_from_name=True, home='/var/lib/salt_test')
|
|
|
|
gid = self.run_function('user.info', ['salt_test'])['gid']
|
|
|
|
result = ret[next(iter(ret))]['result']
|
|
|
|
group_name = grp.getgrgid(gid).gr_name
|
|
|
|
self.assertTrue(result)
|
|
|
|
self.assertTrue(os.stat('/var/lib/salt_test'))
|
|
|
|
self.assertTrue(group_name == 'salt_test')
|
|
|
|
ret = self.run_state('user.absent', name='salt_test')
|
|
|
|
ret = self.run_state('group.absent', name='salt_test')
|
|
|
|
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(UserTest)
|