Skip to content

Commit f555079

Browse files
authored
RUST-1060 Omit non-pub fields from debug output of ClientOptions (#512)
1 parent 67d08ef commit f555079

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/client/options/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ pub struct ClientOptions {
529529
pub default_database: Option<String>,
530530

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

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

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

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

562566
/// Control test behavior of the client.

src/client/options/test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,15 @@ async fn parse_with_no_default_database() {
270270
}
271271
);
272272
}
273+
274+
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
275+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
276+
async fn options_debug_omits_uri() {
277+
let uri = "mongodb://username:password@localhost/";
278+
let options = ClientOptions::parse(uri).await.unwrap();
279+
280+
let debug_output = format!("{:?}", options);
281+
assert!(!debug_output.contains("username"));
282+
assert!(!debug_output.contains("password"));
283+
assert!(!debug_output.contains("uri"));
284+
}

0 commit comments

Comments
 (0)