Skip to content

Commit

Permalink
Fix for NPE for nil request in analytics module (#3599)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 authored Mar 27, 2024
1 parent 67c487d commit c72ffe4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions analytics/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func evaluateActivities(rw *openrtb_ext.RequestWrapper, ac privacy.ActivityContr
}

func updateReqWrapperForAnalytics(rw *openrtb_ext.RequestWrapper, adapterName string, isCloned bool) *openrtb_ext.RequestWrapper {
if rw == nil {
return nil
}
reqExt, _ := rw.GetRequestExt()
reqExtPrebid := reqExt.GetPrebid()
if reqExtPrebid == nil {
Expand Down
12 changes: 11 additions & 1 deletion analytics/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,22 @@ func TestUpdateReqWrapperForAnalytics(t *testing.T) {
Ext: []byte(`{"prebid":{"analytics":{"adapter1":{"client-analytics":true},"adapter2":{"client-analytics":false}}}}`)},
},
},
{
description: "Given request is nil, check there are no exceptions",
givenReqWrapper: nil,
givenAdapterName: "adapter1",
givenIsCloned: false,
expectedUpdatedBidRequest: nil,
expectedCloneRequest: nil,
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
cloneReq := updateReqWrapperForAnalytics(test.givenReqWrapper, test.givenAdapterName, test.givenIsCloned)
assert.Equal(t, test.expectedUpdatedBidRequest, test.givenReqWrapper.BidRequest)
if test.givenReqWrapper != nil {
assert.Equal(t, test.expectedUpdatedBidRequest, test.givenReqWrapper.BidRequest)
}
assert.Equal(t, test.expectedCloneRequest, cloneReq)
})
}
Expand Down

0 comments on commit c72ffe4

Please sign in to comment.