From a907ecb1f13a0de23f44d8f6d5d26c0a3d5b28fc Mon Sep 17 00:00:00 2001 From: Anand Venkatraman Date: Mon, 1 Jul 2024 14:53:33 +0530 Subject: [PATCH] PulsePoint: Marking cp/ct params to be either String or Int (#3677) --- adapters/pulsepoint/params_test.go | 7 +- adapters/pulsepoint/pulsepoint.go | 31 +++++- .../banner-string-bidder-params.json | 102 ++++++++++++++++++ .../bad-prebid-params-missing-param.json | 31 ++++++ .../supplemental/bad-prebid-params.json | 4 +- openrtb_ext/imp_pulsepoint.go | 8 +- static/bidder-params/pulsepoint.json | 10 +- 7 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 adapters/pulsepoint/pulsepointtest/exemplary/banner-string-bidder-params.json create mode 100644 adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params-missing-param.json diff --git a/adapters/pulsepoint/params_test.go b/adapters/pulsepoint/params_test.go index 4b3c6c017db..c97cec03230 100644 --- a/adapters/pulsepoint/params_test.go +++ b/adapters/pulsepoint/params_test.go @@ -37,6 +37,9 @@ func TestInvalidParams(t *testing.T) { var validParams = []string{ `{"cp":1000, "ct": 2000}`, `{"cp":1001, "ct": 2001}`, + `{"cp":"1000", "ct": "2000"}`, + `{"cp":"1000", "ct": 2000}`, + `{"cp":1000, "ct": "2000"}`, `{"cp":1001, "ct": 2001, "cf": "1x1"}`, } @@ -52,8 +55,4 @@ var invalidParams = []string{ `{"ct":"1000"}`, `{"cp":1000}`, `{"ct":1000}`, - `{"cp":1000, "ct":"1000"}`, - `{"cp":1000, "ct": "abcd"}`, - `{"cp":"abcd", "ct": 1000}`, - `{"cp":"1000.2", "ct": "1000.1"}`, } diff --git a/adapters/pulsepoint/pulsepoint.go b/adapters/pulsepoint/pulsepoint.go index c351bb7d051..dffe2754110 100644 --- a/adapters/pulsepoint/pulsepoint.go +++ b/adapters/pulsepoint/pulsepoint.go @@ -2,6 +2,7 @@ package pulsepoint import ( "encoding/json" + "errors" "fmt" "net/http" "strconv" @@ -10,6 +11,7 @@ import ( "github.com/prebid/prebid-server/v2/config" "github.com/prebid/prebid-server/v2/errortypes" "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/jsonutil" "github.com/prebid/openrtb/v20/openrtb2" ) @@ -49,11 +51,25 @@ func (a *PulsePointAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo * continue } // parse pubid and keep it for reference - if pubID == "" && pulsepointExt.PubID > 0 { - pubID = strconv.Itoa(pulsepointExt.PubID) + if pubID == "" { + pubID, err = parseParam("pubID", pulsepointExt.PubID) + if err != nil { + errs = append(errs, &errortypes.BadInput{ + Message: err.Error(), + }) + continue + } } // tag id to be sent - imp.TagID = strconv.Itoa(pulsepointExt.TagID) + var tagID string + tagID, err = parseParam("tagID", pulsepointExt.TagID) + if err != nil { + errs = append(errs, &errortypes.BadInput{ + Message: err.Error(), + }) + continue + } + imp.TagID = tagID imps = append(imps, imp) } @@ -163,3 +179,12 @@ func getBidType(imp openrtb2.Imp) openrtb_ext.BidType { } return "" } + +func parseParam(paramName string, paramValue jsonutil.StringInt) (string, error) { + value := int(paramValue) + // verify we got a non-zero value + if value == 0 { + return "", errors.New("param not found - " + paramName) + } + return strconv.Itoa(value), nil +} diff --git a/adapters/pulsepoint/pulsepointtest/exemplary/banner-string-bidder-params.json b/adapters/pulsepoint/pulsepointtest/exemplary/banner-string-bidder-params.json new file mode 100644 index 00000000000..2a13f4d5b96 --- /dev/null +++ b/adapters/pulsepoint/pulsepointtest/exemplary/banner-string-bidder-params.json @@ -0,0 +1,102 @@ +{ + "mockBidRequest": { + "id": "request-id", + "site": { + "page": "http://publisher.com/index.html", + "publisher": { + "id": "123456789", + "name": "publisher.com" + } + }, + "imp": [{ + "id": "banner-1", + "banner": { + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "cp": "1234", + "ct": "1001" + } + } + }] + }, + "httpCalls": [{ + "expectedRequest": { + "headers": { + "Content-Type": [ + "application/json;charset=utf-8" + ], + "Accept": [ + "application/json" + ] + }, + "uri": "http://bidder.pulsepoint.com", + "body": { + "id": "request-id", + "site": { + "page": "http://publisher.com/index.html", + "publisher": { + "id": "1234", + "name": "publisher.com" + } + }, + "imp": [{ + "id": "banner-1", + "tagid": "1001", + "banner": { + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "cp": "1234", + "ct": "1001" + } + } + }] + }, + "impIDs":["banner-1"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "response-id", + "seatbid": [{ + "bid": [{ + "id": "banner-1-bid", + "impid": "banner-1", + "price": 3.5, + "adm": "
Creative
", + "adomain": [ + "advertiser.com" + ], + "crid": "20", + "w": 300, + "h": 250 + }], + "seat": "pulsepoint-seat" + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "bids": [{ + "bid": { + "id": "banner-1-bid", + "impid": "banner-1", + "price": 3.5, + "adm": "
Creative
", + "adomain": [ + "advertiser.com" + ], + "crid": "20", + "w": 300, + "h": 250 + }, + "type": "banner" + }] + }] +} \ No newline at end of file diff --git a/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params-missing-param.json b/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params-missing-param.json new file mode 100644 index 00000000000..1b90f37d1eb --- /dev/null +++ b/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params-missing-param.json @@ -0,0 +1,31 @@ +{ + "mockBidRequest": { + "id": "request-id", + "site": { + "page": "http://publisher.com/index.html", + "publisher": { + "id": "123456789", + "name": "publisher.com" + } + }, + "imp": [{ + "id": "banner-1", + "banner": { + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "cp": "1234" + } + } + }] + }, + "httpCalls": [], + "expectedMakeRequestsErrors": [{ + "value": "param not found - tagID", + "comparison": "literal" + }], + "expectedBidResponses": [], + "expectedMakeBidsErrors": [] +} \ No newline at end of file diff --git a/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params.json b/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params.json index 2d0c74d39d7..060ffb1ad88 100644 --- a/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params.json +++ b/adapters/pulsepoint/pulsepointtest/supplemental/bad-prebid-params.json @@ -17,14 +17,14 @@ "ext": { "bidder": { "cp": "1234", - "ct": "1001" + "ct": "ab1001" } } }] }, "httpCalls": [], "expectedMakeRequestsErrors": [{ - "value": "json: cannot unmarshal string into Go struct field ExtImpPulsePoint.cp of type int", + "value": "Value looks like Number/Boolean/None, but can't find its end: ',' or '}' symbol", "comparison": "literal" }], "expectedBidResponses": [], diff --git a/openrtb_ext/imp_pulsepoint.go b/openrtb_ext/imp_pulsepoint.go index a901592c45b..c2ed36256e1 100644 --- a/openrtb_ext/imp_pulsepoint.go +++ b/openrtb_ext/imp_pulsepoint.go @@ -1,9 +1,13 @@ package openrtb_ext +import ( + "github.com/prebid/prebid-server/v2/util/jsonutil" +) + // ExtImpPulsePoint defines the json spec for bidrequest.imp[i].ext.prebid.bidder.pulsepoint // PubId/TagId are mandatory params type ExtImpPulsePoint struct { - PubID int `json:"cp"` - TagID int `json:"ct"` + PubID jsonutil.StringInt `json:"cp"` + TagID jsonutil.StringInt `json:"ct"` } diff --git a/static/bidder-params/pulsepoint.json b/static/bidder-params/pulsepoint.json index 673fd2efd6f..05d1e159a43 100644 --- a/static/bidder-params/pulsepoint.json +++ b/static/bidder-params/pulsepoint.json @@ -5,11 +5,17 @@ "type": "object", "properties": { "cp": { - "type": "integer", + "type": [ + "integer", + "string" + ], "description": "An ID which identifies the publisher selling the impression" }, "ct": { - "type": "integer", + "type": [ + "integer", + "string" + ], "description": "An ID which identifies the ad slot being sold" } },