70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
"""Opslagbewaking moet hetzelfde pad controleren als Docker/AIO gaat gebruiken."""
|
|
import pytest
|
|
|
|
from test_mountguard import _buiten_container, via_docker # noqa: F401
|
|
|
|
|
|
OPSLAG = [{"field": "data", "required": True, "start_guard": True}]
|
|
|
|
|
|
def test_ontbrekend_pad_met_spatie_wordt_niet_als_buurmap_goedgekeurd(tmp_path):
|
|
from core import mountguard
|
|
buur = tmp_path / "ncdata"
|
|
buur.mkdir()
|
|
werkelijk = str(buur) + " "
|
|
problemen = mountguard.controleer(OPSLAG, {"data": werkelijk})
|
|
assert len(problemen) == 1
|
|
assert problemen[0]["reason"] == "ontbreekt"
|
|
assert problemen[0]["path"] == werkelijk
|
|
|
|
|
|
def test_bestaand_pad_met_spatie_blijft_bruikbaar(tmp_path):
|
|
from core import mountguard
|
|
werkelijk = tmp_path / "ncdata "
|
|
werkelijk.mkdir()
|
|
assert mountguard.controleer(OPSLAG, {"data": str(werkelijk)}) == []
|
|
|
|
|
|
def test_dockerproef_krijgt_het_werkelijke_pad_met_spatie(via_docker):
|
|
from core import mountguard
|
|
aanroepen, _ = via_docker
|
|
assert mountguard.controleer(OPSLAG, {"data": "/mnt/nas/ncdata "}) == []
|
|
cmd = aanroepen[0]
|
|
assert cmd[cmd.index("--mount") + 1] == \
|
|
"type=bind,source=/mnt/nas/ncdata ,target=/proef,readonly"
|
|
|
|
|
|
def test_dockerweigering_blijft_geblokkeerd_zonder_ander_pad_te_proberen(via_docker):
|
|
from core import mountguard
|
|
aanroepen, uitslag = via_docker
|
|
uitslag.update(rc=125, err="invalid value for source: value should not have whitespace")
|
|
problemen = mountguard.controleer(OPSLAG, {"data": "/mnt/nas/ncdata "})
|
|
assert len(problemen) == 1 and problemen[0]["reason"] == "geen_proef"
|
|
assert problemen[0]["path"] == "/mnt/nas/ncdata "
|
|
assert len(aanroepen) == 1
|
|
|
|
|
|
def test_twee_mappen_met_verschillende_eindspatie_zijn_niet_dubbel(tmp_path):
|
|
from core import mountguard
|
|
eerste, tweede = tmp_path / "ncdata", tmp_path / "ncdata "
|
|
eerste.mkdir()
|
|
tweede.mkdir()
|
|
opslag = OPSLAG + [{"field": "extra", "start_guard": True}]
|
|
assert mountguard.controleer(opslag, {"data": str(eerste), "extra": str(tweede)}) == []
|
|
|
|
|
|
@pytest.mark.parametrize("achtervoegsel", ["\t", "\n", "\r"])
|
|
def test_ongeldig_eindteken_wordt_niet_weggepoetst(tmp_path, achtervoegsel):
|
|
from core import mountguard
|
|
assert mountguard.proef(str(tmp_path) + achtervoegsel)[0] == "ongeldig_pad"
|
|
|
|
|
|
def test_leidende_spatie_maakt_een_hostpad_niet_absoluut(tmp_path):
|
|
from core import mountguard
|
|
assert mountguard.proef(" " + str(tmp_path))[0] == "geen_absoluut_pad"
|
|
|
|
|
|
def test_leeg_optioneel_veld_blijft_overgeslagen():
|
|
from core import mountguard
|
|
assert mountguard.controleer([{"field": "extra", "start_guard": True}],
|
|
{"extra": " "}) == []
|