diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 17:16:23 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 17:16:23 +0000 |
| commit | 8bb76cb266a2fef5d5fe43c0f9643101f59112aa (patch) | |
| tree | ef421aa194b3cac2ab9e2662fcf41ce551260138 /src | |
| parent | e7922f3dd1d985dcb993b624146b2492183f3a11 (diff) | |
| download | aur-build-8bb76cb266a2fef5d5fe43c0f9643101f59112aa.tar.gz aur-build-8bb76cb266a2fef5d5fe43c0f9643101f59112aa.zip | |
config: the test hooks are a gated submodule, not the production surface
Seven fields sat on `Config` next to `signing_key_id` and `bind`: a PATH
override, three shim protocol variables, a fault-injection point in the middle
of `publish()`, and two more shims could obey. m-9's complaint was not that they
exist — the shims are how I4, I5 and I9 are tested for real, and a mock would
have asserted the mock's own behaviour — but that nothing said which of these
was production and which was scaffolding, and the publish path carried a test
branch on every real publish.
They are one `TestHooks` submodule now, documented as what it is, and the whole
submodule is `#[cfg(feature = "test-support")]` — the same feature that already
gates the shims and the raw SQL escape hatch, and which only this crate's own
dev-dependency turns on. A production build has no `hooks` field, no shim
protocol in `child_env`, and no fault-injection branch in `publish()`; the
serialized config skips the section entirely when nothing is hooked, so a real
`config.json` never mentions any of it.
`TestHooks::is_empty()` names the state a real process runs in, and three tests
hold the line: the hook fields may be declared exactly once and only inside
`TestHooks`, every `publish_fault` read in `publish.rs` must sit behind the
feature gate, and a default config serializes without a trace of hooks.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 130 | ||||
| -rw-r--r-- | src/pipeline/publish.rs | 7 |
2 files changed, 89 insertions, 48 deletions
diff --git a/src/config.rs b/src/config.rs index 9226622..3708639 100644 --- a/src/config.rs +++ b/src/config.rs @@ -50,27 +50,11 @@ pub struct Config { pub gpg_bin: String, /// Unprivileged user that runs PKGBUILD code (§14). Empty = current user. pub build_user: String, - /// Directory prepended to PATH for child processes. The test harness puts - /// the toolchain shims here (§16a). - pub path_prepend: Option<PathBuf>, - /// Fixture manifest the shims should obey, exported as `AUR_SHIM_MANIFEST`. - pub shim_manifest: Option<PathBuf>, - /// Where shims record their invocations, exported as `AUR_SHIM_DIR`. - pub shim_dir: Option<PathBuf>, - /// Test hook: abort publish at a named point so I4 (atomic publish) can be - /// exercised for real. Never set in production. - pub publish_fault: Option<String>, - /// Test hook: the named shim must fail, e.g. `makechrootpkg`. - pub shim_fail: Option<String>, - /// Test hook: the named shim SIGKILLs its parent, i.e. the process running - /// the pipeline, mid-step. This is how a real crash is reproduced for I5 — - /// not a caught error, an uncatchable death. Never set in production. - pub shim_kill_parent: Option<String>, - /// Make the build shim plant a symlink to this path in its srcdir, so a test - /// can act out the I9 attack: an untrusted PKGBUILD smuggling bytes in from - /// outside its own staging dir. - #[serde(default)] - pub shim_plant_link: Option<String>, + /// Test-only hooks (§16a). Not part of the production configuration at all + /// unless the crate is built with `test-support` — see [`TestHooks`]. + #[cfg(feature = "test-support")] + #[serde(default, skip_serializing_if = "TestHooks::is_empty")] + pub hooks: TestHooks, /// How many builds may run at once (§8.2 backpressure). Default 1, which /// also means the chroot pool only needs one warm root. pub max_concurrent_builds: usize, @@ -86,6 +70,57 @@ pub struct Config { pub dispatch_tick_secs: u64, } +/// The test harness's handles on a real pipeline (§16a), grouped into one +/// submodule so the production configuration says what it is. +/// +/// Each of these exists because a *fake* pipeline would test something else: +/// I4 (atomic publish) needs a process that really dies between the tmp write +/// and the rename; I5 needs a step that really dies mid-child; I9 needs a +/// PKGBUILD that really reaches outside its staging dir. The alternative was a +/// mock that asserts the mock's own behaviour. +/// +/// They are compiled out entirely unless the crate is built with the +/// `test-support` feature (the same feature that gates the shims, §6 M-4), so a +/// production binary has no fault-injection branch in its publish path and no +/// shim protocol in its child environment. The test suite enables the feature +/// through a dev-dependency on this crate, and nothing else does. +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[serde(default)] +pub struct TestHooks { + /// Directory prepended to PATH for child processes: the toolchain shims. + pub path_prepend: Option<PathBuf>, + /// Fixture manifest the shims should obey, exported as `AUR_SHIM_MANIFEST`. + pub shim_manifest: Option<PathBuf>, + /// Where shims record their invocations, exported as `AUR_SHIM_DIR`. + pub shim_dir: Option<PathBuf>, + /// Abort publish at a named point so I4 (atomic publish) can be exercised + /// for real: `before-rename` or `after-rename`. + pub publish_fault: Option<String>, + /// The named shim must fail, e.g. `makechrootpkg`. + pub shim_fail: Option<String>, + /// The named shim SIGKILLs its parent — the process running the pipeline — + /// mid-step. This is how a real crash is reproduced for I5: not a caught + /// error, an uncatchable death. + pub shim_kill_parent: Option<String>, + /// Make the build shim plant a symlink to this path in its srcdir, so a test + /// can act out the I9 attack: an untrusted PKGBUILD smuggling bytes in from + /// outside its own staging dir. + pub shim_plant_link: Option<String>, +} + +impl TestHooks { + /// True when nothing is hooked — the state every real process runs in. + pub fn is_empty(&self) -> bool { + self.path_prepend.is_none() + && self.shim_manifest.is_none() + && self.shim_dir.is_none() + && self.publish_fault.is_none() + && self.shim_fail.is_none() + && self.shim_kill_parent.is_none() + && self.shim_plant_link.is_none() + } +} + impl Default for Config { fn default() -> Self { Self { @@ -105,13 +140,8 @@ impl Default for Config { repo_add_bin: "repo-add".into(), gpg_bin: "gpg".into(), build_user: String::new(), - path_prepend: None, - shim_manifest: None, - shim_dir: None, - publish_fault: None, - shim_fail: None, - shim_kill_parent: None, - shim_plant_link: None, + #[cfg(feature = "test-support")] + hooks: TestHooks::default(), max_concurrent_builds: 1, lease_secs: 90, min_free_disk_mb: 1024, @@ -148,25 +178,33 @@ impl Config { /// Environment for a child process: PATH with the shims in front, plus the /// shim protocol variables (§16a). + #[cfg_attr(not(feature = "test-support"), allow(unused_variables))] pub fn child_env(&self, cmd: &mut std::process::Command) { - if let Some(dir) = &self.path_prepend { - let path = std::env::var("PATH").unwrap_or_default(); - cmd.env("PATH", format!("{}:{path}", dir.display())); - } - if let Some(m) = &self.shim_manifest { - cmd.env("AUR_SHIM_MANIFEST", m); - } - if let Some(d) = &self.shim_dir { - cmd.env("AUR_SHIM_DIR", d); - } - if let Some(f) = &self.shim_fail { - cmd.env("AUR_SHIM_FAIL", f); - } - if let Some(k) = &self.shim_kill_parent { - cmd.env("AUR_SHIM_KILL_PARENT", k); - } - if let Some(l) = &self.shim_plant_link { - cmd.env("AUR_SHIM_PLANT_LINK", l); + // Without `test-support` there is no shim protocol to export and no + // PATH to rewrite: the child inherits the real environment, which is + // what a real build needs (§16a). + #[cfg(feature = "test-support")] + { + let h = &self.hooks; + if let Some(dir) = &h.path_prepend { + let path = std::env::var("PATH").unwrap_or_default(); + cmd.env("PATH", format!("{}:{path}", dir.display())); + } + if let Some(m) = &h.shim_manifest { + cmd.env("AUR_SHIM_MANIFEST", m); + } + if let Some(d) = &h.shim_dir { + cmd.env("AUR_SHIM_DIR", d); + } + if let Some(f) = &h.shim_fail { + cmd.env("AUR_SHIM_FAIL", f); + } + if let Some(k) = &h.shim_kill_parent { + cmd.env("AUR_SHIM_KILL_PARENT", k); + } + if let Some(l) = &h.shim_plant_link { + cmd.env("AUR_SHIM_PLANT_LINK", l); + } } } diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 4f21e72..d70ba8d 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -117,7 +117,9 @@ pub fn publish(ctx: &Ctx) -> Result<i64> { // Fault injection so I4 can be tested for real: die between the tmp write // and the rename, and the old index must still be what consumers get. - if ctx.cfg.publish_fault.as_deref() == Some("before-rename") { + // Compiled out of a production build (§6 M-9). + #[cfg(feature = "test-support")] + if ctx.cfg.hooks.publish_fault.as_deref() == Some("before-rename") { return Err(Error::other("injected fault: before-rename")); } @@ -148,7 +150,8 @@ pub fn publish(ctx: &Ctx) -> Result<i64> { "unblocked_builds": unblocked, }), )?; - if ctx.cfg.publish_fault.as_deref() == Some("after-rename") { + #[cfg(feature = "test-support")] + if ctx.cfg.hooks.publish_fault.as_deref() == Some("after-rename") { return Err(Error::other("injected fault: after-rename")); } Ok(release_id) |
