Skip to content

Commit

Permalink
Make Targeting in Response Optional (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBVolcy authored Mar 26, 2024
1 parent 25a4466 commit 67c487d
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 104 deletions.
42 changes: 17 additions & 25 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1697,36 +1697,28 @@ func validateRequestExt(req *openrtb_ext.RequestWrapper) []error {
}

func validateTargeting(t *openrtb_ext.ExtRequestTargeting) error {
if t == nil {
return nil
}

if (t.IncludeWinners == nil || !*t.IncludeWinners) && (t.IncludeBidderKeys == nil || !*t.IncludeBidderKeys) {
return errors.New("ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support")
}

if t.PriceGranularity != nil {
if err := validatePriceGranularity(t.PriceGranularity); err != nil {
return err
if t != nil {
if t.PriceGranularity != nil {
if err := validatePriceGranularity(t.PriceGranularity); err != nil {
return err
}
}
}

if t.MediaTypePriceGranularity.Video != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Video); err != nil {
return err
if t.MediaTypePriceGranularity.Video != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Video); err != nil {
return err
}
}
}
if t.MediaTypePriceGranularity.Banner != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Banner); err != nil {
return err
if t.MediaTypePriceGranularity.Banner != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Banner); err != nil {
return err
}
}
}
if t.MediaTypePriceGranularity.Native != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Native); err != nil {
return err
if t.MediaTypePriceGranularity.Native != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Native); err != nil {
return err
}
}
}

return nil
}

Expand Down
85 changes: 7 additions & 78 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1941,9 +1941,13 @@ func TestValidateRequestExt(t *testing.T) {
givenRequestExt: json.RawMessage(`{"prebid":{"cache":{"bids":{},"vastxml":{}}}}`),
},
{
description: "prebid targeting", // test integration with validateTargeting
givenRequestExt: json.RawMessage(`{"prebid":{"targeting":{}}}`),
expectedErrors: []string{"ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support"},
description: "prebid price granularity invalid",
givenRequestExt: json.RawMessage(`{"prebid":{"targeting":{"pricegranularity":{"precision":-1,"ranges":[{"min":0,"max":20,"increment":0.1}]}}}}`),
expectedErrors: []string{"Price granularity error: precision must be non-negative"},
},
{
description: "prebid native media type price granualrity valid",
givenRequestExt: json.RawMessage(`{"prebid":{"targeting":{"mediatypepricegranularity":{"native":{"precision":3,"ranges":[{"max":20,"increment":4.5}]}}}}}`),
},
{
description: "valid multibid",
Expand Down Expand Up @@ -1984,75 +1988,9 @@ func TestValidateTargeting(t *testing.T) {
givenTargeting: nil,
expectedError: nil,
},
{
name: "empty",
givenTargeting: &openrtb_ext.ExtRequestTargeting{},
expectedError: errors.New("ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support"),
},
{
name: "includewinners nil, includebidderkeys false",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeBidderKeys: ptrutil.ToPtr(false),
},
expectedError: errors.New("ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support"),
},
{
name: "includewinners nil, includebidderkeys true",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeBidderKeys: ptrutil.ToPtr(true),
},
expectedError: nil,
},
{
name: "includewinners false, includebidderkeys nil",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(false),
},
expectedError: errors.New("ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support"),
},
{
name: "includewinners true, includebidderkeys nil",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
},
expectedError: nil,
},
{
name: "all false",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(false),
IncludeBidderKeys: ptrutil.ToPtr(false),
},
expectedError: errors.New("ext.prebid.targeting: At least one of includewinners or includebidderkeys must be enabled to enable targeting support"),
},
{
name: "includewinners false, includebidderkeys true",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(false),
IncludeBidderKeys: ptrutil.ToPtr(true),
},
expectedError: nil,
},
{
name: "includewinners false, includebidderkeys true",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
IncludeBidderKeys: ptrutil.ToPtr(false),
},
expectedError: nil,
},
{
name: "includewinners true, includebidderkeys true",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
IncludeBidderKeys: ptrutil.ToPtr(true),
},
expectedError: nil,
},
{
name: "price granularity ranges out of order",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
PriceGranularity: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2066,7 +2004,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity video correct",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Video: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2081,7 +2018,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity banner correct",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2096,7 +2032,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity native correct",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2111,7 +2046,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity video and banner correct",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2132,7 +2066,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity video incorrect",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Video: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2147,7 +2080,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity banner incorrect",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2162,7 +2094,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity native incorrect",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2177,7 +2108,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity video correct and banner incorrect",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2198,7 +2128,6 @@ func TestValidateTargeting(t *testing.T) {
{
name: "media type price granularity native incorrect and banner correct",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
IncludeWinners: ptrutil.ToPtr(true),
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"description": "Targeting flags are all set to false, request is still valid, but no targeting data should be present in bids",
"config": {
"mockBidders": [
{
"bidderName": "appnexus",
"currency": "USD",
"price": 0.00
}
]
},
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "prebid.org"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"appnexus": {
"placementId": 12883451
}
}
}
],
"tmax": 500,
"ext": {
"prebid": {
"targeting": {
"includewinners": false,
"includebidderkeys": false,
"includeformat": false
}
}
}
},
"expectedBidResponse": {
"id": "some-request-id",
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "some-impression-id",
"price": 0
}
],
"seat": "appnexus"
}
],
"bidid": "test bid id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"description": "Targeting flags are all undefined besides includeformat, request is still valid, defaults should come in for other flags so targeting data should be present in bid",
"config": {
"mockBidders": [
{
"bidderName": "appnexus",
"currency": "USD",
"price": 1.00
}
]
},
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "prebid.org"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"appnexus": {
"placementId": 12883451
}
}
}
],
"tmax": 500,
"ext": {
"prebid": {
"targeting": {
"includeformat": true
}
}
}
},
"expectedBidResponse": {
"id": "some-request-id",
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "some-impression-id",
"price": 1.00,
"ext": {
"origbidcpm": 1,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"targeting": {
"hb_bidder": "appnexus",
"hb_bidder_appnexus": "appnexus",
"hb_cache_host": "www.pbcserver.com",
"hb_cache_host_appnex": "www.pbcserver.com",
"hb_cache_path": "/pbcache/endpoint",
"hb_cache_path_appnex": "/pbcache/endpoint",
"hb_format": "banner",
"hb_format_appnexus": "banner",
"hb_pb": "1.00",
"hb_pb_appnexus": "1.00"
},
"type": "banner"
}
}
}
],
"seat": "appnexus"
}
],
"bidid": "test bid id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
}
Loading

0 comments on commit 67c487d

Please sign in to comment.