Skip to content

Commit

Permalink
update adaptor and test cases for headers validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamc-ins committed Dec 12, 2024
1 parent d8f3ca3 commit f0d12f0
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 259 deletions.
17 changes: 6 additions & 11 deletions adapters/insticator/insticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
}

// Populate publisher.id from imp extension
if !isPublisherIdPopulated && (requestCopy.Site != nil || requestCopy.App != nil) {
if err := populatePublisherId(publisherId, &requestCopy); err != nil {
errs = append(errs, err)
continue
}
if !isPublisherIdPopulated {
populatePublisherId(publisherId, &requestCopy)
isPublisherIdPopulated = true
}

Expand Down Expand Up @@ -148,11 +145,11 @@ func (a *adapter) makeRequest(request *openrtb2.BidRequest, impList []openrtb2.I
}

if len(request.Device.IPv6) > 0 {
headers.Add("X-Forwarded-For", request.Device.IPv6)
headers.Set("X-Forwarded-For", request.Device.IPv6)
}

if len(request.Device.IP) > 0 {
headers.Add("X-Forwarded-For", request.Device.IP)
headers.Set("X-Forwarded-For", request.Device.IP)
headers.Add("IP", request.Device.IP)
}
}
Expand Down Expand Up @@ -274,7 +271,7 @@ func resolveBidFloor(bidFloor float64, bidFloorCur string, reqInfo *adapters.Ext
}

func validateVideoParams(video *openrtb2.Video) error {
if (video.W == nil || *video.W == 0) || (video.H == nil || *video.H == 0) || video.MIMEs == nil {
if video.W == nil || *video.W == 0 || video.H == nil || *video.H == 0 || video.MIMEs == nil {
return &errortypes.BadInput{
Message: "One or more invalid or missing video field(s) w, h, mimes",
}
Expand All @@ -284,7 +281,7 @@ func validateVideoParams(video *openrtb2.Video) error {
}

// populatePublisherId function populates site.publisher.id or app.publisher.id
func populatePublisherId(publisherId string, request *openrtb2.BidRequest) error {
func populatePublisherId(publisherId string, request *openrtb2.BidRequest) {

// Populate site.publisher.id if request.Site is not nil
if request.Site != nil {
Expand Down Expand Up @@ -319,6 +316,4 @@ func populatePublisherId(publisherId string, request *openrtb2.BidRequest) error

request.App.Publisher.ID = publisherId
}

return nil
}
262 changes: 147 additions & 115 deletions adapters/insticator/insticatortest/exemplary/app-video.json
Original file line number Diff line number Diff line change
@@ -1,95 +1,128 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 1,
"startdelay": -2,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"bidder": {
"adUnitId": "fake-site-id",
"publisherId": "test-publisher-id"
}
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [
2
],
"placement": 1,
"startdelay": -2,
"playbackmethod": [
2
],
"mimes": [
"foo",
"bar"
]
},
"ext": {
"bidder": {
"adUnitId": "fake-site-id",
"publisherId": "test-publisher-id"
}
}
],
"app": {
"publisher": {
"id": "test-publisher-id"
}
},
"device": {
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"ip": "1.22.22.1",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
}
],
"app": {
"publisher": {
"id": "test-publisher-id"
}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "https://insticator.example.com/v1/pbs",
"body": {
"device": {
"ip": "1.22.22.1",
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
},
"ext": {
"insticator": {
"caller": [
{
"name": "Prebid-Server",
"version": "n/a"
}
"device": {
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"ip": "1.22.22.1",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
}
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
],
"X-Forwarded-For": [
"1.22.22.1"
],
"Ip": [
"1.22.22.1"
]
},
"uri": "https://insticator.example.com/v1/pbs",
"body": {
"device": {
"ip": "1.22.22.1",
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
},
"ext": {
"insticator": {
"caller": [
{
"name": "Prebid-Server",
"version": "n/a"
}
]
}
},
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [
2
],
"placement": 1,
"startdelay": -2,
"playbackmethod": [
2
],
"mimes": [
"foo",
"bar"
]
}
},
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 1,
"startdelay": -2,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"insticator": {
"adUnitId": "fake-site-id",
"publisherId": "test-publisher-id"
}
},
"ext": {
"insticator": {
"adUnitId": "fake-site-id",
"publisherId": "test-publisher-id"
}
}
],
"app": {
"publisher": {
"id": "test-publisher-id"
}
}
},
"impIDs":["test-imp-id"]
],
"app": {
"publisher": {
"id": "test-publisher-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "insticator",
"bid": [{
"impIDs": [
"test-imp-id"
]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "insticator",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
Expand All @@ -103,39 +136,38 @@
"mediaType": "video"
}
}
}]
}
],
"cur": "USD"
}
}
]
}
],
"cur": "USD"
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"w": 728,
"mtype": 2,
"h": 90,
"ext": {
"insticator": {
"mediaType": "video"
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"w": 728,
"mtype": 2,
"h": 90,
"ext": {
"insticator": {
"mediaType": "video"
}
},
"type": "video"
}
]
}
]
}
}
},
"type": "video"
}
]
}
]
}
Loading

0 comments on commit f0d12f0

Please sign in to comment.