Skip to content

Commit

Permalink
Merge branch 'prebid:master' into tradplus
Browse files Browse the repository at this point in the history
  • Loading branch information
tradplus authored Nov 27, 2024
2 parents 5629eb1 + b962448 commit d5aefa7
Show file tree
Hide file tree
Showing 28 changed files with 414 additions and 298 deletions.
21 changes: 15 additions & 6 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3977,6 +3977,7 @@ func TestParseRequestMergeBidderParams(t *testing.T) {
expectedImpExt json.RawMessage
expectedReqExt json.RawMessage
expectedErrorCount int
expectedErrors []error
}{
{
name: "add missing bidder-params from req.ext.prebid.bidderparams to imp[].ext.prebid.bidder",
Expand All @@ -3994,10 +3995,16 @@ func TestParseRequestMergeBidderParams(t *testing.T) {
},
{
name: "add missing bidder-params from req.ext.prebid.bidderparams to imp[].ext for backward compatibility",
givenRequestBody: validRequest(t, "req-ext-bidder-params-backward-compatible-merge.json"),
expectedImpExt: getObject(t, "req-ext-bidder-params-backward-compatible-merge.json", "expectedImpExt"),
expectedReqExt: getObject(t, "req-ext-bidder-params-backward-compatible-merge.json", "expectedReqExt"),
expectedErrorCount: 0,
givenRequestBody: validRequest(t, "req-ext-bidder-params-promotion.json"),
expectedImpExt: getObject(t, "req-ext-bidder-params-promotion.json", "expectedImpExt"),
expectedReqExt: getObject(t, "req-ext-bidder-params-promotion.json", "expectedReqExt"),
expectedErrorCount: 1,
expectedErrors: []error{
&errortypes.Warning{
WarningCode: 0,
Message: "request.imp[0].ext contains unknown bidder: 'arbitraryObject', ignoring",
},
},
},
}
for _, test := range tests {
Expand Down Expand Up @@ -4054,6 +4061,8 @@ func TestParseRequestMergeBidderParams(t *testing.T) {
assert.Equal(t, eReqE, reqE, "req.Ext should match")

assert.Len(t, errL, test.expectedErrorCount, "error length should match")

assert.Equal(t, errL, test.expectedErrors)
})
}
}
Expand Down Expand Up @@ -4658,7 +4667,7 @@ func TestValidateStoredResp(t *testing.T) {
storedBidResponses: stored_responses.ImpBidderStoredResp{"Some-Imp-ID": {"appnexus": json.RawMessage(`{"test":true}`), "rubicon": json.RawMessage(`{"test":true}`)}},
},
{
description: "One imp with 2 stored bid responses and 1 bidders in imp.ext and 1 in imp.ext.prebid.bidder, expect validate request to throw no errors",
description: "One imp with 1 stored bid response and 1 ignored bidder in imp.ext and 1 included bidder in imp.ext.prebid.bidder, expect validate request to throw no errors",
givenRequestWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
ID: "Some-ID",
Expand All @@ -4685,7 +4694,7 @@ func TestValidateStoredResp(t *testing.T) {
},
expectedErrorList: []error{},
hasStoredAuctionResponses: false,
storedBidResponses: stored_responses.ImpBidderStoredResp{"Some-Imp-ID": {"appnexus": json.RawMessage(`{"test":true}`), "telaria": json.RawMessage(`{"test":true}`)}},
storedBidResponses: stored_responses.ImpBidderStoredResp{"Some-Imp-ID": {"telaria": json.RawMessage(`{"test":true}`)}},
},
{
description: "One imp with 2 stored bid responses and 1 bidders in imp.ext and 1 in imp.ext.prebid.bidder that is not defined in stored bid responses, expect validate request to throw an error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
]
},
"ext": {
"prebid": {
"bidder": {}
},
"appnexus": {
"placementId": 12883451
},
Expand All @@ -34,5 +37,5 @@
"tmax": 500
},
"expectedReturnCode": 400,
"expectedErrorMessage": "Invalid request"
"expectedErrorMessage": "Invalid request: request.imp[0].ext.prebid.bidder must contain at least one bidder\n"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
}
},
"expectedReturnCode": 400,
"expectedErrorMessage": "Invalid request: request.imp[0].ext.prebid.bidder contains unknown bidder: noBidderShouldEverHaveThisName. Did you forget an alias in request.ext.prebid.aliases?\n"
"expectedErrorMessage": "Invalid request: request.imp[0].ext.prebid.bidder must contain at least one bidder"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"profile": 1234
}
},
"prebid": {
"bidder": {}
"arbitraryObject": {
"arbitraryField": 1232
}
}
}
Expand Down Expand Up @@ -107,6 +107,9 @@
}
}
}
},
"arbitraryObject": {
"arbitraryField": 1232
}
},
"expectedReturnCode": 200
Expand Down
17 changes: 6 additions & 11 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,20 +718,15 @@ func mergeImpFPD(imp *openrtb2.Imp, fpd json.RawMessage, index int) error {
return nil
}

var allowedImpExtFields = map[string]interface{}{
openrtb_ext.AuctionEnvironmentKey: struct{}{},
openrtb_ext.FirstPartyDataExtKey: struct{}{},
openrtb_ext.FirstPartyDataContextExtKey: struct{}{},
openrtb_ext.GPIDKey: struct{}{},
openrtb_ext.SKAdNExtKey: struct{}{},
openrtb_ext.TIDKey: struct{}{},
}

var allowedImpExtPrebidFields = map[string]interface{}{
openrtb_ext.IsRewardedInventoryKey: struct{}{},
openrtb_ext.OptionsKey: struct{}{},
}

var deniedImpExtFields = map[string]interface{}{
openrtb_ext.PrebidExtKey: struct{}{},
}

func createSanitizedImpExt(impExt, impExtPrebid map[string]json.RawMessage) (map[string]json.RawMessage, error) {
sanitizedImpExt := make(map[string]json.RawMessage, 6)
sanitizedImpPrebidExt := make(map[string]json.RawMessage, 2)
Expand All @@ -753,8 +748,8 @@ func createSanitizedImpExt(impExt, impExtPrebid map[string]json.RawMessage) (map
}

// copy reserved imp[].ext fields known to not be bidder names
for k := range allowedImpExtFields {
if v, exists := impExt[k]; exists {
for k, v := range impExt {
if _, exists := deniedImpExtFields[k]; !exists {
sanitizedImpExt[k] = v
}
}
Expand Down
100 changes: 52 additions & 48 deletions exchange/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,93 +607,97 @@ func TestCreateSanitizedImpExt(t *testing.T) {
{
description: "imp.ext",
givenImpExt: map[string]json.RawMessage{
"anyBidder": json.RawMessage(`"anyBidderValues"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
givenImpExtPrebid: map[string]json.RawMessage{},
expected: map[string]json.RawMessage{
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
expectedError: "",
},
{
description: "imp.ext + imp.ext.prebid - Prebid Bidder Only",
givenImpExt: map[string]json.RawMessage{
"anyBidder": json.RawMessage(`"anyBidderValues"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
givenImpExtPrebid: map[string]json.RawMessage{
"bidder": json.RawMessage(`"anyBidder"`),
},
expected: map[string]json.RawMessage{
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
expectedError: "",
},
{
description: "imp.ext + imp.ext.prebid - Prebid Bidder + Other Forbidden Value",
givenImpExt: map[string]json.RawMessage{
"anyBidder": json.RawMessage(`"anyBidderValues"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
givenImpExtPrebid: map[string]json.RawMessage{
"bidder": json.RawMessage(`"anyBidder"`),
"forbidden": json.RawMessage(`"anyValue"`),
},
expected: map[string]json.RawMessage{
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
expectedError: "",
},
{
description: "imp.ext + imp.ext.prebid - Prebid Bidder + Other Allowed Values",
givenImpExt: map[string]json.RawMessage{
"anyBidder": json.RawMessage(`"anyBidderValues"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"prebid": json.RawMessage(`"ignoredInFavorOfSeparatelyUnmarshalledImpExtPrebid"`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
givenImpExtPrebid: map[string]json.RawMessage{
"bidder": json.RawMessage(`"anyBidder"`),
"is_rewarded_inventory": json.RawMessage(`"anyIsRewardedInventory"`),
"options": json.RawMessage(`"anyOptions"`),
},
expected: map[string]json.RawMessage{
"prebid": json.RawMessage(`{"is_rewarded_inventory":"anyIsRewardedInventory","options":"anyOptions"}`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
"arbitraryField": json.RawMessage(`"arbitraryValue"`),
"prebid": json.RawMessage(`{"is_rewarded_inventory":"anyIsRewardedInventory","options":"anyOptions"}`),
"data": json.RawMessage(`"anyData"`),
"context": json.RawMessage(`"anyContext"`),
"skadn": json.RawMessage(`"anySKAdNetwork"`),
"gpid": json.RawMessage(`"anyGPID"`),
"tid": json.RawMessage(`"anyTID"`),
},
expectedError: "",
},
Expand Down
4 changes: 2 additions & 2 deletions floors/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func validateRules(config config.AccountFloorFetch, priceFloors *openrtb_ext.Pri
return errors.New("skip rate should be greater than or equal to 0 and less than 100")
}

if priceFloors.Data.FetchRate != nil && (*priceFloors.Data.FetchRate < dataRateMin || *priceFloors.Data.FetchRate > dataRateMax) {
return errors.New("FetchRate should be greater than or equal to 0 and less than or equal to 100")
if priceFloors.Data.UseFetchDataRate != nil && (*priceFloors.Data.UseFetchDataRate < dataRateMin || *priceFloors.Data.UseFetchDataRate > dataRateMax) {
return errors.New("usefetchdatarate should be greater than or equal to 0 and less than or equal to 100")
}

for _, modelGroup := range priceFloors.Data.ModelGroups {
Expand Down
4 changes: 2 additions & 2 deletions floors/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestValidatePriceFloorRules(t *testing.T) {
wantErr: true,
},
{
name: "Invalid FetchRate",
name: "Invalid UseFetchDataRate",
args: args{
configs: config.AccountFloorFetch{
Enabled: true,
Expand All @@ -417,7 +417,7 @@ func TestValidatePriceFloorRules(t *testing.T) {
"*|*|www.website.com": 15.01,
},
}},
FetchRate: ptrutil.ToPtr(-11),
UseFetchDataRate: ptrutil.ToPtr(-11),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion floors/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func resolveFloors(account config.Account, bidRequestWrapper *openrtb_ext.Reques
fetchResult, fetchStatus = priceFloorFetcher.Fetch(account.PriceFloors)
}

if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess && useFetchedData(fetchResult.Data.FetchRate) {
if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess && useFetchedData(fetchResult.Data.UseFetchDataRate) {
mergedFloor := mergeFloors(reqFloor, fetchResult, conversions)
floorRules, errList = createFloorsFrom(mergedFloor, account, fetchStatus, openrtb_ext.FetchLocation)
} else if reqFloor != nil {
Expand Down
6 changes: 3 additions & 3 deletions floors/floors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func (m *MockFetchDataRate0) Fetch(configs config.AccountPriceFloors) (*openrtb_
},
},
},
FetchRate: ptrutil.ToPtr(0),
UseFetchDataRate: ptrutil.ToPtr(0),
},
}
return &priceFloors, openrtb_ext.FetchSuccess
Expand Down Expand Up @@ -831,7 +831,7 @@ func (m *MockFetchDataRate100) Fetch(configs config.AccountPriceFloors) (*openrt
},
},
},
FetchRate: ptrutil.ToPtr(100),
UseFetchDataRate: ptrutil.ToPtr(100),
},
}
return &priceFloors, openrtb_ext.FetchSuccess
Expand Down Expand Up @@ -979,7 +979,7 @@ func TestResolveFloorsWithUseDataRate(t *testing.T) {
},
},
},
FetchRate: ptrutil.ToPtr(100),
UseFetchDataRate: ptrutil.ToPtr(100),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/hookexecution/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ func (e *hookExecutor) ExecuteRawBidderResponseStage(response *adapters.BidderRe

stageName := hooks.StageRawBidderResponse.String()
executionCtx := e.newContext(stageName)
payload := hookstage.RawBidderResponsePayload{Bids: response.Bids, Bidder: bidder}
payload := hookstage.RawBidderResponsePayload{BidderResponse: response, Bidder: bidder}

outcome, payload, contexts, reject := executeStage(executionCtx, plan, payload, handler, e.metricEngine)
response.Bids = payload.Bids
response = payload.BidderResponse
outcome.Entity = entity(bidder)
outcome.Stage = stageName

Expand Down
4 changes: 2 additions & 2 deletions hooks/hookexecution/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (e mockTimeoutHook) HandleRawBidderResponseHook(_ context.Context, _ hookst
time.Sleep(20 * time.Millisecond)
c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
c.AddMutation(func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) {
payload.Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"}
payload.BidderResponse.Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"}
return payload, nil
}, hookstage.MutationUpdate, "bidderResponse", "bidMeta.AdapterCode")

Expand Down Expand Up @@ -351,7 +351,7 @@ func (e mockUpdateBidderResponseHook) HandleRawBidderResponseHook(_ context.Cont
c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
c.AddMutation(
func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) {
payload.Bids[0].DealPriority = 10
payload.BidderResponse.Bids[0].DealPriority = 10
return payload, nil
}, hookstage.MutationUpdate, "bidderResponse", "bid.deal-priority",
)
Expand Down
9 changes: 4 additions & 5 deletions hooks/hookstage/rawbidderresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ type RawBidderResponse interface {
) (HookResult[RawBidderResponsePayload], error)
}

// RawBidderResponsePayload consists of a list of adapters.TypedBid
// objects representing bids returned by a particular bidder.
// Hooks are allowed to modify bids using mutations.
// RawBidderResponsePayload consists of a bidder response returned by a particular bidder.
// Hooks are allowed to modify bidder response using mutations.
type RawBidderResponsePayload struct {
Bids []*adapters.TypedBid
Bidder string
BidderResponse *adapters.BidderResponse
Bidder string
}
Loading

0 comments on commit d5aefa7

Please sign in to comment.