repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
test_crossfetch_masks.pyPython47 lines1.3 KiBraw download
import os
import sys
import types

BIN = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "bin"))


def _load_crossfetch():
    if "crossfetch" in sys.modules:
        return sys.modules["crossfetch"]

    # Load the crossfetch script as a module
    mod = types.ModuleType("crossfetch")
    sys.modules["crossfetch"] = mod

    with open(os.path.join(BIN, "crossfetch")) as f:
        code = f.read()

    # Skip the shebang line
    if code.startswith("#!"):
        code = "\n" + code.split("\n", 1)[1]

    exec(code, mod.__dict__)
    return mod


def test_new_emblems_registered():
    cf = _load_crossfetch()
    for name in ("star", "dove", "thorns"):
        assert name in cf.SYMBOLS, name


def test_new_masks_are_well_formed():
    cf = _load_crossfetch()
    for name in ("star", "dove", "thorns"):
        mask = cf.SYMBOLS[name]
        assert len(mask) >= 12, name                       # tall enough to read
        assert all(set(row) <= {"#", " "} for row in mask), name
        assert sum(row.count("#") for row in mask) >= 30, name


def test_set_symbol_accepts_new_names():
    cf = _load_crossfetch()
    for name in ("star", "dove", "thorns", "bethlehem", "spirit"):
        cf.set_symbol(name)
        assert cf.MASK is not cf.CHI_RHO or name in ("chi",), name
    cf.set_symbol("chi")   # restore default for other tests