Skip to content

Commit 2633c6d

Browse files
authored
RUST-2206 Fix potential timeouts in CSE tests (#1418)
1 parent 8a96638 commit 2633c6d

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

src/test/csfle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async fn custom_endpoint_setup(valid: bool) -> Result<ClientEncryption> {
240240
if valid {
241241
"localhost:5698"
242242
} else {
243-
"doesnotexist.local:5698"
243+
"doesnotexist.invalid:5698"
244244
},
245245
);
246246
}

src/test/csfle/prose.rs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ async fn views_prohibited() -> Result<()> {
268268

269269
// Prose test 7. Custom Endpoint
270270
mod custom_endpoint {
271+
use crate::client_encryption::KmipMasterKey;
272+
271273
use super::*;
272274

273275
async fn custom_endpoint_aws_ok(endpoint: Option<String>) -> Result<()> {
@@ -310,18 +312,14 @@ mod custom_endpoint {
310312

311313
// case 4
312314
#[tokio::test]
313-
async fn aws_invalid_port() -> Result<()> {
315+
async fn kmip_invalid_port() -> Result<()> {
314316
let client_encryption = custom_endpoint_setup(true).await?;
315317

316318
let result = client_encryption
317319
.create_data_key(
318-
AwsMasterKey::builder()
319-
.region("us-east-1")
320-
.key(
321-
"arn:aws:kms:us-east-1:579766882180:key/\
322-
89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
323-
)
324-
.endpoint(Some("kms.us-east-1.amazonaws.com:12345".to_string()))
320+
KmipMasterKey::builder()
321+
.key_id("1".to_owned())
322+
.endpoint("localhost:12345".to_owned())
325323
.build(),
326324
)
327325
.await;
@@ -442,6 +440,59 @@ mod custom_endpoint {
442440

443441
Ok(())
444442
}
443+
444+
// case 10
445+
#[cfg(feature = "openssl-tls")]
446+
#[tokio::test]
447+
async fn kmip_valid() -> Result<()> {
448+
let master_key = KmipMasterKey::builder().key_id("1".to_owned()).build();
449+
450+
let client_encryption = custom_endpoint_setup(true).await?;
451+
let key_id = client_encryption
452+
.create_data_key(master_key.clone())
453+
.await?;
454+
validate_roundtrip(&client_encryption, key_id).await?;
455+
456+
let client_encryption_invalid = custom_endpoint_setup(false).await?;
457+
let result = client_encryption_invalid.create_data_key(master_key).await;
458+
assert!(result.unwrap_err().is_network_error());
459+
460+
Ok(())
461+
}
462+
463+
// case 11
464+
#[cfg(feature = "openssl-tls")]
465+
#[tokio::test]
466+
async fn kmip_valid_endpoint() -> Result<()> {
467+
let master_key = KmipMasterKey::builder()
468+
.key_id("1".to_owned())
469+
.endpoint("localhost:5698".to_owned())
470+
.build();
471+
472+
let client_encryption = custom_endpoint_setup(true).await?;
473+
let key_id = client_encryption
474+
.create_data_key(master_key.clone())
475+
.await?;
476+
validate_roundtrip(&client_encryption, key_id).await?;
477+
478+
Ok(())
479+
}
480+
481+
// case 12
482+
#[tokio::test]
483+
async fn kmip_invalid() -> Result<()> {
484+
let master_key = KmipMasterKey::builder()
485+
.key_id("1".to_owned())
486+
.endpoint("doesnotexist.invalid:5698".to_owned())
487+
.build();
488+
489+
let client_encryption = custom_endpoint_setup(true).await?;
490+
let result = client_encryption.create_data_key(master_key).await;
491+
let err = result.unwrap_err();
492+
assert!(err.is_network_error());
493+
494+
Ok(())
495+
}
445496
}
446497

447498
// Prose test 8. Bypass Spawning mongocryptd

0 commit comments

Comments
 (0)