mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-15 13:54:43 -06:00
34 lines
655 B
Python
34 lines
655 B
Python
"""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))
|