-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(claimer): update claimer for repository
- Loading branch information
Showing
7 changed files
with
23 additions
and
106 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
use std::fmt; | ||
pub use url::{self, Url}; | ||
|
||
/// Wrapper that redacts the entire field | ||
#[derive(Clone)] | ||
|
@@ -33,85 +32,3 @@ fn redacts_debug_fmt() { | |
let password = Redacted::new("super-security"); | ||
assert_eq!(format!("{:?}", password), "[REDACTED]"); | ||
} | ||
|
||
/// Wrapper that redacts the credentials in an URL | ||
#[derive(Clone)] | ||
pub struct RedactedUrl(Url); | ||
|
||
impl RedactedUrl { | ||
// pub fn new(url: Url) -> Self { | ||
// Self(url) | ||
// } | ||
|
||
pub fn inner(&self) -> &Url { | ||
&self.0 | ||
} | ||
|
||
// pub fn into_inner(self) -> Url { | ||
// self.0 | ||
// } | ||
} | ||
|
||
impl fmt::Debug for RedactedUrl { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let mut url = self.inner().clone(); | ||
let result = { | ||
if url.cannot_be_a_base() { | ||
Err(()) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
.and_then(|_| { | ||
if !url.username().is_empty() { | ||
url.set_username("***") | ||
} else { | ||
Ok(()) | ||
} | ||
}) | ||
.and_then(|_| { | ||
if url.password().is_some() { | ||
url.set_password(Some("***")) | ||
} else { | ||
Ok(()) | ||
} | ||
}); | ||
match result { | ||
Ok(_) => write!(f, "{}", url.as_str()), | ||
Err(_) => write!(f, "[NON-BASE URL REDACTED]"), | ||
} | ||
} | ||
} | ||
|
||
// #[test] | ||
// fn redacts_valid_url_without_credentials() { | ||
// let url = RedactedUrl::new(Url::parse("http://example.com/").unwrap()); | ||
// assert_eq!(format!("{:?}", url), "http://example.com/"); | ||
// } | ||
|
||
// #[test] | ||
// fn redacts_valid_url_with_username() { | ||
// let url = | ||
// RedactedUrl::new(Url::parse("http://[email protected]/").unwrap()); | ||
// assert_eq!(format!("{:?}", url), "http://***@example.com/"); | ||
// } | ||
|
||
// #[test] | ||
// fn redacts_valid_url_with_password() { | ||
// let url = | ||
// RedactedUrl::new(Url::parse("http://:[email protected]/").unwrap()); | ||
// assert_eq!(format!("{:?}", url), "http://:***@example.com/"); | ||
// } | ||
|
||
// #[test] | ||
// fn redacts_valid_url_with_full_credentials() { | ||
// let url = | ||
// RedactedUrl::new(Url::parse("http://james:[email protected]/").unwrap()); | ||
// assert_eq!(format!("{:?}", url), "http://***:***@example.com/"); | ||
// } | ||
|
||
// #[test] | ||
// fn redacts_non_base_url() { | ||
// let url = RedactedUrl::new(Url::parse("james:[email protected]").unwrap()); | ||
// assert_eq!(format!("{:?}", url), "[NON-BASE URL REDACTED]"); | ||
// } |
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