-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't log username/password in binary mirror proxy URLs
- Loading branch information
1 parent
e058acf
commit 60d007d
Showing
6 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use url::Url; | ||
|
||
pub fn sanitize_url(url: &str) -> Option<String> { | ||
Url::parse(url).ok().and_then(|mut parsed_url| { | ||
if parsed_url.username() != "" { | ||
if parsed_url.set_username("").is_err() { | ||
return None; | ||
} | ||
} | ||
|
||
if parsed_url.set_password(None).is_err() { | ||
return None; | ||
} | ||
|
||
Some(parsed_url.to_string()) | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
const UNAUTHENTICATED_URL: &str = "https://rover.apollo.dev/nix/latest"; | ||
const AUTHENTICATED_URL: &str = "https://username:[email protected]/nix/latest"; | ||
const SANITIZED_AUTHENTICATED_URL: &str = "https://customer.proxy/nix/latest"; | ||
|
||
const INVALID_URL: &str = "not-a-url"; | ||
|
||
#[test] | ||
fn it_leaves_unauthenticated_url_alone() { | ||
let sanitized_url = sanitize_url(UNAUTHENTICATED_URL); | ||
assert_eq!(sanitized_url, Some(UNAUTHENTICATED_URL.to_string())); | ||
} | ||
|
||
#[test] | ||
fn it_sanitizes_authenticated_url() { | ||
let sanitized_url = sanitize_url(AUTHENTICATED_URL); | ||
assert_eq!(sanitized_url, Some(SANITIZED_AUTHENTICATED_URL.to_string())); | ||
} | ||
|
||
#[test] | ||
fn it_returns_none_for_invalid_url() { | ||
let sanitized_url = sanitize_url(INVALID_URL); | ||
assert_eq!(sanitized_url, None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters