Check conf file permission

Since SafeConfigParser.read doesn't thrown an exception
when a file can not be opened, we must explicitly check first.

Change-Id: Ifa5c58e5c30323956a401beae9396ffb0b97dbd9
Closes-Bug: #1692587
This commit is contained in:
Paul Van Eck
2017-05-23 18:17:38 -07:00
parent 2d97cdff88
commit 770acc7765
2 changed files with 17 additions and 0 deletions

View File

@@ -686,6 +686,18 @@ class TestRefstackClient(unittest.TestCase):
client = rc.RefstackClient(args)
self.assertRaises(SystemExit, client.test)
def test_forbidden_conf_file(self):
"""
Test when the user passes in a file that the user does not have
read access to.
"""
file = tempfile.NamedTemporaryFile()
# Remove read access
os.chmod(file.name, 0o220)
args = rc.parse_cli_args(self.mock_argv(conf_file_name=file.name))
client = rc.RefstackClient(args)
self.assertRaises(SystemExit, client.test)
def test_run_tempest_nonexisting_directory(self):
"""
Test when the Tempest directory does not exist.