Skip to content

Commit 1fc1611

Browse files
authored
RUST-873 Test redaction of replies to security-sensitive commands (#403)
1 parent cdbae2d commit 1fc1611

File tree

8 files changed

+365
-91
lines changed

8 files changed

+365
-91
lines changed

src/client/executor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
};
3232

3333
lazy_static! {
34-
static ref REDACTED_COMMANDS: HashSet<&'static str> = {
34+
pub(crate) static ref REDACTED_COMMANDS: HashSet<&'static str> = {
3535
let mut hash_set = HashSet::new();
3636
hash_set.insert("authenticate");
3737
hash_set.insert("saslstart");
@@ -356,12 +356,14 @@ impl Client {
356356
cmd.set_server_api(server_api);
357357
}
358358

359-
self.emit_command_event(|handler| {
359+
let should_redact = {
360360
let name = cmd.name.to_lowercase();
361-
let should_redact = REDACTED_COMMANDS.contains(name.as_str())
361+
REDACTED_COMMANDS.contains(name.as_str())
362362
|| HELLO_COMMAND_NAMES.contains(name.as_str())
363-
&& cmd.body.contains_key("speculativeAuthenticate");
363+
&& cmd.body.contains_key("speculativeAuthenticate")
364+
};
364365

366+
self.emit_command_event(|handler| {
365367
let command_body = if should_redact {
366368
Document::new()
367369
} else {
@@ -471,8 +473,6 @@ impl Client {
471473
}
472474
Ok(response) => {
473475
self.emit_command_event(|handler| {
474-
let should_redact =
475-
REDACTED_COMMANDS.contains(cmd_name.to_lowercase().as_str());
476476
let reply = if should_redact {
477477
Document::new()
478478
} else {

src/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use bson::Bson;
99
use derivative::Derivative;
1010
use std::time::Instant;
1111

12+
#[cfg(test)]
13+
pub(crate) use self::executor::REDACTED_COMMANDS;
1214
#[cfg(test)]
1315
use crate::options::ServerAddress;
1416
use crate::{

0 commit comments

Comments
 (0)