about summary refs log tree commit diff
path: root/tvix/nix-compat/src/derivation
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-21T17·50+0100
committerflokli <flokli@flokli.de>2023-10-23T14·57+0000
commit6fe76848323d99129da415d63dd9880d6d580f15 (patch)
tree4a119c6b3661e5669fa8e186cdc502951c893bfa /tvix/nix-compat/src/derivation
parent34fc4637ebbb906d38647ca8a12fdb80cd2baf18 (diff)
fix(nix-compat/src/derivation/validate): remove break r/6872
If the output was fixed, we broke out of the for loop too early, before
actually validating individual outputs.

Change-Id: I2259697dfa2a157764358f6d326a1f7f6610647c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9815
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/nix-compat/src/derivation')
-rw-r--r--tvix/nix-compat/src/derivation/validate.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/tvix/nix-compat/src/derivation/validate.rs b/tvix/nix-compat/src/derivation/validate.rs
index 6b81c4c80b86..3474dcb5dbbb 100644
--- a/tvix/nix-compat/src/derivation/validate.rs
+++ b/tvix/nix-compat/src/derivation/validate.rs
@@ -43,8 +43,6 @@ impl Derivation {
                         output_name.to_string(),
                     ));
                 }
-
-                break;
             }
 
             if let Err(e) = output.validate(validate_output_paths) {
@@ -127,3 +125,34 @@ impl Derivation {
         Ok(())
     }
 }
+
+#[cfg(test)]
+mod test {
+    use std::collections::BTreeMap;
+
+    use crate::derivation::{CAHash, Derivation, Output};
+
+    /// Regression test: produce a Derivation that's almost valid, except its
+    /// fixed-output output has the wrong hash specified.
+    #[test]
+    fn output_validate() {
+        let mut outputs = BTreeMap::new();
+        outputs.insert(
+            "out".to_string(),
+            Output {
+                path: "".to_string(),
+                ca_hash: Some(CAHash::Text(Box::new([0; 32]))), // This is disallowed
+            },
+        );
+
+        let drv = Derivation {
+            arguments: vec![],
+            builder: "/bin/sh".to_string(),
+            outputs,
+            system: "x86_64-linux".to_string(),
+            ..Default::default()
+        };
+
+        drv.validate(false).expect_err("must fail");
+    }
+}