Fix pathlib resolve (#8311)

* Fix pathlib resolve

* fix test
pull/8313/head
Pascal Vizeli 2017-07-03 07:24:08 +02:00 committed by GitHub
parent 3a6434f566
commit ee7d4710c4
2 changed files with 3 additions and 3 deletions

View File

@ -1079,7 +1079,7 @@ class Config(object):
"""Check if the path is valid for access from outside.""" """Check if the path is valid for access from outside."""
parent = pathlib.Path(path).parent parent = pathlib.Path(path).parent
try: try:
parent.resolve() # pylint: disable=no-member parent = parent.resolve() # pylint: disable=no-member
except (FileNotFoundError, RuntimeError, PermissionError): except (FileNotFoundError, RuntimeError, PermissionError):
return False return False

View File

@ -821,13 +821,13 @@ class TestConfig(unittest.TestCase):
for path in valid: for path in valid:
assert self.config.is_allowed_path(path) assert self.config.is_allowed_path(path)
self.config.whitelist_external_dirs = set(('/home',)) self.config.whitelist_external_dirs = set(('/home', '/var'))
unvalid = [ unvalid = [
"/hass/config/secure", "/hass/config/secure",
"/etc/passwd", "/etc/passwd",
"/root/secure_file", "/root/secure_file",
"/hass/config/test/../../../etc/passwd", "/var/../etc/passwd",
test_file, test_file,
] ]
for path in unvalid: for path in unvalid: