14
14
* limitations under the License.
15
15
*/
16
16
17
- #include "TestSuite.h"
18
- #include "bson/bson.h"
19
17
#include "json-test.h"
20
- #include <mongoc/mongoc.h>
21
-
22
18
#include "test-libmongoc.h"
23
19
24
20
#include <common-bson-dsl-private.h>
@@ -344,15 +340,14 @@ _command_started (const mongoc_apm_command_started_t *event)
344
340
limits_apm_ctx_t * ctx ;
345
341
346
342
ctx = (limits_apm_ctx_t * ) mongoc_apm_command_started_get_context (event );
347
- const char * cmd_name = mongoc_apm_command_started_get_command_name (event );
348
- if (0 == strcmp ("insert" , cmd_name ) || 0 == strcmp ("bulkWrite" , cmd_name )) {
343
+ if (0 == strcmp ("insert" , mongoc_apm_command_started_get_command_name (event ))) {
349
344
ctx -> num_inserts ++ ;
350
345
}
351
346
}
352
347
353
348
/* Prose Test 4: BSON Size Limits and Batch Splitting */
354
349
static void
355
- test_bson_size_limits_and_batch_splitting (bool with_qe )
350
+ test_bson_size_limits_and_batch_splitting (void * unused )
356
351
{
357
352
/* Expect an insert of two documents over 2MiB to split into two inserts but
358
353
* still succeed. */
@@ -375,6 +370,8 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
375
370
const int exceeds_2mib_after_encryption = size_2mib - 2000 ;
376
371
const int exceeds_16mib_after_encryption = size_16mib - 2000 ;
377
372
373
+ BSON_UNUSED (unused );
374
+
378
375
/* Do the test setup. */
379
376
380
377
/* Drop and create db.coll configured with limits-schema.json */
@@ -426,7 +423,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
426
423
coll = mongoc_client_get_collection (client , "db" , "coll" );
427
424
/* End of setup */
428
425
429
- /* Case 1 */
430
426
/* Insert { "_id": "over_2mib_under_16mib", "unencrypted": <the string "a"
431
427
* repeated 2097152 times> } */
432
428
docs [0 ] = BCON_NEW ("_id" , "over_2mib_under_16mib" );
@@ -445,23 +441,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
445
441
ASSERT_OR_PRINT (mongoc_collection_insert_one (coll , docs [0 ], NULL /* opts */ , NULL /* reply */ , & error ), error );
446
442
bson_destroy (docs [0 ]);
447
443
448
- /* Check that inserting close to, but not exceeding, 16MiB, passes */
449
- docs [0 ] = bson_new ();
450
- bson_append_utf8 (docs [0 ], "_id" , -1 , "under_16mib" , -1 );
451
- bson_append_utf8 (docs [0 ], "unencrypted" , -1 , as , exceeds_16mib_after_encryption );
452
- ASSERT_OR_PRINT (mongoc_collection_insert_one (coll , docs [0 ], NULL /* opts */ , NULL /* reply */ , & error ), error );
453
- bson_destroy (docs [0 ]);
454
-
455
- /* but.. exceeding 16 MiB fails */
456
- docs [0 ] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-doc.json" );
457
- bson_append_utf8 (docs [0 ], "_id" , -1 , "under_16mib" , -1 );
458
- bson_append_utf8 (docs [0 ], "unencrypted" , -1 , as , exceeds_16mib_after_encryption );
459
- BSON_ASSERT (!mongoc_collection_insert_one (coll , docs [0 ], NULL /* opts */ , NULL /* reply */ , & error ));
460
- ASSERT_ERROR_CONTAINS (error , MONGOC_ERROR_SERVER , 2 , "too large" );
461
- bson_destroy (docs [0 ]);
462
-
463
- /* Case 2: collection bulkWrite */
464
-
465
444
/* Insert two documents that each exceed 2MiB but no encryption occurs.
466
445
* Expect the bulk write to succeed and run as two separate inserts.
467
446
*/
@@ -495,73 +474,20 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
495
474
bson_destroy (docs [0 ]);
496
475
bson_destroy (docs [1 ]);
497
476
498
- if (with_qe ) {
499
- /* Case 3: client bulkWrite */
500
- mongoc_bulkwriteopts_t * bw_opts = mongoc_bulkwriteopts_new ();
501
- mongoc_bulkwriteopts_set_verboseresults (bw_opts , true);
477
+ /* Check that inserting close to, but not exceeding, 16MiB, passes */
478
+ docs [0 ] = bson_new ();
479
+ bson_append_utf8 (docs [0 ], "_id" , -1 , "under_16mib" , -1 );
480
+ bson_append_utf8 (docs [0 ], "unencrypted" , -1 , as , exceeds_16mib_after_encryption );
481
+ ASSERT_OR_PRINT (mongoc_collection_insert_one (coll , docs [0 ], NULL /* opts */ , NULL /* reply */ , & error ), error );
482
+ bson_destroy (docs [0 ]);
502
483
503
- bson_t * corpus_encryptedFields =
504
- get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-encryptedFields.json" );
505
- bson_t * coll_opts = BCON_NEW ("encryptedFields" , BCON_DOCUMENT (corpus_encryptedFields ));
506
- mongoc_database_t * db = mongoc_client_get_database (client , "db" );
507
- (void ) mongoc_collection_drop (coll , NULL );
508
- // Create a newly named collection to avoid cached previous JSON Schema.
509
- mongoc_collection_t * coll2 = mongoc_database_create_collection (db , "coll2" , coll_opts , & error );
510
- ASSERT_OR_PRINT (coll2 , error );
511
- mongoc_collection_destroy (coll2 );
512
-
513
- /* Insert two documents that each exceed 2MiB but no encryption occurs.
514
- * Expect two separate bulkWrite commands.
515
- */
516
- docs [0 ] = BCON_NEW ("_id" , "over_2mib_3" );
517
- bson_append_utf8 (docs [0 ], "unencrypted" , -1 , as , size_2mib - 1500 );
518
- docs [1 ] = BCON_NEW ("_id" , "over_2mib_4" );
519
- bson_append_utf8 (docs [1 ], "unencrypted" , -1 , as , size_2mib - 1500 );
520
-
521
- ctx .num_inserts = 0 ;
522
- mongoc_bulkwrite_t * bw = mongoc_client_bulkwrite_new (client );
523
- ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll2" , docs [0 ], NULL , & error ), error );
524
- ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll2" , docs [1 ], NULL , & error ), error );
525
-
526
- mongoc_bulkwritereturn_t bwr = mongoc_bulkwrite_execute (bw , bw_opts );
527
- ASSERT_NO_BULKWRITEEXCEPTION (bwr );
528
- ASSERT_CMPINT (ctx .num_inserts , = = , 2 );
529
- bson_destroy (docs [0 ]);
530
- bson_destroy (docs [1 ]);
531
- mongoc_bulkwrite_destroy (bw );
532
- mongoc_bulkwriteresult_destroy (bwr .res );
533
- mongoc_bulkwriteexception_destroy (bwr .exc );
534
-
535
- /* Insert two documents that each exceed 2MiB after encryption occurs. Expect
536
- * the bulk write to succeed and run as two separate inserts.
537
- */
538
-
539
-
540
- docs [0 ] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-qe-doc.json" );
541
- bson_append_utf8 (docs [0 ], "_id" , -1 , "encryption_exceeds_2mib_3" , -1 );
542
- bson_append_utf8 (docs [0 ], "foo" , -1 , as , exceeds_2mib_after_encryption - 1500 );
543
- docs [1 ] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-qe-doc.json" );
544
- bson_append_utf8 (docs [1 ], "_id" , -1 , "encryption_exceeds_2mib_4" , -1 );
545
- bson_append_utf8 (docs [1 ], "foo" , -1 , as , exceeds_2mib_after_encryption - 1500 );
546
-
547
- ctx .num_inserts = 0 ;
548
- bw = mongoc_client_bulkwrite_new (client );
549
- ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll2" , docs [0 ], NULL , & error ), error );
550
- ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw , "db.coll2" , docs [1 ], NULL , & error ), error );
551
-
552
- bwr = mongoc_bulkwrite_execute (bw , bw_opts );
553
- ASSERT_NO_BULKWRITEEXCEPTION (bwr );
554
- ASSERT_CMPINT (ctx .num_inserts , = = , 2 );
555
- bson_destroy (docs [0 ]);
556
- bson_destroy (docs [1 ]);
557
- mongoc_bulkwrite_destroy (bw );
558
- mongoc_bulkwriteresult_destroy (bwr .res );
559
- mongoc_bulkwriteexception_destroy (bwr .exc );
560
- mongoc_bulkwriteopts_destroy (bw_opts );
561
- bson_destroy (corpus_encryptedFields );
562
- bson_destroy (coll_opts );
563
- mongoc_database_destroy (db );
564
- }
484
+ /* but.. exceeding 16 MiB fails */
485
+ docs [0 ] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-doc.json" );
486
+ bson_append_utf8 (docs [0 ], "_id" , -1 , "under_16mib" , -1 );
487
+ bson_append_utf8 (docs [0 ], "unencrypted" , -1 , as , exceeds_16mib_after_encryption );
488
+ BSON_ASSERT (!mongoc_collection_insert_one (coll , docs [0 ], NULL /* opts */ , NULL /* reply */ , & error ));
489
+ ASSERT_ERROR_CONTAINS (error , MONGOC_ERROR_SERVER , 2 , "too large" );
490
+ bson_destroy (docs [0 ]);
565
491
566
492
bson_free (as );
567
493
bson_destroy (kms_providers );
@@ -575,20 +501,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
575
501
mongoc_auto_encryption_opts_destroy (opts );
576
502
}
577
503
578
- static void
579
- test_bson_size_limits_and_batch_splitting_no_qe (void * unused )
580
- {
581
- BSON_UNUSED (unused );
582
- test_bson_size_limits_and_batch_splitting (false);
583
- }
584
-
585
- static void
586
- test_bson_size_limits_and_batch_splitting_qe (void * unused )
587
- {
588
- BSON_UNUSED (unused );
589
- test_bson_size_limits_and_batch_splitting (true);
590
- }
591
-
592
504
typedef struct {
593
505
bson_t * last_cmd ;
594
506
} _datakey_and_double_encryption_ctx_t ;
@@ -6995,19 +6907,11 @@ test_client_side_encryption_install (TestSuite *suite)
6995
6907
test_framework_skip_if_no_auth /* requires auth for error check */ );
6996
6908
TestSuite_AddFull (suite ,
6997
6909
"/client_side_encryption/bson_size_limits_and_batch_splitting" ,
6998
- test_bson_size_limits_and_batch_splitting_no_qe ,
6910
+ test_bson_size_limits_and_batch_splitting ,
6999
6911
NULL ,
7000
6912
NULL ,
7001
6913
test_framework_skip_if_no_client_side_encryption ,
7002
6914
test_framework_skip_if_max_wire_version_less_than_8 );
7003
- TestSuite_AddFull (suite ,
7004
- "/client_side_encryption/bson_size_limits_and_batch_splitting_qe" ,
7005
- test_bson_size_limits_and_batch_splitting_qe ,
7006
- NULL ,
7007
- NULL ,
7008
- test_framework_skip_if_no_client_side_encryption ,
7009
- test_framework_skip_if_max_wire_version_less_than_25 ,
7010
- test_framework_skip_if_single );
7011
6915
TestSuite_AddFull (suite ,
7012
6916
"/client_side_encryption/views_are_prohibited" ,
7013
6917
test_views_are_prohibited ,
0 commit comments