Skip to content

Commit

Permalink
Merge branch 'main' of github.com:postmanlabs/postman-insights-agent …
Browse files Browse the repository at this point in the history
…into mudit/POA-2309
  • Loading branch information
mudit-postman committed Nov 15, 2024
2 parents 97f57dd + 024d69a commit 4dac26f
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 149 deletions.
4 changes: 2 additions & 2 deletions trace/backend_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ func (c *BackendCollector) queueUpload(w *witnessWithInfo) {
if !c.sendWitnessPayloads || !hasOnlyErrorResponses(w.witness.GetMethod()) {
// Obfuscate the original value so type inference engine can use it on the
// backend without revealing the actual value.
c.obfuscator.ObfuscateDataWithZeroValue(w.witness.GetMethod())
c.obfuscator.ZeroAllPrimitivesInMethod(w.witness.GetMethod())
} else {
c.obfuscator.RedactData(w.witness.GetMethod())
c.obfuscator.RedactSensitiveData(w.witness.GetMethod())
}

c.uploadReportBatch.Add(rawReport{
Expand Down
99 changes: 81 additions & 18 deletions trace/backend_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,12 @@ func TestObfuscationConfigs(t *testing.T) {
// Prepare a test cases
streamID := uuid.New()
type testCase struct {
name string
request akinet.HTTPRequest
response akinet.HTTPResponse
expectedWitnesses *api_spec.Witness
}
testCases := []testCase{
{
name: "no sensitive data",
testCases := map[string]testCase{
"no sensitive data": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -589,8 +587,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "sensitive data in header, query param, cookie and URL path",
"sensitive data in header, query param, cookie and URL path": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -687,8 +684,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "sensitive data in body",
"sensitive data in body": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -763,8 +759,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "struct with sensitive keys and values",
"struct with sensitive keys and values": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -869,8 +864,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "list with sensitive keys and values",
"list with sensitive keys and values": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -986,8 +980,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "multipart data, no sensitive data",
"multipart data, no sensitive data": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -1062,8 +1055,7 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
{
name: "multipart data, with sensitive data",
"multipart data, with sensitive data": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Expand Down Expand Up @@ -1152,6 +1144,75 @@ func TestObfuscationConfigs(t *testing.T) {
},
},
},
"null value": {
request: akinet.HTTPRequest{
StreamID: streamID,
Seq: 1204,
Method: "POST",
URL: &url.URL{
Path: "/",
},
Host: "example.com",
Header: map[string][]string{
"Content-Type": {"application/json"},
},
Body: memview.New([]byte(`
{
"null": null
}
`)),
},
response: akinet.HTTPResponse{
StreamID: streamID,
Seq: 1204,
StatusCode: 404,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
Body: memview.New([]byte(`
{
"null": null
}
`)),
},
expectedWitnesses: &pb.Witness{
Method: &pb.Method{
Id: &pb.MethodID{
ApiType: pb.ApiType_HTTP_REST,
},
Args: map[string]*pb.Data{
"sLSDNjJ5umQ=": newTestBodySpecFromStruct(
0,
pb.HTTPBody_JSON,
"application/json",
map[string]*pb.Data{
"null": spec_util.NoneData,
},
),
},
Responses: map[string]*pb.Data{
"2drZdoQw74E=": newTestBodySpecFromStruct(
404,
pb.HTTPBody_JSON,
"application/json",
map[string]*pb.Data{
"null": spec_util.NoneData,
},
),
},
Meta: &pb.MethodMeta{
Meta: &pb.MethodMeta_Http{
Http: &pb.HTTPMethodMeta{
Method: "POST",
PathTemplate: "/",
Host: "example.com",
Obfuscation: api_spec.HTTPMethodMeta_NONE,
},
},
},
},
},
},
}

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

for i, testCase := range testCases {
fmt.Println("Running test case: ", testCase.name)
i := -1
for name, testCase := range testCases {
i++
fmt.Println("Running test case: ", name)

req := akinet.ParsedNetworkTraffic{Content: testCase.request}
resp := akinet.ParsedNetworkTraffic{Content: testCase.response}
Expand Down
Loading

0 comments on commit 4dac26f

Please sign in to comment.