@@ -22,6 +22,7 @@ import (
2222 "net/http"
2323 "testing"
2424
25+ "github.com/pkg/errors"
2526 "github.com/stretchr/testify/assert"
2627 "github.com/stretchr/testify/require"
2728
@@ -43,34 +44,46 @@ func TestSanitizeRequestResponse(t *testing.T) {
4344 req .AddCookie (c )
4445 }
4546
46- tx , _ , _ := apmtest .WithTransaction (func (ctx context.Context ) {
47+ tx , _ , errors := apmtest .WithTransaction (func (ctx context.Context ) {
48+ e := apm .CaptureError (ctx , errors .New ("boom!" ))
49+ defer e .Send ()
50+
4751 tx := apm .TransactionFromContext (ctx )
4852 tx .Context .SetHTTPRequest (req )
53+ e .Context .SetHTTPRequest (req )
4954
5055 h := make (http.Header )
5156 h .Add ("Set-Cookie" , (& http.Cookie {Name : "foo" , Value : "bar" }).String ())
5257 h .Add ("Set-Cookie" , (& http.Cookie {Name : "baz" , Value : "qux" }).String ())
5358 tx .Context .SetHTTPResponseHeaders (h )
5459 tx .Context .SetHTTPStatusCode (http .StatusTeapot )
60+ e .Context .SetHTTPResponseHeaders (h )
61+ e .Context .SetHTTPStatusCode (http .StatusTeapot )
5562 })
5663
57- assert .Equal (t , tx .Context .Request .Cookies , model.Cookies {
58- {Name : "Custom-Credit-Card-Number" , Value : "[REDACTED]" },
59- {Name : "secret" , Value : "[REDACTED]" },
60- {Name : "sessionid" , Value : "[REDACTED]" },
61- {Name : "user_id" , Value : "456" },
62- })
63- assert .Equal (t , model.Headers {{
64- Key : "Authorization" ,
65- Values : []string {"[REDACTED]" },
66- }}, tx .Context .Request .Headers )
67-
68- // NOTE: the response includes multiple Set-Cookie headers,
69- // but we only report a single "[REDACTED]" value.
70- assert .Equal (t , model.Headers {{
71- Key : "Set-Cookie" ,
72- Values : []string {"[REDACTED]" },
73- }}, tx .Context .Response .Headers )
64+ checkContext := func (context * model.Context ) {
65+ assert .Equal (t , context .Request .Cookies , model.Cookies {
66+ {Name : "Custom-Credit-Card-Number" , Value : "[REDACTED]" },
67+ {Name : "secret" , Value : "[REDACTED]" },
68+ {Name : "sessionid" , Value : "[REDACTED]" },
69+ {Name : "user_id" , Value : "456" },
70+ })
71+ assert .Equal (t , model.Headers {{
72+ Key : "Authorization" ,
73+ Values : []string {"[REDACTED]" },
74+ }}, context .Request .Headers )
75+
76+ // NOTE: the response includes multiple Set-Cookie headers,
77+ // but we only report a single "[REDACTED]" value.
78+ assert .Equal (t , model.Headers {{
79+ Key : "Set-Cookie" ,
80+ Values : []string {"[REDACTED]" },
81+ }}, context .Response .Headers )
82+ }
83+ checkContext (tx .Context )
84+ for _ , e := range errors {
85+ checkContext (e .Context )
86+ }
7487}
7588
7689func TestSetSanitizedFieldNamesNone (t * testing.T ) {
0 commit comments