Skip to content

Commit

Permalink
fix: netrc parsing into BasicAuth (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Feb 1, 2024
1 parent c7e0cb0 commit 8098f1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion crates/rattler_networking/src/authentication_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl AuthenticationMiddleware {
let mut header_value = reqwest::header::HeaderValue::from_str(&basic_auth)
.expect("base64 can always be converted to a header value");
header_value.set_sensitive(true);

req.headers_mut()
.insert(reqwest::header::AUTHORIZATION, header_value);
Ok(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ impl NetRcStorage {
}

/// Retrieve the authentication information for the given host
pub fn get_password(&self, host: &str) -> Result<Option<String>, NetRcStorageError> {
pub fn get_password(&self, host: &str) -> Result<Option<Authentication>, NetRcStorageError> {
match self.machines.get(host) {
Some(machine) => Ok(machine.password.clone()),
Some(machine) => Ok(Some(Authentication::BasicHTTP {
username: machine.login.clone().unwrap_or_default(),
password: machine.password.clone().unwrap_or_default(),
})),
None => Ok(None),
}
}
Expand All @@ -89,10 +92,7 @@ impl StorageBackend for NetRcStorage {

fn get(&self, host: &str) -> anyhow::Result<Option<Authentication>> {
match self.get_password(host) {
Ok(Some(password)) => Ok(Some(Authentication::BasicHTTP {
username: host.to_string(),
password,
})),
Ok(Some(auth)) => Ok(Some(auth)),
Ok(None) => Ok(None),
Err(err) => Err(anyhow::Error::new(err)),
}
Expand All @@ -112,13 +112,13 @@ mod tests {

let mut netrc = std::fs::File::create(&path).unwrap();
netrc
.write_all(b"machine test\nlogin test\npassword password\n")
.write_all(b"machine mainmachine\nlogin test\npassword password\n")
.unwrap();
netrc.flush().unwrap();

let storage = NetRcStorage::from_path(path.as_path()).unwrap();
assert_eq!(
storage.get("test").unwrap(),
storage.get("mainmachine").unwrap(),
Some(Authentication::BasicHTTP {
username: "test".to_string(),
password: "password".to_string(),
Expand All @@ -135,7 +135,7 @@ mod tests {

let mut netrc = std::fs::File::create(&path).unwrap();
netrc
.write_all(b"machine test2\nlogin test2\npassword password2\n")
.write_all(b"machine supermachine\nlogin test2\npassword password2\n")
.unwrap();
netrc.flush().unwrap();

Expand All @@ -145,7 +145,7 @@ mod tests {
let storage = NetRcStorage::from_env().unwrap();

assert_eq!(
storage.get("test2").unwrap(),
storage.get("supermachine").unwrap(),
Some(Authentication::BasicHTTP {
username: "test2".to_string(),
password: "password2".to_string(),
Expand Down

0 comments on commit 8098f1d

Please sign in to comment.