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

Fix: Triplelift Native add site.publisher nil check #3824

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions adapters/triplelift_native/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package triplelift_native

import (
"encoding/json"
"testing"

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

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

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

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

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

var validParams = []string{
`{"inventoryCode":"1"}`,
`{"inventoryCode":"test"}`,
`{"inventoryCode":"test", "floor":10}`,
}

var invalidParams = []string{
``,
`null`,
`true`,
`5`,
`4.2`,
`[]`,
`{}`,
`{"inventoryCode":1}`,
`{"inventoryCode":""}`,
`{"inventoryCode":"1", "floor": "10"}`,
}
34 changes: 14 additions & 20 deletions adapters/triplelift_native/triplelift_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ func processImp(imp *openrtb2.Imp, request *openrtb2.BidRequest) error {
// get the triplelift extension
var ext ExtImp
var tlext openrtb_ext.ExtImpTriplelift
var siteCopy openrtb2.Site
var extData ExtImpData
Comment on lines -53 to -54
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out by @guscarreon, these two variables are only ever read; they aren't written so we can get rid of them and just read the data from the original source.


if request.Site != nil {
siteCopy = *request.Site
}

if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return err
Expand All @@ -66,32 +60,32 @@ func processImp(imp *openrtb2.Imp, request *openrtb2.BidRequest) error {
if imp.Native == nil {
return fmt.Errorf("no native object specified")
}
if tlext.InvCode == "" {
return fmt.Errorf("no inv_code specified")
}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

if ext.Data != nil {
extData = *ext.Data
}

if extData.TagCode != "" {
if siteCopy.Publisher.Domain == "msn.com" {
imp.TagID = extData.TagCode
} else {
imp.TagID = tlext.InvCode
}
Comment on lines -73 to -82
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic has been simplified as pointed out by @guscarreon.

if ext.Data != nil && len(ext.Data.TagCode) > 0 && (msnInSite(request) || msnInApp(request)) {
imp.TagID = ext.Data.TagCode
} else {
imp.TagID = tlext.InvCode
}

// floor is optional
if tlext.Floor == nil {
return nil
}
imp.BidFloor = *tlext.Floor
// no error

return nil
}

// msnInApp returns whether msn.com is in request.app.publisher.domain
func msnInApp(request *openrtb2.BidRequest) bool {
return request.App != nil && request.App.Publisher != nil && request.App.Publisher.Domain == "msn.com"
}
Comment on lines +80 to +82
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding support for app.publisher as discussed.


// msnInSite returns whether msn.com is in request.site.publisher.domain
func msnInSite(request *openrtb2.BidRequest) bool {
return request.Site != nil && request.Site.Publisher != nil && request.Site.Publisher.Domain == "msn.com"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nil checks added to address panics.

}

// Returns the effective publisher ID
func effectivePubID(pub *openrtb2.Publisher) string {
if pub != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"publisher": {
"id": "foo",
"name": "foo",
"domain": "msn.com"
}
},
"imp": [{
"native": {
"request": "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"id": "test-imp-id",
"ext": {
"bidder": {
"inventoryCode": "invcode",
"floor": 20
},
"data": {
"tag_code": ""
}
}
}]
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2sn/auction?supplier_id=20",
"body": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"native": {
"request": "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"tagid": "invcode",
"bidfloor": 20,
"ext": {
"bidder": {
"inventoryCode": "invcode",
"floor": 20
},
"data": {
"tag_code": ""
}
}
}],
"app": {
"publisher": {
"id": "foo",
"name": "foo",
"domain": "msn.com"
}
}
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "958",
"bid": [{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"triplelift.com"
],
"iurl": "http://example.com",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": "aaa"
}]
}],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"id": "test-request-id",
"type": "native",
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"triplelift.com"
],
"iurl": "http://example.com",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": "aaa"
},
"bidid": "5778926625248726496",
"cur": "USD"
}]
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"publisher": {
"id": "foo",
"name": "foo",
"domain": "msn.com"
}
},
"imp": [{
"native": {
"request": "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"id": "test-imp-id",
"ext": {
"bidder": {
"inventoryCode": "invcode",
"floor": 20
},
"data": {
"tag_code": "bar"
}
}
}]
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2sn/auction?supplier_id=20",
"body": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"native": {
"request": "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"tagid": "bar",
"bidfloor": 20,
"ext": {
"bidder": {
"inventoryCode": "invcode",
"floor": 20
},
"data": {
"tag_code": "bar"
}
}
}],
"app": {
"publisher": {
"id": "foo",
"name": "foo",
"domain": "msn.com"
}
}
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "958",
"bid": [{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"triplelift.com"
],
"iurl": "http://example.com",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": "aaa"
}]
}],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"id": "test-request-id",
"type": "native",
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"triplelift.com"
],
"iurl": "http://example.com",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": "aaa"
},
"bidid": "5778926625248726496",
"cur": "USD"
}]
}]
}
Loading
Loading