@@ -6218,10 +6218,9 @@ test_auto_datakeys (void *unused)
6218
6218
require (
6219
6219
keyWithType ("0" , doc ), //
6220
6220
parse (require (allOf (key ("keyId" ), strEqual ("keepme" )), nop ))),
6221
- require (
6222
- keyWithType ("1" , doc ),
6223
- parse (require (allOf (keyWithType ("keyId" , int32 )),
6224
- do (ASSERT_CMPINT32 (bsonAs (int32 ), = = , 42 ))))));
6221
+ require (keyWithType ("1" , doc ),
6222
+ parse (require (allOf (keyWithType ("keyId" , int32 )),
6223
+ do (ASSERT_CMPINT32 (bsonAs (int32 ), = = , 42 ))))));
6225
6224
ASSERT (bsonParseError == NULL );
6226
6225
bson_destroy (& out_fields );
6227
6226
@@ -6245,12 +6244,28 @@ test_auto_datakeys (void *unused)
6245
6244
}
6246
6245
6247
6246
static void
6248
- test_create_encrypted_collection_simple (void * unused )
6247
+ _do_cec_test (void (* test ) (const char * kmsProvider ))
6248
+ {
6249
+ test ("local" );
6250
+ test ("aws" );
6251
+ }
6252
+
6253
+ // Declare a createEncryptedCollection test case (See usage below)
6254
+ #define CEC_TEST (name , ...) \
6255
+ static void name##_impl (__VA_ARGS__); \
6256
+ static void name (void *unused) \
6257
+ { \
6258
+ BSON_UNUSED (unused); \
6259
+ _do_cec_test (name##_impl); \
6260
+ } \
6261
+ static void name##_impl (__VA_ARGS__)
6262
+
6263
+ CEC_TEST (test_create_encrypted_collection_simple , const char * kmsProvider )
6249
6264
{
6250
- BSON_UNUSED (unused );
6251
6265
bson_error_t error = {0 };
6252
6266
mongoc_client_t * const client = test_framework_new_default_client ();
6253
- bson_t * const kmsProviders = _make_kms_providers (false, true);
6267
+ bson_t * const kmsProviders = _make_kms_providers (true, true);
6268
+ bson_t * const tlsOptions = _make_tls_opts ();
6254
6269
6255
6270
const char * const dbName = "cec-test-db" ;
6256
6271
@@ -6275,6 +6290,7 @@ test_create_encrypted_collection_simple (void *unused)
6275
6290
mongoc_client_encryption_opts_t * const ceOpts =
6276
6291
mongoc_client_encryption_opts_new ();
6277
6292
mongoc_client_encryption_opts_set_kms_providers (ceOpts , kmsProviders );
6293
+ mongoc_client_encryption_opts_set_tls_opts (ceOpts , tlsOptions );
6278
6294
mongoc_client_encryption_opts_set_keyvault_namespace (
6279
6295
ceOpts , "keyvault" , "datakeys" );
6280
6296
mongoc_client_encryption_opts_set_keyvault_client (ceOpts , client );
@@ -6291,13 +6307,13 @@ test_create_encrypted_collection_simple (void *unused)
6291
6307
kv ("bsonType" , cstr ("string" )),
6292
6308
kv ("keyId" , null )))))));
6293
6309
mongoc_database_t * const db = mongoc_client_get_database (client , dbName );
6294
- mongoc_client_encryption_datakey_opts_t * const dkOpts =
6295
- mongoc_client_encryption_datakey_opts_new ();
6310
+ bson_t * const mkey = _make_kms_masterkey (kmsProvider );
6296
6311
mongoc_collection_t * const coll =
6297
6312
mongoc_client_encryption_create_encrypted_collection (
6298
- ce , db , "test-coll" , & ccOpts , NULL , "local" , dkOpts , & error );
6313
+ ce , db , "test-coll" , & ccOpts , NULL , kmsProvider , mkey , & error );
6299
6314
ASSERT_OR_PRINT (coll , error );
6300
6315
bson_destroy (& ccOpts );
6316
+ bson_destroy (mkey );
6301
6317
6302
6318
bsonBuildDecl (doc , kv ("ssn" , cstr ("123-45-6789" )));
6303
6319
const bool okay =
@@ -6310,7 +6326,7 @@ test_create_encrypted_collection_simple (void *unused)
6310
6326
bson_destroy (& doc );
6311
6327
6312
6328
bson_destroy (kmsProviders );
6313
- mongoc_client_encryption_datakey_opts_destroy ( dkOpts );
6329
+ bson_destroy ( tlsOptions );
6314
6330
mongoc_collection_destroy (coll );
6315
6331
mongoc_database_drop (db , & error );
6316
6332
mongoc_database_destroy (db );
@@ -6320,10 +6336,14 @@ test_create_encrypted_collection_simple (void *unused)
6320
6336
6321
6337
static void
6322
6338
test_create_encrypted_collection_no_encryptedFields_helper (
6323
- mongoc_client_t * client , const char * dbName , const char * collName )
6339
+ mongoc_client_t * client ,
6340
+ const char * dbName ,
6341
+ const char * collName ,
6342
+ const char * kmsProvider )
6324
6343
{
6325
6344
bson_error_t error = {0 };
6326
- bson_t * const kmsProviders = _make_kms_providers (false, true);
6345
+ bson_t * const kmsProviders = _make_kms_providers (true, true);
6346
+ bson_t * const tlsOptions = _make_tls_opts ();
6327
6347
6328
6348
// Drop prior data
6329
6349
{
@@ -6346,6 +6366,7 @@ test_create_encrypted_collection_no_encryptedFields_helper (
6346
6366
mongoc_client_encryption_opts_t * const ceOpts =
6347
6367
mongoc_client_encryption_opts_new ();
6348
6368
mongoc_client_encryption_opts_set_kms_providers (ceOpts , kmsProviders );
6369
+ mongoc_client_encryption_opts_set_tls_opts (ceOpts , tlsOptions );
6349
6370
mongoc_client_encryption_opts_set_keyvault_namespace (
6350
6371
ceOpts , "keyvault" , "datakeys" );
6351
6372
mongoc_client_encryption_opts_set_keyvault_client (ceOpts , client );
@@ -6355,41 +6376,38 @@ test_create_encrypted_collection_no_encryptedFields_helper (
6355
6376
ASSERT_OR_PRINT (ce , error );
6356
6377
6357
6378
// Create the encrypted collection
6358
- bsonBuildDecl (ccOpts , do ());
6379
+ bsonBuildDecl (ccOpts , do ());
6359
6380
mongoc_database_t * const db = mongoc_client_get_database (client , dbName );
6360
- mongoc_client_encryption_datakey_opts_t * const dkOpts =
6361
- mongoc_client_encryption_datakey_opts_new ();
6381
+ bson_t * const mkey = _make_kms_masterkey (kmsProvider );
6362
6382
mongoc_collection_t * const coll =
6363
6383
mongoc_client_encryption_create_encrypted_collection (
6364
- ce , db , collName , & ccOpts , NULL , "local" , dkOpts , & error );
6384
+ ce , db , collName , & ccOpts , NULL , kmsProvider , mkey , & error );
6365
6385
ASSERT_ERROR_CONTAINS (error ,
6366
6386
MONGOC_ERROR_COMMAND ,
6367
6387
MONGOC_ERROR_COMMAND_INVALID_ARG ,
6368
6388
"No 'encryptedFields' are defined" );
6369
6389
bson_destroy (& ccOpts );
6390
+ bson_destroy (mkey );
6370
6391
6371
6392
bson_destroy (kmsProviders );
6372
- mongoc_client_encryption_datakey_opts_destroy ( dkOpts );
6393
+ bson_destroy ( tlsOptions );
6373
6394
mongoc_collection_destroy (coll );
6374
6395
mongoc_database_drop (db , & error );
6375
6396
mongoc_database_destroy (db );
6376
6397
mongoc_client_encryption_destroy (ce );
6377
6398
}
6378
6399
6379
-
6380
- static void
6381
- test_create_encrypted_collection_no_encryptedFields (void * unused )
6400
+ CEC_TEST (test_create_encrypted_collection_no_encryptedFields ,
6401
+ const char * kmsProvider )
6382
6402
{
6383
- BSON_UNUSED (unused );
6384
-
6385
6403
const char * dbName = "cec-test-db" ;
6386
6404
const char * collName = "test-coll" ;
6387
6405
6388
6406
// Test with a default client.
6389
6407
{
6390
6408
mongoc_client_t * const client = test_framework_new_default_client ();
6391
6409
test_create_encrypted_collection_no_encryptedFields_helper (
6392
- client , dbName , collName );
6410
+ client , dbName , collName , kmsProvider );
6393
6411
mongoc_client_destroy (client );
6394
6412
}
6395
6413
@@ -6401,7 +6419,7 @@ test_create_encrypted_collection_no_encryptedFields (void *unused)
6401
6419
mongoc_auto_encryption_opts_t * aeOpts =
6402
6420
mongoc_auto_encryption_opts_new ();
6403
6421
bson_t * const kmsProviders =
6404
- _make_kms_providers (false /* with aws */ , true /* with local */ );
6422
+ _make_kms_providers (true /* with aws */ , true /* with local */ );
6405
6423
char * namespace = bson_strdup_printf ("%s.%s" , dbName , collName );
6406
6424
bson_t * encryptedFieldsMap =
6407
6425
tmp_bson ("{'%s': {'fields': []}}" , namespace );
@@ -6416,7 +6434,7 @@ test_create_encrypted_collection_no_encryptedFields (void *unused)
6416
6434
mongoc_client_enable_auto_encryption (client , aeOpts , & error ), error );
6417
6435
6418
6436
test_create_encrypted_collection_no_encryptedFields_helper (
6419
- client , dbName , collName );
6437
+ client , dbName , collName , kmsProvider );
6420
6438
6421
6439
bson_free (namespace );
6422
6440
bson_destroy (kmsProviders );
@@ -6425,13 +6443,13 @@ test_create_encrypted_collection_no_encryptedFields (void *unused)
6425
6443
}
6426
6444
}
6427
6445
6428
- static void
6429
- test_create_encrypted_collection_bad_keyId ( void * unused )
6446
+ CEC_TEST ( test_create_encrypted_collection_bad_keyId ,
6447
+ const char * const kmsProvider )
6430
6448
{
6431
- BSON_UNUSED (unused );
6432
6449
bson_error_t error = {0 };
6433
6450
mongoc_client_t * const client = test_framework_new_default_client ();
6434
- bson_t * const kmsProviders = _make_kms_providers (false, true);
6451
+ bson_t * const kmsProviders = _make_kms_providers (true, true);
6452
+ bson_t * const tlsOptions = _make_tls_opts ();
6435
6453
6436
6454
const char * const dbName = "cec-test-db" ;
6437
6455
@@ -6456,6 +6474,7 @@ test_create_encrypted_collection_bad_keyId (void *unused)
6456
6474
mongoc_client_encryption_opts_t * const ceOpts =
6457
6475
mongoc_client_encryption_opts_new ();
6458
6476
mongoc_client_encryption_opts_set_kms_providers (ceOpts , kmsProviders );
6477
+ mongoc_client_encryption_opts_set_tls_opts (ceOpts , tlsOptions );
6459
6478
mongoc_client_encryption_opts_set_keyvault_namespace (
6460
6479
ceOpts , "keyvault" , "datakeys" );
6461
6480
mongoc_client_encryption_opts_set_keyvault_client (ceOpts , client );
@@ -6472,19 +6491,19 @@ test_create_encrypted_collection_bad_keyId (void *unused)
6472
6491
kv ("bsonType" , cstr ("string" )),
6473
6492
kv ("keyId" , bool (true))))))));
6474
6493
mongoc_database_t * const db = mongoc_client_get_database (client , dbName );
6475
- mongoc_client_encryption_datakey_opts_t * const dkOpts =
6476
- mongoc_client_encryption_datakey_opts_new ();
6494
+ bson_t * const mkey = _make_kms_masterkey (kmsProvider );
6477
6495
mongoc_collection_t * const coll =
6478
6496
mongoc_client_encryption_create_encrypted_collection (
6479
- ce , db , "test-coll" , & ccOpts , NULL , "local" , dkOpts , & error );
6497
+ ce , db , "test-coll" , & ccOpts , NULL , kmsProvider , mkey , & error );
6480
6498
ASSERT_ERROR_CONTAINS (error ,
6481
6499
MONGOC_ERROR_QUERY ,
6482
6500
MONGOC_ERROR_PROTOCOL_INVALID_REPLY ,
6483
6501
"create.encryptedFields.fields.keyId" );
6484
6502
bson_destroy (& ccOpts );
6503
+ bson_destroy (mkey );
6485
6504
6486
6505
bson_destroy (kmsProviders );
6487
- mongoc_client_encryption_datakey_opts_destroy ( dkOpts );
6506
+ bson_destroy ( tlsOptions );
6488
6507
mongoc_collection_destroy (coll );
6489
6508
mongoc_database_drop (db , & error );
6490
6509
mongoc_database_destroy (db );
@@ -6493,13 +6512,13 @@ test_create_encrypted_collection_bad_keyId (void *unused)
6493
6512
}
6494
6513
6495
6514
// Implements Prose Test 21. Case: 4.
6496
- static void
6497
- test_create_encrypted_collection_insert ( void * unused )
6515
+ CEC_TEST ( test_create_encrypted_collection_insert ,
6516
+ const char * const kmsProvider )
6498
6517
{
6499
- BSON_UNUSED (unused );
6500
6518
bson_error_t error = {0 };
6501
6519
mongoc_client_t * const client = test_framework_new_default_client ();
6502
- bson_t * const kmsProviders = _make_kms_providers (false, true);
6520
+ bson_t * const kmsProviders = _make_kms_providers (true, true);
6521
+ bson_t * const tlsOptions = _make_tls_opts ();
6503
6522
6504
6523
const char * const dbName = "cec-test-db" ;
6505
6524
@@ -6524,6 +6543,7 @@ test_create_encrypted_collection_insert (void *unused)
6524
6543
mongoc_client_encryption_opts_t * const ceOpts =
6525
6544
mongoc_client_encryption_opts_new ();
6526
6545
mongoc_client_encryption_opts_set_kms_providers (ceOpts , kmsProviders );
6546
+ mongoc_client_encryption_opts_set_tls_opts (ceOpts , tlsOptions );
6527
6547
mongoc_client_encryption_opts_set_keyvault_namespace (
6528
6548
ceOpts , "keyvault" , "datakeys" );
6529
6549
mongoc_client_encryption_opts_set_keyvault_client (ceOpts , client );
@@ -6540,14 +6560,14 @@ test_create_encrypted_collection_insert (void *unused)
6540
6560
kv ("bsonType" , cstr ("string" )),
6541
6561
kv ("keyId" , null )))))));
6542
6562
mongoc_database_t * const db = mongoc_client_get_database (client , dbName );
6543
- mongoc_client_encryption_datakey_opts_t * const dkOpts =
6544
- mongoc_client_encryption_datakey_opts_new ();
6545
6563
bson_t new_opts ;
6564
+ bson_t * const mkey = _make_kms_masterkey (kmsProvider );
6546
6565
mongoc_collection_t * const coll =
6547
6566
mongoc_client_encryption_create_encrypted_collection (
6548
- ce , db , "testing1" , & ccOpts , & new_opts , "local" , dkOpts , & error );
6567
+ ce , db , "testing1" , & ccOpts , & new_opts , kmsProvider , mkey , & error );
6549
6568
ASSERT_OR_PRINT (coll , error );
6550
6569
bson_destroy (& ccOpts );
6570
+ bson_destroy (mkey );
6551
6571
6552
6572
// Extract the encryption key ID that was generated by
6553
6573
// CreateEncryptedCollection:
@@ -6561,7 +6581,7 @@ test_create_encrypted_collection_insert (void *unused)
6561
6581
visitEach (require (type (doc )),
6562
6582
parse (require (key ("keyId" ),
6563
6583
require (type (binary )),
6564
- do ({
6584
+ do ({
6565
6585
bson_value_copy (
6566
6586
bson_iter_value (
6567
6587
(bson_iter_t * ) & bsonVisitIter ),
@@ -6598,7 +6618,7 @@ test_create_encrypted_collection_insert (void *unused)
6598
6618
bson_destroy (& doc );
6599
6619
bson_value_destroy (& ciphertext );
6600
6620
bson_destroy (kmsProviders );
6601
- mongoc_client_encryption_datakey_opts_destroy ( dkOpts );
6621
+ bson_destroy ( tlsOptions );
6602
6622
mongoc_collection_destroy (coll );
6603
6623
mongoc_database_drop (db , & error );
6604
6624
mongoc_database_destroy (db );
0 commit comments