import os.path
import sys
import time
import uuid
from pathlib import Path

from clarabot_nano.utility.path.security import set_remote_file_security
from clarabot_nano_tests.utility.path.utility import is_remote_security_set


def test_utility_path_security():
    # NOTE: tmpdir can't be used usually because tmpfs will sticky-deny executable flag
    p = Path(os.path.expanduser(f"~/temp/{uuid.uuid4()}-{int(time.time() * 1000)}"))
    p.parent.mkdir(exist_ok=True)
    p.write_bytes(b"0123")
    if not sys.platform.startswith("win"):
        p.chmod(0o754)

    assert is_remote_security_set(p) is False

    set_remote_file_security(p)

    assert is_remote_security_set(p) is True
