|
40 | 40 | service = removal_helpers.service |
41 | 41 |
|
42 | 42 |
|
| 43 | +@pytest.mark.parametrize("bound_path", ["/workspace", "/external", "/grant-alias"]) |
| 44 | +def test_binding_rejects_canonical_backslashes(service: Any, bound_path: str) -> None: |
| 45 | + manager, container, worker = service |
| 46 | + configured = manifest() |
| 47 | + worker.aliases[bound_path] = r"/private/\root" |
| 48 | + with pytest.raises(ValueError, match="canonical paths containing backslashes"): |
| 49 | + manager.bind_new(container, configured) |
| 50 | + assert manager._bindings == {} |
| 51 | + assert worker.removed == [] |
| 52 | + assert container.events == ["pause", "close", "unpause"] |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.asyncio |
| 56 | +@pytest.mark.parametrize("is_directory", [True, False]) |
| 57 | +async def test_removal_rejects_canonical_backslashes( |
| 58 | + service: Any, monkeypatch: pytest.MonkeyPatch, is_directory: bool |
| 59 | +) -> None: |
| 60 | + manager, container, worker = service |
| 61 | + configured = Manifest( |
| 62 | + root="/workspace", |
| 63 | + extra_path_grants=(SandboxPathGrant(path="/protected", read_only=True),), |
| 64 | + ) |
| 65 | + manager.bind_new(container, configured) |
| 66 | + worker.aliases["/workspace/link/data"] = r"/protected/\..\..\workspace/data" |
| 67 | + original_request = worker.request |
| 68 | + |
| 69 | + def request(**data: Any) -> dict[str, Any]: |
| 70 | + result = original_request(**data) |
| 71 | + if data["operation"] == "inspect": |
| 72 | + result["is_directory"] = is_directory |
| 73 | + return result |
| 74 | + |
| 75 | + monkeypatch.setattr(worker, "request", request) |
| 76 | + current = session(manager, container, configured) |
| 77 | + with pytest.raises(WorkspaceArchiveWriteError) as caught: |
| 78 | + await current.rm("link/data", recursive=True) |
| 79 | + assert caught.value.context["reason"] == "docker_removal_canonical_path" |
| 80 | + assert [call["operation"] for call in worker.calls] == ["bind", "inspect"] |
| 81 | + assert worker.removed == [] |
| 82 | + assert not container.attrs["State"]["Paused"] |
| 83 | + await current.rm("build", recursive=True) |
| 84 | + assert worker.removed == ["/workspace/build"] |
| 85 | + |
| 86 | + |
43 | 87 | @pytest.mark.asyncio |
44 | 88 | @pytest.mark.parametrize(("bound", "change_grants"), [(True, True), (True, False), (False, True)]) |
45 | 89 | async def test_live_manifest_update_preserves_removal_authority( |
|
0 commit comments