mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Use getpass.getuser since os.getlogin requires a tty and tests do not
always run with one.
This commit is contained in:
parent
4401db9a21
commit
aacd9cc5bd
@ -1,4 +1,5 @@
|
||||
# Import python libs
|
||||
import getpass
|
||||
import grp
|
||||
import os
|
||||
import sys
|
||||
@ -24,11 +25,11 @@ class FileModuleTest(integration.ModuleCase):
|
||||
|
||||
@skipIf(sys.platform.startswith('win'), 'No chgrp on Windows')
|
||||
def test_chown(self):
|
||||
user = os.getlogin()
|
||||
user = getpass.getuser()
|
||||
if sys.platform == 'darwin':
|
||||
group = 'staff'
|
||||
elif sys.platform.startswith('linux'):
|
||||
group = os.getlogin()
|
||||
group = getpass.getuser()
|
||||
ret = self.run_function('file.chown',
|
||||
arg=[self.myfile, user, group])
|
||||
self.assertIsNone(ret)
|
||||
@ -39,7 +40,7 @@ class FileModuleTest(integration.ModuleCase):
|
||||
@skipIf(sys.platform.startswith('win'), 'No chgrp on Windows')
|
||||
def test_chown_no_user(self):
|
||||
user = 'notanyuseriknow'
|
||||
group = os.getlogin()
|
||||
group = getpass.getuser()
|
||||
ret = self.run_function('file.chown',
|
||||
arg=[self.myfile, user, group])
|
||||
self.assertIn('not exist', ret)
|
||||
@ -55,11 +56,11 @@ class FileModuleTest(integration.ModuleCase):
|
||||
|
||||
@skipIf(sys.platform.startswith('win'), 'No chgrp on Windows')
|
||||
def test_chown_no_path(self):
|
||||
user = os.getlogin()
|
||||
user = getpass.getuser()
|
||||
if sys.platform == 'darwin':
|
||||
group = 'staff'
|
||||
elif sys.platform.startswith('linux'):
|
||||
group = os.getlogin()
|
||||
group = getpass.getuser()
|
||||
ret = self.run_function('file.chown',
|
||||
arg=['/tmp/nosuchfile', user, group])
|
||||
self.assertIn('File not found', ret)
|
||||
@ -80,7 +81,7 @@ class FileModuleTest(integration.ModuleCase):
|
||||
if sys.platform == 'darwin':
|
||||
group = 'everyone'
|
||||
elif sys.platform.startswith('linux'):
|
||||
group = os.getlogin()
|
||||
group = getpass.getuser()
|
||||
ret = self.run_function('file.chgrp',
|
||||
arg=[self.myfile, group])
|
||||
self.assertIsNone(ret)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import getpass
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
@ -28,7 +29,7 @@ class TestVerify(TestCase):
|
||||
self.assertFalse(zmq_version())
|
||||
|
||||
def test_user(self):
|
||||
self.assertTrue(check_user(os.getlogin(), self.logger))
|
||||
self.assertTrue(check_user(getpass.getuser(), self.logger))
|
||||
|
||||
def test_no_user(self):
|
||||
self.assertFalse(check_user('nouser', self.logger))
|
||||
@ -37,7 +38,7 @@ class TestVerify(TestCase):
|
||||
def test_verify_env(self):
|
||||
root_dir = tempfile.mkdtemp()
|
||||
var_dir = os.path.join(root_dir, 'var', 'log', 'salt')
|
||||
verify_env([var_dir], os.getlogin())
|
||||
verify_env([var_dir], getpass.getuser())
|
||||
self.assertTrue(os.path.exists(var_dir))
|
||||
dir_stat = os.stat(var_dir)
|
||||
self.assertEqual(dir_stat.st_uid, os.getuid())
|
||||
|
Loading…
Reference in New Issue
Block a user