@@ -446,24 +446,97 @@ describe('Plugin', () => {
446
446
} )
447
447
} )
448
448
449
- it ( 'should inject tracing header into request without mutating the header' , done => {
450
- // ensures that the tracer clones request headers instead of mutating.
451
- // Fixes aws-sdk InvalidSignatureException, more info:
452
- // https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1609#issuecomment-1826167348
449
+ it ( 'should skip injecting if the Authorization header contains an AWS signature' , done => {
450
+ const app = express ( )
451
+
452
+ app . get ( '/' , ( req , res ) => {
453
+ try {
454
+ expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . undefined
455
+ expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . undefined
456
+
457
+ res . status ( 200 ) . send ( )
458
+
459
+ done ( )
460
+ } catch ( e ) {
461
+ done ( e )
462
+ }
463
+ } )
464
+
465
+ appListener = server ( app , port => {
466
+ const req = http . request ( {
467
+ port,
468
+ headers : {
469
+ Authorization : 'AWS4-HMAC-SHA256 ...'
470
+ }
471
+ } )
453
472
473
+ req . end ( )
474
+ } )
475
+ } )
476
+
477
+ it ( 'should skip injecting if one of the Authorization headers contains an AWS signature' , done => {
454
478
const app = express ( )
455
479
456
- const originalHeaders = {
457
- Authorization : 'AWS4-HMAC-SHA256 ...'
458
- }
480
+ app . get ( '/' , ( req , res ) => {
481
+ try {
482
+ expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . undefined
483
+ expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . undefined
484
+
485
+ res . status ( 200 ) . send ( )
486
+
487
+ done ( )
488
+ } catch ( e ) {
489
+ done ( e )
490
+ }
491
+ } )
492
+
493
+ appListener = server ( app , port => {
494
+ const req = http . request ( {
495
+ port,
496
+ headers : {
497
+ Authorization : [ 'AWS4-HMAC-SHA256 ...' ]
498
+ }
499
+ } )
500
+
501
+ req . end ( )
502
+ } )
503
+ } )
504
+
505
+ it ( 'should skip injecting if the X-Amz-Signature header is set' , done => {
506
+ const app = express ( )
459
507
460
508
app . get ( '/' , ( req , res ) => {
461
509
try {
462
- expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . a ( 'string' )
463
- expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . a ( 'string' )
510
+ expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . undefined
511
+ expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . undefined
512
+
513
+ res . status ( 200 ) . send ( )
514
+
515
+ done ( )
516
+ } catch ( e ) {
517
+ done ( e )
518
+ }
519
+ } )
520
+
521
+ appListener = server ( app , port => {
522
+ const req = http . request ( {
523
+ port,
524
+ headers : {
525
+ 'X-Amz-Signature' : 'abc123'
526
+ }
527
+ } )
528
+
529
+ req . end ( )
530
+ } )
531
+ } )
532
+
533
+ it ( 'should skip injecting if the X-Amz-Signature query param is set' , done => {
534
+ const app = express ( )
464
535
465
- expect ( originalHeaders [ 'x-datadog-trace-id' ] ) . to . be . undefined
466
- expect ( originalHeaders [ 'x-datadog-parent-id' ] ) . to . be . undefined
536
+ app . get ( '/' , ( req , res ) => {
537
+ try {
538
+ expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . undefined
539
+ expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . undefined
467
540
468
541
res . status ( 200 ) . send ( )
469
542
@@ -476,7 +549,7 @@ describe('Plugin', () => {
476
549
appListener = server ( app , port => {
477
550
const req = http . request ( {
478
551
port,
479
- headers : originalHeaders
552
+ path : '/?X-Amz-Signature=abc123'
480
553
} )
481
554
482
555
req . end ( )
@@ -1020,6 +1093,50 @@ describe('Plugin', () => {
1020
1093
} )
1021
1094
} )
1022
1095
1096
+ describe ( 'with config enablePropagationWithAmazonHeaders enabled' , ( ) => {
1097
+ let config
1098
+
1099
+ beforeEach ( ( ) => {
1100
+ config = {
1101
+ enablePropagationWithAmazonHeaders : true
1102
+ }
1103
+
1104
+ return agent . load ( 'http' , config )
1105
+ . then ( ( ) => {
1106
+ http = require ( pluginToBeLoaded )
1107
+ express = require ( 'express' )
1108
+ } )
1109
+ } )
1110
+
1111
+ it ( 'should inject tracing header into AWS signed request' , done => {
1112
+ const app = express ( )
1113
+
1114
+ app . get ( '/' , ( req , res ) => {
1115
+ try {
1116
+ expect ( req . get ( 'x-datadog-trace-id' ) ) . to . be . a ( 'string' )
1117
+ expect ( req . get ( 'x-datadog-parent-id' ) ) . to . be . a ( 'string' )
1118
+
1119
+ res . status ( 200 ) . send ( )
1120
+
1121
+ done ( )
1122
+ } catch ( e ) {
1123
+ done ( e )
1124
+ }
1125
+ } )
1126
+
1127
+ appListener = server ( app , port => {
1128
+ const req = http . request ( {
1129
+ port,
1130
+ headers : {
1131
+ Authorization : 'AWS4-HMAC-SHA256 ...'
1132
+ }
1133
+ } )
1134
+
1135
+ req . end ( )
1136
+ } )
1137
+ } )
1138
+ } )
1139
+
1023
1140
describe ( 'with validateStatus configuration' , ( ) => {
1024
1141
let config
1025
1142
0 commit comments