f77023db1d
test / integration-docker (pull_request) Successful in 11s
test / unit (pull_request) Successful in 43s
lint / lint (push) Successful in 56s
test / integration-firecracker (pull_request) Successful in 3m19s
test / coverage (pull_request) Successful in 19s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Successful in 7s
Separate the gateway (data plane) from the orchestrator (control plane) at the
module level. The gateway runtime files move out of the package root — and the
backend-neutral Gateway lifecycle ABC + GATEWAY_* constants move out of
orchestrator/ — into a new bot_bottle/gateway/ package:
gateway/__init__.py (was orchestrator/gateway.py: Gateway ABC + consts
+ rotate_gateway_ca)
gateway/gateway_init.py (the PID-1 daemon supervisor)
gateway/egress_addon.py, egress_addon_core.py, egress_dlp_config.py,
dlp_detectors.py (the egress mitmproxy daemon)
gateway/git_http_backend.py (the git-http daemon)
gateway/git_gate_render.py (the git-gate pre-receive rendering)
gateway/supervise_server.py (the supervise MCP daemon)
gateway/policy_resolver.py (the data-plane control-plane RPC client)
orchestrator/ now holds only control-plane files. The shared plan/types/auth
layer (egress.py=EgressPlan, git_gate.py=GitGatePlan, supervise.py,
supervise_types.py, control_auth.py) and the launch-time git-gate provisioning
helpers stay at root, so orchestrator/ and backend/ still own them.
Because these daemons are invoked as `python3 -m bot_bottle.<name>`, loaded flat
by mitmproxy, and referenced in Dockerfile.gateway, the move updates more than
Python imports: the `-m` invocations (firecracker/macOS infra scripts), the
Dockerfile.gateway addon shim + ENTRYPOINT, gateway_init's _DAEMONS module
paths, and the git-gate CGI heredocs all now point at bot_bottle.gateway.*.
No behavior change; full unit suite green (2251).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""Unit: the `rotate_ca` one-shot CLI (issue #450). Docker mocked."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import Mock, patch
|
|
|
|
from bot_bottle.orchestrator import rotate_ca
|
|
from bot_bottle.gateway import GATEWAY_NAME
|
|
from bot_bottle.orchestrator.lifecycle import INFRA_NAME
|
|
from bot_bottle.paths import host_gateway_ca_dir
|
|
from tests.unit import use_bottle_root
|
|
|
|
_RUN = "bot_bottle.orchestrator.rotate_ca.run_docker"
|
|
|
|
|
|
def _proc(returncode: int = 0, stdout: str = "", stderr: str = "") -> Mock:
|
|
return Mock(returncode=returncode, stdout=stdout, stderr=stderr)
|
|
|
|
|
|
class TestRotateCaCli(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self._tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self._tmp.cleanup)
|
|
self.addCleanup(use_bottle_root(Path(self._tmp.name)))
|
|
|
|
def test_clears_ca_and_drops_gateway_containers(self) -> None:
|
|
ca_dir = host_gateway_ca_dir()
|
|
(ca_dir / "mitmproxy-ca.pem").write_text("x")
|
|
(ca_dir / "mitmproxy-ca-cert.pem").write_text("x")
|
|
|
|
calls: list[list[str]] = []
|
|
|
|
def fake(argv: list[str], **_kw: object) -> Mock:
|
|
calls.append(argv)
|
|
# Report a removed container name so the CLI logs it.
|
|
return _proc(stdout=argv[-1])
|
|
|
|
with patch(_RUN, side_effect=fake):
|
|
self.assertEqual(0, rotate_ca.main([]))
|
|
|
|
# Persisted CA is gone → next start remints it.
|
|
self.assertEqual([], list(ca_dir.glob("mitmproxy-ca*")))
|
|
# Both the infra container and the standalone gateway are force-removed
|
|
# so no mitmproxy keeps serving the old CA from memory.
|
|
removed = {c[-1] for c in calls if c[:3] == ["docker", "rm", "--force"]}
|
|
self.assertEqual({INFRA_NAME, GATEWAY_NAME}, removed)
|
|
|
|
def test_succeeds_with_no_persisted_ca(self) -> None:
|
|
with patch(_RUN, return_value=_proc()) as m:
|
|
self.assertEqual(0, rotate_ca.main([]))
|
|
# Still tears down any running gateway even when there was no CA on disk.
|
|
self.assertTrue(m.called)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|