summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs130
1 files changed, 84 insertions, 46 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);
+ }
}
}