Skip to content

Commit 4dac26f

Browse files
committed
Merge branch 'main' of github.com:postmanlabs/postman-insights-agent into mudit/POA-2309
2 parents 97f57dd + 024d69a commit 4dac26f

File tree

5 files changed

+176
-149
lines changed

5 files changed

+176
-149
lines changed

trace/backend_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ func (c *BackendCollector) queueUpload(w *witnessWithInfo) {
295295
if !c.sendWitnessPayloads || !hasOnlyErrorResponses(w.witness.GetMethod()) {
296296
// Obfuscate the original value so type inference engine can use it on the
297297
// backend without revealing the actual value.
298-
c.obfuscator.ObfuscateDataWithZeroValue(w.witness.GetMethod())
298+
c.obfuscator.ZeroAllPrimitivesInMethod(w.witness.GetMethod())
299299
} else {
300-
c.obfuscator.RedactData(w.witness.GetMethod())
300+
c.obfuscator.RedactSensitiveData(w.witness.GetMethod())
301301
}
302302

303303
c.uploadReportBatch.Add(rawReport{

trace/backend_collector_test.go

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,12 @@ func TestObfuscationConfigs(t *testing.T) {
519519
// Prepare a test cases
520520
streamID := uuid.New()
521521
type testCase struct {
522-
name string
523522
request akinet.HTTPRequest
524523
response akinet.HTTPResponse
525524
expectedWitnesses *api_spec.Witness
526525
}
527-
testCases := []testCase{
528-
{
529-
name: "no sensitive data",
526+
testCases := map[string]testCase{
527+
"no sensitive data": {
530528
request: akinet.HTTPRequest{
531529
StreamID: streamID,
532530
Seq: 1204,
@@ -589,8 +587,7 @@ func TestObfuscationConfigs(t *testing.T) {
589587
},
590588
},
591589
},
592-
{
593-
name: "sensitive data in header, query param, cookie and URL path",
590+
"sensitive data in header, query param, cookie and URL path": {
594591
request: akinet.HTTPRequest{
595592
StreamID: streamID,
596593
Seq: 1204,
@@ -687,8 +684,7 @@ func TestObfuscationConfigs(t *testing.T) {
687684
},
688685
},
689686
},
690-
{
691-
name: "sensitive data in body",
687+
"sensitive data in body": {
692688
request: akinet.HTTPRequest{
693689
StreamID: streamID,
694690
Seq: 1204,
@@ -763,8 +759,7 @@ func TestObfuscationConfigs(t *testing.T) {
763759
},
764760
},
765761
},
766-
{
767-
name: "struct with sensitive keys and values",
762+
"struct with sensitive keys and values": {
768763
request: akinet.HTTPRequest{
769764
StreamID: streamID,
770765
Seq: 1204,
@@ -869,8 +864,7 @@ func TestObfuscationConfigs(t *testing.T) {
869864
},
870865
},
871866
},
872-
{
873-
name: "list with sensitive keys and values",
867+
"list with sensitive keys and values": {
874868
request: akinet.HTTPRequest{
875869
StreamID: streamID,
876870
Seq: 1204,
@@ -986,8 +980,7 @@ func TestObfuscationConfigs(t *testing.T) {
986980
},
987981
},
988982
},
989-
{
990-
name: "multipart data, no sensitive data",
983+
"multipart data, no sensitive data": {
991984
request: akinet.HTTPRequest{
992985
StreamID: streamID,
993986
Seq: 1204,
@@ -1062,8 +1055,7 @@ func TestObfuscationConfigs(t *testing.T) {
10621055
},
10631056
},
10641057
},
1065-
{
1066-
name: "multipart data, with sensitive data",
1058+
"multipart data, with sensitive data": {
10671059
request: akinet.HTTPRequest{
10681060
StreamID: streamID,
10691061
Seq: 1204,
@@ -1152,6 +1144,75 @@ func TestObfuscationConfigs(t *testing.T) {
11521144
},
11531145
},
11541146
},
1147+
"null value": {
1148+
request: akinet.HTTPRequest{
1149+
StreamID: streamID,
1150+
Seq: 1204,
1151+
Method: "POST",
1152+
URL: &url.URL{
1153+
Path: "/",
1154+
},
1155+
Host: "example.com",
1156+
Header: map[string][]string{
1157+
"Content-Type": {"application/json"},
1158+
},
1159+
Body: memview.New([]byte(`
1160+
{
1161+
"null": null
1162+
}
1163+
`)),
1164+
},
1165+
response: akinet.HTTPResponse{
1166+
StreamID: streamID,
1167+
Seq: 1204,
1168+
StatusCode: 404,
1169+
Header: map[string][]string{
1170+
"Content-Type": {"application/json"},
1171+
},
1172+
Body: memview.New([]byte(`
1173+
{
1174+
"null": null
1175+
}
1176+
`)),
1177+
},
1178+
expectedWitnesses: &pb.Witness{
1179+
Method: &pb.Method{
1180+
Id: &pb.MethodID{
1181+
ApiType: pb.ApiType_HTTP_REST,
1182+
},
1183+
Args: map[string]*pb.Data{
1184+
"sLSDNjJ5umQ=": newTestBodySpecFromStruct(
1185+
0,
1186+
pb.HTTPBody_JSON,
1187+
"application/json",
1188+
map[string]*pb.Data{
1189+
"null": spec_util.NoneData,
1190+
},
1191+
),
1192+
},
1193+
Responses: map[string]*pb.Data{
1194+
"2drZdoQw74E=": newTestBodySpecFromStruct(
1195+
404,
1196+
pb.HTTPBody_JSON,
1197+
"application/json",
1198+
map[string]*pb.Data{
1199+
"null": spec_util.NoneData,
1200+
},
1201+
),
1202+
},
1203+
Meta: &pb.MethodMeta{
1204+
Meta: &pb.MethodMeta_Http{
1205+
Http: &pb.HTTPMethodMeta{
1206+
Method: "POST",
1207+
PathTemplate: "/",
1208+
Host: "example.com",
1209+
Obfuscation: api_spec.HTTPMethodMeta_NONE,
1210+
},
1211+
},
1212+
},
1213+
},
1214+
},
1215+
},
11551216
}
11561217

11571218
// Setup for running tests
@@ -1167,8 +1228,10 @@ func TestObfuscationConfigs(t *testing.T) {
11671228
AnyTimes().
11681229
Return(nil)
11691230

1170-
for i, testCase := range testCases {
1171-
fmt.Println("Running test case: ", testCase.name)
1231+
i := -1
1232+
for name, testCase := range testCases {
1233+
i++
1234+
fmt.Println("Running test case: ", name)
11721235

11731236
req := akinet.ParsedNetworkTraffic{Content: testCase.request}
11741237
resp := akinet.ParsedNetworkTraffic{Content: testCase.response}

0 commit comments

Comments
 (0)