Skip to content

Commit

Permalink
Allow Bidders To Represent Support Without Default
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxNode committed Aug 12, 2021
1 parent 5649c77 commit 7d3bbb5
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 67 deletions.
30 changes: 23 additions & 7 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R
return nil, err
}

syncersByBidder, err := usersync.BuildSyncers(cfg, bidderInfos)
if err != nil {
return nil, err
syncersByBidder, errs := usersync.BuildSyncers(cfg, bidderInfos)
if errsFiltered := filterSyncerErrors(errs); len(errsFiltered) > 0 {
return nil, errortypes.NewAggregateError("user sync", errsFiltered)
}

syncerKeys := make([]string, 0, len(syncersByBidder))
Expand Down Expand Up @@ -341,7 +341,7 @@ func applyBidderInfoConfigOverrides(bidderInfos config.BidderInfos, adaptersCfg
// the new config.
if adapterCfg.UserSyncURL != "" {
if bidderInfo.Syncer == nil {
return fmt.Errorf("failed to apply legacy usersync_url setting for bidder %s, bidder does not define a user sync or is disabled", bidderName)
return fmt.Errorf("adapters.%s.usersync_url cannot be applied, bidder does not define a user sync", strings.ToLower(bidderName))
}

endpointsCount := 0
Expand All @@ -355,17 +355,17 @@ func applyBidderInfoConfigOverrides(bidderInfos config.BidderInfos, adaptersCfg
}

if endpointsCount == 0 {
return fmt.Errorf("failed to apply legacy usersync_url setting for bidder %s, bidder does not define user sync endpoints", bidderName)
return fmt.Errorf("adapters.%s.usersync_url cannot be applied, bidder does not define user sync endpoints", strings.ToLower(bidderName))
}

// if the bidder defines both an iframe and redirect endpoint, we can't be sure which config value to
// override, and it wouldn't be both. this is a fatal configuration error.
if endpointsCount > 1 {
return fmt.Errorf("failed to apply legacy usersync_url setting for bidder %s, bidder defines multiple user sync endpoints", bidderName)
return fmt.Errorf("adapters.%s.usersync_url cannot be applied, bidder defines multiple user sync endpoints", strings.ToLower(bidderName))
}

// provide a warning that this compatibility layer is temporary
glog.Warningf("legacy usersync_url setting for bidder %s will be removed in a future version of Prebid Server. please update to the latest user sync config values", bidderName)
glog.Warningf("adapters.%s.usersync_url is deprecated and will be removed in a future version, please update to the latest user sync config values", strings.ToLower(bidderName))
}

bidderInfos[bidderName] = bidderInfo
Expand All @@ -374,6 +374,22 @@ func applyBidderInfoConfigOverrides(bidderInfos config.BidderInfos, adaptersCfg
return nil
}

func filterSyncerErrors(errs []error) []error {
var fatalErrors []error

for _, err := range errs {
syncerBuildErr, ok := err.(usersync.SyncerBuildError)
if ok && syncerBuildErr.Err == usersync.ErrSyncerURLRequired {
bidderName := strings.ToLower(syncerBuildErr.Bidder)
glog.Warningf("bidder %s supports user syncing but has endpoints with no default url, no syncs will be performed with %s.", bidderName, bidderName)
} else {
fatalErrors = append(fatalErrors, err)
}
}

return fatalErrors
}

// Fixes #648
//
// These CORS options pose a security risk... but it's a calculated one.
Expand Down
53 changes: 50 additions & 3 deletions router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package router

import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -104,19 +107,19 @@ func TestApplyBidderInfoConfigOverrides(t *testing.T) {
description: "UserSyncURL Override Syncer Not Defined",
givenBidderInfos: config.BidderInfos{"a": {}},
givenAdaptersCfg: map[string]config.Adapter{"a": {UserSyncURL: "override"}},
expectedError: "failed to apply legacy usersync_url setting for bidder a, bidder does not define a user sync or is disabled",
expectedError: "adapters.a.usersync_url cannot be applied, bidder does not define a user sync",
},
{
description: "UserSyncURL Override Syncer Endpoints Not Defined",
givenBidderInfos: config.BidderInfos{"a": {Syncer: &config.Syncer{}}},
givenAdaptersCfg: map[string]config.Adapter{"a": {UserSyncURL: "override"}},
expectedError: "failed to apply legacy usersync_url setting for bidder a, bidder does not define user sync endpoints",
expectedError: "adapters.a.usersync_url cannot be applied, bidder does not define user sync endpoints",
},
{
description: "UserSyncURL Override Ambiguous",
givenBidderInfos: config.BidderInfos{"a": {Syncer: &config.Syncer{IFrame: &config.SyncerEndpoint{URL: "originalIFrame"}, Redirect: &config.SyncerEndpoint{URL: "originalRedirect"}}}},
givenAdaptersCfg: map[string]config.Adapter{"a": {UserSyncURL: "override"}},
expectedError: "failed to apply legacy usersync_url setting for bidder a, bidder defines multiple user sync endpoints",
expectedError: "adapters.a.usersync_url cannot be applied, bidder defines multiple user sync endpoints",
},
}

Expand All @@ -131,6 +134,50 @@ func TestApplyBidderInfoConfigOverrides(t *testing.T) {
}
}

func TestFilterSyncerErrors(t *testing.T) {
fatalErrorA := errors.New("errorA")
fatalErrorB := &errortypes.BadInput{Message: "errorB"}
buildErrorURLRequired := usersync.SyncerBuildError{Bidder: "anyBidder", SyncerKey: "anyKey", Err: usersync.ErrSyncerURLRequired}
buildErrorOther := usersync.SyncerBuildError{Bidder: "anyBidder", SyncerKey: "anyKey", Err: usersync.ErrSyncerKeyRequired}

var testCases = []struct {
description string
givenErrors []error
expectedErrors []error
}{
{
description: "Nil",
givenErrors: nil,
expectedErrors: nil,
},
{
description: "Empty",
givenErrors: []error{},
expectedErrors: nil,
},
{
description: "One - Not Filtered",
givenErrors: []error{fatalErrorA},
expectedErrors: []error{fatalErrorA},
},
{
description: "One - Filtered",
givenErrors: []error{buildErrorURLRequired},
expectedErrors: nil,
},
{
description: "Many - Mixed",
givenErrors: []error{fatalErrorA, fatalErrorB, buildErrorURLRequired, buildErrorOther},
expectedErrors: []error{fatalErrorA, fatalErrorB, buildErrorOther},
},
}

for _, test := range testCases {
filteredErrs := filterSyncerErrors(test.givenErrors)
assert.Equal(t, test.expectedErrors, filteredErrs, test.description)
}
}

// Prevents #648
func TestCORSSupport(t *testing.T) {
const origin = "https://publisher-domain.com"
Expand Down
5 changes: 5 additions & 0 deletions static/bidder-info/adocean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ capabilities:
site:
mediaTypes:
- banner
userSync:
redirect:
# adocean supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/adtarget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
iframe:
# adtarget supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/adtelligent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
iframe:
# adtelligent supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/adxcg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ capabilities:
- banner
- video
- native
userSync:
redirect:
# adxcg supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/audienceNetwork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ capabilities:
- banner
- video
- native
userSync:
redirect:
# facebook's audience network supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/bmtm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
redirect:
# bmtm supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
7 changes: 6 additions & 1 deletion static/bidder-info/criteo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ capabilities:
- banner
site:
mediaTypes:
- banner
- banner
userSync:
redirect:
# criteo supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/dmx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
redirect:
# dmx supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/gamma.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
iframe:
# gamma supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/invibes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ capabilities:
site:
mediaTypes:
- banner
userSync:
iframe:
# invibes supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
16 changes: 9 additions & 7 deletions static/bidder-info/lockerdome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ capabilities:
site:
mediaTypes:
- banner
# lockerdome requires a platform id for their user sync process. replace <<PlatformID>>
# in the url below and uncomment the userSync section to enable.
#
#userSync:
# redirect:
# url: "https://lockerdome.com/usync/prebidserver?pid=<<PlatformID>>&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect={{.RedirectURL}}"
# userMacro: "{{uid}}"
userSync:
redirect:
# lockerdome supports user syncing, but requires a platform id to be configured by
# the host. remove the empty url, replace <<PlatformID>> with the value provided, and
# uncomment to enable.
#
# url: "https://lockerdome.com/usync/prebidserver?pid=<<PlatformID>>&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect={{.RedirectURL}}"
url: ""
userMacro: "{{uid}}"
5 changes: 5 additions & 0 deletions static/bidder-info/mediafuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
iframe:
# mediafuse supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/rtbhouse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ capabilities:
site:
mediaTypes:
- banner
userSync:
redirect:
# rtbhouse supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/rubicon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
redirect:
# rubicon supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/smarthub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ capabilities:
- banner
- video
- native
userSync:
redirect:
# smarthub supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/synacormedia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ userSync:
iframe:
url: "https://sync.technoratimedia.com/services?srv=cs&pid=70&cb={{.RedirectURL}}"
userMacro: "[USER_ID]"
userSync:
iframe:
# synacormedia supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/verizonmedia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ capabilities:
site:
mediaTypes:
- banner
userSync:
redirect:
# verizonmedia supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/viewdeos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ capabilities:
mediaTypes:
- banner
- video
userSync:
redirect:
# viewdeos supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
5 changes: 5 additions & 0 deletions static/bidder-info/vrtcal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ capabilities:
app:
mediaTypes:
- banner
userSync:
redirect:
# vrtcal supports user syncing, but requires configuration by the host. paste the
# url provided by the bidder below to enable.
url: ""
Loading

0 comments on commit 7d3bbb5

Please sign in to comment.