9e5d00c6fa
The consolidated gateway serves every bottle's repos under /git/<bottle_id>/ (slice 10), so each bottle's bare repos + per-repo credential config must be provisioned into that namespace. This adds the renderer for that; placing the creds + running it inside the gateway is the launch-wiring step. - Extract the credential-wiring `init_repo` shell into a shared `_git_gate_init_repo_fn(repo_root, creds_dir)` — one source for the security-sensitive logic. The single-tenant daemon entrypoint is byte-unchanged (still /git + /git-gate/creds; existing tests green). - git_gate_render_provision(bottle_id, upstreams): posix-sh that inits ONE bottle's bare repos under /git/<bottle_id>/ reading creds from /git-gate/creds/<bottle_id>/. Init-only (no `git daemon` — the shared gateway already serves). Isolating each bottle's repo root + creds dir by id is what keeps one bottle's push credentials out of another's repos. - bottle_id is embedded unquoted in the script, so it's restricted to a shell/path-safe alphabet (registry ids are token_hex; defense in depth). pyright 0 errors; pylint 9.83/10; unit suite green (1724 tests; the 13 test_sidecar_init /bin/sleep errors are pre-existing NixOS-local noise). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WBMWTEtQdJ4W5UrWuLHCck
68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
"""Unit: consolidated per-bottle git-gate provisioning render (PRD 0070)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from bot_bottle.git_gate_render import (
|
|
GitGateUpstream,
|
|
git_gate_render_entrypoint,
|
|
git_gate_render_provision,
|
|
)
|
|
|
|
|
|
def _ups(*names: str) -> tuple[GitGateUpstream, ...]:
|
|
return tuple(
|
|
GitGateUpstream(
|
|
name=n,
|
|
upstream_url=f"ssh://git@github.com/x/{n}.git",
|
|
upstream_host="github.com",
|
|
upstream_port="22",
|
|
identity_file="",
|
|
known_host_key="",
|
|
)
|
|
for n in names
|
|
)
|
|
|
|
|
|
class TestProvisionRender(unittest.TestCase):
|
|
def test_namespaces_repos_and_creds_by_bottle_id(self) -> None:
|
|
script = git_gate_render_provision("bottleab12", _ups("foo"))
|
|
self.assertIn("repo=/git/bottleab12/${name}.git", script)
|
|
self.assertIn("keyfile=/git-gate/creds/bottleab12/${name}-key", script)
|
|
self.assertIn("mkdir -p /git/bottleab12", script)
|
|
|
|
def test_one_init_repo_call_per_upstream(self) -> None:
|
|
script = git_gate_render_provision("b1", _ups("foo", "bar"))
|
|
calls = [l for l in script.splitlines() if l.startswith("init_repo ")]
|
|
self.assertEqual(2, len(calls))
|
|
|
|
def test_provision_does_not_start_the_daemon(self) -> None:
|
|
# The shared gateway already serves; provisioning is init-only.
|
|
self.assertNotIn("git daemon", git_gate_render_provision("b1", _ups("foo")))
|
|
|
|
def test_installs_pre_receive_hook(self) -> None:
|
|
script = git_gate_render_provision("b1", _ups("foo"))
|
|
self.assertIn("install -m 755 /etc/git-gate/pre-receive", script)
|
|
|
|
def test_rejects_unsafe_bottle_id(self) -> None:
|
|
for bad in ("../etc", "a/b", "a b", "a;rm", ""):
|
|
with self.assertRaises(ValueError):
|
|
git_gate_render_provision(bad, _ups("foo"))
|
|
|
|
|
|
class TestEntrypointUnchanged(unittest.TestCase):
|
|
"""The shared `_git_gate_init_repo_fn` refactor must not alter the
|
|
single-tenant daemon entrypoint's output."""
|
|
|
|
def test_entrypoint_still_single_tenant_flat(self) -> None:
|
|
script = git_gate_render_entrypoint(_ups("foo"))
|
|
self.assertIn("repo=/git/${name}.git", script) # flat, not namespaced
|
|
self.assertIn("keyfile=/git-gate/creds/${name}-key", script)
|
|
self.assertIn("--base-path=/git", script)
|
|
self.assertIn("exec git daemon", script)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|