Skip to content

Commit 9cedb09

Browse files
authored
RUST-1060 Omit non-pub fields from Debug output of ClientOptions (#517)
1 parent 1ca6570 commit 9cedb09

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/client/options/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub struct ClientOptions {
290290
pub app_name: Option<String>,
291291

292292
#[builder(default)]
293+
#[derivative(Debug = "ignore")]
293294
pub(crate) compressors: Option<Vec<String>>,
294295

295296
/// The handler that should process all Connection Monitoring and Pooling events. See the
@@ -404,6 +405,7 @@ pub struct ClientOptions {
404405
///
405406
/// The default value is to have no declared API version
406407
#[builder(default, skip)]
408+
#[derivative(Debug = "ignore")]
407409
pub(crate) server_api: Option<ServerApi>,
408410

409411
/// The amount of time the Client should attempt to select a server for an operation before
@@ -414,6 +416,7 @@ pub struct ClientOptions {
414416
pub server_selection_timeout: Option<Duration>,
415417

416418
#[builder(default)]
419+
#[derivative(Debug = "ignore")]
417420
pub(crate) socket_timeout: Option<Duration>,
418421

419422
/// The TLS configuration for the Client to use in its connections with the server.
@@ -439,9 +442,11 @@ pub struct ClientOptions {
439442
pub(crate) zlib_compression: Option<i32>,
440443

441444
#[builder(default)]
445+
#[derivative(Debug = "ignore")]
442446
pub(crate) original_srv_hostname: Option<String>,
443447

444448
#[builder(default)]
449+
#[derivative(Debug = "ignore")]
445450
pub(crate) original_uri: Option<String>,
446451

447452
/// Configuration of the trust-dns resolver used for SRV and TXT lookups.
@@ -451,10 +456,12 @@ pub struct ClientOptions {
451456
/// configuration, so a custom configuration is recommended.
452457
#[builder(default)]
453458
#[serde(skip)]
459+
#[derivative(Debug = "ignore")]
454460
pub(crate) resolver_config: Option<ResolverConfig>,
455461

456462
/// Used by tests to override MIN_HEARTBEAT_FREQUENCY.
457463
#[builder(default)]
464+
#[derivative(Debug = "ignore")]
458465
pub(crate) heartbeat_freq_test: Option<Duration>,
459466
}
460467

src/client/options/test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,15 @@ async fn parse_unknown_options() {
372372
.await;
373373
parse_uri("maxstalenessms", Some("maxstalenessseconds")).await;
374374
}
375+
376+
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
377+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
378+
async fn options_debug_omits_uri() {
379+
let uri = "mongodb://username:password@localhost/";
380+
let options = ClientOptions::parse(uri).await.unwrap();
381+
382+
let debug_output = format!("{:?}", options);
383+
assert!(!debug_output.contains("username"));
384+
assert!(!debug_output.contains("password"));
385+
assert!(!debug_output.contains("uri"));
386+
}

0 commit comments

Comments
 (0)