Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xdevel authored Jun 29, 2024
2 parents d4ef043 + 057e25d commit dbfb1b5
Show file tree
Hide file tree
Showing 142 changed files with 6,187 additions and 210 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _obj
_test
.cover/
.idea/
.vscode/

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down Expand Up @@ -42,11 +43,8 @@ inventory_url.yaml
analytics/config/testFiles/
analytics/filesystem/testFiles/

# autogenerated version file
# static/version.txt

.idea/
.vscode/
# autogenerated files
prebid-server.iml

# autogenerated mac file

Expand Down
1 change: 1 addition & 0 deletions adapters/adgeneration/adgeneration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func checkBidResponse(t *testing.T, bidderResponse *adapters.BidderResponse, exp
var expectedCrID string = "Dummy_supership.jp"
var extectedDealID string = "test-deal-id"

//nolint: staticcheck // false positive SA5011: possible nil pointer dereference
assert.Equal(t, expectedCurrency, bidderResponse.Currency)
assert.Equal(t, 1, len(bidderResponse.Bids))
assert.Equal(t, expectedID, bidderResponse.Bids[0].Bid.ID)
Expand Down
6 changes: 5 additions & 1 deletion adapters/adtarget/adtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func validateImpressionAndSetExt(imp *openrtb2.Imp) (int, error) {
impExtBuffer, err = json.Marshal(&adtargetImpExt{
Adtarget: impExt,
})

if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, error while encoding impExt, err: %s", imp.ID, err),
}
}
if impExt.BidFloor > 0 {
imp.BidFloor = impExt.BidFloor
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/advangelists/advangelists.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (adapter *AdvangelistsAdapter) buildEndpointURL(params *openrtb_ext.ExtImpA

// MakeBids translates advangelists bid response to prebid-server specific format
func (adapter *AdvangelistsAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var msg = ""
var msg string
if response.StatusCode == http.StatusNoContent {
return nil, nil
}
Expand Down
3 changes: 3 additions & 0 deletions adapters/algorix/algorix.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func preProcess(request *openrtb2.BidRequest) {
videoCopy := *request.Imp[i].Video
videoExt := algorixVideoExt{Rewarded: 1}
videoCopy.Ext, err = json.Marshal(&videoExt)
if err != nil {
continue
}
request.Imp[i].Video = &videoCopy
}
}
Expand Down
21 changes: 18 additions & 3 deletions adapters/amx/amx.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ func (adapter *AMXAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
}

type amxBidExt struct {
StartDelay *int `json:"startdelay,omitempty"`
CreativeType *int `json:"ct,omitempty"`
StartDelay *int `json:"startdelay,omitempty"`
CreativeType *int `json:"ct,omitempty"`
DemandSource *string `json:"ds,omitempty"`
BidderCode *string `json:"bc,omitempty"`
}

// MakeBids will parse the bids from the AMX server
Expand Down Expand Up @@ -154,12 +156,25 @@ func (adapter *AMXAdapter) MakeBids(request *openrtb2.BidRequest, externalReques
continue
}

demandSource := ""
if bidExt.DemandSource != nil {
demandSource = *bidExt.DemandSource
}

bidType := getMediaTypeForBid(bidExt)
b := &adapters.TypedBid{
Bid: &bid,
Bid: &bid,
BidMeta: &openrtb_ext.ExtBidPrebidMeta{
AdvertiserDomains: bid.ADomain,
DemandSource: demandSource,
},
BidType: bidType,
}

if bidExt.BidderCode != nil {
b.Seat = openrtb_ext.BidderName(*bidExt.BidderCode)
}

bidResponse.Bids = append(bidResponse.Bids, b)
}
}
Expand Down
29 changes: 19 additions & 10 deletions adapters/amx/amx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,24 @@ func TestMakeBids(t *testing.T) {
}

type testCase struct {
bidType openrtb_ext.BidType
adm string
extRaw string
valid bool
bidType openrtb_ext.BidType
adm string
extRaw string
seatName string
demandSource string
valid bool
}

tests := []testCase{
{openrtb_ext.BidTypeNative, `{"assets":[]}`, `{"ct":10}`, true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"ct": 1}`, true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"ct": "invalid"}`, false},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{}`, true},
{openrtb_ext.BidTypeVideo, sampleVastADM, `{"startdelay": 1}`, true},
{openrtb_ext.BidTypeBanner, sampleVastADM, `{"ct": 1}`, true}, // the server shouldn't do this
{openrtb_ext.BidTypeNative, `{"assets":[]}`, `{"ct":10}`, "", "", true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"ct": 1}`, "", "", true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"ct": "invalid"}`, "", "", false},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{}`, "", "", true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"bc": "amx-pmp"}`, "amx-pmp", "", true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"ds": "pmp-1"}`, "", "pmp-1", true},
{openrtb_ext.BidTypeBanner, sampleDisplayADM, `{"bc": "amx-pmp", "ds": "pmp-1"}`, "amx-pmp", "pmp-1", true},
{openrtb_ext.BidTypeVideo, sampleVastADM, `{"startdelay": 1}`, "", "", true},
{openrtb_ext.BidTypeBanner, sampleVastADM, `{"ct": 1}`, "", "", true}, // the server shouldn't do this
}

for _, test := range tests {
Expand Down Expand Up @@ -233,6 +238,10 @@ func TestMakeBids(t *testing.T) {

assert.Len(t, bids.Bids, 1)
assert.Equal(t, test.bidType, bids.Bids[0].BidType)

br := bids.Bids[0]
assert.Equal(t, openrtb_ext.BidderName(test.seatName), br.Seat)
assert.Equal(t, test.demandSource, br.BidMeta.DemandSource)
}

}
6 changes: 5 additions & 1 deletion adapters/amx/amxtest/exemplary/display-multiple.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
"cid": "668",
"crid": "253510977",
"ext": {
"bc": "amx-pmp"
},
"h": 250,
"id": "8911104898220857797",
Expand Down Expand Up @@ -258,14 +259,17 @@
],
"cid": "668",
"crid": "253510977",
"ext": {},
"ext": {
"bc": "amx-pmp"
},
"h": 250,
"id": "8911104898220857797",
"impid": "6a362d3a9db4eba300x250",
"nurl": "https://1x1.a-mo.net/hbx/bwin",
"price": 0.50,
"w": 300
},
"seat": "amx-pmp",
"type": "banner"
},
{
Expand Down
91 changes: 48 additions & 43 deletions adapters/appnexus/appnexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ type adapter struct {
randomGenerator randomutil.RandomGenerator
}

// impExtIncoming defines the incoming data contract from the Prebid Server request.
type impExtIncoming struct {
Bidder openrtb_ext.ExtImpAppnexus `json:"bidder"`
GPID string `json:"gpid"`
}

// Builder builds a new instance of the AppNexus adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
uri, err := url.Parse(config.Endpoint)
Expand Down Expand Up @@ -72,18 +78,18 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E

validImps := []openrtb2.Imp{}
for i := 0; i < len(request.Imp); i++ {
appnexusExt, err := validateAndBuildAppNexusExt(&request.Imp[i])
impExtIncoming, err := validateAndBuildImpExt(&request.Imp[i])
if err != nil {
errs = append(errs, err)
continue
}

if err := buildRequestImp(&request.Imp[i], &appnexusExt, displayManagerVer); err != nil {
if err := buildRequestImp(&request.Imp[i], impExtIncoming, displayManagerVer); err != nil {
errs = append(errs, err)
continue
}

memberId := appnexusExt.Member
memberId := impExtIncoming.Bidder.Member
if memberId != "" {
// The Appnexus API requires a Member ID in the URL. This means the request may fail if
// different impressions have different member IDs.
Expand All @@ -96,7 +102,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
}
}

shouldGenerateAdPodIdForImp := appnexusExt.AdPodId
shouldGenerateAdPodIdForImp := impExtIncoming.Bidder.AdPodId
if shouldGenerateAdPodId == nil {
shouldGenerateAdPodId = &shouldGenerateAdPodIdForImp
} else if *shouldGenerateAdPodId != shouldGenerateAdPodIdForImp {
Expand Down Expand Up @@ -250,24 +256,19 @@ func (a *adapter) getAppnexusExt(extMap map[string]json.RawMessage, isAMP int, i
return appnexusExt, nil
}

func validateAndBuildAppNexusExt(imp *openrtb2.Imp) (openrtb_ext.ExtImpAppnexus, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return openrtb_ext.ExtImpAppnexus{}, err
}

var appnexusExt openrtb_ext.ExtImpAppnexus
if err := json.Unmarshal(bidderExt.Bidder, &appnexusExt); err != nil {
return openrtb_ext.ExtImpAppnexus{}, err
func validateAndBuildImpExt(imp *openrtb2.Imp) (impExtIncoming, error) {
var ext impExtIncoming
if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return impExtIncoming{}, err
}

handleLegacyParams(&appnexusExt)
handleLegacyParams(&ext.Bidder)

if err := validateAppnexusExt(&appnexusExt); err != nil {
return openrtb_ext.ExtImpAppnexus{}, err
if err := validateAppnexusExt(&ext.Bidder); err != nil {
return impExtIncoming{}, err
}

return appnexusExt, nil
return ext, nil
}

func handleLegacyParams(appnexusExt *openrtb_ext.ExtImpAppnexus) {
Expand All @@ -285,6 +286,15 @@ func handleLegacyParams(appnexusExt *openrtb_ext.ExtImpAppnexus) {
}
}

func validateAppnexusExt(appnexusExt *openrtb_ext.ExtImpAppnexus) error {
if appnexusExt.PlacementId == 0 && (appnexusExt.InvCode == "" || appnexusExt.Member == "") {
return &errortypes.BadInput{
Message: "No placement or member+invcode provided",
}
}
return nil
}

func groupByPods(imps []openrtb2.Imp) map[string]([]openrtb2.Imp) {
// find number of pods in response
podImps := make(map[string][]openrtb2.Imp)
Expand Down Expand Up @@ -350,29 +360,21 @@ func splitRequests(imps []openrtb2.Imp, request *openrtb2.BidRequest, requestExt
return resArr, errs
}

func validateAppnexusExt(appnexusExt *openrtb_ext.ExtImpAppnexus) error {
if appnexusExt.PlacementId == 0 && (appnexusExt.InvCode == "" || appnexusExt.Member == "") {
return &errortypes.BadInput{
Message: "No placement or member+invcode provided",
}
}
return nil
}

func buildRequestImp(imp *openrtb2.Imp, appnexusExt *openrtb_ext.ExtImpAppnexus, displayManagerVer string) error {
if appnexusExt.InvCode != "" {
imp.TagID = appnexusExt.InvCode
func buildRequestImp(imp *openrtb2.Imp, ext impExtIncoming, displayManagerVer string) error {
if ext.Bidder.InvCode != "" {
imp.TagID = ext.Bidder.InvCode
}

if imp.BidFloor <= 0 && appnexusExt.Reserve > 0 {
imp.BidFloor = appnexusExt.Reserve // This will be broken for non-USD currency.
if imp.BidFloor <= 0 && ext.Bidder.Reserve > 0 {
imp.BidFloor = ext.Bidder.Reserve // This will be broken for non-USD currency.
}

if imp.Banner != nil {
bannerCopy := *imp.Banner
if appnexusExt.Position == "above" {

if ext.Bidder.Position == "above" {
bannerCopy.Pos = adcom1.PositionAboveFold.Ptr()
} else if appnexusExt.Position == "below" {
} else if ext.Bidder.Position == "below" {
bannerCopy.Pos = adcom1.PositionBelowFold.Ptr()
}

Expand All @@ -389,18 +391,21 @@ func buildRequestImp(imp *openrtb2.Imp, appnexusExt *openrtb_ext.ExtImpAppnexus,
imp.DisplayManagerVer = displayManagerVer
}

impExt := impExt{Appnexus: impExtAppnexus{
PlacementID: int(appnexusExt.PlacementId),
TrafficSourceCode: appnexusExt.TrafficSourceCode,
Keywords: appnexusExt.Keywords.String(),
UsePmtRule: appnexusExt.UsePaymentRule,
PrivateSizes: appnexusExt.PrivateSizes,
ExtInvCode: appnexusExt.ExtInvCode,
ExternalImpID: appnexusExt.ExternalImpId,
}}
impExt := impExt{
Appnexus: impExtAppnexus{
PlacementID: int(ext.Bidder.PlacementId),
TrafficSourceCode: ext.Bidder.TrafficSourceCode,
Keywords: ext.Bidder.Keywords.String(),
UsePmtRule: ext.Bidder.UsePaymentRule,
PrivateSizes: ext.Bidder.PrivateSizes,
ExtInvCode: ext.Bidder.ExtInvCode,
ExternalImpID: ext.Bidder.ExternalImpId,
},
GPID: ext.GPID,
}

var err error
imp.Ext, err = json.Marshal(&impExt)
imp.Ext, err = json.Marshal(impExt)

return err
}
Expand Down
Loading

0 comments on commit dbfb1b5

Please sign in to comment.