Skip to content

Commit

Permalink
Adapter Name Case Insensitive: ext.prebid.multibid (#3217)
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon authored Oct 18, 2023
1 parent 11ef54d commit bde7bcf
Show file tree
Hide file tree
Showing 4 changed files with 654 additions and 4 deletions.
8 changes: 6 additions & 2 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,14 @@ func buildMultiBidMap(prebid *openrtb_ext.ExtRequestPrebid) map[string]openrtb_e
multiBidMap := make(map[string]openrtb_ext.ExtMultiBid)
for _, multiBid := range prebid.MultiBid {
if multiBid.Bidder != "" {
multiBidMap[multiBid.Bidder] = *multiBid
if bidderNormalized, bidderFound := openrtb_ext.NormalizeBidderName(multiBid.Bidder); bidderFound {
multiBidMap[string(bidderNormalized)] = *multiBid
}
} else {
for _, bidder := range multiBid.Bidders {
multiBidMap[bidder] = *multiBid
if bidderNormalized, bidderFound := openrtb_ext.NormalizeBidderName(bidder); bidderFound {
multiBidMap[string(bidderNormalized)] = *multiBid
}
}
}
}
Expand Down
197 changes: 197 additions & 0 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2259,8 +2259,13 @@ func TestTimeoutComputation(t *testing.T) {
func TestExchangeJSON(t *testing.T) {
if specFiles, err := os.ReadDir("./exchangetest"); err == nil {
for _, specFile := range specFiles {
if !strings.HasSuffix(specFile.Name(), ".json") {
continue
}

fileName := "./exchangetest/" + specFile.Name()
fileDisplayName := "exchange/exchangetest/" + specFile.Name()

t.Run(fileDisplayName, func(t *testing.T) {
specData, err := loadFile(fileName)
if assert.NoError(t, err, "Failed to load contents of file %s: %v", fileDisplayName, err) {
Expand Down Expand Up @@ -5750,3 +5755,195 @@ func TestSetSeatNonBid(t *testing.T) {
})
}
}

func TestBuildMultiBidMap(t *testing.T) {
type testCase struct {
desc string
inPrebid *openrtb_ext.ExtRequestPrebid
expected map[string]openrtb_ext.ExtMultiBid
}
testGroups := []struct {
groupDesc string
tests []testCase
}{
{
groupDesc: "Nil or empty tests",
tests: []testCase{
{
desc: "prebid nil, expect nil map",
inPrebid: nil,
expected: nil,
},
{
desc: "prebid.MultiBid nil, expect nil map",
inPrebid: &openrtb_ext.ExtRequestPrebid{},
expected: nil,
},
{
desc: "not-nil prebid.MultiBid is empty, expect empty map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
},
},
{
groupDesc: "prebid.MultiBid.Bidder tests",
tests: []testCase{
{
desc: "Lowercase prebid.MultiBid.Bidder is found in the BidderName list, entry is mapped",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidder: "appnexus"},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"appnexus": {Bidder: "appnexus"},
},
},
{
desc: "Uppercase prebid.MultiBid.Bidder is found in the BidderName list, entry is mapped",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidder: "APPNEXUS"},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"appnexus": {Bidder: "APPNEXUS"},
},
},
{
desc: "Lowercase prebid.MultiBid.Bidder is not found in the BidderName list, expect empty map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidder: "unknown"},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
{
desc: "Mixed-case prebid.MultiBid.Bidder is not found in the BidderName list, expect empty map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidder: "UnknownBidder"},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
{
desc: "Different-cased prebid.MultiBid.Bidder entries that refer to the same adapter are found in the BidderName list are mapped once",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidder: "AppNexus"},
{Bidder: "appnexus"},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"appnexus": {Bidder: "appnexus"},
},
},
},
},
{
groupDesc: "prebid.MultiBid.Bidders tests",
tests: []testCase{
{
desc: "Lowercase prebid.MultiBid.Bidder is found in the BidderName list, entry is mapped",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidders: []string{"appnexus"}},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"appnexus": {
Bidders: []string{"appnexus"},
},
},
},
{
desc: "Lowercase prebid.MultiBid.Bidder is not found in the BidderName list, expect empty map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidders: []string{"unknown"}},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
{
desc: "Mixed-case prebid.MultiBid.Bidder is not found in the BidderName list, expect empty map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidders: []string{"UnknownBidder"}},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
{
desc: "Different-cased prebid.MultiBid.Bidder entries that refer to the same adapter are found in the BidderName list are mapped once",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{Bidders: []string{"AppNexus", "appnexus", "UnknownBidder"}},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"appnexus": {
Bidders: []string{"AppNexus", "appnexus", "UnknownBidder"},
},
},
},
},
},
{
groupDesc: "prebid.MultiBid.Bidder and prebid.MultiBid.Bidders entries in tests",
tests: []testCase{
{
desc: "prebid.MultiBid.Bidder found, ignore entries in prebid.MultiBid.Bidders, even if its unknown",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{
Bidder: "UnknownBidder",
Bidders: []string{"appnexus", "rubicon", "pubmatic"},
},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{},
},
{
desc: "prebid.MultiBid.Bidder found in one entry, prebid.MultiBid.Bidders in another. Add all to map",
inPrebid: &openrtb_ext.ExtRequestPrebid{
MultiBid: []*openrtb_ext.ExtMultiBid{
{
Bidder: "pubmatic",
Bidders: []string{"appnexus", "rubicon", "UnknownBidder"},
},
{
Bidders: []string{"UnknownBidder", "appnexus", "rubicon"},
},
},
},
expected: map[string]openrtb_ext.ExtMultiBid{
"pubmatic": {
Bidder: "pubmatic",
Bidders: []string{"appnexus", "rubicon", "UnknownBidder"},
},
"appnexus": {
Bidders: []string{"UnknownBidder", "appnexus", "rubicon"},
},
"rubicon": {
Bidders: []string{"UnknownBidder", "appnexus", "rubicon"},
},
},
},
},
},
}
for _, group := range testGroups {
for _, tc := range group.tests {
t.Run(group.groupDesc+tc.desc, func(t *testing.T) {
multiBidMap := buildMultiBidMap(tc.inPrebid)
assert.Equal(t, tc.expected, multiBidMap, tc.desc)
})
}
}
}
Loading

0 comments on commit bde7bcf

Please sign in to comment.