@@ -371,6 +371,31 @@ _get_handshake_document (bool default_append)
371
371
return handshake_doc ;
372
372
}
373
373
374
+ /* Override host info with plausible but short strings to avoid any
375
+ * truncation */
376
+ static void
377
+ _override_host_platform_os (void )
378
+ {
379
+ _reset_handshake ();
380
+ mongoc_handshake_t * md = _mongoc_handshake_get ();
381
+ bson_free (md -> os_type );
382
+ md -> os_type = bson_strdup ("Linux" );
383
+ bson_free (md -> os_name );
384
+ md -> os_name = bson_strdup ("mongoc" );
385
+ bson_free (md -> os_architecture );
386
+ md -> os_architecture = bson_strdup ("x86_64" );
387
+ bson_free (md -> driver_name );
388
+ md -> driver_name = bson_strdup ("test_e" );
389
+ bson_free (md -> driver_version );
390
+ md -> driver_version = bson_strdup ("1.25.0" );
391
+ bson_free (md -> platform );
392
+ md -> platform = bson_strdup ("posix=1234" );
393
+ bson_free (md -> compiler_info );
394
+ md -> compiler_info = bson_strdup ("CC=GCC" );
395
+ bson_free (md -> flags );
396
+ md -> flags = bson_strdup ("CFLAGS=\"-fPIE\"" );
397
+ }
398
+
374
399
// erase all FaaS variables used in testing
375
400
static void
376
401
clear_faas_env (void )
@@ -391,7 +416,7 @@ clear_faas_env (void)
391
416
static void
392
417
test_mongoc_handshake_data_append_success (void )
393
418
{
394
- _reset_handshake ();
419
+ _override_host_platform_os ();
395
420
bson_t * doc = _get_handshake_document (true);
396
421
bson_iter_t md_iter ;
397
422
bson_iter_init (& md_iter , doc );
@@ -412,7 +437,7 @@ test_valid_aws_lambda (void *test_ctx)
412
437
ASSERT (_mongoc_setenv ("AWS_REGION" , "us-east-2" ));
413
438
ASSERT (_mongoc_setenv ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" , "1024" ));
414
439
415
- _reset_handshake ();
440
+ _override_host_platform_os ();
416
441
bson_t * doc = _get_handshake_document (true);
417
442
_handshake_check_required_fields (doc );
418
443
_handshake_check_env (doc , default_memory_mb , 0 , "us-east-2" );
@@ -444,7 +469,7 @@ test_valid_aws_and_vercel (void *test_ctx)
444
469
ASSERT (_mongoc_setenv ("VERCEL" , "1" ));
445
470
ASSERT (_mongoc_setenv ("VERCEL_REGION" , "cdg1" ));
446
471
447
- _reset_handshake ();
472
+ _override_host_platform_os ();
448
473
bson_t * doc = _get_handshake_document (true);
449
474
_handshake_check_required_fields (doc );
450
475
_handshake_check_env (doc , 0 , 0 , "cdg1" );
@@ -463,8 +488,9 @@ test_valid_aws (void *test_ctx)
463
488
ASSERT (_mongoc_setenv ("AWS_REGION" , "us-east-2" ));
464
489
ASSERT (_mongoc_setenv ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" , "1024" ));
465
490
466
- _reset_handshake ();
491
+ _override_host_platform_os ();
467
492
bson_t * doc = _get_handshake_document (true);
493
+
468
494
_handshake_check_required_fields (doc );
469
495
_handshake_check_env (doc , default_memory_mb , 0 , "us-east-2" );
470
496
_handshake_check_env_name (doc , "aws.lambda" );
@@ -486,7 +512,7 @@ test_valid_azure (void *test_ctx)
486
512
BSON_UNUSED (test_ctx );
487
513
ASSERT (_mongoc_setenv ("FUNCTIONS_WORKER_RUNTIME" , "node" ));
488
514
489
- _reset_handshake ();
515
+ _override_host_platform_os ();
490
516
bson_t * doc = _get_handshake_document (true);
491
517
_handshake_check_required_fields (doc );
492
518
_handshake_check_env (doc , 0 , 0 , NULL );
@@ -506,7 +532,7 @@ test_valid_gcp (void *test_ctx)
506
532
ASSERT (_mongoc_setenv ("FUNCTION_TIMEOUT_SEC" , "60" ));
507
533
ASSERT (_mongoc_setenv ("FUNCTION_REGION" , "us-central1" ));
508
534
509
- _reset_handshake ();
535
+ _override_host_platform_os ();
510
536
bson_t * doc = _get_handshake_document (true);
511
537
_handshake_check_required_fields (doc );
512
538
_handshake_check_env (
@@ -525,7 +551,7 @@ test_valid_vercel (void *test_ctx)
525
551
ASSERT (_mongoc_setenv ("VERCEL" , "1" ));
526
552
ASSERT (_mongoc_setenv ("VERCEL_REGION" , "cdg1" ));
527
553
528
- _reset_handshake ();
554
+ _override_host_platform_os ();
529
555
bson_t * doc = _get_handshake_document (true);
530
556
_handshake_check_required_fields (doc );
531
557
_handshake_check_env (doc , 0 , 0 , "cdg1" );
@@ -544,7 +570,7 @@ test_multiple_faas (void *test_ctx)
544
570
ASSERT (_mongoc_setenv ("AWS_EXECUTION_ENV" , "AWS_Lambda_java8" ));
545
571
ASSERT (_mongoc_setenv ("FUNCTIONS_WORKER_RUNTIME" , "node" ));
546
572
547
- _reset_handshake ();
573
+ _override_host_platform_os ();
548
574
bson_t * doc = _get_handshake_document (true);
549
575
_handshake_check_required_fields (doc );
550
576
@@ -566,7 +592,7 @@ test_truncate_region (void *test_ctx)
566
592
long_region [region_len - 1 ] = '\0' ;
567
593
ASSERT (_mongoc_setenv ("AWS_REGION" , long_region ));
568
594
569
- _reset_handshake ();
595
+ _override_host_platform_os ();
570
596
bson_t * doc = _get_handshake_document (true);
571
597
_handshake_check_required_fields (doc );
572
598
_handshake_check_env_name (doc , "aws.lambda" );
@@ -593,7 +619,7 @@ test_wrong_types (void *test_ctx)
593
619
ASSERT (_mongoc_setenv ("AWS_EXECUTION_ENV" , "AWS_Lambda_java8" ));
594
620
ASSERT (_mongoc_setenv ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" , "big" ));
595
621
596
- _reset_handshake ();
622
+ _override_host_platform_os ();
597
623
bson_t * doc = _get_handshake_document (true);
598
624
_handshake_check_required_fields (doc );
599
625
_handshake_check_env_name (doc , "aws.lambda" );
@@ -617,7 +643,7 @@ test_aws_not_lambda (void *test_ctx)
617
643
// Entire env field must be omitted with non-lambda AWS
618
644
ASSERT (_mongoc_setenv ("AWS_EXECUTION_ENV" , "EC2" ));
619
645
620
- _reset_handshake ();
646
+ _override_host_platform_os ();
621
647
bson_t * doc = _get_handshake_document (true);
622
648
_handshake_check_required_fields (doc );
623
649
0 commit comments