Skip to content

Commit

Permalink
Add bidder level toggle for alternatebiddercodes config (prebid#2326)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate authored and jorgeluisrocha committed Sep 22, 2022
1 parent 99d2b5f commit 47bf6c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
6 changes: 4 additions & 2 deletions config/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type AlternateBidderCodes struct {
}

type AdapterAlternateBidderCodes struct {
Enabled bool `mapstructure:"enabled" json:"enabled"`
AllowedBidderCodes []string `mapstructure:"allowedbiddercodes" json:"allowedbiddercodes"`
}

Expand All @@ -255,11 +256,12 @@ func (bidderCodes *AlternateBidderCodes) IsValidBidderCode(bidder, alternateBidd
return false, fmt.Errorf(ErrAlternateBidderNotDefined, bidder, alternateBidder)
}

if len(adapterCfg.AllowedBidderCodes) == 0 {
if !adapterCfg.Enabled {
// config has bidder entry but is not enabled, report it
return false, fmt.Errorf("alternateBidderCodes disabled for %q, rejecting bids for %q", bidder, alternateBidder)
}

if adapterCfg.AllowedBidderCodes[0] == "*" {
if adapterCfg.AllowedBidderCodes == nil || (len(adapterCfg.AllowedBidderCodes) == 1 && adapterCfg.AllowedBidderCodes[0] == "*") {
return true, nil
}

Expand Down
36 changes: 34 additions & 2 deletions config/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,20 +771,34 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
wantErr: errors.New(`alternateBidderCodes not defined for adapter "pubmatic", rejecting bids for "groupm"`),
},
{
name: "account.alternatebiddercodes config enabled but adapter config has allowedBidderCodes list empty or not defined",
name: "account.alternatebiddercodes config enabled but adapter config is disabled",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {},
"pubmatic": {Enabled: false},
},
},
wantIsValid: false,
wantErr: errors.New(`alternateBidderCodes disabled for "pubmatic", rejecting bids for "groupm"`),
},
{
name: "account.alternatebiddercodes and adapter config enabled but adapter config does not have allowedBidderCodes defined",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {Enabled: true},
},
},
wantIsValid: true,
},
{
name: "allowedBidderCodes is *",
args: args{
Expand All @@ -795,6 +809,7 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"*"},
},
},
Expand All @@ -811,6 +826,7 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand All @@ -827,13 +843,29 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"xyz"},
},
},
},
wantIsValid: false,
wantErr: errors.New(`invalid biddercode "groupm" sent by adapter "pubmatic"`),
},
{
name: "account.alternatebiddercodes and adapter config enabled but adapter config has allowedBidderCodes list empty",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Bidders: map[string]AdapterAlternateBidderCodes{
"pubmatic": {Enabled: true, AllowedBidderCodes: []string{}},
},
},
wantIsValid: false,
wantErr: errors.New(`invalid biddercode "groupm" sent by adapter "pubmatic"`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions exchange/bidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,7 @@ func TestExtraBid(t *testing.T) {
Enabled: true,
Bidders: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down Expand Up @@ -2354,6 +2355,7 @@ func TestExtraBidWithAlternateBidderCodeDisabled(t *testing.T) {
Enabled: true,
Bidders: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm-allowed"},
},
},
Expand Down Expand Up @@ -2462,6 +2464,7 @@ func TestExtraBidWithBidAdjustments(t *testing.T) {
Enabled: true,
Bidders: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down Expand Up @@ -2572,6 +2575,7 @@ func TestExtraBidWithBidAdjustmentsUsingAdapterCode(t *testing.T) {
Enabled: true,
Bidders: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down

0 comments on commit 47bf6c9

Please sign in to comment.