From a46400668c9d13fab5037e75be6dce853d5cd648 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Fri, 7 Jul 2023 15:08:57 +0200 Subject: [PATCH] also check if credentials stored under wildcard host (#252) * also check if credentials stored under wildcard host * fix up the code --- .../src/authentication_storage/storage.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/rattler_networking/src/authentication_storage/storage.rs b/crates/rattler_networking/src/authentication_storage/storage.rs index c1dd610b2..b7fab6cb5 100644 --- a/crates/rattler_networking/src/authentication_storage/storage.rs +++ b/crates/rattler_networking/src/authentication_storage/storage.rs @@ -154,14 +154,31 @@ impl AuthenticationStorage { } /// Retrieve the authentication information for the given URL + /// (including the authentication information for the wildcard + /// host if no credentials are found for the given host) + /// + /// E.g. if credentials are stored for `*.prefix.dev` and the + /// given URL is `https://repo.prefix.dev`, the credentials + /// for `*.prefix.dev` will be returned. pub fn get_by_url( &self, url: U, ) -> Result<(Url, Option), reqwest::Error> { let url = url.into_url()?; - if let Some(host) = url.host_str() { let credentials = self.get(host); + + let credentials = match credentials { + Ok(None) => { + // Check for credentials under e.g. `*.prefix.dev` + let mut parts = host.rsplitn(2, '.').collect::>(); + parts.reverse(); + let wildcard_host = format!("*.{}", parts.join(".")); + self.get(&wildcard_host) + } + _ => credentials, + }; + match credentials { Ok(None) => Ok((url, None)), Ok(Some(credentials)) => Ok((url, Some(credentials))),