Skip to content

Commit

Permalink
Merge pull request #4331 from wasmerio/validate-nonexistent-packages
Browse files Browse the repository at this point in the history
Fix visibility validation to work when publishing a new package
  • Loading branch information
Michael Bryan authored Nov 28, 2023
2 parents 13ded1d + 46f934c commit 476d95d
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 115 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ impl fmt::Display for QueryPackageError {
match self {
QueryPackageError::ErrorSendingQuery(q) => write!(f, "error sending query: {q}"),
QueryPackageError::NoPackageFound { name, version } => {
write!(f, "no package found for {name:?} (version = {version:?})")
write!(f, "no package found for {name:?}")?;
if let Some(version) = version {
write!(f, " (version = {version:?})")?;
}

Ok(())
}
}
}
Expand Down Expand Up @@ -170,9 +175,13 @@ pub fn query_package_from_registry(
QueryPackageError::ErrorSendingQuery(format!("Error sending GetPackagesQuery: {e}"))
})?;

let v = response.package_version.as_ref().ok_or_else(|| {
QueryPackageError::ErrorSendingQuery(format!("no package version for {name:?}"))
})?;
let v = response
.package_version
.as_ref()
.ok_or_else(|| QueryPackageError::NoPackageFound {
name: name.to_string(),
version: None,
})?;

let manifest = toml::from_str::<wasmer_toml::Manifest>(&v.manifest).map_err(|e| {
QueryPackageError::ErrorSendingQuery(format!("Invalid manifest for crate {name:?}: {e}"))
Expand Down
13 changes: 10 additions & 3 deletions lib/registry/src/package/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,21 @@ mod validate {
registry: &str,
auth_token: &str,
) -> Result<bool, ValidationError> {
let package_version = crate::query_package_from_registry(
let result = crate::query_package_from_registry(
registry,
&manifest.package.name,
None,
Some(auth_token),
)?;
);

Ok(package_version.is_private != manifest.package.private)
match result {
Ok(package_version) => Ok(package_version.is_private != manifest.package.private),
Err(QueryPackageError::NoPackageFound { .. }) => {
// The package hasn't been published yet
Ok(false)
}
Err(e) => Err(e.into()),
}
}

fn validate_module(
Expand Down
Loading

0 comments on commit 476d95d

Please sign in to comment.