#!/usr/bin/python3
import importlib
import os
import subprocess
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory() as directory:
    os.chdir(directory)
    subprocess.run(["mssqlpwner", "-h"], check=True, stdout=subprocess.DEVNULL, timeout=30)
    module = importlib.import_module("mssqlpwner.playbooks.playbooks")
    resources = Path(module.__file__).resolve().parent / "custom-asm"
    for name in ["CmdExec-x64.dll", "CmdExec-x86.dll", "LdapServer-x64.dll", "LdapServer-x86.dll"]:
        assembly = resources / name
        assert assembly.is_file(), assembly
        assert assembly.read_bytes().startswith(b"MZ"), assembly
    assert not list(resources.parent.rglob(".DS_Store")), "macOS metadata was installed"
