diff options
Diffstat (limited to 'cli/args/lockfile.rs')
-rw-r--r-- | cli/args/lockfile.rs | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 87f47255a..db9ace515 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -289,12 +289,7 @@ impl Lockfile { ) -> Result<(), LockfileError> { let specifier = package.id.as_serialized(); if let Some(package_info) = self.content.npm.packages.get(&specifier) { - let integrity = package - .dist - .integrity - .as_ref() - .unwrap_or(&package.dist.shasum); - if &package_info.integrity != integrity { + if package_info.integrity.as_str() != package.dist.integrity().as_str() { return Err(LockfileError(format!( "Integrity check failed for npm package: \"{}\". Unable to verify that the package is the same as when the lockfile was generated. @@ -321,15 +316,10 @@ Use \"--lock-write\" flag to regenerate the lockfile at \"{}\".", .map(|(name, id)| (name.to_string(), id.as_serialized())) .collect::<BTreeMap<String, String>>(); - let integrity = package - .dist - .integrity - .as_ref() - .unwrap_or(&package.dist.shasum); self.content.npm.packages.insert( package.id.as_serialized(), NpmPackageInfo { - integrity: integrity.to_string(), + integrity: package.dist.integrity().to_string(), dependencies, }, ); @@ -545,11 +535,11 @@ mod tests { peer_dependencies: Vec::new(), }, copy_index: 0, - dist: NpmPackageVersionDistInfo { - tarball: "foo".to_string(), - shasum: "foo".to_string(), - integrity: Some("sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==".to_string()) - }, + dist: NpmPackageVersionDistInfo::new( + "foo".to_string(), + "shasum".to_string(), + Some("sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==".to_string()), + ), dependencies: HashMap::new(), }; let check_ok = lockfile.check_or_insert_npm_package(&npm_package); @@ -562,11 +552,11 @@ mod tests { peer_dependencies: Vec::new(), }, copy_index: 0, - dist: NpmPackageVersionDistInfo { - tarball: "foo".to_string(), - shasum: "foo".to_string(), - integrity: Some("sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==".to_string()) - }, + dist: NpmPackageVersionDistInfo::new( + "foo".to_string(), + "shasum".to_string(), + Some("sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==".to_string()), + ), dependencies: HashMap::new(), }; // Integrity is borked in the loaded lockfile @@ -580,11 +570,11 @@ mod tests { peer_dependencies: Vec::new(), }, copy_index: 0, - dist: NpmPackageVersionDistInfo { - tarball: "foo".to_string(), - shasum: "foo".to_string(), - integrity: Some("sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==".to_string()) - }, + dist: NpmPackageVersionDistInfo::new( + "foo".to_string(), + "foo".to_string(), + Some("sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==".to_string()), + ), dependencies: HashMap::new(), }; // Not present in lockfile yet, should be inserted and check passed. @@ -598,11 +588,11 @@ mod tests { peer_dependencies: Vec::new(), }, copy_index: 0, - dist: NpmPackageVersionDistInfo { - tarball: "foo".to_string(), - shasum: "foo".to_string(), - integrity: Some("sha512-foobar".to_string()), - }, + dist: NpmPackageVersionDistInfo::new( + "foo".to_string(), + "foo".to_string(), + Some("sha512-foobar".to_string()), + ), dependencies: HashMap::new(), }; // Now present in lockfile, should file due to borked integrity |