From 5ca444fc012f7d305525fe2417dbe1debb809821 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Thu, 28 Aug 2025 12:22:12 +0200 Subject: [PATCH 01/14] Return buyer exts in response to DSP --- adapters/openx/openx.go | 83 ++++++++++++++ adapters/openx/openx_test.go | 79 ++++++++++++++ .../openxtest/exemplary/bid-ext-meta.json | 103 ++++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 adapters/openx/openxtest/exemplary/bid-ext-meta.json diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index f10985f3085..7dbbc5a3f53 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v3/adapters" @@ -32,6 +33,12 @@ type openxRespExt struct { FledgeAuctionConfigs map[string]json.RawMessage `json:"fledge_auction_configs,omitempty"` } +type oxBidExt struct { + DspId *string `json:"dsp_id,omitempty"` + BrandId *string `json:"brand_id,omitempty"` + BuyerId *string `json:"buyer_id,omitempty"` +} + func (a *OpenxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var errs []error var bannerAndNativeImps []openrtb2.Imp @@ -233,7 +240,13 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRe } for _, sb := range bidResp.SeatBid { + var ext *oxBidExt + if sb.Ext != nil { + _ = jsonutil.Unmarshal(sb.Ext, &ext) + } for i := range sb.Bid { + var bid = &sb.Bid[i] + bid.Ext = updateBidExtWithMeta(bid, ext) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &sb.Bid[i], BidType: getBidType(sb.Bid[i].MType, sb.Bid[i].ImpID, internalRequest.Imp), @@ -298,3 +311,73 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co } return bidder, nil } + +func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { + if ext == nil { + return nil + } + buyerId := getBuyerIdFromExt(ext) + dspId := getDspIdFromExt(ext) + brandId := getBrandIdFromExt(ext) + if buyerId <= 0 && dspId <= 0 && brandId <= 0 { + return nil + } + var extBidPrebid *openrtb_ext.ExtBidPrebid + if bid.Ext != nil { + if err := jsonutil.Unmarshal(bid.Ext, &extBidPrebid); err != nil { + return nil + } + } + + if extBidPrebid != nil { + if extBidPrebid.Meta != nil { + extBidPrebid.Meta.NetworkID = buyerId + extBidPrebid.Meta.AdvertiserID = dspId + extBidPrebid.Meta.BrandID = brandId + } else { + extBidPrebid.Meta = &openrtb_ext.ExtBidPrebidMeta{ + NetworkID: buyerId, + AdvertiserID: dspId, + BrandID: brandId, + } + } + } else { + extBidPrebid = &openrtb_ext.ExtBidPrebid{ + Meta: &openrtb_ext.ExtBidPrebidMeta{ + NetworkID: buyerId, + AdvertiserID: dspId, + BrandID: brandId, + }, + } + } + + marshalledExt, err := json.Marshal(&extBidPrebid) + if err == nil { + return marshalledExt + } + return nil +} + +func getBuyerIdFromExt(ext *oxBidExt) int { + if ext.BuyerId == nil { + return 0 + } + buyerID, _ := strconv.Atoi(*ext.BuyerId) + return buyerID +} + +func getDspIdFromExt(ext *oxBidExt) int { + if ext.DspId == nil { + return 0 + } + dspId, _ := strconv.Atoi(*ext.DspId) + return dspId +} + +func getBrandIdFromExt(ext *oxBidExt) int { + if ext.BrandId == nil { + return 0 + } + brandId, _ := strconv.Atoi(*ext.BrandId) + return brandId +} diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 092e9190f90..e4d7544fcdf 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -2,6 +2,7 @@ package openx import ( "encoding/json" + "github.com/prebid/prebid-server/v3/util/jsonutil" "testing" "github.com/prebid/openrtb/v20/openrtb2" @@ -33,6 +34,84 @@ func TestResponseWithCurrencies(t *testing.T) { assertCurrencyInBidResponse(t, "EUR", ¤cy) } +func TestUpdateBidExtWithMeta(t *testing.T) { + buyerId := "123" + dspId := "456" + bradId := "789" + + bidExts := []*openrtb_ext.ExtBidPrebid{ + nil, + {}, + {Meta: &openrtb_ext.ExtBidPrebidMeta{}}, + } + + testCases := []struct { + ext *oxBidExt + expectedBuyerId int + expectedDspId int + expectedBrandId int + }{ + { + &oxBidExt{BuyerId: &buyerId, DspId: &dspId, BrandId: &bradId}, + 123, + 456, + 789, + }, + { + &oxBidExt{BuyerId: &buyerId, DspId: &dspId}, + 123, + 456, + 0, + }, + { + &oxBidExt{BuyerId: &buyerId, BrandId: &bradId}, + 123, + 0, + 789, + }, + { + &oxBidExt{DspId: &dspId, BrandId: &bradId}, + 0, + 456, + 789, + }, + { + &oxBidExt{BuyerId: &buyerId}, + 123, + 0, + 0, + }, + { + &oxBidExt{DspId: &dspId}, + 0, + 456, + 0, + }, + { + &oxBidExt{BrandId: &bradId}, + 0, + 0, + 789, + }, + } + + for _, testCase := range testCases { + for _, bidExt := range bidExts { + marshaledExt, _ := json.Marshal(bidExt) + bid := &openrtb2.Bid{Ext: marshaledExt} + + bid.Ext = updateBidExtWithMeta(bid, testCase.ext) + + var updatedExt *openrtb_ext.ExtBidPrebid + _ = jsonutil.Unmarshal(bid.Ext, &updatedExt) + + assert.Equal(t, testCase.expectedBuyerId, updatedExt.Meta.NetworkID) + assert.Equal(t, testCase.expectedDspId, updatedExt.Meta.AdvertiserID) + assert.Equal(t, testCase.expectedBrandId, updatedExt.Meta.BrandID) + } + } +} + func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) { bidder, buildErr := Builder(openrtb_ext.BidderOpenx, config.Adapter{ Endpoint: "http://rtb.openx.net/prebid"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) diff --git a/adapters/openx/openxtest/exemplary/bid-ext-meta.json b/adapters/openx/openxtest/exemplary/bid-ext-meta.json new file mode 100644 index 00000000000..396fcca812b --- /dev/null +++ b/adapters/openx/openxtest/exemplary/bid-ext-meta.json @@ -0,0 +1,103 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "ext": { + "ae": 1, + "bidder": { + "unit": "539439964", + "delDomain": "se-demo-d.openx.net" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://rtb.openx.net/prebid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 728, "h": 90}] + }, + "tagid": "539439964", + "ext": { + "ae": 1 + } + } + ], + "ext": { + "bc": "hb_pbs_1.0.0", + "delDomain": "se-demo-d.openx.net" + } + }, + "impIDs":["test-imp-id"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "openx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "crid_10", + "h": 90, + "w": 728, + "mtype": 1 + }], + "ext": { + "dsp_id": "123", + "brand_id": "456", + "buyer_id": "789" + } + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "crid_10", + "ext": { + "meta": { + "advertiserId": 123, + "brandId": 456, + "networkId": 789 + } + }, + "w": 728, + "h": 90, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} From c67d07cf8d78433d24c51bf15f5ed5536e8350f4 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Thu, 28 Aug 2025 12:27:57 +0200 Subject: [PATCH 02/14] refactor --- adapters/openx/openx.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 7dbbc5a3f53..fa5e8ebbe40 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -322,11 +322,10 @@ func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { if buyerId <= 0 && dspId <= 0 && brandId <= 0 { return nil } + var extBidPrebid *openrtb_ext.ExtBidPrebid if bid.Ext != nil { - if err := jsonutil.Unmarshal(bid.Ext, &extBidPrebid); err != nil { - return nil - } + _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) } if extBidPrebid != nil { @@ -351,9 +350,9 @@ func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { } } - marshalledExt, err := json.Marshal(&extBidPrebid) + marshaledExt, err := json.Marshal(&extBidPrebid) if err == nil { - return marshalledExt + return marshaledExt } return nil } From a4c4fc4958d1a3c595775944e3afdb9a47eae0b8 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Thu, 28 Aug 2025 12:34:41 +0200 Subject: [PATCH 03/14] refactor --- adapters/openx/openx.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index fa5e8ebbe40..be93e760847 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -324,9 +324,7 @@ func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { } var extBidPrebid *openrtb_ext.ExtBidPrebid - if bid.Ext != nil { - _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) - } + _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) if extBidPrebid != nil { if extBidPrebid.Meta != nil { From 2b54e68cc125608b8f3d14a858631d31c75bfa7e Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Thu, 28 Aug 2025 13:10:32 +0200 Subject: [PATCH 04/14] extract buyer ext from bid not seatBid --- adapters/openx/openx.go | 43 ++++++++----------- adapters/openx/openx_test.go | 26 ++++------- .../openxtest/exemplary/bid-ext-meta.json | 12 +++--- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index be93e760847..687d47bcd04 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -240,13 +240,9 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRe } for _, sb := range bidResp.SeatBid { - var ext *oxBidExt - if sb.Ext != nil { - _ = jsonutil.Unmarshal(sb.Ext, &ext) - } for i := range sb.Bid { var bid = &sb.Bid[i] - bid.Ext = updateBidExtWithMeta(bid, ext) + bid.Ext = updateBidExtMeta(bid) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &sb.Bid[i], BidType: getBidType(sb.Bid[i].MType, sb.Bid[i].ImpID, internalRequest.Imp), @@ -312,10 +308,16 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co return bidder, nil } -func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { - if ext == nil { +func updateBidExtMeta(bid *openrtb2.Bid) json.RawMessage { + if bid.Ext == nil { return nil } + + var ext *oxBidExt + if err := jsonutil.Unmarshal(bid.Ext, &ext); err != nil { + return nil + } + buyerId := getBuyerIdFromExt(ext) dspId := getDspIdFromExt(ext) brandId := getBrandIdFromExt(ext) @@ -325,26 +327,15 @@ func updateBidExtWithMeta(bid *openrtb2.Bid, ext *oxBidExt) json.RawMessage { var extBidPrebid *openrtb_ext.ExtBidPrebid _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) - - if extBidPrebid != nil { - if extBidPrebid.Meta != nil { - extBidPrebid.Meta.NetworkID = buyerId - extBidPrebid.Meta.AdvertiserID = dspId - extBidPrebid.Meta.BrandID = brandId - } else { - extBidPrebid.Meta = &openrtb_ext.ExtBidPrebidMeta{ - NetworkID: buyerId, - AdvertiserID: dspId, - BrandID: brandId, - } - } + if extBidPrebid.Meta != nil { + extBidPrebid.Meta.NetworkID = buyerId + extBidPrebid.Meta.AdvertiserID = dspId + extBidPrebid.Meta.BrandID = brandId } else { - extBidPrebid = &openrtb_ext.ExtBidPrebid{ - Meta: &openrtb_ext.ExtBidPrebidMeta{ - NetworkID: buyerId, - AdvertiserID: dspId, - BrandID: brandId, - }, + extBidPrebid.Meta = &openrtb_ext.ExtBidPrebidMeta{ + NetworkID: buyerId, + AdvertiserID: dspId, + BrandID: brandId, } } diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index e4d7544fcdf..3a5445840a7 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -34,17 +34,11 @@ func TestResponseWithCurrencies(t *testing.T) { assertCurrencyInBidResponse(t, "EUR", ¤cy) } -func TestUpdateBidExtWithMeta(t *testing.T) { +func TestUpdateBidExtMeta(t *testing.T) { buyerId := "123" dspId := "456" bradId := "789" - bidExts := []*openrtb_ext.ExtBidPrebid{ - nil, - {}, - {Meta: &openrtb_ext.ExtBidPrebidMeta{}}, - } - testCases := []struct { ext *oxBidExt expectedBuyerId int @@ -96,19 +90,17 @@ func TestUpdateBidExtWithMeta(t *testing.T) { } for _, testCase := range testCases { - for _, bidExt := range bidExts { - marshaledExt, _ := json.Marshal(bidExt) - bid := &openrtb2.Bid{Ext: marshaledExt} + marshaledExt, _ := json.Marshal(testCase.ext) + bid := &openrtb2.Bid{Ext: marshaledExt} - bid.Ext = updateBidExtWithMeta(bid, testCase.ext) + bid.Ext = updateBidExtMeta(bid) - var updatedExt *openrtb_ext.ExtBidPrebid - _ = jsonutil.Unmarshal(bid.Ext, &updatedExt) + var updatedExt *openrtb_ext.ExtBidPrebid + _ = jsonutil.Unmarshal(bid.Ext, &updatedExt) - assert.Equal(t, testCase.expectedBuyerId, updatedExt.Meta.NetworkID) - assert.Equal(t, testCase.expectedDspId, updatedExt.Meta.AdvertiserID) - assert.Equal(t, testCase.expectedBrandId, updatedExt.Meta.BrandID) - } + assert.Equal(t, testCase.expectedBuyerId, updatedExt.Meta.NetworkID) + assert.Equal(t, testCase.expectedDspId, updatedExt.Meta.AdvertiserID) + assert.Equal(t, testCase.expectedBrandId, updatedExt.Meta.BrandID) } } diff --git a/adapters/openx/openxtest/exemplary/bid-ext-meta.json b/adapters/openx/openxtest/exemplary/bid-ext-meta.json index 396fcca812b..22cd96194b9 100644 --- a/adapters/openx/openxtest/exemplary/bid-ext-meta.json +++ b/adapters/openx/openxtest/exemplary/bid-ext-meta.json @@ -56,15 +56,15 @@ "price": 0.500000, "adm": "some-test-ad", "crid": "crid_10", + "ext": { + "dsp_id": "123", + "brand_id": "456", + "buyer_id": "789" + }, "h": 90, "w": 728, "mtype": 1 - }], - "ext": { - "dsp_id": "123", - "brand_id": "456", - "buyer_id": "789" - } + }] } ], "cur": "USD" From d840da6dfb69f479f17cfa55eb267fd6729694c6 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 11:26:32 +0200 Subject: [PATCH 05/14] refactor getBidMeta --- adapters/openx/openx.go | 11 +++-------- adapters/openx/openx_test.go | 14 +++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 687d47bcd04..44ccfb4f349 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -241,12 +241,11 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRe for _, sb := range bidResp.SeatBid { for i := range sb.Bid { - var bid = &sb.Bid[i] - bid.Ext = updateBidExtMeta(bid) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &sb.Bid[i], BidType: getBidType(sb.Bid[i].MType, sb.Bid[i].ImpID, internalRequest.Imp), BidVideo: getBidVideo(&sb.Bid[i]), + BidMeta: getBidMeta(&sb.Bid[i]), }) } } @@ -308,7 +307,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co return bidder, nil } -func updateBidExtMeta(bid *openrtb2.Bid) json.RawMessage { +func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { if bid.Ext == nil { return nil } @@ -339,11 +338,7 @@ func updateBidExtMeta(bid *openrtb2.Bid) json.RawMessage { } } - marshaledExt, err := json.Marshal(&extBidPrebid) - if err == nil { - return marshaledExt - } - return nil + return extBidPrebid.Meta } func getBuyerIdFromExt(ext *oxBidExt) int { diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 3a5445840a7..568503e0d72 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -2,7 +2,6 @@ package openx import ( "encoding/json" - "github.com/prebid/prebid-server/v3/util/jsonutil" "testing" "github.com/prebid/openrtb/v20/openrtb2" @@ -34,7 +33,7 @@ func TestResponseWithCurrencies(t *testing.T) { assertCurrencyInBidResponse(t, "EUR", ¤cy) } -func TestUpdateBidExtMeta(t *testing.T) { +func TestGetBidMeta(t *testing.T) { buyerId := "123" dspId := "456" bradId := "789" @@ -93,14 +92,11 @@ func TestUpdateBidExtMeta(t *testing.T) { marshaledExt, _ := json.Marshal(testCase.ext) bid := &openrtb2.Bid{Ext: marshaledExt} - bid.Ext = updateBidExtMeta(bid) + upadtedMeta := getBidMeta(bid) - var updatedExt *openrtb_ext.ExtBidPrebid - _ = jsonutil.Unmarshal(bid.Ext, &updatedExt) - - assert.Equal(t, testCase.expectedBuyerId, updatedExt.Meta.NetworkID) - assert.Equal(t, testCase.expectedDspId, updatedExt.Meta.AdvertiserID) - assert.Equal(t, testCase.expectedBrandId, updatedExt.Meta.BrandID) + assert.Equal(t, testCase.expectedBuyerId, upadtedMeta.NetworkID) + assert.Equal(t, testCase.expectedDspId, upadtedMeta.AdvertiserID) + assert.Equal(t, testCase.expectedBrandId, upadtedMeta.BrandID) } } From 285b8798242851ace5c08a5b8ac3645b3b6a3b6f Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 11:35:44 +0200 Subject: [PATCH 06/14] fix setting meta parameters --- adapters/openx/openx.go | 8 ++++---- adapters/openx/openx_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 44ccfb4f349..207d35a842f 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -327,13 +327,13 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { var extBidPrebid *openrtb_ext.ExtBidPrebid _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) if extBidPrebid.Meta != nil { - extBidPrebid.Meta.NetworkID = buyerId - extBidPrebid.Meta.AdvertiserID = dspId + extBidPrebid.Meta.NetworkID = dspId + extBidPrebid.Meta.AdvertiserID = buyerId extBidPrebid.Meta.BrandID = brandId } else { extBidPrebid.Meta = &openrtb_ext.ExtBidPrebidMeta{ - NetworkID: buyerId, - AdvertiserID: dspId, + NetworkID: dspId, + AdvertiserID: buyerId, BrandID: brandId, } } diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 568503e0d72..cd375474990 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -94,8 +94,8 @@ func TestGetBidMeta(t *testing.T) { upadtedMeta := getBidMeta(bid) - assert.Equal(t, testCase.expectedBuyerId, upadtedMeta.NetworkID) - assert.Equal(t, testCase.expectedDspId, upadtedMeta.AdvertiserID) + assert.Equal(t, testCase.expectedDspId, upadtedMeta.NetworkID) + assert.Equal(t, testCase.expectedBuyerId, upadtedMeta.AdvertiserID) assert.Equal(t, testCase.expectedBrandId, upadtedMeta.BrandID) } } From c249393b75389ef6a7d41b170e9d528fd2a5b950 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 13:07:29 +0200 Subject: [PATCH 07/14] test refactor --- adapters/openx/openx.go | 18 +-- adapters/openx/openx_test.go | 56 +++++----- .../openxtest/exemplary/bid-ext-meta.json | 103 ------------------ 3 files changed, 30 insertions(+), 147 deletions(-) delete mode 100644 adapters/openx/openxtest/exemplary/bid-ext-meta.json diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 207d35a842f..a95c6977637 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -324,21 +324,11 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { return nil } - var extBidPrebid *openrtb_ext.ExtBidPrebid - _ = jsonutil.Unmarshal(bid.Ext, &extBidPrebid) - if extBidPrebid.Meta != nil { - extBidPrebid.Meta.NetworkID = dspId - extBidPrebid.Meta.AdvertiserID = buyerId - extBidPrebid.Meta.BrandID = brandId - } else { - extBidPrebid.Meta = &openrtb_ext.ExtBidPrebidMeta{ - NetworkID: dspId, - AdvertiserID: buyerId, - BrandID: brandId, - } + return &openrtb_ext.ExtBidPrebidMeta{ + NetworkID: dspId, + AdvertiserID: buyerId, + BrandID: brandId, } - - return extBidPrebid.Meta } func getBuyerIdFromExt(ext *oxBidExt) int { diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index cd375474990..639b8d105ec 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -2,6 +2,7 @@ package openx import ( "encoding/json" + "net/http" "testing" "github.com/prebid/openrtb/v20/openrtb2" @@ -39,65 +40,60 @@ func TestGetBidMeta(t *testing.T) { bradId := "789" testCases := []struct { - ext *oxBidExt - expectedBuyerId int - expectedDspId int - expectedBrandId int + ext *oxBidExt + expectedMeta *openrtb_ext.ExtBidPrebidMeta }{ { &oxBidExt{BuyerId: &buyerId, DspId: &dspId, BrandId: &bradId}, - 123, - 456, - 789, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 789}, }, { &oxBidExt{BuyerId: &buyerId, DspId: &dspId}, - 123, - 456, - 0, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 0}, }, { &oxBidExt{BuyerId: &buyerId, BrandId: &bradId}, - 123, - 0, - 789, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 789}, }, { &oxBidExt{DspId: &dspId, BrandId: &bradId}, - 0, - 456, - 789, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 789}, }, { &oxBidExt{BuyerId: &buyerId}, - 123, - 0, - 0, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 0}, }, { &oxBidExt{DspId: &dspId}, - 0, - 456, - 0, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 0}, }, { &oxBidExt{BrandId: &bradId}, - 0, - 0, - 789, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 0, BrandID: 789}, }, } for _, testCase := range testCases { marshaledExt, _ := json.Marshal(testCase.ext) bid := &openrtb2.Bid{Ext: marshaledExt} + updatedMeta := getBidMeta(bid) + assert.Equal(t, testCase.expectedMeta, updatedMeta) + } +} - upadtedMeta := getBidMeta(bid) - - assert.Equal(t, testCase.expectedDspId, upadtedMeta.NetworkID) - assert.Equal(t, testCase.expectedBuyerId, upadtedMeta.AdvertiserID) - assert.Equal(t, testCase.expectedBrandId, upadtedMeta.BrandID) +func TestOpenxAdapter_MakeBids_BidsMeta(t *testing.T) { + responseBody := `{"id":"test-request-id","seatbid":[{"seat":"openx","bid":[{"id":"all-buyer-ext","impid":"all-buyer-ext-imp-id","price":0.5,"adm":"some-test-ad","crid":"crid_10","ext":{"dsp_id":"123","brand_id":"456","buyer_id":"789"},"h":90,"w":728,"mtype":1},{"id":"only-dspId","impid":"only-dspId-imp-id","price":0.6,"adm":"some-test-ad","crid":"crid_11","ext":{"dsp_id":"321"},"h":90,"w":728,"mtype":1}]}],"cur":"USD"}` + allBuyerMeta := &openrtb_ext.ExtBidPrebidMeta{NetworkID: 123, BrandID: 456, AdvertiserID: 789} + onlyDspIdMeta := &openrtb_ext.ExtBidPrebidMeta{NetworkID: 321} + response := &adapters.ResponseData{ + StatusCode: http.StatusOK, + Body: []byte(responseBody), } + adapter := &OpenxAdapter{bidderName: "", endpoint: ""} + bids, _ := adapter.MakeBids(&openrtb2.BidRequest{}, &adapters.RequestData{}, response) + assert.Equal(t, len(bids.Bids), 2) + assert.Equal(t, bids.Bids[0].BidMeta, allBuyerMeta) + assert.Equal(t, bids.Bids[1].BidMeta, onlyDspIdMeta) } func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) { diff --git a/adapters/openx/openxtest/exemplary/bid-ext-meta.json b/adapters/openx/openxtest/exemplary/bid-ext-meta.json deleted file mode 100644 index 22cd96194b9..00000000000 --- a/adapters/openx/openxtest/exemplary/bid-ext-meta.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "mockBidRequest": { - "id": "test-request-id", - "imp": [ - { - "id": "test-imp-id", - "banner": { - "format": [{"w": 728, "h": 90}] - }, - "ext": { - "ae": 1, - "bidder": { - "unit": "539439964", - "delDomain": "se-demo-d.openx.net" - } - } - } - ] - }, - - "httpCalls": [ - { - "expectedRequest": { - "uri": "http://rtb.openx.net/prebid", - "body": { - "id": "test-request-id", - "imp": [ - { - "id": "test-imp-id", - "banner": { - "format": [{"w": 728, "h": 90}] - }, - "tagid": "539439964", - "ext": { - "ae": 1 - } - } - ], - "ext": { - "bc": "hb_pbs_1.0.0", - "delDomain": "se-demo-d.openx.net" - } - }, - "impIDs":["test-imp-id"] - }, - "mockResponse": { - "status": 200, - "body": { - "id": "test-request-id", - "seatbid": [ - { - "seat": "openx", - "bid": [{ - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id", - "price": 0.500000, - "adm": "some-test-ad", - "crid": "crid_10", - "ext": { - "dsp_id": "123", - "brand_id": "456", - "buyer_id": "789" - }, - "h": 90, - "w": 728, - "mtype": 1 - }] - } - ], - "cur": "USD" - } - } - } - ], - - "expectedBidResponses": [ - { - "currency": "USD", - "bids": [ - { - "bid": { - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id", - "price": 0.5, - "adm": "some-test-ad", - "crid": "crid_10", - "ext": { - "meta": { - "advertiserId": 123, - "brandId": 456, - "networkId": 789 - } - }, - "w": 728, - "h": 90, - "mtype": 1 - }, - "type": "banner" - } - ] - } - ] -} From 8aac64fd1a5c8581363fb828cfe12318d2f21358 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 15:23:10 +0200 Subject: [PATCH 08/14] suggestions --- adapters/openx/openx.go | 18 +++++----- adapters/openx/openx_test.go | 68 +++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index a95c6977637..93426bcb139 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -34,9 +34,9 @@ type openxRespExt struct { } type oxBidExt struct { - DspId *string `json:"dsp_id,omitempty"` - BrandId *string `json:"brand_id,omitempty"` - BuyerId *string `json:"buyer_id,omitempty"` + DspId string `json:"dsp_id,omitempty"` + BrandId string `json:"brand_id,omitempty"` + BuyerId string `json:"buyer_id,omitempty"` } func (a *OpenxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { @@ -332,25 +332,25 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { } func getBuyerIdFromExt(ext *oxBidExt) int { - if ext.BuyerId == nil { + buyerID, err := strconv.Atoi(ext.BuyerId) + if err != nil { return 0 } - buyerID, _ := strconv.Atoi(*ext.BuyerId) return buyerID } func getDspIdFromExt(ext *oxBidExt) int { - if ext.DspId == nil { + dspId, err := strconv.Atoi(ext.DspId) + if err != nil { return 0 } - dspId, _ := strconv.Atoi(*ext.DspId) return dspId } func getBrandIdFromExt(ext *oxBidExt) int { - if ext.BrandId == nil { + brandId, err := strconv.Atoi(ext.BrandId) + if err != nil { return 0 } - brandId, _ := strconv.Atoi(*ext.BrandId) return brandId } diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 639b8d105ec..576506e6efd 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -35,42 +35,46 @@ func TestResponseWithCurrencies(t *testing.T) { } func TestGetBidMeta(t *testing.T) { - buyerId := "123" - dspId := "456" - bradId := "789" - testCases := []struct { ext *oxBidExt expectedMeta *openrtb_ext.ExtBidPrebidMeta }{ { - &oxBidExt{BuyerId: &buyerId, DspId: &dspId, BrandId: &bradId}, + &oxBidExt{BuyerId: "123", DspId: "456", BrandId: "789"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 789}, }, { - &oxBidExt{BuyerId: &buyerId, DspId: &dspId}, + &oxBidExt{BuyerId: "123", DspId: "456"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 0}, }, { - &oxBidExt{BuyerId: &buyerId, BrandId: &bradId}, + &oxBidExt{BuyerId: "123", BrandId: "789"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 789}, }, { - &oxBidExt{DspId: &dspId, BrandId: &bradId}, + &oxBidExt{DspId: "456", BrandId: "789"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 789}, }, { - &oxBidExt{BuyerId: &buyerId}, + &oxBidExt{BuyerId: "123"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 0}, }, { - &oxBidExt{DspId: &dspId}, + &oxBidExt{DspId: "456"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 0}, }, { - &oxBidExt{BrandId: &bradId}, + &oxBidExt{BrandId: "789"}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 0, BrandID: 789}, }, + { + &oxBidExt{BuyerId: "123", DspId: "456", BrandId: "badId"}, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 0}, + }, + { + &oxBidExt{BuyerId: "badId", DspId: "badId", BrandId: "badId"}, + nil, + }, } for _, testCase := range testCases { @@ -83,17 +87,49 @@ func TestGetBidMeta(t *testing.T) { func TestOpenxAdapter_MakeBids_BidsMeta(t *testing.T) { responseBody := `{"id":"test-request-id","seatbid":[{"seat":"openx","bid":[{"id":"all-buyer-ext","impid":"all-buyer-ext-imp-id","price":0.5,"adm":"some-test-ad","crid":"crid_10","ext":{"dsp_id":"123","brand_id":"456","buyer_id":"789"},"h":90,"w":728,"mtype":1},{"id":"only-dspId","impid":"only-dspId-imp-id","price":0.6,"adm":"some-test-ad","crid":"crid_11","ext":{"dsp_id":"321"},"h":90,"w":728,"mtype":1}]}],"cur":"USD"}` - allBuyerMeta := &openrtb_ext.ExtBidPrebidMeta{NetworkID: 123, BrandID: 456, AdvertiserID: 789} - onlyDspIdMeta := &openrtb_ext.ExtBidPrebidMeta{NetworkID: 321} response := &adapters.ResponseData{ StatusCode: http.StatusOK, Body: []byte(responseBody), } adapter := &OpenxAdapter{bidderName: "", endpoint: ""} bids, _ := adapter.MakeBids(&openrtb2.BidRequest{}, &adapters.RequestData{}, response) - assert.Equal(t, len(bids.Bids), 2) - assert.Equal(t, bids.Bids[0].BidMeta, allBuyerMeta) - assert.Equal(t, bids.Bids[1].BidMeta, onlyDspIdMeta) + assert.Equal(t, *bids, adapters.BidderResponse{ + Currency: "USD", + Bids: []*adapters.TypedBid{ + { + Bid: &openrtb2.Bid{ + ID: "all-buyer-ext", + ImpID: "all-buyer-ext-imp-id", + Price: 0.5, + AdM: "some-test-ad", + CrID: "crid_10", + W: 728, + H: 90, + MType: 1, + Ext: json.RawMessage(`{"dsp_id":"123","brand_id":"456","buyer_id":"789"}`), + }, + BidMeta: &openrtb_ext.ExtBidPrebidMeta{NetworkID: 123, BrandID: 456, AdvertiserID: 789}, + BidType: "banner", + BidVideo: &openrtb_ext.ExtBidPrebidVideo{Duration: 0, PrimaryCategory: ""}, + }, + { + Bid: &openrtb2.Bid{ + ID: "only-dspId", + ImpID: "only-dspId-imp-id", + Price: 0.6, + AdM: "some-test-ad", + CrID: "crid_11", + W: 728, + H: 90, + MType: 1, + Ext: json.RawMessage(`{"dsp_id":"321"}`), + }, + BidMeta: &openrtb_ext.ExtBidPrebidMeta{NetworkID: 321}, + BidType: "banner", + BidVideo: &openrtb_ext.ExtBidPrebidVideo{Duration: 0, PrimaryCategory: ""}, + }, + }, + }) } func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) { From 1322c1b8644ab79d7b39b0295b2f8c54b5de6939 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 15:27:09 +0200 Subject: [PATCH 09/14] refactor --- adapters/openx/openx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 93426bcb139..0378f41befa 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -332,11 +332,11 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { } func getBuyerIdFromExt(ext *oxBidExt) int { - buyerID, err := strconv.Atoi(ext.BuyerId) + buyerId, err := strconv.Atoi(ext.BuyerId) if err != nil { return 0 } - return buyerID + return buyerId } func getDspIdFromExt(ext *oxBidExt) int { From 264aed760b9b1a45424bfdb65ed3a4f8cc7f9e92 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Fri, 29 Aug 2025 15:52:13 +0200 Subject: [PATCH 10/14] add empty string check --- adapters/openx/openx.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 0378f41befa..6ea279064fe 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -332,6 +332,9 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { } func getBuyerIdFromExt(ext *oxBidExt) int { + if ext.BuyerId == "" { + return 0 + } buyerId, err := strconv.Atoi(ext.BuyerId) if err != nil { return 0 @@ -340,6 +343,9 @@ func getBuyerIdFromExt(ext *oxBidExt) int { } func getDspIdFromExt(ext *oxBidExt) int { + if ext.DspId == "" { + return 0 + } dspId, err := strconv.Atoi(ext.DspId) if err != nil { return 0 @@ -348,6 +354,9 @@ func getDspIdFromExt(ext *oxBidExt) int { } func getBrandIdFromExt(ext *oxBidExt) int { + if ext.BrandId == "" { + return 0 + } brandId, err := strconv.Atoi(ext.BrandId) if err != nil { return 0 From 8cd070bf2dcd07a06c0e76ab2bdd497ea8ad59a6 Mon Sep 17 00:00:00 2001 From: "kacper.fus" Date: Mon, 1 Sep 2025 10:35:26 +0200 Subject: [PATCH 11/14] suggested refactor --- adapters/openx/openx_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 576506e6efd..6735464978d 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -34,7 +34,7 @@ func TestResponseWithCurrencies(t *testing.T) { assertCurrencyInBidResponse(t, "EUR", ¤cy) } -func TestGetBidMeta(t *testing.T) { +func TestOpenxAdapter_GetBidMeta(t *testing.T) { testCases := []struct { ext *oxBidExt expectedMeta *openrtb_ext.ExtBidPrebidMeta @@ -85,7 +85,7 @@ func TestGetBidMeta(t *testing.T) { } } -func TestOpenxAdapter_MakeBids_BidsMeta(t *testing.T) { +func TestOpenxAdapter_MakeBids(t *testing.T) { responseBody := `{"id":"test-request-id","seatbid":[{"seat":"openx","bid":[{"id":"all-buyer-ext","impid":"all-buyer-ext-imp-id","price":0.5,"adm":"some-test-ad","crid":"crid_10","ext":{"dsp_id":"123","brand_id":"456","buyer_id":"789"},"h":90,"w":728,"mtype":1},{"id":"only-dspId","impid":"only-dspId-imp-id","price":0.6,"adm":"some-test-ad","crid":"crid_11","ext":{"dsp_id":"321"},"h":90,"w":728,"mtype":1}]}],"cur":"USD"}` response := &adapters.ResponseData{ StatusCode: http.StatusOK, @@ -93,7 +93,7 @@ func TestOpenxAdapter_MakeBids_BidsMeta(t *testing.T) { } adapter := &OpenxAdapter{bidderName: "", endpoint: ""} bids, _ := adapter.MakeBids(&openrtb2.BidRequest{}, &adapters.RequestData{}, response) - assert.Equal(t, *bids, adapters.BidderResponse{ + expectedBidderResponse := adapters.BidderResponse{ Currency: "USD", Bids: []*adapters.TypedBid{ { @@ -129,7 +129,8 @@ func TestOpenxAdapter_MakeBids_BidsMeta(t *testing.T) { BidVideo: &openrtb_ext.ExtBidPrebidVideo{Duration: 0, PrimaryCategory: ""}, }, }, - }) + } + assert.Equal(t, expectedBidderResponse, *bids) } func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) { From 880b7b88ec53cfa10ec6ca683fc216975e88a8a8 Mon Sep 17 00:00:00 2001 From: Rafal Sieczka Date: Tue, 9 Sep 2025 09:23:19 +0000 Subject: [PATCH 12/14] Unmarshal DspID and BrandID to int --- adapters/openx/openx.go | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/adapters/openx/openx.go b/adapters/openx/openx.go index 6ea279064fe..992baa0cdc7 100644 --- a/adapters/openx/openx.go +++ b/adapters/openx/openx.go @@ -34,8 +34,8 @@ type openxRespExt struct { } type oxBidExt struct { - DspId string `json:"dsp_id,omitempty"` - BrandId string `json:"brand_id,omitempty"` + DspId int `json:"dsp_id,string,omitempty"` + BrandId int `json:"brand_id,string,omitempty"` BuyerId string `json:"buyer_id,omitempty"` } @@ -318,16 +318,14 @@ func getBidMeta(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidMeta { } buyerId := getBuyerIdFromExt(ext) - dspId := getDspIdFromExt(ext) - brandId := getBrandIdFromExt(ext) - if buyerId <= 0 && dspId <= 0 && brandId <= 0 { + if buyerId <= 0 && ext.DspId <= 0 && ext.BrandId <= 0 { return nil } return &openrtb_ext.ExtBidPrebidMeta{ - NetworkID: dspId, + NetworkID: ext.DspId, AdvertiserID: buyerId, - BrandID: brandId, + BrandID: ext.BrandId, } } @@ -341,25 +339,3 @@ func getBuyerIdFromExt(ext *oxBidExt) int { } return buyerId } - -func getDspIdFromExt(ext *oxBidExt) int { - if ext.DspId == "" { - return 0 - } - dspId, err := strconv.Atoi(ext.DspId) - if err != nil { - return 0 - } - return dspId -} - -func getBrandIdFromExt(ext *oxBidExt) int { - if ext.BrandId == "" { - return 0 - } - brandId, err := strconv.Atoi(ext.BrandId) - if err != nil { - return 0 - } - return brandId -} From 2bb4719c32d365f4aa92e4a8e4615a8d1b57a939 Mon Sep 17 00:00:00 2001 From: Rafal Sieczka Date: Tue, 9 Sep 2025 09:23:56 +0000 Subject: [PATCH 13/14] Refactor test to use json.RawMessage --- adapters/openx/openx_test.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 6735464978d..984d03c503d 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -36,51 +36,57 @@ func TestResponseWithCurrencies(t *testing.T) { func TestOpenxAdapter_GetBidMeta(t *testing.T) { testCases := []struct { - ext *oxBidExt + bid *openrtb2.Bid expectedMeta *openrtb_ext.ExtBidPrebidMeta }{ { - &oxBidExt{BuyerId: "123", DspId: "456", BrandId: "789"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456","brand_id":"789","buyer_id":"123"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 789}, }, { - &oxBidExt{BuyerId: "123", DspId: "456"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456","brand_id":"malformed","buyer_id":"123"}`)}, + nil, + }, + { + &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456","brand_id":"789","buyer_id":"123-456"}`)}, + &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 789}, + }, + { + &openrtb2.Bid{Ext: json.RawMessage(`{"buyer_id":"123","dsp_id":"456"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 0}, }, { - &oxBidExt{BuyerId: "123", BrandId: "789"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"buyer_id":"123","brand_id":"789"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 789}, }, { - &oxBidExt{DspId: "456", BrandId: "789"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456","brand_id":"789"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 789}, }, { - &oxBidExt{BuyerId: "123"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"buyer_id":"123"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 0, BrandID: 0}, }, { - &oxBidExt{DspId: "456"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 456, BrandID: 0}, }, { - &oxBidExt{BrandId: "789"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"brand_id":"789"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 0, NetworkID: 0, BrandID: 789}, }, { - &oxBidExt{BuyerId: "123", DspId: "456", BrandId: "badId"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"buyer_id":"123","dsp_id":"456"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 0}, }, { - &oxBidExt{BuyerId: "badId", DspId: "badId", BrandId: "badId"}, + &openrtb2.Bid{Ext: json.RawMessage(`{"buyer_id":"malformed","dsp_id":"malformed","brand_id":"malformed"}`)}, nil, }, } for _, testCase := range testCases { - marshaledExt, _ := json.Marshal(testCase.ext) - bid := &openrtb2.Bid{Ext: marshaledExt} - updatedMeta := getBidMeta(bid) + updatedMeta := getBidMeta(testCase.bid) assert.Equal(t, testCase.expectedMeta, updatedMeta) } } From 5330f79ae9e48410d29900cdae8f53dcb9538b33 Mon Sep 17 00:00:00 2001 From: Rafal Sieczka Date: Tue, 9 Sep 2025 09:27:17 +0000 Subject: [PATCH 14/14] Add additional test cases --- adapters/openx/openx_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adapters/openx/openx_test.go b/adapters/openx/openx_test.go index 984d03c503d..fdfb37cc4a0 100644 --- a/adapters/openx/openx_test.go +++ b/adapters/openx/openx_test.go @@ -39,6 +39,14 @@ func TestOpenxAdapter_GetBidMeta(t *testing.T) { bid *openrtb2.Bid expectedMeta *openrtb_ext.ExtBidPrebidMeta }{ + { + &openrtb2.Bid{Ext: json.RawMessage(`malformed`)}, + nil, + }, + { + &openrtb2.Bid{Ext: json.RawMessage(`{}`)}, + nil, + }, { &openrtb2.Bid{Ext: json.RawMessage(`{"dsp_id":"456","brand_id":"789","buyer_id":"123"}`)}, &openrtb_ext.ExtBidPrebidMeta{AdvertiserID: 123, NetworkID: 456, BrandID: 789},