From 98d62fb07699e9ffb500806f0eb7af009976de4e Mon Sep 17 00:00:00 2001 From: Harbar Dmytro Date: Fri, 10 Apr 2020 14:28:50 +0300 Subject: [PATCH 1/2] Add Cropping of BAdv for Rubicon Adapter BAdv size is limited to 50 --- adapters/rubicon/rubicon.go | 9 +++++++ adapters/rubicon/rubicon_test.go | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/adapters/rubicon/rubicon.go b/adapters/rubicon/rubicon.go index 46caf262108..7a2a1f2d346 100644 --- a/adapters/rubicon/rubicon.go +++ b/adapters/rubicon/rubicon.go @@ -740,6 +740,15 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap request.App = &appCopy } + // Сrop badv to 50 elements + badvLimitSize := 50 + reqBadv := request.BAdv + if reqBadv != nil { + if len(reqBadv) > badvLimitSize { + request.BAdv = reqBadv[:badvLimitSize] + } + } + request.Imp = []openrtb.Imp{thisImp} request.Cur = nil request.Ext = nil diff --git a/adapters/rubicon/rubicon_test.go b/adapters/rubicon/rubicon_test.go index d386daed5b1..75cb78efb37 100644 --- a/adapters/rubicon/rubicon_test.go +++ b/adapters/rubicon/rubicon_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "strconv" "testing" "time" @@ -1133,6 +1134,48 @@ func TestOpenRTBRequestWithImpAndAdSlotIncluded(t *testing.T) { "Unexpected dfp_ad_unit_code: %s", rubiconExtInventory["dfp_ad_unit_code"]) } +func TestOpenRTBRequestWithBadvOverflowed(t *testing.T) { + SIZE_ID := getTestSizes() + bidder := new(RubiconAdapter) + + badvOverflowed := make([]string, 100) + for i := range badvOverflowed { + badvOverflowed[i] = strconv.Itoa(i) + } + + request := &openrtb.BidRequest{ + ID: "test-request-id", + BAdv: badvOverflowed, + Imp: []openrtb.Imp{{ + ID: "test-imp-id", + Banner: &openrtb.Banner{ + Format: []openrtb.Format{ + SIZE_ID[15], + }, + }, + Ext: json.RawMessage(`{ + "bidder": { + "zoneId": 8394, + "siteId": 283282, + "accountId": 7891, + "inventory": {"key1" : "val1"}, + "visitor": {"key2" : "val2"} + } + }`), + }}, + } + + reqs, _ := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{}) + + rubiconReq := &openrtb.BidRequest{} + if err := json.Unmarshal(reqs[0].Body, rubiconReq); err != nil { + t.Fatalf("Unexpected error while decoding request: %s", err) + } + + badbRequest := rubiconReq.BAdv + assert.Equal(t, badvOverflowed[:50], badbRequest, "Unexpected dfp_ad_unit_code: %s") +} + func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) { SIZE_ID := getTestSizes() bidder := new(RubiconAdapter) From 2e56653b4c41e3216e70f9b48b82aa471775b008 Mon Sep 17 00:00:00 2001 From: Harbar Dmytro Date: Mon, 13 Apr 2020 08:14:33 +0300 Subject: [PATCH 2/2] Fix after review --- adapters/rubicon/rubicon.go | 4 ++-- adapters/rubicon/rubicon_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adapters/rubicon/rubicon.go b/adapters/rubicon/rubicon.go index 7a2a1f2d346..dad85ee1184 100644 --- a/adapters/rubicon/rubicon.go +++ b/adapters/rubicon/rubicon.go @@ -21,6 +21,8 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) +const badvLimitSize = 50 + type RubiconAdapter struct { http *adapters.HTTPAdapter URI string @@ -740,8 +742,6 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap request.App = &appCopy } - // Сrop badv to 50 elements - badvLimitSize := 50 reqBadv := request.BAdv if reqBadv != nil { if len(reqBadv) > badvLimitSize { diff --git a/adapters/rubicon/rubicon_test.go b/adapters/rubicon/rubicon_test.go index 75cb78efb37..96623659d08 100644 --- a/adapters/rubicon/rubicon_test.go +++ b/adapters/rubicon/rubicon_test.go @@ -1172,8 +1172,8 @@ func TestOpenRTBRequestWithBadvOverflowed(t *testing.T) { t.Fatalf("Unexpected error while decoding request: %s", err) } - badbRequest := rubiconReq.BAdv - assert.Equal(t, badvOverflowed[:50], badbRequest, "Unexpected dfp_ad_unit_code: %s") + badvRequest := rubiconReq.BAdv + assert.Equal(t, badvOverflowed[:50], badvRequest, "Unexpected dfp_ad_unit_code: %s") } func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {