Skip to content

Commit

Permalink
CPMStar: Fixed for loop index reference bug (prebid#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMGoldstein authored Apr 29, 2024
1 parent 5da25e3 commit 30082c0
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 4 deletions.
8 changes: 4 additions & 4 deletions adapters/cpmstar/cpmstar.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func (a *Adapter) MakeBids(bidRequest *openrtb2.BidRequest, unused *adapters.Req
var errors []error

for _, seatbid := range bidResponse.SeatBid {
for _, bid := range seatbid.Bid {
for i := range seatbid.Bid {
foundMatchingBid := false
bidType := openrtb_ext.BidTypeBanner
for _, imp := range bidRequest.Imp {
if imp.ID == bid.ImpID {
if imp.ID == seatbid.Bid[i].ImpID {
foundMatchingBid = true
if imp.Banner != nil {
bidType = openrtb_ext.BidTypeBanner
Expand All @@ -143,12 +143,12 @@ func (a *Adapter) MakeBids(bidRequest *openrtb2.BidRequest, unused *adapters.Req

if foundMatchingBid {
rv.Bids = append(rv.Bids, &adapters.TypedBid{
Bid: &bid,
Bid: &seatbid.Bid[i],
BidType: bidType,
})
} else {
errors = append(errors, &errortypes.BadServerResponse{
Message: fmt.Sprintf("bid id='%s' could not find valid impid='%s'", bid.ID, bid.ImpID),
Message: fmt.Sprintf("bid id='%s' could not find valid impid='%s'", seatbid.Bid[i].ID, seatbid.Bid[i].ImpID),
})
}
}
Expand Down
153 changes: 153 additions & 0 deletions adapters/cpmstar/cpmstartest/exemplary/multiple-banners.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-banner-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"placementId": 154,
"subpoolId": 123
}
}
},
{
"id": "test-banner-imp-id-2",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"placementId": 154,
"subpoolId": 500
}
}
}
],
"site": {
"id": "fake-site-id"
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "//host",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-banner-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"placementId": 154,
"subpoolId": 123
}
},
{
"id": "test-banner-imp-id-2",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"placementId": 154,
"subpoolId": 500
}
}
],
"site": {
"id": "fake-site-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "cpmstar",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-banner-imp-id",
"price": 0.500000,
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
},
{
"id": "06f0f605-0359-4b2d-9916-e4f06a4cdc1d",
"impid": "test-banner-imp-id-2",
"price": 1.000000,
"adm": "some-test-ad-2",
"crid": "crid_11",
"h": 90,
"w": 728
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-banner-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
},
"type": "banner"
},
{
"bid": {
"id": "06f0f605-0359-4b2d-9916-e4f06a4cdc1d",
"impid": "test-banner-imp-id-2",
"price": 1.0,
"adm": "some-test-ad-2",
"crid": "crid_11",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}

0 comments on commit 30082c0

Please sign in to comment.