Skip to content

Commit

Permalink
Fix for null string unmarshal error (#3284)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 authored Nov 13, 2023
1 parent 5941d46 commit 9099264
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, bidderRequest Bidde

func addNativeTypes(bid *openrtb2.Bid, request *openrtb2.BidRequest) (*nativeResponse.Response, []error) {
var errs []error
var nativeMarkup *nativeResponse.Response
var nativeMarkup nativeResponse.Response
if err := jsonutil.UnmarshalValid(json.RawMessage(bid.AdM), &nativeMarkup); err != nil || len(nativeMarkup.Assets) == 0 {
// Some bidders are returning non-IAB compliant native markup. In this case Prebid server will not be able to add types. E.g Facebook
return nil, errs
Expand All @@ -429,7 +429,7 @@ func addNativeTypes(bid *openrtb2.Bid, request *openrtb2.BidRequest) (*nativeRes
}
}

return nativeMarkup, errs
return &nativeMarkup, errs
}

func setAssetTypes(asset nativeResponse.Asset, nativePayload nativeRequests.Request) error {
Expand Down
40 changes: 40 additions & 0 deletions exchange/bidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,46 @@ func TestMobileNativeTypes(t *testing.T) {
}
}

func TestAddNativeTypes(t *testing.T) {
testCases := []struct {
description string
bidderRequest *openrtb2.BidRequest
bid *openrtb2.Bid
expectedResponse *nativeResponse.Response
expectedErrors []error
}{
{
description: "Null in bid.Adm in response",
bidderRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "some-imp-id",
Native: &openrtb2.Native{
Request: "{\"ver\":\"1.1\",\"context\":1,\"contextsubtype\":11,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":500}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":1,\"hmin\":1}},{\"id\":3,\"required\":0,\"data\":{\"type\":1,\"len\":200}},{\"id\":4,\"required\":0,\"data\":{\"type\":2,\"len\":15000}},{\"id\":5,\"required\":0,\"data\":{\"type\":6,\"len\":40}}]}",
},
},
},
App: &openrtb2.App{},
},
bid: &openrtb2.Bid{
ImpID: "some-imp-id",
AdM: "null",
Price: 10,
},
expectedResponse: nil,
expectedErrors: nil,
},
}

for _, tt := range testCases {
t.Run(tt.description, func(t *testing.T) {
resp, errs := addNativeTypes(tt.bid, tt.bidderRequest)
assert.Equal(t, tt.expectedResponse, resp, "response")
assert.Equal(t, tt.expectedErrors, errs, "errors")
})
}
}

func TestRequestBidsStoredBidResponses(t *testing.T) {
respBody := "{\"bid\":false}"
respStatus := 200
Expand Down

0 comments on commit 9099264

Please sign in to comment.