mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
The Settings upgrade can switch to a chosen branch (#954)
* The Settings upgrade can switch to a chosen branch
The Upgrade panel gains a Branch input: a dropdown listing the current
branch, master, and release that also takes a typed branch name.
/api/upgrade/start accepts an optional {"branch": ...}; without it the
current branch is upgraded as before. A branch is written into the systemd
env file and passed to `upgrade.sh -b`, so only plain git branch names are
accepted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Controller upgrade refuses a branch that is not a plain branch name
The Controller's upgrade script wrote its branch straight into the systemd
env file, so a newline in it added a variable, and a leading dash became an
upgrade.sh option. It now accepts the same branch names as the API, and no
script parameter may span lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f3f762ef1b
commit
d88db90ce9
10 changed files with 304 additions and 28 deletions
|
|
@ -6,6 +6,8 @@ import subprocess
|
|||
import time
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from controller.lib.scripts import (
|
||||
_get_service_timing,
|
||||
AVAILABLE_SCRIPTS,
|
||||
|
|
@ -280,6 +282,26 @@ class TestStartScript:
|
|||
popen.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("branch", [
|
||||
"master\nEVIL=1", "master\rEVIL=1", "-b", "a..b", "a b", "foo.lock", "foo/", "/foo", "a//b", "a$b", "x" * 256,
|
||||
])
|
||||
def test_invalid_branch_is_rejected(self, tmp_path, branch):
|
||||
"""The branch is written into the systemd env file and passed to `upgrade.sh -b`; a branch name git would
|
||||
refuse, or one that could add a line to the env file, never starts an upgrade."""
|
||||
result, env_file, popen = self._start_upgrade(tmp_path, {"branch": branch})
|
||||
assert result["success"] is False
|
||||
assert "branch" in result["error"].lower()
|
||||
assert not env_file.exists()
|
||||
popen.assert_not_called()
|
||||
|
||||
@pytest.mark.parametrize("branch", ["master", "release", "feature/new-thing", "v1.2_fix"])
|
||||
def test_valid_branch_is_written(self, tmp_path, branch):
|
||||
result, env_file, popen = self._start_upgrade(tmp_path, {"branch": branch})
|
||||
assert result["success"] is True
|
||||
assert env_file.read_text() == f"BRANCH={branch}\n"
|
||||
popen.assert_called_once()
|
||||
|
||||
|
||||
class TestGetScriptOutput:
|
||||
"""Tests for get_script_output function."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue