feat: PowerShell 7 preflight and launcher - preflight.ps1, wikitool.ps1, doctor policy and Mark of the Web checks, pwsh CI job (#151, B)
Files changed: - .gitea/workflows/ci.yml - CHANGES.md - INSTALL.md - README.md - VERSION - docs/why-gates-are-code.md - instructions/bootstrap.md - instructions/bug-report.md - instructions/preflight.md - instructions/setup-instance.md - instructions/upgrade-instance.md - tools/CONTRACT.md - tools/README.md - tools/bugreport.py - tools/chemenu/cli.py - tools/chemenu/commands/dist_cmd.py - tools/chemenu/commands/doctor.py - tools/chemenu/prerequisites.py - tools/chemenu/tests/conftest.py - tools/chemenu/tests/test_bugreport.py - tools/chemenu/tests/test_doctor.py - tools/chemenu/tests/test_preflight.py - tools/chemenu/tests/test_preflight_pwsh.py - tools/chemenu/toolpaths.py - tools/preflight.ps1 - tools/wikitool - tools/wikitool.ps1
This commit is contained in:
1 parent
4035b1ba12
commit
210e0c8286
27 files changed
+1513
-32
No files matched your search
@@ -103,6 +103,10 @@ def _detail(checks, name) -> str:
|
||||
return next(c.detail for c in checks if c.name == name)
|
||||
|
||||
|
||||
def _fix(checks, name) -> str:
|
||||
return next(c.fix or "" for c in checks if c.name == name)
|
||||
|
||||
|
||||
def test_healthy_instance_has_no_fail(instance):
|
||||
checks = doctor.run_doctor()
|
||||
assert not any(c.status == "FAIL" for c in checks)
|
||||
@@ -640,3 +644,70 @@ def test_install_dir_is_not_limited_off_windows(instance, monkeypatch):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "linux")
|
||||
monkeypatch.setattr(prerequisites, "install_dir", lambda: "/" + "x" * 300)
|
||||
assert _status(doctor.run_doctor(), "install-dir") == "OK"
|
||||
|
||||
|
||||
# --- PowerShell: execution policy and Mark of the Web (Gitea #151) -----------------
|
||||
|
||||
OPEN_POLICY = "MachinePolicy=Undefined,UserPolicy=Undefined,Process=Undefined,CurrentUser=Undefined,LocalMachine=RemoteSigned"
|
||||
|
||||
|
||||
def _windows(monkeypatch, policy=None, marked=None):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "windows")
|
||||
if policy is not None:
|
||||
monkeypatch.setenv(prerequisites.ENV_POLICY, policy)
|
||||
if marked is not None:
|
||||
monkeypatch.setenv(prerequisites.ENV_MARKED, marked)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("check", ["execution-policy", "script-marks"])
|
||||
def test_powershell_checks_do_not_apply_off_windows(instance, monkeypatch, check):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "linux")
|
||||
monkeypatch.setenv(prerequisites.ENV_POLICY, "CurrentUser=AllSigned")
|
||||
monkeypatch.setenv(prerequisites.ENV_MARKED, "wikitool.ps1")
|
||||
assert _status(doctor.run_doctor(), check) == "OK"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("policy, expected", [
|
||||
(OPEN_POLICY, "OK"),
|
||||
("CurrentUser=Unrestricted,LocalMachine=Restricted", "OK"),
|
||||
("Process=Restricted,LocalMachine=RemoteSigned", "OK"),
|
||||
("CurrentUser=Undefined,LocalMachine=Undefined", "OK"),
|
||||
("CurrentUser=Restricted,LocalMachine=RemoteSigned", "FAIL"),
|
||||
("LocalMachine=AllSigned", "FAIL"),
|
||||
])
|
||||
def test_execution_policy_blocks_only_restricted_and_allsigned(instance, monkeypatch, policy, expected):
|
||||
_windows(monkeypatch, policy=policy)
|
||||
assert _status(doctor.run_doctor(), "execution-policy") == expected
|
||||
|
||||
|
||||
def test_execution_policy_fix_names_the_one_line_command(instance, monkeypatch):
|
||||
_windows(monkeypatch, policy="CurrentUser=Restricted")
|
||||
fix = _fix(doctor.run_doctor(), "execution-policy")
|
||||
assert "Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned" in fix
|
||||
|
||||
|
||||
@pytest.mark.parametrize("scope", ["MachinePolicy", "UserPolicy"])
|
||||
def test_a_group_policy_gets_no_command_it_could_not_obey(instance, monkeypatch, scope):
|
||||
_windows(monkeypatch, policy=f"{scope}=AllSigned,LocalMachine=RemoteSigned")
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "execution-policy") == "FAIL"
|
||||
assert "Set-ExecutionPolicy" not in _fix(checks, "execution-policy")
|
||||
assert "Git Bash" in _fix(checks, "execution-policy")
|
||||
|
||||
|
||||
def test_execution_policy_that_cannot_be_read_is_a_warning(instance, monkeypatch):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "windows")
|
||||
assert _status(doctor.run_doctor(), "execution-policy") == "WARN"
|
||||
|
||||
|
||||
def test_marked_scripts_fail_with_the_unblock_command(instance, monkeypatch):
|
||||
_windows(monkeypatch, marked="wikitool.ps1,preflight.ps1")
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "script-marks") == "FAIL"
|
||||
assert "wikitool.ps1" in _detail(checks, "script-marks")
|
||||
assert "Unblock-File" in _fix(checks, "script-marks")
|
||||
|
||||
|
||||
def test_unmarked_scripts_are_ok(instance, monkeypatch):
|
||||
_windows(monkeypatch)
|
||||
assert _status(doctor.run_doctor(), "script-marks") == "OK"
|
||||
Reference in new issue
Block a user