Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for null string unmarshal error #3284

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
AlexBVolcy marked this conversation as resolved.
Show resolved Hide resolved
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
Loading