1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-04-17 23:33:35 +01:00

Check path on extractall (#1336)

* Check path on extractall

* code cleanup

* Add logger

* Fix issue

* Add tests
This commit is contained in:
Pascal Vizeli
2019-10-21 12:23:00 +02:00
committed by GitHub
parent a9ebb147c5
commit 05c8022db3
4 changed files with 61 additions and 7 deletions

View File

@@ -0,0 +1,33 @@
"""Test Tarfile functions."""
import attr
from hassio.utils.tar import secure_path
@attr.s
class TarInfo:
"""Fake TarInfo"""
name: str = attr.ib()
def test_secure_path():
"""Test Secure Path."""
test_list = [
TarInfo("test.txt"),
TarInfo("data/xy.blob"),
TarInfo("bla/blu/ble"),
TarInfo("data/../xy.blob"),
]
assert test_list == list(secure_path(test_list))
def test_not_secure_path():
"""Test Not secure path."""
test_list = [
TarInfo("/test.txt"),
TarInfo("data/../../xy.blob"),
TarInfo("/bla/blu/ble"),
]
assert [] == list(secure_path(test_list))