A pass over every feature against a real Docker daemon, then clicking through the UI as admin and read-only user, on a desktop and a phone. Security. /ws/deploy ran compose up for the read-only role; it is admin-only now. A container's inspect view, a stack's compose file (POSTGRES_PASSWORD: hunter2) and the viewer's .env tab no longer show credentials to that role. Git branch and URL values that git would read as options (-x, ext::) are refused. SFTP host keys are checked: pinned on first use or entered by hand (key line or SHA256 fingerprint), a different key is refused before the password is sent. A backup name from the API can no longer reach outside the destination folder. The file browser refuses to move or rename a browse root, as delete did. Docker lifecycle. Closing the deploy console released the stack lock while compose was still running and logged rc=None as success; deploys and updates are now background runs that hold the lock to the end, report the real exit code and can be re-attached to. Every closed log view left a `compose logs -f` behind. A dozen open tabs exhausted the default thread pool and hung the API; event and exec streams have their own threads. Auto-update and the update endpoint ignored failed pulls. A deleted git stack was recreated and started by the next webhook or poll; deleting a stack now drops its git source, auto-update policy and schedule entries. Deleting no longer walks into mounted shares, is refused while a backup runs, and removes the containers even when the compose file is broken. Stack folders compose has to normalise (Nextcloud -> nextcloud) work everywhere and group correctly on the volumes, networks and images pages. Detection. Host port conflicts read the container's own network namespace; /proc/1/net is read instead. Images referenced as docker.io/… were never update-checked; local builds no longer report "needs credentials". NVIDIA GPUs are read from the driver's procfs. The backup dialog's "path mismatch" warning came from mountinfo's filesystem-relative root and fired for any stacks folder on its own disk, ZFS dataset or btrfs subvolume; the host path now comes from Docker's mounts. Backups and destinations. The download ignored the folder/volume selection (axios sent binds[]). Restoring under a new name kept the old one. A report header past nginx's buffer turned a good backup into a 502. SFTP/S3 errors were bare 500s and "Test" did not try to write. A destination used by a schedule could be deleted. Backup file names are in the schedule's or the browser's time zone instead of UTC. Editor and converter. `docker run` conversion produced invalid compose for --network host, named volumes and -dit; --gpus and --mount were dropped; a multi-line command pasted into the one-line field became `image: ' '` (now a textarea, and flattened continuations are read). Validation failed for env_file stacks. The editor overwrote unsaved edits on every container event, lost them on a stray click (now asks), threw when closing the diff, and its helper panel listed the starter service "app" for every existing stack. Monaco is bundled instead of loaded from jsdelivr, so the editor works offline (and monaco-editor 0.57 drops the dompurify advisory; axios and react-router updated). UI. All times were two hours off: offset-less UTC from SQLite was read as local time, and "next run" always said "just now". A token refresh mid-session duplicated deploys, reset terminals and doubled logs. A backend restart (update, self-update) signed everyone out on reload; the page now waits for it. The editor was unusable on a phone, tables and tabs overflowed, dialog text was black on the dark theme, and the file browser opened on an error with the default roots. Read-only users get "Admin only" pages instead of 403s; in-use networks offer no delete; "Scan all" covers StackPilot's own stacks only and runs in the background instead of timing out at 600s. Deployment. nginx passes the port in Host (the OIDC redirect URI lost :5009) and keeps an outer proxy's X-Forwarded-Proto. The frontend waits for a healthy backend (healthcheck probes every 2s while starting). The frontend image builds with npm ci. Secrets are 0644 in a 0700 folder so non-root containers can read them; existing files are fixed at startup. The test suite no longer starts real containers on a host with Docker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fx7gcuy8d6nPd95g43rGHu
138 lines
4.6 KiB
Python
138 lines
4.6 KiB
Python
"""Smaller regressions found in the 0.67 review, one test each.
|
|
|
|
* NVIDIA cards were never detected: the image has no nvidia-smi and the DRI
|
|
scan skips NVIDIA on purpose. The driver's /proc entries are read instead.
|
|
* A container's inspect view handed its environment — credentials, by
|
|
convention — to the read-only role, which does not get the stack's .env.
|
|
* Git branch names and URLs go to git's command line; a leading "-" made them
|
|
options.
|
|
* "Scan all" ran for longer than the proxy waits; it now runs in the
|
|
background and reports through /scan-status.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
|
|
|
|
def test_nvidia_gpus_are_read_from_the_driver_procfs(tmp_path, monkeypatch):
|
|
from config import settings
|
|
from services import gpu_service
|
|
|
|
gpus = tmp_path / "driver" / "nvidia" / "gpus"
|
|
(gpus / "0000:01:00.0").mkdir(parents=True)
|
|
(gpus / "0000:01:00.0" / "information").write_text(
|
|
"Model: \t\t NVIDIA GeForce RTX 3060\n"
|
|
"IRQ: \t\t 150\n"
|
|
"GPU UUID: \t GPU-1234-abcd\n"
|
|
"Device Minor: \t 0\n"
|
|
)
|
|
(tmp_path / "driver" / "nvidia" / "version").write_text(
|
|
"NVRM version: NVIDIA UNIX x86_64 Kernel Module 550.120 Fri Sep 13 2024\n"
|
|
)
|
|
monkeypatch.setattr(settings, "HOST_PROC_PATH", str(tmp_path))
|
|
monkeypatch.setattr(gpu_service, "_detect_nvidia", lambda: [])
|
|
monkeypatch.setattr(gpu_service, "_detect_dri", lambda: [])
|
|
|
|
(gpu,) = gpu_service.detect_gpus()
|
|
assert gpu.vendor == "nvidia"
|
|
assert gpu.name == "NVIDIA GeForce RTX 3060"
|
|
assert gpu.uuid == "GPU-1234-abcd"
|
|
assert gpu.index == 0
|
|
assert gpu.driver == "550.120"
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_container(monkeypatch):
|
|
from services import container_service
|
|
|
|
monkeypatch.setattr(
|
|
container_service,
|
|
"inspect_container",
|
|
lambda container_id: {"id": container_id, "env": ["DB_PASSWORD=hunter2", "NOVALUE"]},
|
|
)
|
|
|
|
|
|
def test_container_env_values_are_hidden_from_the_read_only_role(as_user, fake_container):
|
|
env = as_user.get("/api/containers/abc").json()["env"]
|
|
assert env == ["DB_PASSWORD=••••••", "NOVALUE"]
|
|
|
|
|
|
def test_admins_still_see_the_environment(as_admin, fake_container):
|
|
assert as_admin.get("/api/containers/abc").json()["env"][0] == "DB_PASSWORD=hunter2"
|
|
|
|
|
|
def test_a_missing_container_is_a_404(as_admin, monkeypatch):
|
|
from docker_client import DockerError
|
|
from services import container_service
|
|
|
|
def missing(container_id):
|
|
raise DockerError("not_found", "No such container")
|
|
|
|
monkeypatch.setattr(container_service, "inspect_container", missing)
|
|
assert as_admin.get("/api/containers/nope").status_code == 404
|
|
|
|
|
|
@pytest.mark.parametrize("branch", ["-x", "--upload-pack=sh", "a..b", "x.lock", ""])
|
|
def test_branch_names_that_git_would_read_as_options_are_refused(branch):
|
|
from services import git_service
|
|
|
|
with pytest.raises(git_service.GitError):
|
|
git_service.validate_branch(branch)
|
|
|
|
|
|
@pytest.mark.parametrize("url", ["-oProxyCommand=x", "ext::sh -c id", "fd::3", ""])
|
|
def test_repository_urls_that_run_commands_are_refused(url):
|
|
from services import git_service
|
|
|
|
with pytest.raises(git_service.GitError):
|
|
git_service.validate_url(url)
|
|
|
|
|
|
def test_ordinary_branches_and_urls_pass():
|
|
from services import git_service
|
|
|
|
assert git_service.validate_branch("release/1.2") == "release/1.2"
|
|
assert git_service.validate_url("git@forge:me/stack.git") == "git@forge:me/stack.git"
|
|
|
|
|
|
def test_scan_all_in_the_background_is_active_before_the_request_returns(monkeypatch, db):
|
|
from services import scan_service
|
|
|
|
release = asyncio.Event()
|
|
|
|
async def slow_scan(session, image):
|
|
await release.wait()
|
|
|
|
class Row:
|
|
error = None
|
|
|
|
return Row()
|
|
|
|
monkeypatch.setattr(scan_service, "scan", slow_scan)
|
|
|
|
async def scenario():
|
|
status = scan_service.start_sweep(["a", "b"])
|
|
assert status["active"] is True and status["total"] == 2
|
|
with pytest.raises(scan_service.ScanError):
|
|
scan_service.start_sweep(["c"])
|
|
release.set()
|
|
for _ in range(100):
|
|
if not scan_service.sweep_status()["active"]:
|
|
break
|
|
await asyncio.sleep(0.01)
|
|
final = scan_service.sweep_status()
|
|
assert final["active"] is False
|
|
assert final["scanned"] == 2 and final["failed"] == 0
|
|
|
|
asyncio.run(scenario())
|
|
|
|
|
|
def test_setup_refuses_an_empty_account(client, db, monkeypatch):
|
|
import auth as auth_mod
|
|
|
|
monkeypatch.setattr(auth_mod, "users_exist", lambda session: False)
|
|
response = client.post("/api/auth/setup", json={"username": " ", "password": ""})
|
|
assert response.status_code == 400
|