All checks were successful
Deploy server-up (dev) / deploy (push) Successful in 6m9s
Voegt een zelfstandige inventarisatie-CLI, begrensde tar/gzip-inspectie met SHA-256 en strikte planning voor NextcloudPi naar managed toe. Blokkeert onbekende gegevens, afwijkende Nextcloud-versies en MariaDB-downgrades. Plant archief- en stagingruimte; voert geen migratie uit. Gereviewd door Claude, inclusief DATABASE_OUDER-correctie. Validatie: 84 gerichte tests groen.
441 lines
19 KiB
Python
441 lines
19 KiB
Python
"""NCP met gesimuleerde broncommando's en gemaakte tarfiles, zonder echte diensten."""
|
|
import copy
|
|
import hashlib
|
|
import importlib.util
|
|
import io
|
|
import json
|
|
import subprocess
|
|
import tarfile
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def modules():
|
|
# Geen core/__init__ nodig; dit blijft ook bruikbaar op een kale NCP-bron.
|
|
basis = Path(__file__).resolve().parents[1]
|
|
uit = []
|
|
for naam, pad in (
|
|
("ncp_migratie", basis / "server-up/core/ncp_migratie.py"),
|
|
("ncp_backup", basis / "server-up/core/ncp_backup.py"),
|
|
("ncp_cli", basis / "tools/ncp_inventaris.py"),
|
|
):
|
|
spec = importlib.util.spec_from_file_location(naam, pad)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
uit.append(module)
|
|
return uit
|
|
|
|
|
|
class Bron:
|
|
def __init__(self):
|
|
self.commands = []
|
|
self.status = {"version": "31.0.9.1", "installed": True, "maintenance": False,
|
|
"needsDbUpgrade": False, "dbpassword": "GEHEIM"}
|
|
self.apps = {"enabled": {"files": "2.3.1", "nextcloudpi": "0.0.1"}, "disabled": {}}
|
|
self.config = {"dbtype": "mysql", "dbhost": "localhost", "dbname": "nextcloud",
|
|
"datadirectory": "/media/data ", "objectstore": "__SERVERUP_NIET_INGESTELD__",
|
|
"objectstore_multibucket": "__SERVERUP_NIET_INGESTELD__"}
|
|
self.encryption = {"enabled": False}
|
|
self.failed = None
|
|
self.reads = []
|
|
|
|
def lees(self, pad):
|
|
self.reads.append(pad)
|
|
return {"/usr/local/etc/ncp-version": "v1.55.0\n", "/etc/machine-id": "a" * 32,
|
|
"/usr/local/etc/ncp-config.d/nc-backup.cfg": json.dumps({"params": [
|
|
{"id": "INCLUDEDATA", "value": "no"}, {"id": "COMPRESS", "value": "yes"},
|
|
{"id": "PASSWORD", "value": "GEHEIM"}]})}[pad]
|
|
|
|
def run(self, cmd):
|
|
self.commands.append(cmd)
|
|
if self.failed and self.failed in cmd:
|
|
return SimpleNamespace(returncode=1, stdout="GEHEIM", stderr="GEHEIM")
|
|
if cmd[0] == "ncc":
|
|
assert cmd[-1] == "--output=json"
|
|
if cmd[1] == "status":
|
|
antwoord = self.status
|
|
elif cmd[1] == "app:list":
|
|
antwoord = self.apps
|
|
elif cmd[1] == "encryption:status":
|
|
antwoord = self.encryption
|
|
else:
|
|
assert cmd[1] == "config:system:get"
|
|
assert "--default-value=__SERVERUP_NIET_INGESTELD__" in cmd
|
|
antwoord = self.config[cmd[2]]
|
|
uitvoer = json.dumps(antwoord)
|
|
elif cmd[0] == "mariadb":
|
|
assert cmd[-1].startswith("SELECT VERSION(); SELECT COALESCE(")
|
|
uitvoer = "10.11.6-MariaDB-0+deb12u1\n10000\n"
|
|
elif cmd[0] == "du":
|
|
assert cmd == ["du", "--dereference-args", "--summarize", "--bytes", "--", "/media/data "]
|
|
uitvoer = "20000\t/media/data \n"
|
|
elif cmd[0] == "findmnt":
|
|
uitvoer = json.dumps({"filesystems": [{"target": "/media", "fstype": "ext4"}]})
|
|
else:
|
|
raise AssertionError(cmd)
|
|
return SimpleNamespace(returncode=0, stdout=uitvoer, stderr="")
|
|
|
|
def inventory(self, module, **kwargs):
|
|
return module.inventariseer(run=self.run, lees=self.lees,
|
|
disk_usage=lambda pad: SimpleNamespace(free=10**12), **kwargs)
|
|
|
|
|
|
def maak_tar(tmp_path, extra=(), *, data=True, mode="w", entries=None):
|
|
pad = tmp_path / ("ncp.tar.gz" if mode == "w:gz" else "ncp.tar")
|
|
if entries is None:
|
|
entries = [("nextcloud-sqlbkp_20261030.bak", b"-- database GEHEIM"),
|
|
("nextcloud/config/config.php", b"<?php /* GEHEIM */"),
|
|
("nextcloud/version.php", b"<?php $OC_Version = array(31,0,9,1);"),
|
|
("nextcloud/data/.ocdata", b"")]
|
|
if data:
|
|
entries += [("data /.ocdata", b""), ("data /user/files/a.txt", b"bestand")]
|
|
with tarfile.open(pad, mode) as tar:
|
|
for naam, inhoud in [*entries, *extra]:
|
|
lid = naam if isinstance(naam, tarfile.TarInfo) else tarfile.TarInfo(naam)
|
|
lid.size = len(inhoud)
|
|
tar.addfile(lid, io.BytesIO(inhoud))
|
|
return pad
|
|
|
|
|
|
def codes(rapport):
|
|
return {r["code"] for r in rapport.get("risks", rapport.get("blockers", []))}
|
|
|
|
|
|
@pytest.fixture
|
|
def geldig(modules, tmp_path):
|
|
migratie, backup, _ = modules
|
|
inventory = Bron().inventory(migratie, meet_data=True)
|
|
archief = backup.inspecteer(maak_tar(tmp_path), source_datadir=inventory["storage"]["datadir"])
|
|
doel = {"host_id": "b" * 64, "nextcloud": {"release": "31.0.9"},
|
|
"database": {"engine": "mariadb", "version": "11.4.5"},
|
|
"storage": {"datadir": "/srv/nextcloud/data", "mounted": True, "writable": True,
|
|
"empty": True, "free_bytes": 10**12}}
|
|
return inventory, doel, archief
|
|
|
|
|
|
def test_bron_leest_selectief_en_behoudt_exact_datapad(modules):
|
|
bron = Bron()
|
|
inventaris = bron.inventory(modules[0])
|
|
assert inventaris["source"]["host_id"] == hashlib.sha256(("a" * 32).encode()).hexdigest()
|
|
assert inventaris["storage"]["datadir"] == "/media/data "
|
|
assert inventaris["storage"]["bytes"] is None
|
|
assert not any(cmd[0] == "du" for cmd in bron.commands)
|
|
assert "GEHEIM" not in json.dumps(inventaris)
|
|
assert inventaris["backup"]["include_data_default"] is False
|
|
assert inventaris["backup"]["compressed_default"] is True
|
|
assert inventaris["backup"]["config_export_is_backup"] is False
|
|
assert set(bron.reads) == {"/etc/machine-id", "/usr/local/etc/ncp-version",
|
|
"/usr/local/etc/ncp-config.d/nc-backup.cfg"}
|
|
assert all(cmd[0] in ("ncc", "mariadb", "findmnt") for cmd in bron.commands)
|
|
assert set(cmd[1] for cmd in bron.commands if cmd[0] == "ncc") == {
|
|
"status", "config:system:get", "app:list", "encryption:status"}
|
|
|
|
|
|
@pytest.mark.parametrize("commando", ["status", "app:list", "encryption:status", "mariadb", "findmnt", "du"])
|
|
def test_commandofout_onbekend_geen_geheim(modules, commando):
|
|
bron = Bron()
|
|
bron.failed = commando
|
|
rapport = bron.inventory(modules[0], meet_data=True)
|
|
assert any(r["severity"] == "blocker" for r in rapport["risks"])
|
|
assert "GEHEIM" not in json.dumps(rapport)
|
|
|
|
|
|
def test_timeout_en_ongeldige_json_worden_geredigeerd(modules):
|
|
bron = Bron()
|
|
def timeout(cmd):
|
|
raise subprocess.TimeoutExpired(cmd, 120, output="GEHEIM")
|
|
rapport = modules[0].inventariseer(run=timeout, lees=bron.lees)
|
|
assert "GEHEIM" not in json.dumps(rapport)
|
|
assert "STATUS_ONBEKEND" in codes(rapport)
|
|
rapport = modules[0].inventariseer(
|
|
run=lambda cmd: SimpleNamespace(returncode=0, stdout="{GEHEIM"), lees=bron.lees)
|
|
assert "GEHEIM" not in json.dumps(rapport)
|
|
assert rapport["nextcloud"]["version"] is None
|
|
|
|
|
|
@pytest.mark.parametrize("datapad", ["/", "//", "/./", "/data/../etc", "relatief", "/data\nx"])
|
|
def test_bron_weigert_ongeldige_datapaden(modules, datapad):
|
|
bron = Bron()
|
|
bron.config["datadirectory"] = datapad
|
|
rapport = bron.inventory(modules[0], meet_data=True)
|
|
assert rapport["storage"]["datadir"] is None
|
|
assert "DATAMAP_ONGELDIG" in codes(rapport)
|
|
assert not any(cmd[0] == "du" for cmd in bron.commands)
|
|
|
|
|
|
def test_database_naam_is_geen_sql_invoer(modules):
|
|
bron = Bron()
|
|
bron.config["dbname"] = "nextcloud'; DROP DATABASE nextcloud; --"
|
|
rapport = bron.inventory(modules[0])
|
|
assert rapport["database"]["engine"] is None
|
|
assert not any(cmd[0] == "mariadb" for cmd in bron.commands)
|
|
|
|
|
|
@pytest.mark.parametrize("veld,waarde", [("objectstore", "S3"), ("objectstore_multibucket", "S3")])
|
|
def test_primaire_objectopslag_blokkeert(modules, veld, waarde):
|
|
bron = Bron()
|
|
bron.config[veld] = waarde
|
|
assert "OBJECTOPSLAG" in codes(bron.inventory(modules[0]))
|
|
|
|
|
|
def test_encryptie_en_onvolledige_applijst_blokkeren(modules):
|
|
bron = Bron()
|
|
bron.encryption = {"enabled": True}
|
|
bron.apps = {"enabled": {"files": "2.3.1"}}
|
|
rapport = bron.inventory(modules[0])
|
|
assert {"ENCRYPTIE", "APPS_ONVOLLEDIG"} <= codes(rapport)
|
|
assert rapport["storage"]["external_storage_enabled"] is None
|
|
|
|
|
|
@pytest.mark.parametrize("mode", ["w", "w:gz"])
|
|
def test_backup_inhoud_en_vingerafdruk_zonder_extractie(modules, tmp_path, mode):
|
|
pad = maak_tar(tmp_path, mode=mode)
|
|
rapport = modules[1].inspecteer(pad, source_datadir="/media/data ")
|
|
assert rapport["format"] == "nextcloudpi"
|
|
assert rapport["version"] == "31.0.9.1"
|
|
assert rapport["data_included"] is True
|
|
assert rapport["data_root"] == "data "
|
|
assert rapport["verified"] is False
|
|
assert rapport["archive_sha256"] == hashlib.sha256(pad.read_bytes()).hexdigest()
|
|
assert "GEHEIM" not in json.dumps(rapport)
|
|
assert sorted(p.name for p in tmp_path.iterdir()) == [pad.name]
|
|
|
|
|
|
def test_placeholder_is_geen_databackup(modules, tmp_path):
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, data=False))
|
|
assert rapport["format"] == "nextcloudpi"
|
|
assert rapport["data_included"] is False
|
|
assert "DATA_NIET_AANGETOOND" in codes(rapport)
|
|
|
|
|
|
def test_nieuwe_en_dubbele_datamarker_tellen_als_een_tak(modules, tmp_path):
|
|
pad = maak_tar(tmp_path, extra=[("data /.ncdata", b"")])
|
|
assert modules[1].inspecteer(pad)["data_included"] is True
|
|
pad = maak_tar(tmp_path, data=False, extra=[("data /.ncdata", b"")])
|
|
assert modules[1].inspecteer(pad)["data_included"] is True
|
|
|
|
|
|
def test_meerdere_datatakken_zijn_onzeker_zonder_bron(modules, tmp_path):
|
|
pad = maak_tar(tmp_path, extra=[("andere-data/.ocdata", b"")])
|
|
assert modules[1].inspecteer(pad)["data_included"] is False
|
|
assert modules[1].inspecteer(pad, source_datadir="/media/data ")["data_root"] == "data "
|
|
|
|
|
|
def test_ncp_config_export_is_geen_backup(modules, tmp_path):
|
|
pad = maak_tar(tmp_path, entries=[("nc-backup.cfg", b'{"password":"GEHEIM"}')])
|
|
rapport = modules[1].inspecteer(pad)
|
|
assert rapport["format"] == "ncp-config-export"
|
|
assert "ALLEEN_NCP_CONFIG" in codes(rapport)
|
|
assert "GEHEIM" not in json.dumps(rapport)
|
|
|
|
|
|
@pytest.mark.parametrize("pad", ["../escaped", "/etc/passwd", "a/../../escape", "x\\y", "x\nz"])
|
|
def test_gevaarlijke_archiefpaden_blokkeren(modules, tmp_path, pad):
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, extra=[(pad, b"x")]))
|
|
assert "ONVEILIG_ARCHIEFPAD" in codes(rapport)
|
|
assert rapport["readable"] is False
|
|
assert rapport["archive_sha256"] is None
|
|
|
|
|
|
@pytest.mark.parametrize("soort,doel", [(tarfile.SYMTYPE, "../../etc"), (tarfile.SYMTYPE, "/etc"),
|
|
(tarfile.LNKTYPE, "../etc"), (tarfile.LNKTYPE, "/etc")])
|
|
def test_links_buiten_backup_blokkeren(modules, tmp_path, soort, doel):
|
|
lid = tarfile.TarInfo("map/link")
|
|
lid.type, lid.linkname = soort, doel
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, extra=[(lid, b"")]))
|
|
assert "ONVEILIGE_ARCHIEFLINK" in codes(rapport)
|
|
|
|
|
|
def test_dubbele_paden_en_bestand_naar_map_blokkeren(modules, tmp_path):
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, extra=[("./nextcloud/config/config.php", b"x")]))
|
|
assert "DUBBELE_ARCHIEFINGANG" in codes(rapport)
|
|
lid = tarfile.TarInfo("nextcloud/config/config.php")
|
|
lid.type = tarfile.DIRTYPE
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, extra=[(lid, b"")]))
|
|
assert "DUBBELE_ARCHIEFINGANG" in codes(rapport)
|
|
|
|
|
|
@pytest.mark.parametrize("kwargs,code", [
|
|
({"max_members": 2}, "TE_VEEL_BESTANDEN"), ({"max_payload_bytes": 2}, "BACKUP_TE_GROOT"),
|
|
({"max_archive_bytes": 2}, "ARCHIEF_TE_GROOT"),
|
|
])
|
|
def test_inspectiegrenzen(modules, tmp_path, kwargs, code):
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path), **kwargs)
|
|
assert code in codes(rapport)
|
|
assert rapport["readable"] is False
|
|
|
|
|
|
def test_truncatie_en_php_uitvoering_blokkeren(modules, tmp_path):
|
|
pad = maak_tar(tmp_path, entries=[("nextcloud/version.php", b"x" * 1024)])
|
|
pad.write_bytes(pad.read_bytes()[:600])
|
|
assert "BACKUP_ONLEESBAAR" in codes(modules[1].inspecteer(pad))
|
|
pad = maak_tar(tmp_path, entries=[("nextcloud/version.php", b'<?php $OC_Version = get_version();')])
|
|
assert "BACKUP_VERSIE_ONBEKEND" in codes(modules[1].inspecteer(pad))
|
|
|
|
|
|
@pytest.mark.parametrize("corruptie", ["checksum", "lengte", "afgebroken"])
|
|
def test_gzip_trailer_wordt_gecontroleerd(modules, tmp_path, corruptie):
|
|
pad = maak_tar(tmp_path, mode="w:gz")
|
|
data = bytearray(pad.read_bytes())
|
|
if corruptie == "afgebroken":
|
|
data = data[:-5]
|
|
else:
|
|
data[-8 if corruptie == "checksum" else -4] ^= 255
|
|
pad.write_bytes(data)
|
|
rapport = modules[1].inspecteer(pad)
|
|
assert "BACKUP_ONLEESBAAR" in codes(rapport)
|
|
assert rapport["readable"] is False
|
|
assert rapport["archive_sha256"] is None
|
|
|
|
|
|
def test_archief_verandert_tijdens_inspectie(modules, tmp_path, monkeypatch):
|
|
backup = modules[1]
|
|
pad = maak_tar(tmp_path)
|
|
origineel = backup.os.fstat
|
|
keer = 0
|
|
def gewijzigd(fd):
|
|
nonlocal keer
|
|
keer += 1
|
|
stat = origineel(fd)
|
|
if keer == 2:
|
|
return SimpleNamespace(st_size=stat.st_size, st_mtime_ns=stat.st_mtime_ns + 1,
|
|
st_ctime_ns=stat.st_ctime_ns)
|
|
return stat
|
|
monkeypatch.setattr(backup.os, "fstat", gewijzigd)
|
|
rapport = backup.inspecteer(pad)
|
|
assert "BACKUP_GEWIJZIGD" in codes(rapport)
|
|
assert rapport["archive_sha256"] is None
|
|
|
|
|
|
def test_bestandstype_en_groot_versiebestand_blokkeren(modules, tmp_path):
|
|
lid = tarfile.TarInfo("apparaat")
|
|
lid.type = tarfile.CHRTYPE
|
|
rapport = modules[1].inspecteer(maak_tar(tmp_path, extra=[(lid, b"")]))
|
|
assert "BIJZONDER_ARCHIEFBESTAND" in codes(rapport)
|
|
pad = maak_tar(tmp_path, entries=[("nextcloud/version.php", b" " * (65536 + 1))])
|
|
assert "VERSIEBESTAND_TE_GROOT" in codes(modules[1].inspecteer(pad))
|
|
|
|
|
|
def test_geldig_plan_is_nooit_uitvoering_en_telt_staging(modules, geldig):
|
|
inventory, doel, backup = geldig
|
|
plan = modules[0].plan(*geldig)
|
|
assert plan["status"] == "plan_ready", plan["blockers"]
|
|
assert plan["execution_ready"] is False
|
|
assert plan["restore_test_required"] is True
|
|
assert plan["image"] == "nextcloud:31.0.9-apache"
|
|
basis = 20000 + 2 * 10000 + backup["archive_bytes"] + backup["payload_bytes"]
|
|
assert plan["required_bytes"] == basis + 1024**3
|
|
assert plan["facts"]["backup_sha256"] == backup["archive_sha256"]
|
|
assert plan["source_datadir"] == "/media/data "
|
|
|
|
|
|
@pytest.mark.parametrize("nummer,pad,waarde,code", [
|
|
(0, "schema", True, "BRON_ONBEKEND"),
|
|
(0, "nextcloud.installed", "true", "BRON_NIET_GEREED"),
|
|
(0, "nextcloud.needs_db_upgrade", None, "BRON_NIET_GEREED"),
|
|
(0, "nextcloud.version", "32.0.0.1", "VERSIE_ONBEKEND"),
|
|
(1, "nextcloud.release", "31.0.10", "VERSIE_VERSCHILT"),
|
|
(0, "database.engine", "mysql", "DATABASE_ENGINE"),
|
|
(1, "database.version", {}, "DATABASE_VERSIE"),
|
|
(1, "host_id", None, "HOST_ONBEKEND"),
|
|
(0, "storage.server_side_encryption", None, "SERVER_SIDE_ENCRYPTION"),
|
|
(0, "storage.object_store_primary", True, "OBJECT_STORE_PRIMARY"),
|
|
(1, "storage.datadir", "/./", "DATAMAP"),
|
|
(0, "storage.datadir", "//", "DATAMAP"),
|
|
(1, "storage.empty", 1, "DOEL_EMPTY"),
|
|
(1, "storage.mounted", False, "DOEL_MOUNTED"),
|
|
(1, "storage.writable", None, "DOEL_WRITABLE"),
|
|
(0, "storage.bytes", None, "OMVANG_ONBEKEND"),
|
|
(0, "database.bytes", True, "OMVANG_ONBEKEND"),
|
|
(1, "storage.free_bytes", 1024, "TE_WEINIG_RUIMTE"),
|
|
(2, "archive_bytes", -1, "OMVANG_ONBEKEND"),
|
|
(2, "archive_sha256", None, "BACKUP_ONTBREEKT"),
|
|
(2, "version", "31.0.9.2", "BACKUP_VERSIE"),
|
|
(2, "risks", {}, "BACKUP_ONVEILIG"),
|
|
(0, "risks", 2, "INVENTARIS_ONVOLLEDIG"),
|
|
(0, "risks", [{"severity": "typo"}], "INVENTARIS_ONVOLLEDIG"),
|
|
(0, "apps", [{"id": "bad"}], "APPS_ONVOLLEDIG"),
|
|
])
|
|
def test_onbekend_of_afwijking_blokkeert_plan(modules, geldig, nummer, pad, waarde, code):
|
|
gegevens = copy.deepcopy(geldig)
|
|
sectie = gegevens[nummer]
|
|
sleutels = pad.split(".")
|
|
for sleutel in sleutels[:-1]:
|
|
sectie = sectie[sleutel]
|
|
sectie[sleutels[-1]] = waarde
|
|
plan = modules[0].plan(*gegevens)
|
|
assert plan["status"] == "blocked"
|
|
assert code in codes(plan)
|
|
|
|
|
|
def test_zelfde_host_en_gewijzigde_facts(modules, geldig):
|
|
inventory, doel, backup = copy.deepcopy(geldig)
|
|
origineel = modules[0].plan(inventory, doel, backup)
|
|
inventory["apps"][0]["version"] = "2.3.2"
|
|
assert modules[0].plan(inventory, doel, backup)["plan_hash"] != origineel["plan_hash"]
|
|
doel["host_id"] = inventory["source"]["host_id"]
|
|
assert "ZELFDE_HOST" in codes(modules[0].plan(inventory, doel, backup))
|
|
for index, sleutel in [(1, "archive_sha256"), (0, "version")]:
|
|
kopie = copy.deepcopy(geldig)
|
|
if index:
|
|
kopie[2][sleutel] = "c" * 64
|
|
else:
|
|
kopie[1]["database"][sleutel] = "11.4.6"
|
|
assert modules[0].plan(*kopie)["plan_hash"] != origineel["plan_hash"]
|
|
|
|
|
|
@pytest.mark.parametrize("versie", ["10.3.39-MariaDB", "10.11.5-MariaDB"])
|
|
def test_migratie_naar_oudere_database_blokkeert(modules, geldig, versie):
|
|
inventory, doel, backup = copy.deepcopy(geldig)
|
|
doel["database"]["version"] = versie
|
|
plan = modules[0].plan(inventory, doel, backup)
|
|
assert plan["status"] == "blocked"
|
|
assert "DATABASE_OUDER" in codes(plan)
|
|
|
|
|
|
@pytest.mark.parametrize("app", ["notify_push", "richdocumentscode", "files_antivirus", "fulltextsearch_elasticsearch"])
|
|
def test_aanvullende_diensten_worden_explicitiet_genoemd(modules, geldig, app):
|
|
inventory, doel, backup = copy.deepcopy(geldig)
|
|
inventory["apps"].append({"id": app, "version": "1.0.0", "enabled": True})
|
|
plan = modules[0].plan(inventory, doel, backup)
|
|
assert "AANVULLENDE_DIENSTEN" in {r["code"] for r in plan["warnings"]}
|
|
|
|
|
|
@pytest.mark.parametrize("ongeldig", [None, [], "GEHEIM", 42, {"risks": 5}])
|
|
def test_onbetrouwbare_rapporten_crashen_niet(modules, ongeldig):
|
|
plan = modules[0].plan(ongeldig, ongeldig, ongeldig)
|
|
assert plan["status"] == "blocked"
|
|
assert "GEHEIM" not in json.dumps(plan)
|
|
|
|
|
|
def test_cli_help_laat_bron_met_rust(modules, monkeypatch, capsys):
|
|
cli = modules[2]
|
|
monkeypatch.setattr(cli, "_module", lambda naam: pytest.fail("bron aangeroepen"))
|
|
with pytest.raises(SystemExit) as fout:
|
|
cli.main(["--help"])
|
|
assert fout.value.code == 0
|
|
assert "--meet-data" in capsys.readouterr().out
|
|
|
|
|
|
def test_cli_doelfout_voor_broninspectie(modules, monkeypatch, tmp_path, capsys):
|
|
cli = modules[2]
|
|
monkeypatch.setattr(cli, "_module", lambda naam: pytest.fail("bron aangeroepen"))
|
|
doel = tmp_path / "doel.json"
|
|
doel.write_text("{GEHEIM")
|
|
assert cli.main(["--doel", str(doel)]) == 2
|
|
assert "GEHEIM" not in capsys.readouterr().out
|
|
|
|
|
|
def test_cli_volledig_rapport_met_gesimuleerde_bron(modules, monkeypatch, geldig, tmp_path, capsys):
|
|
migratie, backup, cli = modules
|
|
monkeypatch.setattr(migratie, "inventariseer", lambda **kwargs: copy.deepcopy(geldig[0]))
|
|
monkeypatch.setattr(cli, "_module", lambda naam: {"ncp_migratie": migratie, "ncp_backup": backup}[naam])
|
|
doel = tmp_path / "doel.json"
|
|
doel.write_text(json.dumps(geldig[1]))
|
|
assert cli.main(["--meet-data", "--backup", str(maak_tar(tmp_path)), "--doel", str(doel)]) == 0
|
|
rapport = json.loads(capsys.readouterr().out)
|
|
assert rapport["plan"]["status"] == "plan_ready"
|
|
assert rapport["plan"]["execution_ready"] is False
|