@@ -63,13 +63,23 @@ NR_PHP_WRAPPER_END
63
63
64
64
NR_PHP_WRAPPER (aws_lambda_invoke_wrapper ) {
65
65
nr_segment_cloud_attrs_t cloud_attrs = {0 };
66
+ /*
67
+ * Because argument 1 is not used in instrumentation, we will use it
68
+ * to pass in the expected value
69
+ */
66
70
zval * expected = nr_php_get_user_func_arg (1 , NR_EXECUTE_ORIG_ARGS );
67
71
nr_aws_lambda_invoke (NR_EXECUTE_ORIG_ARGS , & cloud_attrs );
68
72
(void )wraprec ;
69
73
70
- tlib_pass_if_str_equal ("Expected should match reconstructed arn" ,
71
- Z_STRVAL_P (expected ),
72
- cloud_attrs .cloud_resource_id );
74
+ if (nr_php_is_zval_valid_string (expected )) {
75
+ tlib_pass_if_str_equal ("Expected should match reconstructed arn" ,
76
+ Z_STRVAL_P (expected ),
77
+ cloud_attrs .cloud_resource_id );
78
+ } else {
79
+ tlib_pass_if_str_equal ("Expected should match reconstructed arn" ,
80
+ NULL ,
81
+ cloud_attrs .cloud_resource_id );
82
+ }
73
83
NR_PHP_WRAPPER_CALL ;
74
84
}
75
85
NR_PHP_WRAPPER_END
@@ -471,28 +481,102 @@ static void test_nr_lib_aws_sdk_php_handle_version(void) {
471
481
tlib_php_request_end ();
472
482
}
473
483
484
+ #if ZEND_MODULE_API_NO >= ZEND_8_1_X_API_NO
474
485
static void test_nr_lib_aws_sdk_php_lambda_invoke () {
475
- tlib_php_engine_create ("" );
486
+ tlib_php_engine_create ("newrelic.cloud.aws.account_id=\"test_account\" " );
476
487
tlib_php_request_start ();
477
488
478
489
tlib_php_request_eval ("function lambda_invoke($a, $b) { return; }" );
479
490
nr_php_wrap_user_function (NR_PSTR ("lambda_invoke" ), aws_lambda_invoke_wrapper );
480
491
492
+ /* Test full-info run */
481
493
char * args
482
494
= "array("
483
495
" 0 => array("
484
- " 'FunctionName' => 'us-east-2:012345678901:function'"
496
+ " 'FunctionName' => 'us-east-2:012345678901:function:my-function '"
485
497
" )"
486
498
")" ;
487
499
zval * array_arg = tlib_php_request_eval_expr (args );
488
- char * expect = "'arn:aws:lamba :us-east-2:012345678901:function'" ;
500
+ char * expect = "'arn:aws:lambda :us-east-2:012345678901:function:my- function'" ;
489
501
zval * expect_arg = tlib_php_request_eval_expr (expect );
490
502
zval * expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
491
503
tlib_pass_if_not_null ("Expression should evaluate." , expr );
504
+ nr_php_zval_free (& expr );
505
+ nr_php_zval_free (& expect_arg );
506
+ nr_php_zval_free (& array_arg );
507
+
508
+ /* Test alias full-info run */
509
+ args
510
+ = "array("
511
+ " 0 => array("
512
+ " 'FunctionName' => 'us-east-2:012345678901:function:my-function:v1'"
513
+ " )"
514
+ ")" ;
515
+ array_arg = tlib_php_request_eval_expr (args );
516
+ expect = "'arn:aws:lambda:us-east-2:012345678901:function:my-function:v1'" ;
517
+ expect_arg = tlib_php_request_eval_expr (expect );
518
+ expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
519
+ tlib_pass_if_not_null ("Expression should evaluate." , expr );
520
+ nr_php_zval_free (& expr );
521
+ nr_php_zval_free (& expect_arg );
522
+ nr_php_zval_free (& array_arg );
523
+
524
+ /* Test INI extract */
525
+ args
526
+ = "array("
527
+ " 0 => array("
528
+ " 'FunctionName' => 'us-east-2:my-function'"
529
+ " )"
530
+ ")" ;
531
+ array_arg = tlib_php_request_eval_expr (args );
532
+ expect = "'arn:aws:lambda:us-east-2:test_account:function:my-function'" ;
533
+ expect_arg = tlib_php_request_eval_expr (expect );
534
+ expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
535
+ tlib_pass_if_not_null ("Expression should evaluate." , expr );
536
+ nr_php_zval_free (& expr );
537
+ nr_php_zval_free (& expect_arg );
538
+ nr_php_zval_free (& array_arg );
539
+
540
+ /* Test invalid arg 1 */
541
+ args
542
+ = "array("
543
+ " 0 => array("
544
+ " 'FunctionName' => 123"
545
+ " )"
546
+ ")" ;
547
+ array_arg = tlib_php_request_eval_expr (args );
548
+ expect = "NULL" ;
549
+ expect_arg = tlib_php_request_eval_expr (expect );
550
+ expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
551
+ tlib_pass_if_not_null ("Expression should evaluate." , expr );
552
+ nr_php_zval_free (& expr );
553
+ nr_php_zval_free (& array_arg );
554
+
555
+ /* Test invalid arg 2 */
556
+ args
557
+ = "array("
558
+ " 0 => array("
559
+ " )"
560
+ ")" ;
561
+ array_arg = tlib_php_request_eval_expr (args );
562
+ expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
563
+ tlib_pass_if_not_null ("Expression should evaluate." , expr );
564
+ nr_php_zval_free (& expr );
565
+ nr_php_zval_free (& array_arg );
566
+
567
+ /* Test invalid arg 3 */
568
+ args = "array()" ;
569
+ array_arg = tlib_php_request_eval_expr (args );
570
+ expr = nr_php_call (NULL , "lambda_invoke" , expect_arg , array_arg );
571
+ tlib_pass_if_not_null ("Expression should evaluate." , expr );
572
+ nr_php_zval_free (& expr );
573
+ nr_php_zval_free (& expect_arg );
574
+ nr_php_zval_free (& array_arg );
492
575
493
576
tlib_php_request_end ();
494
577
tlib_php_engine_destroy ();
495
578
}
579
+ #endif /* PHP 8.1+ */
496
580
497
581
void test_main (void * p NRUNUSED ) {
498
582
tlib_php_engine_create ("" );
0 commit comments