Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST-1060 Omit non-pub fields from debug output of ClientOptions #512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ pub struct ClientOptions {
pub default_database: Option<String>,

#[builder(default, setter(skip))]
#[derivative(Debug = "ignore")]
pub(crate) socket_timeout: Option<Duration>,

/// The TLS configuration for the Client to use in its connections with the server.
Expand All @@ -545,9 +546,11 @@ pub struct ClientOptions {
/// Information from the SRV URI that generated these client options, if applicable.
#[builder(default, setter(skip))]
#[serde(skip)]
#[derivative(Debug = "ignore")]
pub(crate) original_srv_info: Option<OriginalSrvInfo>,

#[builder(default, setter(skip))]
#[derivative(Debug = "ignore")]
pub(crate) original_uri: Option<String>,

/// Configuration of the trust-dns resolver used for SRV and TXT lookups.
Expand All @@ -557,6 +560,7 @@ pub struct ClientOptions {
/// configuration, so a custom configuration is recommended.
#[builder(default, setter(skip))]
#[serde(skip)]
#[derivative(Debug = "ignore")]
pub(crate) resolver_config: Option<ResolverConfig>,

/// Control test behavior of the client.
Expand Down
12 changes: 12 additions & 0 deletions src/client/options/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,15 @@ async fn parse_with_no_default_database() {
}
);
}

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
async fn options_debug_omits_uri() {
let uri = "mongodb://username:password@localhost/";
let options = ClientOptions::parse(uri).await.unwrap();

let debug_output = format!("{:?}", options);
assert!(!debug_output.contains("username"));
assert!(!debug_output.contains("password"));
assert!(!debug_output.contains("uri"));
}