diff --git a/lib/cli/src/commands/auth/login/mod.rs b/lib/cli/src/commands/auth/login/mod.rs index 0c3a2bf8dee..9a2da3cc5da 100644 --- a/lib/cli/src/commands/auth/login/mod.rs +++ b/lib/cli/src/commands/auth/login/mod.rs @@ -181,6 +181,7 @@ impl Login { } #[cfg(test)] { + _ = user; false } } else { diff --git a/lib/cli/src/commands/package/download.rs b/lib/cli/src/commands/package/download.rs index 8a9a7a48ea9..c4a79e24611 100644 --- a/lib/cli/src/commands/package/download.rs +++ b/lib/cli/src/commands/package/download.rs @@ -279,8 +279,6 @@ impl PackageDownload { #[cfg(test)] mod tests { - use crate::config::UserRegistry; - use super::*; /// Download a package from the dev registry. diff --git a/lib/cli/src/config/env.rs b/lib/cli/src/config/env.rs index 0048627d1b5..0a3fbf9d1fc 100644 --- a/lib/cli/src/config/env.rs +++ b/lib/cli/src/config/env.rs @@ -56,12 +56,11 @@ impl WasmerEnv { let mut url = self.registry_endpoint()?; url.set_path(""); - let domain = url - .host_str() - .context("url has no host")? - .strip_prefix("registry.") - .context("could not derive registry public url")? - .to_string(); + let mut domain = url.host_str().context("url has no host")?.to_string(); + if domain.starts_with("registry.") { + domain = domain.strip_prefix("registry.").unwrap().to_string(); + } + url.set_host(Some(&domain)) .context("could not derive registry public url")?; @@ -209,6 +208,10 @@ mod tests { [[registry.tokens]] registry = "https://registry.wasmer.io/graphql" token = "prod-token" + + [[registry.tokens]] + registry = "http://localhost:11/graphql" + token = "invalid" "#; #[test] @@ -310,4 +313,35 @@ mod tests { assert_eq!(env.token().unwrap(), "prod-token"); assert_eq!(env.cache_dir(), expected_cache_dir); } + + #[test] + fn registries_have_public_url() { + let temp = TempDir::new().unwrap(); + std::fs::write(temp.path().join("wasmer.toml"), WASMER_TOML).unwrap(); + + let inputs = [ + ("https://wasmer.io/", "https://registry.wasmer.io/graphql"), + ("https://wasmer.wtf/", "https://registry.wasmer.wtf/graphql"), + ("https://wasmer.wtf/", "https://registry.wasmer.wtf/graphql"), + ( + "https://wasmer.wtf/", + "https://registry.wasmer.wtf/something/else", + ), + ("https://wasmer.wtf/", "https://wasmer.wtf/graphql"), + ("https://wasmer.wtf/", "https://wasmer.wtf/graphql"), + ("http://localhost:8000/", "http://localhost:8000/graphql"), + ("http://localhost:8000/", "http://localhost:8000/graphql"), + ]; + + for (want, input) in inputs { + let env = WasmerEnv { + wasmer_dir: temp.path().to_path_buf(), + registry: Some(UserRegistry::from(input)), + cache_dir: temp.path().join("cache").to_path_buf(), + token: None, + }; + + assert_eq!(want, &env.registry_public_url().unwrap().to_string()) + } + } } diff --git a/lib/registry/src/wasmer_env.rs b/lib/registry/src/wasmer_env.rs index 5ba71834693..dbcc267a717 100644 --- a/lib/registry/src/wasmer_env.rs +++ b/lib/registry/src/wasmer_env.rs @@ -46,12 +46,10 @@ impl WasmerEnv { let mut url = self.registry_endpoint()?; url.set_path(""); - let domain = url - .host_str() - .context("url has no host")? - .strip_prefix("registry.") - .context("could not derive registry public url")? - .to_string(); + let mut domain = url.host_str().context("url has no host")?.to_string(); + if domain.starts_with("registry.") { + domain = domain.strip_prefix("registry.").unwrap().to_string(); + } url.set_host(Some(&domain)) .context("could not derive registry public url")?;