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

make case insensitive comparison in auction request #3113

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,12 +1510,12 @@ func (deps *endpointDeps) validateImpExt(imp *openrtb_ext.ImpWrapper, aliases ma
errL := []error{}

for bidder, ext := range prebid.Bidder {
coreBidder := bidder
coreBidder, _ := openrtb_ext.NormalizeBidderName(bidder)
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
if tmp, isAlias := aliases[bidder]; isAlias {
coreBidder = tmp
coreBidder = openrtb_ext.BidderName(tmp)
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
}

if coreBidderNormalized, isValid := deps.bidderMap[coreBidder]; isValid {
if coreBidderNormalized, isValid := deps.bidderMap[coreBidder.String()]; isValid {
if err := deps.paramsValidator.Validate(coreBidderNormalized, ext); err != nil {
return []error{fmt.Errorf("request.imp[%d].ext.prebid.bidder.%s failed validation.\n%v", impIndex, bidder, err)}
}
Expand Down
22 changes: 12 additions & 10 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2833,19 +2833,21 @@ func TestValidateImpExt(t *testing.T) {

for _, group := range testGroups {
for _, test := range group.testCases {
imp := &openrtb2.Imp{Ext: test.impExt}
impWrapper := &openrtb_ext.ImpWrapper{Imp: imp}
t.Run(test.description, func(t *testing.T) {
imp := &openrtb2.Imp{Ext: test.impExt}
impWrapper := &openrtb_ext.ImpWrapper{Imp: imp}

errs := deps.validateImpExt(impWrapper, nil, 0, false, nil)
errs := deps.validateImpExt(impWrapper, nil, 0, false, nil)

assert.NoError(t, impWrapper.RebuildImp(), test.description+":rebuild_imp")
assert.NoError(t, impWrapper.RebuildImp(), test.description+":rebuild_imp")

if len(test.expectedImpExt) > 0 {
assert.JSONEq(t, test.expectedImpExt, string(imp.Ext), "imp.ext JSON does not match expected. Test: %s. %s\n", group.description, test.description)
} else {
assert.Empty(t, imp.Ext, "imp.ext expected to be empty but was: %s. Test: %s. %s\n", string(imp.Ext), group.description, test.description)
}
assert.Equal(t, test.expectedErrs, errs, "errs slice does not match expected. Test: %s. %s\n", group.description, test.description)
if len(test.expectedImpExt) > 0 {
assert.JSONEq(t, test.expectedImpExt, string(imp.Ext), "imp.ext JSON does not match expected. Test: %s. %s\n", group.description, test.description)
} else {
assert.Empty(t, imp.Ext, "imp.ext expected to be empty but was: %s. Test: %s. %s\n", string(imp.Ext), group.description, test.description)
}
assert.Equal(t, test.expectedErrs, errs, "errs slice does not match expected. Test: %s. %s\n", group.description, test.description)
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"description": "Simple request",
"config": {
"mockBidders": [
{"bidderName": "appnexus", "currency": "USD", "price": 0.00}
{
"bidderName": "appnexus",
"currency": "USD",
"price": 0.00
}
]
},
"mockBidRequest": {
Expand All @@ -26,7 +30,7 @@
]
},
"ext": {
"appnexus": {
"Appnexus": {
"placementId": 12883451
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand All @@ -36,22 +40,22 @@
"ext": {}
},
"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
"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
}
}
6 changes: 3 additions & 3 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func TestAdapterCurrency(t *testing.T) {
categoriesFetcher: nilCategoryFetcher{},
bidIDGenerator: &mockBidIDGenerator{false, false},
adapterMap: map[openrtb_ext.BidderName]AdaptedBidder{
openrtb_ext.BidderName("foo"): AdaptBidder(mockBidder, nil, &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderName("foo"), nil, ""),
openrtb_ext.BidderName("appnexus"): AdaptBidder(mockBidder, nil, &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderName("appnexus"), nil, ""),
hhhjort marked this conversation as resolved.
Show resolved Hide resolved
},
}
e.requestSplitter = requestSplitter{
Expand All @@ -783,7 +783,7 @@ func TestAdapterCurrency(t *testing.T) {
Imp: []openrtb2.Imp{{
ID: "some-impression-id",
Banner: &openrtb2.Banner{Format: []openrtb2.Format{{W: 300, H: 250}, {W: 300, H: 600}}},
Ext: json.RawMessage(`{"prebid":{"bidder":{"foo":{"placementId":1}}}}`),
Ext: json.RawMessage(`{"prebid":{"bidder":{"appnexus":{"placementId":1}}}}`),
}},
Site: &openrtb2.Site{
Page: "prebid.org",
Expand All @@ -805,7 +805,7 @@ func TestAdapterCurrency(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "some-request-id", response.ID, "Response ID")
assert.Empty(t, response.SeatBid, "Response Bids")
assert.Contains(t, string(response.Ext), `"errors":{"foo":[{"code":5,"message":"The adapter failed to generate any bid requests, but also failed to generate an error explaining why"}]}`, "Response Ext")
assert.Contains(t, string(response.Ext), `"errors":{"appnexus":[{"code":5,"message":"The adapter failed to generate any bid requests, but also failed to generate an error explaining why"}]}`, "Response Ext")

// Test Currency Converter Properly Passed To Adapter
if assert.NotNil(t, mockBidder.lastExtraRequestInfo, "Currency Conversion Argument") {
Expand Down
3 changes: 2 additions & 1 deletion exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,11 @@ func setUserExtWithCopy(request *openrtb2.BidRequest, userExtJSON json.RawMessag

// resolveBidder returns the known BidderName associated with bidder, if bidder is an alias. If it's not an alias, the bidder is returned.
func resolveBidder(bidder string, aliases map[string]string) openrtb_ext.BidderName {
normalisedBidderName, _ := openrtb_ext.NormalizeBidderName(bidder)
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
if coreBidder, ok := aliases[bidder]; ok {
return openrtb_ext.BidderName(coreBidder)
}
return openrtb_ext.BidderName(bidder)
return normalisedBidderName
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
}

// parseAliases parses the aliases from the BidRequest
Expand Down