Skip to content

Commit

Permalink
Add validations for Imp
Browse files Browse the repository at this point in the history
  • Loading branch information
margsliu committed Sep 19, 2019
1 parent b641e65 commit 226a541
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
52 changes: 50 additions & 2 deletions adapters/lockerdome/lockerdome.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

const unexpectedStatusCodeMessage = "Unexpected status code: %d. Run with request.debug = 1 for more info"
Expand All @@ -20,6 +21,52 @@ type LockerDomeAdapter struct {
// MakeRequests makes the HTTP requests which should be made to fetch bids [from the bidder, in this case, LockerDome]
func (adapter *LockerDomeAdapter) MakeRequests(openRTBRequest *openrtb.BidRequest, extraReqInfo *adapters.ExtraRequestInfo) (requestsToBidder []*adapters.RequestData, errs []error) {

numberOfImps := len(openRTBRequest.Imp)

if openRTBRequest.Imp == nil || numberOfImps == 0 { // lockerdometest/supplemental/empty_imps.json
err := &errortypes.BadInput{
Message: "No valid impressions in the bid request.",
}
errs = append(errs, err)
return nil, errs
}

for i := 0; i < numberOfImps; i++ {
// LockerDome currently only supports banner impressions, and requires data in the ext field.
if openRTBRequest.Imp[i].Banner == nil { // lockerdometest/supplemental/unsupported_imp_type.json
err := &errortypes.BadInput{
Message: "LockerDome does not currently support non-banner types.",
}
errs = append(errs, err)
return nil, errs
}
var bidderExt adapters.ExtImpBidder
err := json.Unmarshal(openRTBRequest.Imp[i].Ext, &bidderExt)
if err != nil { // lockerdometest/supplemental/no_ext.json
err = &errortypes.BadInput{
Message: "ext was not provided.",
}
errs = append(errs, err)
return nil, errs
}
var lockerdomeExt openrtb_ext.ExtImpLockerDome
err = json.Unmarshal(bidderExt.Bidder, &lockerdomeExt)
if err != nil { // lockerdometest/supplemental/no_adUnitId_param.json
err = &errortypes.BadInput{
Message: "ext.bidder.adUnitId was not provided.",
}
errs = append(errs, err)
return nil, errs
}
if lockerdomeExt.AdUnitId == "" { // lockerdometest/supplemental/empty_adUnitId_param.json
err := &errortypes.BadInput{
Message: "ext.bidder.adUnitId is empty.",
}
errs = append(errs, err)
return nil, errs
}
}

openRTBRequestJSON, err := json.Marshal(openRTBRequest)
if err != nil {
errs = append(errs, err)
Expand All @@ -40,7 +87,8 @@ func (adapter *LockerDomeAdapter) MakeRequests(openRTBRequest *openrtb.BidReques

requestsToBidder = append(requestsToBidder, requestToBidder)

return requestsToBidder, errs
return requestsToBidder, nil

}

// MakeBids unpacks the server's response into Bids.
Expand Down Expand Up @@ -77,7 +125,7 @@ func (adapter *LockerDomeAdapter) MakeBids(openRTBRequest *openrtb.BidRequest, r

for _, seatBid := range openRTBBidderResponse.SeatBid {
for i := range seatBid.Bid {
typedBid := adapters.TypedBid{Bid: &seatBid.Bid[i], BidType: "banner"}
typedBid := adapters.TypedBid{Bid: &seatBid.Bid[i], BidType: openrtb_ext.BidTypeBanner}
bidderResponse.Bids = append(bidderResponse.Bids, &typedBid)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"adUnitId": ""
}
}
}
]
},

"expectedMakeRequestsErrors": [
"ext.bidder.adUnitId is empty."
]
}
10 changes: 10 additions & 0 deletions adapters/lockerdome/lockerdometest/supplemental/empty_imps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": []
},

"expectedMakeRequestsErrors": [
"No valid impressions in the bid request."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {}
}
]
},

"expectedMakeRequestsErrors": [
"ext.bidder.adUnitId was not provided."
]
}
22 changes: 22 additions & 0 deletions adapters/lockerdome/lockerdometest/supplemental/no_ext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
}
}
]
},

"expectedMakeRequestsErrors": [
"ext was not provided."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"adUnitId": "LD9434769725128806"
}
}
}
]
},

"expectedMakeRequestsErrors": [
"LockerDome does not currently support non-banner types."
]
}
7 changes: 7 additions & 0 deletions openrtb_ext/imp_lockerdome.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package openrtb_ext

// ExtImpLockerDome defines the contract for bidrequest.imp[i].ext.lockerdome
type ExtImpLockerDome struct {
// LockerDome params
AdUnitId string `json:"adUnitId"`
}

0 comments on commit 226a541

Please sign in to comment.