From 6b136dfd23c03cc61d189ad5d41dd881e45b677e Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 30 Dec 2023 03:01:59 +0100 Subject: feat(tvix/glue): emit a warning in case of bad SRI hashes And include a test to ensure we show the warning. Change-Id: Ib6a436dbba2592b398b54e44f15a48d1aa345099 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10470 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/glue/src/builtins/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tvix/glue/src/builtins/mod.rs') diff --git a/tvix/glue/src/builtins/mod.rs b/tvix/glue/src/builtins/mod.rs index 86924cefef7f..aeae8a7c3baa 100644 --- a/tvix/glue/src/builtins/mod.rs +++ b/tvix/glue/src/builtins/mod.rs @@ -154,4 +154,24 @@ mod tests { "/171rf4jhx57xqz3p7swniwkig249cif71pa08p80mgaf0mqz5bmr" ); } + + /// constructs calls to builtins.derivation that should succeed, but produce warnings + #[test_case(r#"(builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; outputHashMode = "recursive"; outputHashAlgo = "sha256"; outputHash = "sha256-fgIr3TyFGDAXP5+qoAaiMKDg/a1MlT6Fv/S/DaA24S8===="; }).outPath"#, "/nix/store/xm1l9dx4zgycv9qdhcqqvji1z88z534b-foo"; "r:sha256 wrong padding")] + fn builtins_derivation_hash_wrong_padding_warn(code: &str, expected_path: &str) { + let eval_result = eval(code); + + let value = eval_result.value.expect("must succeed"); + + match value { + tvix_eval::Value::String(s) => { + assert_eq!(expected_path, s.as_str()); + } + _ => panic!("unexpected value type: {:?}", value), + } + + assert!( + !eval_result.warnings.is_empty(), + "warnings should not be empty" + ); + } } -- cgit 1.4.1