@@ -69,7 +69,7 @@ func TestAppSec(t *testing.T) {
69
69
handler , mt , cleanup := setup ()
70
70
defer cleanup ()
71
71
72
- _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "dd-test-scanner-log-block" }, "GET" , "/" , 0 )
72
+ _ , _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "dd-test-scanner-log-block" }, "GET" , "/" , 0 )
73
73
74
74
require .Equal (t , 403 , blockedAct .statusCode )
75
75
require .Equal (t , "application/json" , blockedAct .headers ["Content-Type" ])
@@ -87,7 +87,7 @@ func TestAppSec(t *testing.T) {
87
87
handler , mt , cleanup := setup ()
88
88
defer cleanup ()
89
89
90
- _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Mistake Not..." }, "GET" , "/hello?match=match-request-query" , 0 )
90
+ _ , _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Mistake Not..." }, "GET" , "/hello?match=match-request-query" , 0 )
91
91
92
92
require .Equal (t , 418 , blockedAct .statusCode )
93
93
require .Equal (t , "application/json" , blockedAct .headers ["Content-Type" ])
@@ -105,7 +105,7 @@ func TestAppSec(t *testing.T) {
105
105
handler , mt , cleanup := setup ()
106
106
defer cleanup ()
107
107
108
- _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"Cookie" : "foo=jdfoSDGFkivRG_234" }, "OPTIONS" , "/" , 0 )
108
+ _ , _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"Cookie" : "foo=jdfoSDGFkivRG_234" }, "OPTIONS" , "/" , 0 )
109
109
110
110
require .Equal (t , 418 , blockedAct .statusCode )
111
111
require .Equal (t , "application/json" , blockedAct .headers ["Content-Type" ])
@@ -144,7 +144,7 @@ func TestAppSec(t *testing.T) {
144
144
handler , mt , cleanup := setup ()
145
145
defer cleanup ()
146
146
147
- _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Mistake not..." , "X-Forwarded-For" : "111.222.111.222" }, "GET" , "/" , 0 )
147
+ _ , _ , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Mistake not..." , "X-Forwarded-For" : "111.222.111.222" }, "GET" , "/" , 0 )
148
148
149
149
// Handle the immediate response
150
150
require .Equal (t , 403 , blockedAct .statusCode )
@@ -230,7 +230,7 @@ func TestAppSecBodyParsingEnabled(t *testing.T) {
230
230
handler , mt , cleanup := setup ()
231
231
defer cleanup ()
232
232
233
- spanId , requestedRequestBody , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , 0 )
233
+ spanId , requestedRequestBody , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , 0 )
234
234
require .False (t , requestedRequestBody )
235
235
require .Nil (t , blockedAct )
236
236
@@ -258,7 +258,7 @@ func TestAppSecBodyParsingEnabled(t *testing.T) {
258
258
defer cleanup ()
259
259
260
260
body := []byte (`{ "name": "$globals" }` )
261
- spanId , requestedRequestBody , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , len (body ))
261
+ spanId , requestedRequestBody , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , len (body ))
262
262
require .True (t , requestedRequestBody )
263
263
require .Nil (t , blockedAct )
264
264
@@ -335,7 +335,7 @@ func TestAppSecBodyParsingEnabled(t *testing.T) {
335
335
}
336
336
requestBody := fmt .Sprintf (`{ "name": "$globals", "text": "%s" }` , largeText )
337
337
338
- spanId , bodyRequested , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , len (requestBody ))
338
+ spanId , bodyRequested , _ , blockedAct := sendProcessingRequestHeaders (t , handler , map [string ]string {"User-Agent" : "Chromium" , "Content-Type" : "application/json" }, "GET" , "/" , len (requestBody ))
339
339
require .True (t , bodyRequested )
340
340
require .Nil (t , blockedAct )
341
341
@@ -466,6 +466,32 @@ func TestGeneratedSpan(t *testing.T) {
466
466
require .Equal (t , "00000000000000000000000000003039" , span .Context ().TraceID ())
467
467
require .Equal (t , uint64 (67890 ), span .ParentID ())
468
468
})
469
+ t .Run ("span-with-propagation-headers-set" , func (t * testing.T ) {
470
+ handler , mt , cleanup := setup ()
471
+ defer cleanup ()
472
+
473
+ spanId , _ , injectedHeaders , _ := sendProcessingRequestHeaders (t , handler , map [string ]string {}, "GET" , "/../../../resource-span/.?id=test" , 0 )
474
+
475
+ // Check for trace propagation headers injected
476
+ require .Contains (t , injectedHeaders , "tracing_x_datadog_trace_id" )
477
+ require .Contains (t , injectedHeaders , "tracing_x_datadog_parent_id" )
478
+ require .Contains (t , injectedHeaders , "tracing_x_datadog_tags" )
479
+
480
+ sendProcessingResponseHeaders (t , handler , nil , "200" , spanId , 0 )
481
+
482
+ finished := mt .FinishedSpans ()
483
+ require .Len (t , finished , 1 )
484
+
485
+ // Check for tags
486
+ span := finished [0 ]
487
+ require .Equal (t , "http.request" , span .OperationName ())
488
+ require .Equal (t , "https://datadoghq.com/../../../resource-span/.?id=test" , span .Tag ("http.url" ))
489
+ require .Equal (t , "GET" , span .Tag ("http.method" ))
490
+ require .Equal (t , "datadoghq.com" , span .Tag ("http.host" ))
491
+ require .Equal (t , "GET /resource-span" , span .Tag ("resource.name" ))
492
+ require .Equal (t , "server" , span .Tag ("span.kind" ))
493
+ require .Equal (t , "haproxy-spoa" , span .Tag ("component" ))
494
+ })
469
495
}
470
496
471
497
func TestMalformedHAProxyProcessing (t * testing.T ) {
@@ -509,7 +535,7 @@ func TestMalformedHAProxyProcessing(t *testing.T) {
509
535
handler , mt , cleanup := setup ()
510
536
defer cleanup ()
511
537
512
- spanId , requestBody , blockedAct := sendProcessingRequestHeaders (t , handler , nil , "GET" , "/%u002e/%ZZ/%tt/%uuuu/%uwu/%%" , 0 )
538
+ spanId , requestBody , _ , blockedAct := sendProcessingRequestHeaders (t , handler , nil , "GET" , "/%u002e/%ZZ/%tt/%uuuu/%uwu/%%" , 0 )
513
539
require .False (t , requestBody )
514
540
require .Nil (t , blockedAct )
515
541
require .Empty (t , spanId )
@@ -544,7 +570,7 @@ type haproxyAppsecRig struct {
544
570
545
571
// Helper functions
546
572
547
- func sendProcessingRequestHeaders (t * testing.T , handler func (* request.Request ), headers map [string ]string , method string , path string , bodyLength int ) (string , bool , * blockedAction ) {
573
+ func sendProcessingRequestHeaders (t * testing.T , handler func (* request.Request ), headers map [string ]string , method string , path string , bodyLength int ) (string , bool , map [ string ] string , * blockedAction ) {
548
574
t .Helper ()
549
575
550
576
if headers == nil {
@@ -596,20 +622,28 @@ func sendProcessingRequestHeaders(t *testing.T, handler func(*request.Request),
596
622
blockedAct , err := createBlockedAction (pRequest .Actions )
597
623
require .NoError (t , err )
598
624
if blockedAct != nil {
599
- return "" , false , blockedAct
625
+ return "" , false , nil , blockedAct
600
626
}
601
627
602
628
spanId , err := findVar (pRequest .Actions , "span_id" )
603
629
if err != nil {
604
- return "" , false , nil
630
+ return "" , false , nil , nil
605
631
}
606
632
607
633
requestedBody , err := findVar (pRequest .Actions , "request_body" )
608
634
if err != nil {
609
635
requestedBody = false
610
636
}
611
637
612
- return spanId .(string ), requestedBody .(bool ), nil
638
+ // Handle injected headers
639
+ injectedValues := make (map [string ]string , len (haproxyTracingHeaderActions ))
640
+ for _ , actionName := range haproxyTracingHeaderActions {
641
+ if v , err := findVar (pRequest .Actions , actionName ); err == nil {
642
+ injectedValues [actionName ] = v .(string )
643
+ }
644
+ }
645
+
646
+ return spanId .(string ), requestedBody .(bool ), injectedValues , nil
613
647
}
614
648
615
649
// sendProcessingRequestBody sends the request body
@@ -809,7 +843,7 @@ func end2EndStreamRequest(t *testing.T, handler func(*request.Request), path str
809
843
// First part: request
810
844
// 1- Send the headers
811
845
requestBodyLength := len (requestBody )
812
- spanId , requestBodyRequested , blocked := sendProcessingRequestHeaders (t , handler , requestHeaders , method , path , requestBodyLength )
846
+ spanId , requestBodyRequested , _ , blocked := sendProcessingRequestHeaders (t , handler , requestHeaders , method , path , requestBodyLength )
813
847
require .Nil (t , blocked , "expected no blocked action when sending request headers" )
814
848
815
849
require .NotEmpty (t , spanId )
0 commit comments