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

Add mapping of user.ext.eids[] for LiveIntent in Rubicon bidder #1089

Merged
merged 8 commits into from
Dec 11, 2019
1 change: 1 addition & 0 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
if len(userExt.Eids) > 0 {
if tpIds, segments, errors := getTpIdsAndSegments(userExt.Eids); len(errors) > 0 {
errs = append(errs, errors...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably wanna add a continue after this line as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

continue
} else if err := updateUserExtWithTpIdsAndSegments(&userExtRP, tpIds, segments); err != nil {
errs = append(errs, err)
continue
Expand Down
140 changes: 98 additions & 42 deletions adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"

Expand Down Expand Up @@ -66,7 +65,14 @@ type rubiBidInfo struct {
var rubidata rubiBidInfo

func DummyRubiconServer(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
defer func() {
err := r.Body.Close()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}()

body, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -285,7 +291,7 @@ func TestRubiconBasicResponse(t *testing.T) {

assert.Equal(t, tag.content, bid.Adm, "Incorrect bid markup '%s' expected '%s'", bid.Adm, tag.content)

assert.True(t, reflect.DeepEqual(bid.AdServerTargeting, tag.adServerTargeting),
assert.Equal(t, bid.AdServerTargeting, tag.adServerTargeting,
"Incorrect targeting '%+v' expected '%+v'", bid.AdServerTargeting, tag.adServerTargeting)

assert.Equal(t, tag.mediaType, bid.CreativeMediaType, "Incorrect media type '%s' expected '%s'", bid.CreativeMediaType, tag.mediaType)
Expand Down Expand Up @@ -681,7 +687,7 @@ func TestZeroPriceBidResponse(t *testing.T) {
an, ctx, pbReq := CreatePrebidRequest(server, t)
b, err := an.Call(ctx, pbReq, pbReq.Bidders[0])

assert.NotNil(t, "\n\n\n0 price bids are being included %d, err : %v", len(b), err)
assert.Nil(t, b, "\n\n\n0 price bids are being included %d, err : %v", len(b), err)
}

func TestDifferentRequest(t *testing.T) {
Expand Down Expand Up @@ -942,30 +948,10 @@ func TestOpenRTBRequest(t *testing.T) {
"keyv": 1,
"pref": 0
},
"eids": [
{
"source": "adserver.org",
"uids": [{
"id": "3d50a262-bd8e-4be3-90b8-246291523907",
"ext": {
"rtiPartner": "TDID"
}
}]
},
{
"eids": [{
"source": "pubcid",
"id": "2402fc76-7b39-4f0e-bfc2-060ef7693648"
},
{
"source": "liveintent.com",
"uids": [{
"id": "T7JiRRvsRAmh88"
}],
"ext": {
"segments": ["999","888"]
}
}
]
}]
}`),
},
Ext: json.RawMessage(`{"prebid": {}}`),
Expand Down Expand Up @@ -1040,22 +1026,8 @@ func TestOpenRTBRequest(t *testing.T) {
assert.Equal(t, 0, userExt.DigiTrust.Pref, "DigiTrust Pref id not as expected!")

assert.NotNil(t, userExt.Eids)
assert.Equal(t, 3, len(userExt.Eids), "Eids values are not as expected!")

assert.NotNil(t, userExt.TpID)
assert.Equal(t, 2, len(userExt.TpID), "TpID values are not as expected!")

assert.Equal(t, "tdid", userExt.TpID[0].Source, "TpID source value is not as expected!")
assert.Equal(t, "liveintent.com", userExt.TpID[1].Source, "TpID source value is not as expected!")

userExtRPTarget := make(map[string]interface{})
if err := json.Unmarshal(userExt.RP.Target, &userExtRPTarget); err != nil {
t.Fatal("Error unmarshalling request.user.ext.rp.target object.")
}

assert.Contains(t, userExtRPTarget, "LIseg", "request.user.ext.rp.target value is not as expected!")
assert.Contains(t, userExtRPTarget["LIseg"], "888", "No segments as expected!")
assert.Contains(t, userExtRPTarget["LIseg"], "999", "No segments as expected!")
assert.Equal(t, 1, len(userExt.Eids), "Eids values are not as expected!")
assert.Contains(t, userExt.Eids, openrtb_ext.ExtUserEid{Source: "pubcid", ID: "2402fc76-7b39-4f0e-bfc2-060ef7693648"})
}
}

Expand Down Expand Up @@ -1161,6 +1133,90 @@ func TestOpenRTBRequestWithImpAndAdSlotIncluded(t *testing.T) {
"Unexpected dfp_ad_unit_code: %s", rubiconExtInventory["dfp_ad_unit_code"])
}

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

request := &openrtb.BidRequest{
ID: "test-request-id",
Imp: []openrtb.Imp{{
ID: "test-imp-id",
Banner: &openrtb.Banner{
Format: []openrtb.Format{
SIZE_ID[15],
SIZE_ID[10],
},
},
Ext: json.RawMessage(`{"bidder": {
"zoneId": 8394,
"siteId": 283282,
"accountId": 7891
}}`),
}},
User: &openrtb.User{
Ext: json.RawMessage(`{"eids": [
{
"source": "pubcid",
"id": "2402fc76-7b39-4f0e-bfc2-060ef7693648"
},
{
"source": "adserver.org",
"uids": [{
"id": "3d50a262-bd8e-4be3-90b8-246291523907",
"ext": {
"rtiPartner": "TDID"
}
}]
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit pick but can you please just fix the indentation for this json blob?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks.

"source": "liveintent.com",
"uids": [{
"id": "T7JiRRvsRAmh88"
}],
"ext": {
"segments": ["999","888"]
}
}
]}`),
},
}

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)
}

assert.NotNil(t, rubiconReq.User.Ext, "User.Ext object should not be nil.")

var userExt rubiconUserExt
if err := json.Unmarshal(rubiconReq.User.Ext, &userExt); err != nil {
t.Fatal("Error unmarshalling request.user.ext object.")
}

assert.NotNil(t, userExt.Eids)
assert.Equal(t, 3, len(userExt.Eids), "Eids values are not as expected!")

assert.NotNil(t, userExt.TpID)
assert.Equal(t, 2, len(userExt.TpID), "TpID values are not as expected!")

// adserver.org
assert.Equal(t, "tdid", userExt.TpID[0].Source, "TpID source value is not as expected!")

// liveintent.com
assert.Equal(t, "liveintent.com", userExt.TpID[1].Source, "TpID source value is not as expected!")

userExtRPTarget := make(map[string]interface{})
if err := json.Unmarshal(userExt.RP.Target, &userExtRPTarget); err != nil {
t.Fatal("Error unmarshalling request.user.ext.rp.target object.")
}

assert.Contains(t, userExtRPTarget, "LIseg", "request.user.ext.rp.target value is not as expected!")
assert.Contains(t, userExtRPTarget["LIseg"], "888", "No segment with 888 as expected!")
assert.Contains(t, userExtRPTarget["LIseg"], "999", "No segment with 999 as expected!")
}

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