diff --git a/tests/integration/modules/file.py b/tests/integration/modules/file.py index 57be23731c..0722032128 100644 --- a/tests/integration/modules/file.py +++ b/tests/integration/modules/file.py @@ -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) diff --git a/tests/unit/utils/verify_test.py b/tests/unit/utils/verify_test.py index 3e22b45ef4..3f5aa53648 100644 --- a/tests/unit/utils/verify_test.py +++ b/tests/unit/utils/verify_test.py @@ -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())