Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bidder level toggle for alternatebiddercodes config #2326

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I recommend using the following declaration to make it clear to the reader this is the case for a nil AllowedBidderCodes:

"pubmatic": {
    Enabled:            true,
    AllowedBidderCodes: nil
},

},
},
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 @@ -2081,6 +2081,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 @@ -2184,6 +2185,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 @@ -2284,6 +2286,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 @@ -2386,6 +2389,7 @@ func TestExtraBidWithBidAdjustmentsUsingAdapterCode(t *testing.T) {
Enabled: true,
Bidders: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down