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

Sovrn: Accept imp.ext bidfloor as number or string #3955

Merged
merged 11 commits into from
Jan 18, 2025
53 changes: 53 additions & 0 deletions adapters/sovrn/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package sovrn

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v3/openrtb_ext"
)

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")

if err != nil {
t.Fatalf("Failed to fetch json-schemas. %v", err)
}

for _, param := range validParams {
if err := validator.Validate(openrtb_ext.BidderSovrn, json.RawMessage(param)); err != nil {
t.Errorf("Schema rejected sovrn params: %s", param)
}
}
}

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")

if err != nil {
t.Fatalf("Failed to fetch json-schemas. %v", err)
}

for _, param := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderSovrn, json.RawMessage(param)); err == nil {
t.Errorf("Schema allowed sovrn params: %s", param)
}
}
}

var validParams = []string{
`{"tagId":"1"}`,
`{"tagid":"2"}`,
`{"tagId":"1","bidfloor":"0.5"}`,
`{"tagId":"1","bidfloor":0.5}`,
`{"tagId":"1","bidfloor":"0.5", "adunitcode":"0.5"}`,
}

var invalidParams = []string{
``,
`null`,
`true`,
`0`,
`[]`,
`{}`,
}
17 changes: 15 additions & 2 deletions adapters/sovrn/sovrn.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func (s *SovrnAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt

imp.TagID = tagId

if imp.BidFloor == 0 && sovrnExt.BidFloor > 0 {
imp.BidFloor = sovrnExt.BidFloor
extBidFloor := getExtBidFloor(sovrnExt)
if imp.BidFloor == 0 && extBidFloor > 0 {
imp.BidFloor = extBidFloor
}

var impExtBuffer []byte
Expand Down Expand Up @@ -191,6 +192,18 @@ func (s *SovrnAdapter) MakeBids(request *openrtb2.BidRequest, bidderRequest *ada
return response, errs
}

func getExtBidFloor(sovrnExt openrtb_ext.ExtImpSovrn) float64 {
switch v := sovrnExt.BidFloor.(type) {
case string:
if numValue, err := strconv.ParseFloat(v, 64); err == nil {
return numValue
}
case float64:
return v
}
return 0
}

func getTagId(sovrnExt openrtb_ext.ExtImpSovrn) string {
if len(sovrnExt.Tagid) > 0 {
return sovrnExt.Tagid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"bidfloor": 0,
"ext": {
"bidder": {
"tagid": "123456",
"bidfloor": "4.20"
}
}
}
],
"device": { },
"site": {
"domain": "www.publisher.com",
"page": "http://www.publisher.com/awesome/site"
},
"user": {
"buyeruid": "test_reader_id"
}
},

"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": ["application/json"],
"Cookie": ["ljt_reader=test_reader_id"]
},
"uri": "http://sovrn.com/test/endpoint",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"tagid": "123456",
"bidfloor": 4.2,
"ext": {
"bidder": {
"tagid": "123456",
"bidfloor": "4.20"
}
}
}
],
"site": {
"domain": "www.publisher.com",
"page": "http://www.publisher.com/awesome/site"
},
"user": {
"buyeruid": "test_reader_id"
},
"device": { }
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "a_449642_554a13d3b9f348fba707cf83f0f63800",
"impid": "test-imp-id",
"price": 3.5,
"nurl": "http://sovrn.com/rtb/impression?bannerid=138743&campaignid=3699&zoneid=449642&cb=69493397&tid=a_449642_554a13d3b9f348fba707cf83f0f63800",
"adm": "some-test-ad",
"w": 300,
"h": 250
}
]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "a_449642_554a13d3b9f348fba707cf83f0f63800",
"impid": "test-imp-id",
"price": 3.5,
"adm": "some-test-ad",
"nurl": "http://sovrn.com/rtb/impression?bannerid=138743&campaignid=3699&zoneid=449642&cb=69493397&tid=a_449642_554a13d3b9f348fba707cf83f0f63800",
"w": 300,
"h": 250
},
"type": "banner"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"tagid": "123456",
"bidfloor": "4.2"
}
}
}
],
"device": { },
"site": {
"domain": "www.publisher.com",
"page": "http://www.publisher.com/awesome/site"
},
"user": {
"buyeruid": "test_reader_id"
}
},

"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": ["application/json"],
"Cookie": ["ljt_reader=test_reader_id"]
},
"uri": "http://sovrn.com/test/endpoint",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"tagid": "123456",
"bidfloor": 4.2,
"ext": {
"bidder": {
"tagid": "123456",
"bidfloor": "4.2"
}
}
}
],
"site": {
"domain": "www.publisher.com",
"page": "http://www.publisher.com/awesome/site"
},
"user": {
"buyeruid": "test_reader_id"
},
"device": { }
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "a_449642_554a13d3b9f348fba707cf83f0f63800",
"impid": "test-imp-id",
"price": 3.5,
"nurl": "http://sovrn.com/rtb/impression?bannerid=138743&campaignid=3699&zoneid=449642&cb=69493397&tid=a_449642_554a13d3b9f348fba707cf83f0f63800",
"adm": "some-test-ad",
"w": 300,
"h": 250
}
]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "a_449642_554a13d3b9f348fba707cf83f0f63800",
"impid": "test-imp-id",
"price": 3.5,
"adm": "some-test-ad",
"nurl": "http://sovrn.com/rtb/impression?bannerid=138743&campaignid=3699&zoneid=449642&cb=69493397&tid=a_449642_554a13d3b9f348fba707cf83f0f63800",
"w": 300,
"h": 250
},
"type": "banner"
}
]
}
]
}
Loading
Loading