From 11b6546f5bffe2737cdf0eb6c9a98d346e138504 Mon Sep 17 00:00:00 2001 From: Alex Maltsev Date: Mon, 23 Sep 2024 16:54:18 +0300 Subject: [PATCH] Rubicon: Pass PBS host info to XAPI (#3903) --- adapters/rubicon/rubicon.go | 12 +++- adapters/rubicon/rubicon_test.go | 69 ++++++++++++++++++- .../exemplary/25-26-transition-period.json | 5 +- .../rubicontest/exemplary/app-imp-fpd.json | 5 +- .../exemplary/bidonmultiformat.json | 10 ++- .../exemplary/flexible-schema.json | 5 +- .../exemplary/hardcode-secure.json | 5 +- .../exemplary/non-bidonmultiformat.json | 5 +- .../rubicontest/exemplary/simple-banner.json | 5 +- .../rubicontest/exemplary/simple-native.json | 5 +- .../rubicontest/exemplary/simple-video.json | 5 +- .../rubicontest/exemplary/site-imp-fpd.json | 5 +- .../rubicontest/exemplary/user-fpd.json | 5 +- .../supplemental/no-site-content-data.json | 5 +- .../supplemental/no-site-content.json | 5 +- 15 files changed, 134 insertions(+), 17 deletions(-) diff --git a/adapters/rubicon/rubicon.go b/adapters/rubicon/rubicon.go index 1cb2ab49465..9cf8eb6ff20 100644 --- a/adapters/rubicon/rubicon.go +++ b/adapters/rubicon/rubicon.go @@ -3,6 +3,7 @@ package rubicon import ( "encoding/json" "fmt" + "github.com/prebid/prebid-server/v2/version" "net/http" "net/url" "strconv" @@ -25,6 +26,7 @@ var bannerExtContent = []byte(`{"rp":{"mime":"text/html"}}`) type RubiconAdapter struct { URI string + externalURI string XAPIUsername string XAPIPassword string } @@ -219,6 +221,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co bidder := &RubiconAdapter{ URI: uri, + externalURI: server.ExternalUrl, XAPIUsername: config.XAPI.Username, XAPIPassword: config.XAPI.Password, } @@ -271,7 +274,7 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada rubiconRequest := *request for imp, bidderExt := range impsToExtMap { rubiconExt := bidderExt.Bidder - target, err := updateImpRpTargetWithFpdAttributes(bidderExt, rubiconExt, *imp, request.Site, request.App) + target, err := a.updateImpRpTarget(bidderExt, rubiconExt, *imp, request.Site, request.App) if err != nil { errs = append(errs, err) continue @@ -650,7 +653,7 @@ func resolveBidFloor(bidFloor float64, bidFloorCur string, reqInfo *adapters.Ext return bidFloor, nil } -func updateImpRpTargetWithFpdAttributes(extImp rubiconExtImpBidder, extImpRubicon openrtb_ext.ExtImpRubicon, +func (a *RubiconAdapter) updateImpRpTarget(extImp rubiconExtImpBidder, extImpRubicon openrtb_ext.ExtImpRubicon, imp openrtb2.Imp, site *openrtb2.Site, app *openrtb2.App) (json.RawMessage, error) { existingTarget, _, _, err := jsonparser.Get(imp.Ext, "rp", "target") @@ -743,6 +746,11 @@ func updateImpRpTargetWithFpdAttributes(extImp rubiconExtImpBidder, extImpRubico if len(extImpRubicon.Keywords) > 0 { addStringArrayAttribute(extImpRubicon.Keywords, target, "keywords") } + + target["pbs_login"] = a.XAPIUsername + target["pbs_version"] = version.Ver + target["pbs_url"] = a.externalURI + updatedTarget, err := json.Marshal(target) if err != nil { return nil, err diff --git a/adapters/rubicon/rubicon_test.go b/adapters/rubicon/rubicon_test.go index 18850d96f9f..ba72727c41c 100644 --- a/adapters/rubicon/rubicon_test.go +++ b/adapters/rubicon/rubicon_test.go @@ -608,6 +608,73 @@ func TestOpenRTBFirstPartyDataPopulating(t *testing.T) { } } +func TestPbsHostInfoPopulating(t *testing.T) { + bidder := RubiconAdapter{ + URI: "url", + externalURI: "externalUrl", + XAPIUsername: "username", + XAPIPassword: "password", + } + + request := &openrtb2.BidRequest{ + ID: "test-request-id", + Imp: []openrtb2.Imp{{ + ID: "test-imp-id", + Banner: &openrtb2.Banner{ + Format: []openrtb2.Format{ + {W: 300, H: 250}, + }, + }, + Ext: json.RawMessage(`{ + "bidder": { + "zoneId": 8394, + "siteId": 283282, + "accountId": 7891, + "inventory": {"key1" : "val1"}, + "visitor": {"key2" : "val2"} + } + }`), + }}, + App: &openrtb2.App{ + ID: "com.test", + Name: "testApp", + }, + } + + reqs, _ := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{}) + + rubiconReq := &openrtb2.BidRequest{} + if err := json.Unmarshal(reqs[0].Body, rubiconReq); err != nil { + t.Fatalf("Unexpected error while decoding request: %s", err) + } + + var rpImpExt rubiconImpExt + if err := json.Unmarshal(rubiconReq.Imp[0].Ext, &rpImpExt); err != nil { + t.Fatalf("Error unmarshalling imp.ext: %s", err) + } + + var pbsLogin string + pbsLogin, err := jsonparser.GetString(rpImpExt.RP.Target, "pbs_login") + if err != nil { + t.Fatal("Error extracting pbs_login") + } + assert.Equal(t, pbsLogin, "username", "Unexpected pbs_login value") + + var pbsVersion string + pbsVersion, err = jsonparser.GetString(rpImpExt.RP.Target, "pbs_version") + if err != nil { + t.Fatal("Error extracting pbs_version") + } + assert.Equal(t, pbsVersion, "", "Unexpected pbs_version value") + + var pbsUrl string + pbsUrl, err = jsonparser.GetString(rpImpExt.RP.Target, "pbs_url") + if err != nil { + t.Fatal("Error extracting pbs_url") + } + assert.Equal(t, pbsUrl, "externalUrl", "Unexpected pbs_url value") +} + func TestOpenRTBRequestWithBadvOverflowed(t *testing.T) { bidder := new(RubiconAdapter) @@ -990,7 +1057,7 @@ func TestOpenRTBResponseOverridePriceFromCorrespondingImp(t *testing.T) { "siteId": 68780, "zoneId": 327642, "debug": { - "cpmoverride" : 20 + "cpmoverride" : 20 } }}`), }}, diff --git a/adapters/rubicon/rubicontest/exemplary/25-26-transition-period.json b/adapters/rubicon/rubicontest/exemplary/25-26-transition-period.json index d64f2361521..0196c93049a 100644 --- a/adapters/rubicon/rubicontest/exemplary/25-26-transition-period.json +++ b/adapters/rubicon/rubicontest/exemplary/25-26-transition-period.json @@ -364,7 +364,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/app-imp-fpd.json b/adapters/rubicon/rubicontest/exemplary/app-imp-fpd.json index 914cfce03de..4e7c2a92148 100644 --- a/adapters/rubicon/rubicontest/exemplary/app-imp-fpd.json +++ b/adapters/rubicon/rubicontest/exemplary/app-imp-fpd.json @@ -349,7 +349,10 @@ "sectioncat": [ "sectionCat1", "sectionCat2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/bidonmultiformat.json b/adapters/rubicon/rubicontest/exemplary/bidonmultiformat.json index 33757cd889d..c47cd3f9c36 100644 --- a/adapters/rubicon/rubicontest/exemplary/bidonmultiformat.json +++ b/adapters/rubicon/rubicontest/exemplary/bidonmultiformat.json @@ -106,7 +106,10 @@ ], "search": [ "someSearch" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", @@ -213,7 +216,10 @@ ], "search": [ "someSearch" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/flexible-schema.json b/adapters/rubicon/rubicontest/exemplary/flexible-schema.json index 0434f6bab83..f4dcebc2280 100644 --- a/adapters/rubicon/rubicontest/exemplary/flexible-schema.json +++ b/adapters/rubicon/rubicontest/exemplary/flexible-schema.json @@ -349,7 +349,10 @@ "sectioncat": [ "sectionCat1", "sectionCat2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/hardcode-secure.json b/adapters/rubicon/rubicontest/exemplary/hardcode-secure.json index c349b86da91..9df133385c6 100644 --- a/adapters/rubicon/rubicontest/exemplary/hardcode-secure.json +++ b/adapters/rubicon/rubicontest/exemplary/hardcode-secure.json @@ -323,7 +323,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/non-bidonmultiformat.json b/adapters/rubicon/rubicontest/exemplary/non-bidonmultiformat.json index 1e1485861fd..dae54aca730 100644 --- a/adapters/rubicon/rubicontest/exemplary/non-bidonmultiformat.json +++ b/adapters/rubicon/rubicontest/exemplary/non-bidonmultiformat.json @@ -105,7 +105,10 @@ ], "search": [ "someSearch" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/simple-banner.json b/adapters/rubicon/rubicontest/exemplary/simple-banner.json index d2da4ce8a8d..21ec12990da 100644 --- a/adapters/rubicon/rubicontest/exemplary/simple-banner.json +++ b/adapters/rubicon/rubicontest/exemplary/simple-banner.json @@ -323,7 +323,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/simple-native.json b/adapters/rubicon/rubicontest/exemplary/simple-native.json index f5e43ff9211..98bfdb4f845 100644 --- a/adapters/rubicon/rubicontest/exemplary/simple-native.json +++ b/adapters/rubicon/rubicontest/exemplary/simple-native.json @@ -307,7 +307,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/simple-video.json b/adapters/rubicon/rubicontest/exemplary/simple-video.json index 5552dd71816..3bceef2cf38 100644 --- a/adapters/rubicon/rubicontest/exemplary/simple-video.json +++ b/adapters/rubicon/rubicontest/exemplary/simple-video.json @@ -322,7 +322,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/site-imp-fpd.json b/adapters/rubicon/rubicontest/exemplary/site-imp-fpd.json index 87c20e227b1..b8519dabdb3 100644 --- a/adapters/rubicon/rubicontest/exemplary/site-imp-fpd.json +++ b/adapters/rubicon/rubicontest/exemplary/site-imp-fpd.json @@ -473,7 +473,10 @@ "sectionCat1", "sectionCat2" ], - "dfp_ad_unit_code": "adSlotFromData" + "dfp_ad_unit_code": "adSlotFromData", + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/exemplary/user-fpd.json b/adapters/rubicon/rubicontest/exemplary/user-fpd.json index 42ab0f0babe..c989c6a1e19 100644 --- a/adapters/rubicon/rubicontest/exemplary/user-fpd.json +++ b/adapters/rubicon/rubicontest/exemplary/user-fpd.json @@ -275,7 +275,10 @@ "search": [ "someSearch" ], - "dfp_ad_unit_code": "someAdSlot" + "dfp_ad_unit_code": "someAdSlot", + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/supplemental/no-site-content-data.json b/adapters/rubicon/rubicontest/supplemental/no-site-content-data.json index b2f463a95dc..b121d75a0f6 100644 --- a/adapters/rubicon/rubicontest/supplemental/no-site-content-data.json +++ b/adapters/rubicon/rubicontest/supplemental/no-site-content-data.json @@ -234,7 +234,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "", diff --git a/adapters/rubicon/rubicontest/supplemental/no-site-content.json b/adapters/rubicon/rubicontest/supplemental/no-site-content.json index 5744b2c9e47..65c3cacd858 100644 --- a/adapters/rubicon/rubicontest/supplemental/no-site-content.json +++ b/adapters/rubicon/rubicontest/supplemental/no-site-content.json @@ -230,7 +230,10 @@ "pagecat": [ "val1", "val2" - ] + ], + "pbs_login": "xuser", + "pbs_url": "http://hosturl.com", + "pbs_version": "" }, "track": { "mint": "",