@@ -268,6 +268,8 @@ async fn views_prohibited() -> Result<()> {
268
268
269
269
// Prose test 7. Custom Endpoint
270
270
mod custom_endpoint {
271
+ use crate :: client_encryption:: KmipMasterKey ;
272
+
271
273
use super :: * ;
272
274
273
275
async fn custom_endpoint_aws_ok ( endpoint : Option < String > ) -> Result < ( ) > {
@@ -310,18 +312,14 @@ mod custom_endpoint {
310
312
311
313
// case 4
312
314
#[ tokio:: test]
313
- async fn aws_invalid_port ( ) -> Result < ( ) > {
315
+ async fn kmip_invalid_port ( ) -> Result < ( ) > {
314
316
let client_encryption = custom_endpoint_setup ( true ) . await ?;
315
317
316
318
let result = client_encryption
317
319
. 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 ( ) )
325
323
. build ( ) ,
326
324
)
327
325
. await ;
@@ -442,6 +440,59 @@ mod custom_endpoint {
442
440
443
441
Ok ( ( ) )
444
442
}
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
+ }
445
496
}
446
497
447
498
// Prose test 8. Bypass Spawning mongocryptd
0 commit comments