Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Add Cropping of BAdv for Rubicon Adapter (prebid#1254)
Browse files Browse the repository at this point in the history
* Add Cropping of BAdv for Rubicon Adapter

BAdv size is limited to 50

* Fix after review

Co-authored-by: Harbar Dmytro <dharbar@rubiconproject.com>
  • Loading branch information
DGarbar and Harbar Dmytro authored Apr 14, 2020
1 parent 76d9c22 commit 154ba2b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/prebid/prebid-server/openrtb_ext"
)

const badvLimitSize = 50

type RubiconAdapter struct {
http *adapters.HTTPAdapter
URI string
Expand Down Expand Up @@ -740,6 +742,13 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
request.App = &appCopy
}

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
Expand Down
43 changes: 43 additions & 0 deletions adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -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)
}

badvRequest := rubiconReq.BAdv
assert.Equal(t, badvOverflowed[:50], badvRequest, "Unexpected dfp_ad_unit_code: %s")
}

func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {
SIZE_ID := getTestSizes()
bidder := new(RubiconAdapter)
Expand Down

0 comments on commit 154ba2b

Please sign in to comment.