Skip to content

Commit 00bdbef

Browse files
Support case insensitive bidder name in ext.prebid.storedbidresponse.bidder (prebid#3139)
1 parent bc81af5 commit 00bdbef

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

endpoints/openrtb2/auction.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,12 @@ func validateStoredBidRespAndImpExtBidders(bidderExts map[string]json.RawMessage
24862486
}
24872487

24882488
for bidderName := range bidResponses {
2489-
if _, present := bidderExts[bidderName]; !present {
2489+
bidder := bidderName
2490+
normalizedCoreBidder, ok := openrtb_ext.NormalizeBidderName(bidder)
2491+
if ok {
2492+
bidder = normalizedCoreBidder.String()
2493+
}
2494+
if _, present := bidderExts[bidder]; !present {
24902495
return generateStoredBidResponseValidationError(impId)
24912496
}
24922497
}

endpoints/openrtb2/auction_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4954,9 +4954,11 @@ func TestParseRequestStoredResponses(t *testing.T) {
49544954
func TestParseRequestStoredBidResponses(t *testing.T) {
49554955
bidRespId1 := json.RawMessage(`{"id": "resp_id1", "seatbid": [{"bid": [{"id": "bid_id1"}], "seat": "testBidder1"}], "bidid": "123", "cur": "USD"}`)
49564956
bidRespId2 := json.RawMessage(`{"id": "resp_id2", "seatbid": [{"bid": [{"id": "bid_id2"}], "seat": "testBidder2"}], "bidid": "124", "cur": "USD"}`)
4957+
bidRespId3 := json.RawMessage(`{"id": "resp_id3", "seatbid": [{"bid": [{"id": "bid_id3"}], "seat": "APPNEXUS"}], "bidid": "125", "cur": "USD"}`)
49574958
mockStoredBidResponses := map[string]json.RawMessage{
49584959
"bidResponseId1": bidRespId1,
49594960
"bidResponseId2": bidRespId2,
4961+
"bidResponseId3": bidRespId3,
49604962
}
49614963

49624964
tests := []struct {
@@ -4974,6 +4976,14 @@ func TestParseRequestStoredBidResponses(t *testing.T) {
49744976
},
49754977
expectedErrorCount: 0,
49764978
},
4979+
{
4980+
name: "req imp has valid stored bid response with case insensitive bidder name",
4981+
givenRequestBody: validRequest(t, "imp-with-stored-bid-resp-insensitive-bidder-name.json"),
4982+
expectedStoredBidResponses: map[string]map[string]json.RawMessage{
4983+
"imp-id3": {"APPNEXUS": bidRespId3},
4984+
},
4985+
expectedErrorCount: 0,
4986+
},
49774987
{
49784988
name: "req has two imps with valid stored bid responses",
49794989
givenRequestBody: validRequest(t, "req-two-imps-stored-bid-responses.json"),
@@ -5014,7 +5024,7 @@ func TestParseRequestStoredBidResponses(t *testing.T) {
50145024
map[string]string{},
50155025
false,
50165026
[]byte{},
5017-
map[string]openrtb_ext.BidderName{"testBidder1": "testBidder1", "testBidder2": "testBidder2"},
5027+
map[string]openrtb_ext.BidderName{"testBidder1": "testBidder1", "testBidder2": "testBidder2", "appnexus": "appnexus"},
50185028
nil,
50195029
nil,
50205030
hardcodedResponseIPValidator{response: true},
@@ -5027,7 +5037,6 @@ func TestParseRequestStoredBidResponses(t *testing.T) {
50275037

50285038
req := httptest.NewRequest("POST", "/openrtb2/auction", strings.NewReader(test.givenRequestBody))
50295039
_, _, _, storedBidResponses, _, _, errL := deps.parseRequest(req, &metrics.Labels{}, hookExecutor)
5030-
50315040
if test.expectedErrorCount == 0 {
50325041
assert.Equal(t, test.expectedStoredBidResponses, storedBidResponses, "stored responses should match")
50335042
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"description": "request with impression with stored bid response with sensitive bidder name",
3+
"mockBidRequest": {
4+
"id": "request-with-stored-resp",
5+
"site": {
6+
"page": "test.somepage.com"
7+
},
8+
"imp": [
9+
{
10+
"id": "imp-id3",
11+
"banner": {
12+
"format": [
13+
{
14+
"w": 300,
15+
"h": 600
16+
}
17+
]
18+
},
19+
"ext": {
20+
"appnexus": {
21+
"placementId": 12883451
22+
},
23+
"prebid": {
24+
"storedbidresponse": [
25+
{
26+
"bidder": "APPNEXUS",
27+
"id": "bidResponseId3"
28+
}
29+
]
30+
}
31+
}
32+
}
33+
],
34+
"user": {
35+
"yob": 1989
36+
}
37+
},
38+
"expectedReturnCode": 200
39+
}

stored_responses/stored_responses.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ func extractStoredResponsesIds(impInfo []ImpExtPrebidData,
9797
if len(bidderResp.ID) == 0 || len(bidderResp.Bidder) == 0 {
9898
return nil, nil, nil, nil, fmt.Errorf("request.imp[%d] has ext.prebid.storedbidresponse specified, but \"id\" or/and \"bidder\" fields are missing ", index)
9999
}
100+
bidderName := bidderResp.Bidder
101+
normalizedCoreBidder, ok := openrtb_ext.NormalizeBidderName(bidderResp.Bidder)
102+
if ok {
103+
bidderName = normalizedCoreBidder.String()
104+
}
100105
//check if bidder is valid/exists
101-
if _, isValid := bidderMap[bidderResp.Bidder]; !isValid {
106+
if _, isValid := bidderMap[bidderName]; !isValid {
102107
return nil, nil, nil, nil, fmt.Errorf("request.imp[impId: %s].ext.prebid.bidder contains unknown bidder: %s. Did you forget an alias in request.ext.prebid.aliases?", impId, bidderResp.Bidder)
103108
}
104109
// bidder is unique per one bid stored response

0 commit comments

Comments
 (0)