"""Régression — installeur OTA tolérant à la profondeur d'imbrication du ZIP."""
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from server import _strip_to_whitelist_root as f


def test_simple_deploy_prefix():
    assert f("deploy/backend/server.py") == "backend/server.py"


def test_no_prefix():
    assert f("backend/server.py") == "backend/server.py"


def test_nested_prefix():
    assert f("Ajout-Copilote/Co-Pilote/backend/server.py") == "backend/server.py"


def test_double_nested_with_deploy():
    assert f("deploy/Ajout-Copilote/Co-Pilote/backend/server.py") == "backend/server.py"


def test_frontend_build_kept():
    assert f("deploy/frontend/build/static/js/main.js") == "frontend/build/static/js/main.js"


def test_frontend_src_rejected():
    assert f("deploy/frontend/src/App.js") is None


def test_tests_subfolder_rejected():
    assert f("deploy/backend/tests/foo.py") is None


def test_macosx_artifacts_rejected():
    assert f("__MACOSX/deploy/backend/server.py") is None


def test_ds_store_rejected():
    assert f("deploy/.DS_Store") is None


def test_path_traversal_rejected():
    assert f("../etc/passwd") is None


def test_directory_rejected():
    assert f("deploy/backend/") is None


def test_random_folder_rejected():
    assert f("deploy/random/stuff.txt") is None
