From b699f425e1b7cfcb8180a7b563e304a342c6f088 Mon Sep 17 00:00:00 2001 From: faithnh Date: Thu, 28 Jan 2021 14:28:03 +0900 Subject: [PATCH 01/25] add bidder-info, bidder-params for UNICORN --- openrtb_ext/imp_unicorn.go | 9 +++++++++ static/bidder-info/unicorn.yaml | 11 +++++++++++ static/bidder-params/unicorn.json | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 openrtb_ext/imp_unicorn.go create mode 100644 static/bidder-info/unicorn.yaml create mode 100644 static/bidder-params/unicorn.json diff --git a/openrtb_ext/imp_unicorn.go b/openrtb_ext/imp_unicorn.go new file mode 100644 index 00000000000..d1bab3c1d69 --- /dev/null +++ b/openrtb_ext/imp_unicorn.go @@ -0,0 +1,9 @@ +package openrtb_ext + +// ExtImpUnicorn defines the contract for bidrequest.imp[i].ext.unicorn +type ExtImpUnicorn struct { + PlacementId string `json:"placementId"` + PublisherId int `json:"publisherId"` + MediaId string `json:"mediaId"` + AccountId int `json:"accountId"` +} diff --git a/static/bidder-info/unicorn.yaml b/static/bidder-info/unicorn.yaml new file mode 100644 index 00000000000..2af6d0581af --- /dev/null +++ b/static/bidder-info/unicorn.yaml @@ -0,0 +1,11 @@ +maintainer: + email: service+prebid.js@bulbit.jp +capabilities: + app: + mediaTypes: + - banner + - native + site: + mediaTypes: + - banner + - native \ No newline at end of file diff --git a/static/bidder-params/unicorn.json b/static/bidder-params/unicorn.json new file mode 100644 index 00000000000..121d03dacfc --- /dev/null +++ b/static/bidder-params/unicorn.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "UNICORN Adapter Params", + "description": "A schema which validates params accepted by the UNICORN adapter", + "type": "object", + "properties": { + "placementId": { + "type": "string", + "description": "If placementId is empty, adunit code will be used as placementId." + }, + "publisherId": { + "type": "integer", + "description": "Account specific publisher id" + }, + "mediaId": { + "type": "string", + "description": "Publisher specific media id" + }, + "accountId": { + "type": "integer", + "description": "Account ID for charge request" + } + }, + "required" : ["mediaId", "accountId"] +} \ No newline at end of file From 956aa9132080f2eac88ab79e678ba71f60f0529f Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 1 Feb 2021 13:57:57 +0900 Subject: [PATCH 02/25] Add adapter --- adapters/unicorn/unicorn.go | 213 ++++++++++++++++++++++++++++++++ config/config.go | 1 + exchange/adapter_builders.go | 2 + static/bidder-info/unicorn.yaml | 4 - 4 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 adapters/unicorn/unicorn.go diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go new file mode 100644 index 00000000000..d6a7efbcf1d --- /dev/null +++ b/adapters/unicorn/unicorn.go @@ -0,0 +1,213 @@ +package unicorn + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/buger/jsonparser" + "github.com/mxmCherry/openrtb" + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/openrtb_ext" +) + +const ( + unicornDefaultCurrency = "JPY" + unicornAuctionType = 1 +) + +// UnicornAdapter describes a Smaato prebid server adapter. +type UnicornAdapter struct { + endpoint string +} + +type unicornImpExt struct { + bidder unicornBidder `json:"bidder"` +} + +type unicornBidder struct { + accountID int64 `json:"account_id"` + publisherID int64 `json:"publisher_id"` + mediaID string `json:"media_id"` + placementID string `json:"placement_id"` +} + +type unicornAppExt struct { + prebid unicornAppExtPrebid `json:"prebid"` +} + +type unicornAppExtPrebid struct { + version string `json:"version"` + source string `json:"source"` +} + +type unicornSourceExt struct { + stype string `json:"stype"` + bidder string `json"bidder"` +} + +// Builder builds a new instance of the Foo adapter for the given bidder with the given config. +func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { + bidder := &UnicornAdapter{ + endpoint: config.Endpoint, + } + return bidder, nil +} + +// MakeRequests makes the HTTP requests which should be made to fetch bids. +func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + var extRegs openrtb_ext.ExtRegs + if request.Regs != nil { + if request.Regs.COPPA == 1 { + return nil, []error{} + } + if err := json.Unmarshal(request.Regs.Ext, &extRegs); err == nil { + if extRegs.GDPR != nil && (*extRegs.GDPR == 1) { + return nil, []error{} + } + if extRegs.USPrivacy != "" { + return nil, []error{} + } + } + } + + request.AT = unicornAuctionType + + imp, err := getImps(request, requestInfo) + if err != nil { + return nil, []error{err} + } + + request.Imp = imp + request.Cur = []string{unicornDefaultCurrency} + + request.App.Ext, err = getAppExt(request) + if err != nil { + return nil, []error{err} + } + + request.Source.Ext, err = getSourceExt() + if err != nil { + return nil, []error{err} + } + + requestJSON, err := json.Marshal(request) + if err != nil { + return nil, []error{err} + } + + requestData := &adapters.RequestData{ + Method: "POST", + Uri: a.endpoint, + Body: requestJSON, + } + + return []*adapters.RequestData{requestData}, nil +} + +func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { + for i := 0; i < len(request.Imp); i++ { + imp := request.Imp[i] + + placementID, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "placementId") + if err != nil { + placementID = imp.TagID + } + publisherID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "publisherId") + if err != nil { + publisherID = 0 + } + mediaID, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "mediaId") + if err != nil { + mediaID = "" + } + accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") + if err != nil { + accountID = 0 + } + + secure := int8(1) + imp.Secure = &secure + imp.TagID = placementID + impBidder := unicornBidder { + accountID: accountID, + publisherID: publisherID, + mediaID: mediaID, + placementID: placementID, + } + impExt := &unicornImpExt { + bidder: impBidder, + } + imp.Ext, err = json.Marshal(impExt) + if err != nil { + return nil, err + } + } + return request.Imp, nil +} + +func getSourceExt() (json.RawMessage, error) { + siteExt, err := json.Marshal(unicornSourceExt{ + stype: "prebid_uncn", + bidder: "unicorn", + }) + if err != nil { + return nil, err + } + return siteExt, nil +} + +func getAppExt(request *openrtb.BidRequest) (json.RawMessage, error) { + appExtPrebid := unicornAppExtPrebid{ + version: request.App.Ver, + source: "prebid-mobile", + } + appExt, err := json.Marshal(unicornAppExt{ + prebid: appExtPrebid, + }) + if err != nil { + return nil, err + } + return appExt, nil +} + +// MakeBids unpacks the server's response into Bids. +func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if responseData.StatusCode == http.StatusNoContent { + return nil, nil + } + + if responseData.StatusCode == http.StatusBadRequest { + err := &errortypes.BadInput{ + Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + } + return nil, []error{err} + } + + if responseData.StatusCode != http.StatusOK { + err := &errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), + } + return nil, []error{err} + } + + var response openrtb.BidResponse + if err := json.Unmarshal(responseData.Body, &response); err != nil { + return nil, []error{err} + } + + bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) + bidResponse.Currency = response.Cur + for _, seatBid := range response.SeatBid { + for _, bid := range seatBid.Bid { + b := &adapters.TypedBid{ + Bid: &bid, + BidType: "", + } + bidResponse.Bids = append(bidResponse.Bids, b) + } + } + return bidResponse, nil +} \ No newline at end of file diff --git a/config/config.go b/config/config.go index 0db6ca61880..0db4145d899 100644 --- a/config/config.go +++ b/config/config.go @@ -891,6 +891,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.triplelift_native.extra_info", "{\"publisher_whitelist\":[]}") v.SetDefault("adapters.triplelift.endpoint", "https://tlx.3lift.com/s2s/auction?sra=1&supplier_id=20") v.SetDefault("adapters.ucfunnel.endpoint", "https://pbs.aralego.com/prebid") + v.SetDefault("adapters.unicorn.endpoint", "https://ds.uncn.jp/pb/0/bid.json") v.SetDefault("adapters.unruly.endpoint", "http://targeting.unrulymedia.com/openrtb/2.2") v.SetDefault("adapters.valueimpression.endpoint", "https://rtb.valueimpression.com/endpoint") v.SetDefault("adapters.verizonmedia.disabled", true) diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index 1b3e229f413..e2aed572d69 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -89,6 +89,7 @@ import ( "github.com/prebid/prebid-server/adapters/triplelift" "github.com/prebid/prebid-server/adapters/triplelift_native" "github.com/prebid/prebid-server/adapters/ucfunnel" + "github.com/prebid/prebid-server/adapter/unicorn" "github.com/prebid/prebid-server/adapters/unruly" "github.com/prebid/prebid-server/adapters/valueimpression" "github.com/prebid/prebid-server/adapters/verizonmedia" @@ -195,6 +196,7 @@ func newAdapterBuilders() map[openrtb_ext.BidderName]adapters.Builder { openrtb_ext.BidderTriplelift: triplelift.Builder, openrtb_ext.BidderTripleliftNative: triplelift_native.Builder, openrtb_ext.BidderUcfunnel: ucfunnel.Builder, + openrtb_ext.BidderUnicorn: unicorn.Builder, openrtb_ext.BidderUnruly: unruly.Builder, openrtb_ext.BidderValueImpression: valueimpression.Builder, openrtb_ext.BidderVerizonMedia: verizonmedia.Builder, diff --git a/static/bidder-info/unicorn.yaml b/static/bidder-info/unicorn.yaml index 2af6d0581af..6f5fcc69e98 100644 --- a/static/bidder-info/unicorn.yaml +++ b/static/bidder-info/unicorn.yaml @@ -2,10 +2,6 @@ maintainer: email: service+prebid.js@bulbit.jp capabilities: app: - mediaTypes: - - banner - - native - site: mediaTypes: - banner - native \ No newline at end of file From 9bdb44b31be45dbc5d453fe3f9ad77f283f92edc Mon Sep 17 00:00:00 2001 From: faithnh Date: Tue, 2 Feb 2021 13:37:57 +0900 Subject: [PATCH 03/25] Fix Bidder unicorn parameter name --- adapters/unicorn/unicorn.go | 103 ++++++++++++++++++++++------------- exchange/adapter_builders.go | 2 +- openrtb_ext/bidders.go | 2 + openrtb_ext/imp_unicorn.go | 8 +-- 4 files changed, 71 insertions(+), 44 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index d6a7efbcf1d..c3752f19e3f 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -23,29 +23,45 @@ type UnicornAdapter struct { endpoint string } +// unicornImpExt is imp ext for UNICORN type unicornImpExt struct { - bidder unicornBidder `json:"bidder"` + Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` } type unicornBidder struct { - accountID int64 `json:"account_id"` - publisherID int64 `json:"publisher_id"` - mediaID string `json:"media_id"` - placementID string `json:"placement_id"` + AccountID int64 `json:"account_id"` + PublisherID int64 `json:"publisher_id"` + MediaID string `json:"media_id"` + PlacementID string `json:"placement_id"` } +// unicornAppExt is app ext for UNICORN type unicornAppExt struct { - prebid unicornAppExtPrebid `json:"prebid"` + Prebid unicornAppExtPrebid `json:"prebid"` } type unicornAppExtPrebid struct { - version string `json:"version"` - source string `json:"source"` + Version string `json:"version"` + Source string `json:"source"` } +// unicornSourceExt is source ext for UNICORN type unicornSourceExt struct { - stype string `json:"stype"` - bidder string `json"bidder"` + Stype string `json:"stype"` + Bidder string `json"bidder"` +} + +type unicornExt struct { + Prebid unicornExtPrebid `json:"prebid"` + AccountID int64 `json:"account_id"` +} + +type unicornExtPrebid struct { + Data unicornExtPrebidData `json:"data"` +} + +type unicornExtPrebidData struct { + Bidder string `json:"bidder"` } // Builder builds a new instance of the Foo adapter for the given bidder with the given config. @@ -111,47 +127,37 @@ func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo for i := 0; i < len(request.Imp); i++ { imp := request.Imp[i] - placementID, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "placementId") - if err != nil { - placementID = imp.TagID - } - publisherID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "publisherId") + var ext unicornImpExt + err := json.Unmarshal(imp.Ext, &ext) + if err != nil { - publisherID = 0 + return nil, err } - mediaID, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "mediaId") - if err != nil { - mediaID = "" + + var placementID string + if ext.Bidder.PlacementID == "" { + placementID = imp.TagID + } else { + placementID = ext.Bidder.PlacementID } - accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") + ext.Bidder.PlacementID = placementID + + imp.Ext, err = json.Marshal(ext) if err != nil { - accountID = 0 + return nil, err } secure := int8(1) imp.Secure = &secure imp.TagID = placementID - impBidder := unicornBidder { - accountID: accountID, - publisherID: publisherID, - mediaID: mediaID, - placementID: placementID, - } - impExt := &unicornImpExt { - bidder: impBidder, - } - imp.Ext, err = json.Marshal(impExt) - if err != nil { - return nil, err - } } return request.Imp, nil } func getSourceExt() (json.RawMessage, error) { siteExt, err := json.Marshal(unicornSourceExt{ - stype: "prebid_uncn", - bidder: "unicorn", + Stype: "prebid_uncn", + Bidder: "unicorn", }) if err != nil { return nil, err @@ -161,11 +167,11 @@ func getSourceExt() (json.RawMessage, error) { func getAppExt(request *openrtb.BidRequest) (json.RawMessage, error) { appExtPrebid := unicornAppExtPrebid{ - version: request.App.Ver, - source: "prebid-mobile", + Version: request.App.Ver, + Source: "prebid-mobile", } appExt, err := json.Marshal(unicornAppExt{ - prebid: appExtPrebid, + Prebid: appExtPrebid, }) if err != nil { return nil, err @@ -173,6 +179,25 @@ func getAppExt(request *openrtb.BidRequest) (json.RawMessage, error) { return appExt, nil } +func getExt(request *openrtb.BidRequest) (json.RawMessage, error) { + accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") + if err != nil { + accountID = 0 + } + ext, err := json.Marshal(unicornExt{ + Prebid: unicornExtPrebid{ + Data: unicornExtPrebidData{ + Bidder: "unicorn", + }, + }, + AccountID: accountID, + }) + if err != nil { + return nil, err + } + return ext, nil +} + // MakeBids unpacks the server's response into Bids. func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { if responseData.StatusCode == http.StatusNoContent { diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index e2aed572d69..a4248327297 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -89,7 +89,7 @@ import ( "github.com/prebid/prebid-server/adapters/triplelift" "github.com/prebid/prebid-server/adapters/triplelift_native" "github.com/prebid/prebid-server/adapters/ucfunnel" - "github.com/prebid/prebid-server/adapter/unicorn" + "github.com/prebid/prebid-server/adapters/unicorn" "github.com/prebid/prebid-server/adapters/unruly" "github.com/prebid/prebid-server/adapters/valueimpression" "github.com/prebid/prebid-server/adapters/verizonmedia" diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 13ff4b7ff31..a3ec2f648f6 100755 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -162,6 +162,7 @@ const ( BidderTriplelift BidderName = "triplelift" BidderTripleliftNative BidderName = "triplelift_native" BidderUcfunnel BidderName = "ucfunnel" + BidderUnicorn BidderName = "unicorn" BidderUnruly BidderName = "unruly" BidderValueImpression BidderName = "valueimpression" BidderVerizonMedia BidderName = "verizonmedia" @@ -266,6 +267,7 @@ func CoreBidderNames() []BidderName { BidderTriplelift, BidderTripleliftNative, BidderUcfunnel, + BidderUnicorn, BidderUnruly, BidderValueImpression, BidderVerizonMedia, diff --git a/openrtb_ext/imp_unicorn.go b/openrtb_ext/imp_unicorn.go index d1bab3c1d69..64bd7fad13f 100644 --- a/openrtb_ext/imp_unicorn.go +++ b/openrtb_ext/imp_unicorn.go @@ -2,8 +2,8 @@ package openrtb_ext // ExtImpUnicorn defines the contract for bidrequest.imp[i].ext.unicorn type ExtImpUnicorn struct { - PlacementId string `json:"placementId"` - PublisherId int `json:"publisherId"` - MediaId string `json:"mediaId"` - AccountId int `json:"accountId"` + PlacementID string `json:"placementId,omitempty"` + PublisherID int `json:"publisherId,omitempty"` + MediaID string `json:"mediaId"` + AccountID int `json:"accountId"` } From 0515c2896c60a75a64e7a5d22b766088fc4de396 Mon Sep 17 00:00:00 2001 From: faithnh Date: Wed, 3 Feb 2021 17:06:19 +0900 Subject: [PATCH 04/25] remove modifing request.app.ext, append modifing request.ext --- adapters/unicorn/unicorn.go | 49 +++++++++++-------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index c3752f19e3f..8c58cf03702 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -52,16 +52,8 @@ type unicornSourceExt struct { } type unicornExt struct { - Prebid unicornExtPrebid `json:"prebid"` - AccountID int64 `json:"account_id"` -} - -type unicornExtPrebid struct { - Data unicornExtPrebidData `json:"data"` -} - -type unicornExtPrebidData struct { - Bidder string `json:"bidder"` + Prebid openrtb_ext.ExtImpPrebid `json:"prebid"` + AccountID int64 `json:"account_id,omitempty"` } // Builder builds a new instance of the Foo adapter for the given bidder with the given config. @@ -99,12 +91,12 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * request.Imp = imp request.Cur = []string{unicornDefaultCurrency} - request.App.Ext, err = getAppExt(request) + request.Source.Ext, err = getSourceExt() if err != nil { return nil, []error{err} } - request.Source.Ext, err = getSourceExt() + request.Ext, err = getExt(request) if err != nil { return nil, []error{err} } @@ -125,7 +117,7 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { for i := 0; i < len(request.Imp); i++ { - imp := request.Imp[i] + imp := &request.Imp[i] var ext unicornImpExt err := json.Unmarshal(imp.Ext, &ext) @@ -165,33 +157,19 @@ func getSourceExt() (json.RawMessage, error) { return siteExt, nil } -func getAppExt(request *openrtb.BidRequest) (json.RawMessage, error) { - appExtPrebid := unicornAppExtPrebid{ - Version: request.App.Ver, - Source: "prebid-mobile", - } - appExt, err := json.Marshal(unicornAppExt{ - Prebid: appExtPrebid, - }) - if err != nil { - return nil, err - } - return appExt, nil -} - func getExt(request *openrtb.BidRequest) (json.RawMessage, error) { accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") if err != nil { accountID = 0 } - ext, err := json.Marshal(unicornExt{ - Prebid: unicornExtPrebid{ - Data: unicornExtPrebidData{ - Bidder: "unicorn", - }, - }, - AccountID: accountID, - }) + var decodedExt *unicornExt + err = json.Unmarshal(request.Ext, &decodedExt) + if err != nil { + return nil, err + } + decodedExt.AccountID = accountID + + ext, err := json.Marshal(decodedExt) if err != nil { return nil, err } @@ -200,6 +178,7 @@ func getExt(request *openrtb.BidRequest) (json.RawMessage, error) { // MakeBids unpacks the server's response into Bids. func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if responseData.StatusCode == http.StatusNoContent { return nil, nil } From 36ae31f7113bee580b4c6e3194ccf7468ec1e980 Mon Sep 17 00:00:00 2001 From: faithnh Date: Thu, 4 Feb 2021 17:35:24 +0900 Subject: [PATCH 05/25] add test code and fix adapter logic --- adapters/unicorn/params_test.go | 61 +++++ adapters/unicorn/unicorn.go | 67 ++--- adapters/unicorn/unicorn_test.go | 20 ++ .../unicorntest/exemplary/banner-app.json | 230 ++++++++++++++++++ .../unicorntest/params/race/banner.json | 6 + 5 files changed, 353 insertions(+), 31 deletions(-) create mode 100644 adapters/unicorn/params_test.go create mode 100644 adapters/unicorn/unicorn_test.go create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app.json create mode 100644 adapters/unicorn/unicorntest/params/race/banner.json diff --git a/adapters/unicorn/params_test.go b/adapters/unicorn/params_test.go new file mode 100644 index 00000000000..99b8d7e7044 --- /dev/null +++ b/adapters/unicorn/params_test.go @@ -0,0 +1,61 @@ +package unicorn + +import ( + "encoding/json" + "testing" + + "github.com/prebid/prebid-server/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 schema. %v", err) + } + + for _, p := range validParams { + if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err != nil { + t.Errorf("Schema rejected valid params: %s", p) + } + } +} + +func TestInvalidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json schema. %v", err) + } + + for _, p := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err == nil { + t.Errorf("Schema allowed invalid params: %s", p) + } + } +} + +var validParams = []string{ + `{ + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + }`, + `{ + "accountId": 199578, + "mediaId": "test_media" + }`, +} + +var invalidParams = []string{ + `{}`, + `{ + "accountId": "199578", + "publisherId": "123456", + "mediaId": 12345, + "placementId": 12345 + }`, + `{ + "publisherId": 123456, + "placementId": "test_placement" + }`, +} \ No newline at end of file diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 8c58cf03702..e432bc79825 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -28,32 +28,16 @@ type unicornImpExt struct { Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` } -type unicornBidder struct { - AccountID int64 `json:"account_id"` - PublisherID int64 `json:"publisher_id"` - MediaID string `json:"media_id"` - PlacementID string `json:"placement_id"` -} - -// unicornAppExt is app ext for UNICORN -type unicornAppExt struct { - Prebid unicornAppExtPrebid `json:"prebid"` -} - -type unicornAppExtPrebid struct { - Version string `json:"version"` - Source string `json:"source"` -} - // unicornSourceExt is source ext for UNICORN type unicornSourceExt struct { Stype string `json:"stype"` Bidder string `json"bidder"` } +// unicornExt is ext for UNICORN type unicornExt struct { - Prebid openrtb_ext.ExtImpPrebid `json:"prebid"` - AccountID int64 `json:"account_id,omitempty"` + Prebid *openrtb_ext.ExtImpPrebid `json:"prebid,omitempty"` + AccountID int64 `json:"accountId,omitempty"` } // Builder builds a new instance of the Foo adapter for the given bidder with the given config. @@ -83,7 +67,7 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * request.AT = unicornAuctionType - imp, err := getImps(request, requestInfo) + imp, err := setImps(request, requestInfo) if err != nil { return nil, []error{err} } @@ -91,12 +75,12 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * request.Imp = imp request.Cur = []string{unicornDefaultCurrency} - request.Source.Ext, err = getSourceExt() + request.Source.Ext, err = setSourceExt() if err != nil { return nil, []error{err} } - request.Ext, err = getExt(request) + request.Ext, err = setExt(request) if err != nil { return nil, []error{err} } @@ -115,7 +99,7 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * return []*adapters.RequestData{requestData}, nil } -func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { +func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { for i := 0; i < len(request.Imp); i++ { imp := &request.Imp[i] @@ -123,7 +107,9 @@ func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo err := json.Unmarshal(imp.Ext, &ext) if err != nil { - return nil, err + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while decoding imp[%d].ext, err: %s", i, err), + } } var placementID string @@ -136,7 +122,9 @@ func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo imp.Ext, err = json.Marshal(ext) if err != nil { - return nil, err + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding imp[%d].ext, err: %s", i, err), + } } secure := int8(1) @@ -146,18 +134,20 @@ func getImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo return request.Imp, nil } -func getSourceExt() (json.RawMessage, error) { +func setSourceExt() (json.RawMessage, error) { siteExt, err := json.Marshal(unicornSourceExt{ Stype: "prebid_uncn", Bidder: "unicorn", }) if err != nil { - return nil, err + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), + } } return siteExt, nil } -func getExt(request *openrtb.BidRequest) (json.RawMessage, error) { +func setExt(request *openrtb.BidRequest) (json.RawMessage, error) { accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") if err != nil { accountID = 0 @@ -165,13 +155,17 @@ func getExt(request *openrtb.BidRequest) (json.RawMessage, error) { var decodedExt *unicornExt err = json.Unmarshal(request.Ext, &decodedExt) if err != nil { - return nil, err + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while decoding ext, err: %s", err), + } } decodedExt.AccountID = accountID ext, err := json.Marshal(decodedExt) if err != nil { - return nil, err + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding ext, err: %s", err), + } } return ext, nil } @@ -206,9 +200,20 @@ func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adap bidResponse.Currency = response.Cur for _, seatBid := range response.SeatBid { for _, bid := range seatBid.Bid { + var bidType openrtb_ext.BidType + for _, imp := range request.Imp { + if imp.ID == bid.ImpID { + if imp.Banner != nil { + bidType = openrtb_ext.BidTypeBanner + } + if imp.Native != nil { + bidType = openrtb_ext.BidTypeNative + } + } + } b := &adapters.TypedBid{ Bid: &bid, - BidType: "", + BidType: bidType, } bidResponse.Bids = append(bidResponse.Bids, b) } diff --git a/adapters/unicorn/unicorn_test.go b/adapters/unicorn/unicorn_test.go new file mode 100644 index 00000000000..4a04c208cd0 --- /dev/null +++ b/adapters/unicorn/unicorn_test.go @@ -0,0 +1,20 @@ +package unicorn + +import ( + "testing" + + "github.com/prebid/prebid-server/adapters/adapterstest" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/openrtb_ext" +) + +func TestJsonSamples(t *testing.T) { + bidder, buildErr := Builder(openrtb_ext.BidderUnicorn, config.Adapter{ + Endpoint: "http://localhost:4000"}) + + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } + + adapterstest.RunJSONBidderTest(t, "unicorntest", bidder) +} \ No newline at end of file diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app.json b/adapters/unicorn/unicorntest/exemplary/banner-app.json new file mode 100644 index 00000000000..12833e11acc --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app.json @@ -0,0 +1,230 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "http://localhost:4000", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/params/race/banner.json b/adapters/unicorn/unicorntest/params/race/banner.json new file mode 100644 index 00000000000..668983e3d19 --- /dev/null +++ b/adapters/unicorn/unicorntest/params/race/banner.json @@ -0,0 +1,6 @@ +{ + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" +} From ec496399a1a509e4c05325f874d81eddcbbbf67f Mon Sep 17 00:00:00 2001 From: faithnh Date: Sat, 6 Feb 2021 02:26:29 +0900 Subject: [PATCH 06/25] fix stype, add message that COPPA and GDPR and CCPA is not supported, Add header --- adapters/unicorn/unicorn.go | 38 +++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index e432bc79825..f4c9ecc1abd 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -53,14 +53,20 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * var extRegs openrtb_ext.ExtRegs if request.Regs != nil { if request.Regs.COPPA == 1 { - return nil, []error{} + return nil, []error{&errortypes.BadInput{ + Message: "COPPA is not supported", + }} } if err := json.Unmarshal(request.Regs.Ext, &extRegs); err == nil { if extRegs.GDPR != nil && (*extRegs.GDPR == 1) { - return nil, []error{} + return nil, []error{&errortypes.BadInput{ + Message: "GDPR is not supported", + }} } if extRegs.USPrivacy != "" { - return nil, []error{} + return nil, []error{&errortypes.BadInput{ + Message: "CCPA is not supported", + }} } } } @@ -94,11 +100,35 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * Method: "POST", Uri: a.endpoint, Body: requestJSON, + Headers: getHeaders(request), } return []*adapters.RequestData{requestData}, nil } +func getHeaders(request *openrtb.BidRequest) http.Header { + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Add("X-Openrtb-Version", "2.5") + + if request.Device != nil { + if len(request.Device.UA) > 0 { + headers.Add("User-Agent", request.Device.UA) + } + + if len(request.Device.IPv6) > 0 { + headers.Add("X-Forwarded-For", request.Device.IPv6) + } + + if len(request.Device.IP) > 0 { + headers.Add("X-Forwarded-For", request.Device.IP) + } + } + + return headers +} + func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { for i := 0; i < len(request.Imp); i++ { imp := &request.Imp[i] @@ -136,7 +166,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo func setSourceExt() (json.RawMessage, error) { siteExt, err := json.Marshal(unicornSourceExt{ - Stype: "prebid_uncn", + Stype: "prebid_server_uncn", Bidder: "unicorn", }) if err != nil { From 725321d05fb318ad26a09d464ba7d223ab12803d Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 8 Feb 2021 14:02:41 +0900 Subject: [PATCH 07/25] change logic for placement_id not set. change stype. add test case --- adapters/unicorn/unicorn.go | 108 ++++++--- .../exemplary/banner-app-without-ext.json | 212 ++++++++++++++++ .../banner-app-without-placementid.json | 229 ++++++++++++++++++ .../unicorntest/exemplary/banner-app.json | 2 +- 4 files changed, 514 insertions(+), 37 deletions(-) create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index f4c9ecc1abd..d34bb776952 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -15,7 +15,7 @@ import ( const ( unicornDefaultCurrency = "JPY" - unicornAuctionType = 1 + unicornAuctionType = 1 ) // UnicornAdapter describes a Smaato prebid server adapter. @@ -107,26 +107,26 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * } func getHeaders(request *openrtb.BidRequest) http.Header { - headers := http.Header{} - headers.Add("Content-Type", "application/json;charset=utf-8") - headers.Add("Accept", "application/json") - headers.Add("X-Openrtb-Version", "2.5") - - if request.Device != nil { - if len(request.Device.UA) > 0 { - headers.Add("User-Agent", request.Device.UA) - } - - if len(request.Device.IPv6) > 0 { - headers.Add("X-Forwarded-For", request.Device.IPv6) - } - - if len(request.Device.IP) > 0 { - headers.Add("X-Forwarded-For", request.Device.IP) - } - } - - return headers + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Add("X-Openrtb-Version", "2.5") + + if request.Device != nil { + if len(request.Device.UA) > 0 { + headers.Add("User-Agent", request.Device.UA) + } + + if len(request.Device.IPv6) > 0 { + headers.Add("X-Forwarded-For", request.Device.IPv6) + } + + if len(request.Device.IP) > 0 { + headers.Add("X-Forwarded-For", request.Device.IP) + } + } + + return headers } func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { @@ -138,23 +138,29 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while decoding imp[%d].ext, err: %s", i, err), - } + Message: fmt.Sprintf("Error while decoding imp[%d].ext, err: %s", i, err), + } } var placementID string - if ext.Bidder.PlacementID == "" { - placementID = imp.TagID - } else { + if ext.Bidder.PlacementID != "" { placementID = ext.Bidder.PlacementID + } else { + placementID, err = getStoredRequestImpID(imp) + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error get StoredRequestImpID from imp[%d]: %s", i, err), + } + } } + ext.Bidder.PlacementID = placementID imp.Ext, err = json.Marshal(ext) if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding imp[%d].ext, err: %s", i, err), - } + Message: fmt.Sprintf("Error while encoding imp[%d].ext, err: %s", i, err), + } } secure := int8(1) @@ -164,15 +170,45 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo return request.Imp, nil } +func getStoredRequestImpID(imp *openrtb.Imp) (string, error) { + var impExt map[string]json.RawMessage + + err := json.Unmarshal(imp.Ext, &impExt) + + if err != nil { + return "", fmt.Errorf("Error while decoding ext because: %s", err) + } + + rawPrebidExt, ok := impExt[openrtb_ext.PrebidExtKey] + + if !ok { + return "", fmt.Errorf("ext.prebid is null") + } + + var prebidExt openrtb_ext.ExtImpPrebid + + err = json.Unmarshal(rawPrebidExt, &prebidExt) + + if err != nil { + return "", fmt.Errorf("cannot decoding ext.prebid because: %s", err) + } + + if prebidExt.StoredRequest == nil { + return "", fmt.Errorf("ext.prebid.storedrequest is null") + } + + return prebidExt.StoredRequest.ID, nil +} + func setSourceExt() (json.RawMessage, error) { siteExt, err := json.Marshal(unicornSourceExt{ - Stype: "prebid_server_uncn", + Stype: "prebid_server_uncn", Bidder: "unicorn", }) if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), - } + Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), + } } return siteExt, nil } @@ -185,17 +221,17 @@ func setExt(request *openrtb.BidRequest) (json.RawMessage, error) { var decodedExt *unicornExt err = json.Unmarshal(request.Ext, &decodedExt) if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while decoding ext, err: %s", err), - } + decodedExt = &unicornExt{ + Prebid: nil, + } } decodedExt.AccountID = accountID ext, err := json.Marshal(decodedExt) if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding ext, err: %s", err), - } + Message: fmt.Sprintf("Error while encoding ext, err: %s", err), + } } return ext, nil } diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json new file mode 100644 index 00000000000..b789d4974a0 --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json @@ -0,0 +1,212 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "http://localhost:4000", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json new file mode 100644 index 00000000000..3effaa4c4d7 --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json @@ -0,0 +1,229 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_unicorn" + } + }, + "tagid": "test_unicorn", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "http://localhost:4000", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app.json b/adapters/unicorn/unicorntest/exemplary/banner-app.json index 12833e11acc..c4364b6959e 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app.json @@ -148,7 +148,7 @@ "source": { "ext": { "Bidder": "unicorn", - "stype": "prebid_uncn" + "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" }, From 003e27d6591598de256456da45c51ebcb45a7348 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 8 Feb 2021 15:20:41 +0900 Subject: [PATCH 08/25] indicate that user sync is not supported, add supplement test case --- adapters/unicorn/unicorn.go | 8 +- .../unicorn/unicorntest/supplemental/204.json | 168 +++++++++++++++++ .../unicorn/unicorntest/supplemental/400.json | 173 ++++++++++++++++++ .../unicorn/unicorntest/supplemental/500.json | 173 ++++++++++++++++++ .../supplemental/ccpa-is-enabled.json | 78 ++++++++ .../supplemental/coppa-is-enabled.json | 76 ++++++++ .../supplemental/gdpr-is-enabled.json | 78 ++++++++ .../supplemental/no-imp-ext-prebid.json | 65 +++++++ .../unicorntest/supplemental/no-imp-ext.json | 60 ++++++ .../supplemental/no-storedrequest-imp.json | 67 +++++++ config/config.go | 1 + 11 files changed, 943 insertions(+), 4 deletions(-) create mode 100644 adapters/unicorn/unicorntest/supplemental/204.json create mode 100644 adapters/unicorn/unicorntest/supplemental/400.json create mode 100644 adapters/unicorn/unicorntest/supplemental/500.json create mode 100644 adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json create mode 100644 adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json create mode 100644 adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json create mode 100644 adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json create mode 100644 adapters/unicorn/unicorntest/supplemental/no-imp-ext.json create mode 100644 adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index d34bb776952..cf16411f7c5 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -138,7 +138,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while decoding imp[%d].ext, err: %s", i, err), + Message: fmt.Sprintf("Error while decoding imp[%d].ext: %s", i, err), } } @@ -159,7 +159,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo imp.Ext, err = json.Marshal(ext) if err != nil { return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding imp[%d].ext, err: %s", i, err), + Message: fmt.Sprintf("Error while encoding imp[%d].ext: %s", i, err), } } @@ -245,14 +245,14 @@ func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adap if responseData.StatusCode == http.StatusBadRequest { err := &errortypes.BadInput{ - Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + Message: "Unexpected http status code: 400", } return nil, []error{err} } if responseData.StatusCode != http.StatusOK { err := &errortypes.BadServerResponse{ - Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), + Message: fmt.Sprintf("Unexpected http status code: %d", responseData.StatusCode), } return nil, []error{err} } diff --git a/adapters/unicorn/unicorntest/supplemental/204.json b/adapters/unicorn/unicorntest/supplemental/204.json new file mode 100644 index 00000000000..e76859976a7 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/204.json @@ -0,0 +1,168 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "status": 204, + "body": {} + } + } + ], + "expectedBidResponses": [] +} + diff --git a/adapters/unicorn/unicorntest/supplemental/400.json b/adapters/unicorn/unicorntest/supplemental/400.json new file mode 100644 index 00000000000..38fbc52cb84 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/400.json @@ -0,0 +1,173 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "status": 500, + "body": {} + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected http status code: 500", + "comparison": "literal" + } + ] +} + diff --git a/adapters/unicorn/unicorntest/supplemental/500.json b/adapters/unicorn/unicorntest/supplemental/500.json new file mode 100644 index 00000000000..03793d0fa73 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/500.json @@ -0,0 +1,173 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "status": 400, + "body": {} + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected http status code: 400", + "comparison": "literal" + } + ] +} + diff --git a/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json new file mode 100644 index 00000000000..4805c246fbd --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json @@ -0,0 +1,78 @@ +{ + "mockBidRequest": { + "regs": { + "ext": { + "us_privacy": "1YNN" + } + }, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "CCPA is not supported", + "comparison": "literal" + } + ] +} diff --git a/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json new file mode 100644 index 00000000000..aa324efa994 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json @@ -0,0 +1,76 @@ +{ + "mockBidRequest": { + "regs": { + "coppa": 1 + }, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "COPPA is not supported", + "comparison": "literal" + } + ] +} diff --git a/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json new file mode 100644 index 00000000000..448c1e657f5 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json @@ -0,0 +1,78 @@ +{ + "mockBidRequest": { + "regs": { + "ext": { + "gdpr": 1 + } + }, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "GDPR is not supported", + "comparison": "literal" + } + ] +} diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json new file mode 100644 index 00000000000..3bc56e6fca7 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json @@ -0,0 +1,65 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors" : [{ + "value": "Error get StoredRequestImpID from imp[0]: ext.prebid is null", + "comparison": "literal" + }] +} diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json new file mode 100644 index 00000000000..c0cf25d4dd4 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json @@ -0,0 +1,60 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "Error while decoding imp[0].ext: unexpected end of JSON input", + "comparison": "literal" + } + ] +} diff --git a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json new file mode 100644 index 00000000000..901ee8f4ec8 --- /dev/null +++ b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json @@ -0,0 +1,67 @@ +{ + "mockBidRequest": { + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media" + } + } + } + ], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + } + }, + "expectedMakeRequestsErrors" : [{ + "value": "Error get StoredRequestImpID from imp[0]: ext.prebid.storedrequest is null", + "comparison": "literal" + }] +} diff --git a/config/config.go b/config/config.go index 0db4145d899..e85b13c4ae0 100644 --- a/config/config.go +++ b/config/config.go @@ -636,6 +636,7 @@ func (cfg *Configuration) setDerivedDefaults() { setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderTriplelift, "https://eb2.3lift.com/getuid?gdpr={{.GDPR}}&cmp_cs={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dtriplelift%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderTripleliftNative, "https://eb2.3lift.com/getuid?gdpr={{.GDPR}}&cmp_cs={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dtriplelift_native%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderUcfunnel, "https://sync.aralego.com/idsync?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&usprivacy={{.USPrivacy}}&redirect="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Ducfunnel%26uid%3DSspCookieUserId") + // openrtb_ext.BidderUnicorn doesn't have a good default. setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderUnruly, "https://usermatch.targeting.unrulymedia.com/pbsync?gdpr={{.GDPR}}&consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&rurl="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dunruly%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderValueImpression, "https://rtb.valueimpression.com/usersync?gdpr={{.GDPR}}&consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dvalueimpression%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderVisx, "https://t.visx.net/s2s_sync?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dvisx%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24%7BUUID%7D") From 95844a4ec7ba48566030dbd666c46a889f4c33ed Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 8 Feb 2021 15:22:42 +0900 Subject: [PATCH 09/25] banner only, native later support --- static/bidder-info/unicorn.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/bidder-info/unicorn.yaml b/static/bidder-info/unicorn.yaml index 6f5fcc69e98..fb36a99abe9 100644 --- a/static/bidder-info/unicorn.yaml +++ b/static/bidder-info/unicorn.yaml @@ -3,5 +3,4 @@ maintainer: capabilities: app: mediaTypes: - - banner - - native \ No newline at end of file + - banner \ No newline at end of file From ca3026a937b206db719247be630c775f8b18c74d Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 8 Feb 2021 15:30:34 +0900 Subject: [PATCH 10/25] fix description placementid --- static/bidder-params/unicorn.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/bidder-params/unicorn.json b/static/bidder-params/unicorn.json index 121d03dacfc..f9c4e1677b6 100644 --- a/static/bidder-params/unicorn.json +++ b/static/bidder-params/unicorn.json @@ -6,7 +6,7 @@ "properties": { "placementId": { "type": "string", - "description": "If placementId is empty, adunit code will be used as placementId." + "description": "In Application, if placementId is empty, prebid server configuration id will be used as placementId." }, "publisherId": { "type": "integer", From 285c5d7c6a70047f95012e9e5c8d3dc730d4b597 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 8 Feb 2021 15:34:23 +0900 Subject: [PATCH 11/25] fix syncer_test.go --- usersync/usersyncers/syncer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/usersync/usersyncers/syncer_test.go b/usersync/usersyncers/syncer_test.go index 8e3b05a6ab8..bcca2d3ea10 100755 --- a/usersync/usersyncers/syncer_test.go +++ b/usersync/usersyncers/syncer_test.go @@ -116,6 +116,7 @@ func TestNewSyncerMap(t *testing.T) { openrtb_ext.BidderRevcontent: true, openrtb_ext.BidderSilverMob: true, openrtb_ext.BidderSmaato: true, + openrtb_ext.BidderUnicorn: true, openrtb_ext.BidderYeahmobi: true, } From f1c24279b035133fb96621894ee4b19829a43962 Mon Sep 17 00:00:00 2001 From: faithnh Date: Tue, 9 Feb 2021 11:18:20 +0900 Subject: [PATCH 12/25] apply gofmt --- adapters/unicorn/params_test.go | 58 ++-- adapters/unicorn/unicorn.go | 458 +++++++++++++++---------------- adapters/unicorn/unicorn_test.go | 22 +- openrtb_ext/imp_unicorn.go | 8 +- 4 files changed, 273 insertions(+), 273 deletions(-) diff --git a/adapters/unicorn/params_test.go b/adapters/unicorn/params_test.go index 99b8d7e7044..4a534208e84 100644 --- a/adapters/unicorn/params_test.go +++ b/adapters/unicorn/params_test.go @@ -1,61 +1,61 @@ package unicorn import ( - "encoding/json" - "testing" + "encoding/json" + "testing" - "github.com/prebid/prebid-server/openrtb_ext" + "github.com/prebid/prebid-server/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 schema. %v", err) - } - - for _, p := range validParams { - if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err != nil { - t.Errorf("Schema rejected valid params: %s", p) - } - } + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json schema. %v", err) + } + + for _, p := range validParams { + if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err != nil { + t.Errorf("Schema rejected valid params: %s", p) + } + } } func TestInvalidParams(t *testing.T) { - validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") - if err != nil { - t.Fatalf("Failed to fetch the json schema. %v", err) - } - - for _, p := range invalidParams { - if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err == nil { - t.Errorf("Schema allowed invalid params: %s", p) - } - } + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json schema. %v", err) + } + + for _, p := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderUnicorn, json.RawMessage(p)); err == nil { + t.Errorf("Schema allowed invalid params: %s", p) + } + } } var validParams = []string{ - `{ + `{ "accountId": 199578, "publisherId": 123456, "mediaId": "test_media", "placementId": "test_placement" }`, - `{ + `{ "accountId": 199578, "mediaId": "test_media" }`, } var invalidParams = []string{ - `{}`, - `{ + `{}`, + `{ "accountId": "199578", "publisherId": "123456", "mediaId": 12345, "placementId": 12345 }`, - `{ + `{ "publisherId": 123456, "placementId": "test_placement" }`, -} \ No newline at end of file +} diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index cf16411f7c5..5d8a38ebf4d 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -1,288 +1,288 @@ package unicorn import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/buger/jsonparser" - "github.com/mxmCherry/openrtb" - "github.com/prebid/prebid-server/adapters" - "github.com/prebid/prebid-server/config" - "github.com/prebid/prebid-server/errortypes" - "github.com/prebid/prebid-server/openrtb_ext" + "encoding/json" + "fmt" + "net/http" + + "github.com/buger/jsonparser" + "github.com/mxmCherry/openrtb" + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/openrtb_ext" ) const ( - unicornDefaultCurrency = "JPY" - unicornAuctionType = 1 + unicornDefaultCurrency = "JPY" + unicornAuctionType = 1 ) // UnicornAdapter describes a Smaato prebid server adapter. type UnicornAdapter struct { - endpoint string + endpoint string } // unicornImpExt is imp ext for UNICORN type unicornImpExt struct { - Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` + Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` } // unicornSourceExt is source ext for UNICORN type unicornSourceExt struct { - Stype string `json:"stype"` - Bidder string `json"bidder"` + Stype string `json:"stype"` + Bidder string `json"bidder"` } // unicornExt is ext for UNICORN type unicornExt struct { - Prebid *openrtb_ext.ExtImpPrebid `json:"prebid,omitempty"` - AccountID int64 `json:"accountId,omitempty"` + Prebid *openrtb_ext.ExtImpPrebid `json:"prebid,omitempty"` + AccountID int64 `json:"accountId,omitempty"` } // Builder builds a new instance of the Foo adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { - bidder := &UnicornAdapter{ - endpoint: config.Endpoint, - } - return bidder, nil + bidder := &UnicornAdapter{ + endpoint: config.Endpoint, + } + return bidder, nil } // MakeRequests makes the HTTP requests which should be made to fetch bids. func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { - var extRegs openrtb_ext.ExtRegs - if request.Regs != nil { - if request.Regs.COPPA == 1 { - return nil, []error{&errortypes.BadInput{ - Message: "COPPA is not supported", - }} - } - if err := json.Unmarshal(request.Regs.Ext, &extRegs); err == nil { - if extRegs.GDPR != nil && (*extRegs.GDPR == 1) { - return nil, []error{&errortypes.BadInput{ - Message: "GDPR is not supported", - }} - } - if extRegs.USPrivacy != "" { - return nil, []error{&errortypes.BadInput{ - Message: "CCPA is not supported", - }} - } - } - } - - request.AT = unicornAuctionType - - imp, err := setImps(request, requestInfo) - if err != nil { - return nil, []error{err} - } - - request.Imp = imp - request.Cur = []string{unicornDefaultCurrency} - - request.Source.Ext, err = setSourceExt() - if err != nil { - return nil, []error{err} - } - - request.Ext, err = setExt(request) - if err != nil { - return nil, []error{err} - } - - requestJSON, err := json.Marshal(request) - if err != nil { - return nil, []error{err} - } - - requestData := &adapters.RequestData{ - Method: "POST", - Uri: a.endpoint, - Body: requestJSON, - Headers: getHeaders(request), - } - - return []*adapters.RequestData{requestData}, nil + var extRegs openrtb_ext.ExtRegs + if request.Regs != nil { + if request.Regs.COPPA == 1 { + return nil, []error{&errortypes.BadInput{ + Message: "COPPA is not supported", + }} + } + if err := json.Unmarshal(request.Regs.Ext, &extRegs); err == nil { + if extRegs.GDPR != nil && (*extRegs.GDPR == 1) { + return nil, []error{&errortypes.BadInput{ + Message: "GDPR is not supported", + }} + } + if extRegs.USPrivacy != "" { + return nil, []error{&errortypes.BadInput{ + Message: "CCPA is not supported", + }} + } + } + } + + request.AT = unicornAuctionType + + imp, err := setImps(request, requestInfo) + if err != nil { + return nil, []error{err} + } + + request.Imp = imp + request.Cur = []string{unicornDefaultCurrency} + + request.Source.Ext, err = setSourceExt() + if err != nil { + return nil, []error{err} + } + + request.Ext, err = setExt(request) + if err != nil { + return nil, []error{err} + } + + requestJSON, err := json.Marshal(request) + if err != nil { + return nil, []error{err} + } + + requestData := &adapters.RequestData{ + Method: "POST", + Uri: a.endpoint, + Body: requestJSON, + Headers: getHeaders(request), + } + + return []*adapters.RequestData{requestData}, nil } func getHeaders(request *openrtb.BidRequest) http.Header { - headers := http.Header{} - headers.Add("Content-Type", "application/json;charset=utf-8") - headers.Add("Accept", "application/json") - headers.Add("X-Openrtb-Version", "2.5") - - if request.Device != nil { - if len(request.Device.UA) > 0 { - headers.Add("User-Agent", request.Device.UA) - } - - if len(request.Device.IPv6) > 0 { - headers.Add("X-Forwarded-For", request.Device.IPv6) - } - - if len(request.Device.IP) > 0 { - headers.Add("X-Forwarded-For", request.Device.IP) - } - } - - return headers + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Add("X-Openrtb-Version", "2.5") + + if request.Device != nil { + if len(request.Device.UA) > 0 { + headers.Add("User-Agent", request.Device.UA) + } + + if len(request.Device.IPv6) > 0 { + headers.Add("X-Forwarded-For", request.Device.IPv6) + } + + if len(request.Device.IP) > 0 { + headers.Add("X-Forwarded-For", request.Device.IP) + } + } + + return headers } func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { - for i := 0; i < len(request.Imp); i++ { - imp := &request.Imp[i] - - var ext unicornImpExt - err := json.Unmarshal(imp.Ext, &ext) - - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while decoding imp[%d].ext: %s", i, err), - } - } - - var placementID string - if ext.Bidder.PlacementID != "" { - placementID = ext.Bidder.PlacementID - } else { - placementID, err = getStoredRequestImpID(imp) - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error get StoredRequestImpID from imp[%d]: %s", i, err), - } - } - } - - ext.Bidder.PlacementID = placementID - - imp.Ext, err = json.Marshal(ext) - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding imp[%d].ext: %s", i, err), - } - } - - secure := int8(1) - imp.Secure = &secure - imp.TagID = placementID - } - return request.Imp, nil + for i := 0; i < len(request.Imp); i++ { + imp := &request.Imp[i] + + var ext unicornImpExt + err := json.Unmarshal(imp.Ext, &ext) + + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while decoding imp[%d].ext: %s", i, err), + } + } + + var placementID string + if ext.Bidder.PlacementID != "" { + placementID = ext.Bidder.PlacementID + } else { + placementID, err = getStoredRequestImpID(imp) + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error get StoredRequestImpID from imp[%d]: %s", i, err), + } + } + } + + ext.Bidder.PlacementID = placementID + + imp.Ext, err = json.Marshal(ext) + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding imp[%d].ext: %s", i, err), + } + } + + secure := int8(1) + imp.Secure = &secure + imp.TagID = placementID + } + return request.Imp, nil } func getStoredRequestImpID(imp *openrtb.Imp) (string, error) { - var impExt map[string]json.RawMessage + var impExt map[string]json.RawMessage - err := json.Unmarshal(imp.Ext, &impExt) + err := json.Unmarshal(imp.Ext, &impExt) - if err != nil { - return "", fmt.Errorf("Error while decoding ext because: %s", err) - } + if err != nil { + return "", fmt.Errorf("Error while decoding ext because: %s", err) + } - rawPrebidExt, ok := impExt[openrtb_ext.PrebidExtKey] + rawPrebidExt, ok := impExt[openrtb_ext.PrebidExtKey] - if !ok { - return "", fmt.Errorf("ext.prebid is null") - } + if !ok { + return "", fmt.Errorf("ext.prebid is null") + } - var prebidExt openrtb_ext.ExtImpPrebid + var prebidExt openrtb_ext.ExtImpPrebid - err = json.Unmarshal(rawPrebidExt, &prebidExt) + err = json.Unmarshal(rawPrebidExt, &prebidExt) - if err != nil { - return "", fmt.Errorf("cannot decoding ext.prebid because: %s", err) - } + if err != nil { + return "", fmt.Errorf("cannot decoding ext.prebid because: %s", err) + } - if prebidExt.StoredRequest == nil { - return "", fmt.Errorf("ext.prebid.storedrequest is null") - } + if prebidExt.StoredRequest == nil { + return "", fmt.Errorf("ext.prebid.storedrequest is null") + } - return prebidExt.StoredRequest.ID, nil + return prebidExt.StoredRequest.ID, nil } func setSourceExt() (json.RawMessage, error) { - siteExt, err := json.Marshal(unicornSourceExt{ - Stype: "prebid_server_uncn", - Bidder: "unicorn", - }) - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), - } - } - return siteExt, nil + siteExt, err := json.Marshal(unicornSourceExt{ + Stype: "prebid_server_uncn", + Bidder: "unicorn", + }) + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), + } + } + return siteExt, nil } func setExt(request *openrtb.BidRequest) (json.RawMessage, error) { - accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") - if err != nil { - accountID = 0 - } - var decodedExt *unicornExt - err = json.Unmarshal(request.Ext, &decodedExt) - if err != nil { - decodedExt = &unicornExt{ - Prebid: nil, - } - } - decodedExt.AccountID = accountID - - ext, err := json.Marshal(decodedExt) - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding ext, err: %s", err), - } - } - return ext, nil + accountID, err := jsonparser.GetInt(request.Imp[0].Ext, "bidder", "accountId") + if err != nil { + accountID = 0 + } + var decodedExt *unicornExt + err = json.Unmarshal(request.Ext, &decodedExt) + if err != nil { + decodedExt = &unicornExt{ + Prebid: nil, + } + } + decodedExt.AccountID = accountID + + ext, err := json.Marshal(decodedExt) + if err != nil { + return nil, &errortypes.BadInput{ + Message: fmt.Sprintf("Error while encoding ext, err: %s", err), + } + } + return ext, nil } // MakeBids unpacks the server's response into Bids. func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { - if responseData.StatusCode == http.StatusNoContent { - return nil, nil - } - - if responseData.StatusCode == http.StatusBadRequest { - err := &errortypes.BadInput{ - Message: "Unexpected http status code: 400", - } - return nil, []error{err} - } - - if responseData.StatusCode != http.StatusOK { - err := &errortypes.BadServerResponse{ - Message: fmt.Sprintf("Unexpected http status code: %d", responseData.StatusCode), - } - return nil, []error{err} - } - - var response openrtb.BidResponse - if err := json.Unmarshal(responseData.Body, &response); err != nil { - return nil, []error{err} - } - - bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) - bidResponse.Currency = response.Cur - for _, seatBid := range response.SeatBid { - for _, bid := range seatBid.Bid { - var bidType openrtb_ext.BidType - for _, imp := range request.Imp { - if imp.ID == bid.ImpID { - if imp.Banner != nil { - bidType = openrtb_ext.BidTypeBanner - } - if imp.Native != nil { - bidType = openrtb_ext.BidTypeNative - } - } - } - b := &adapters.TypedBid{ - Bid: &bid, - BidType: bidType, - } - bidResponse.Bids = append(bidResponse.Bids, b) - } - } - return bidResponse, nil -} \ No newline at end of file + if responseData.StatusCode == http.StatusNoContent { + return nil, nil + } + + if responseData.StatusCode == http.StatusBadRequest { + err := &errortypes.BadInput{ + Message: "Unexpected http status code: 400", + } + return nil, []error{err} + } + + if responseData.StatusCode != http.StatusOK { + err := &errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unexpected http status code: %d", responseData.StatusCode), + } + return nil, []error{err} + } + + var response openrtb.BidResponse + if err := json.Unmarshal(responseData.Body, &response); err != nil { + return nil, []error{err} + } + + bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) + bidResponse.Currency = response.Cur + for _, seatBid := range response.SeatBid { + for _, bid := range seatBid.Bid { + var bidType openrtb_ext.BidType + for _, imp := range request.Imp { + if imp.ID == bid.ImpID { + if imp.Banner != nil { + bidType = openrtb_ext.BidTypeBanner + } + if imp.Native != nil { + bidType = openrtb_ext.BidTypeNative + } + } + } + b := &adapters.TypedBid{ + Bid: &bid, + BidType: bidType, + } + bidResponse.Bids = append(bidResponse.Bids, b) + } + } + return bidResponse, nil +} diff --git a/adapters/unicorn/unicorn_test.go b/adapters/unicorn/unicorn_test.go index 4a04c208cd0..5254ee9ae9c 100644 --- a/adapters/unicorn/unicorn_test.go +++ b/adapters/unicorn/unicorn_test.go @@ -1,20 +1,20 @@ package unicorn import ( - "testing" + "testing" - "github.com/prebid/prebid-server/adapters/adapterstest" - "github.com/prebid/prebid-server/config" - "github.com/prebid/prebid-server/openrtb_ext" + "github.com/prebid/prebid-server/adapters/adapterstest" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/openrtb_ext" ) func TestJsonSamples(t *testing.T) { - bidder, buildErr := Builder(openrtb_ext.BidderUnicorn, config.Adapter{ - Endpoint: "http://localhost:4000"}) + bidder, buildErr := Builder(openrtb_ext.BidderUnicorn, config.Adapter{ + Endpoint: "http://localhost:4000"}) - if buildErr != nil { - t.Fatalf("Builder returned unexpected error %v", buildErr) - } + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } - adapterstest.RunJSONBidderTest(t, "unicorntest", bidder) -} \ No newline at end of file + adapterstest.RunJSONBidderTest(t, "unicorntest", bidder) +} diff --git a/openrtb_ext/imp_unicorn.go b/openrtb_ext/imp_unicorn.go index 64bd7fad13f..ad75414caa5 100644 --- a/openrtb_ext/imp_unicorn.go +++ b/openrtb_ext/imp_unicorn.go @@ -2,8 +2,8 @@ package openrtb_ext // ExtImpUnicorn defines the contract for bidrequest.imp[i].ext.unicorn type ExtImpUnicorn struct { - PlacementID string `json:"placementId,omitempty"` - PublisherID int `json:"publisherId,omitempty"` - MediaID string `json:"mediaId"` - AccountID int `json:"accountId"` + PlacementID string `json:"placementId,omitempty"` + PublisherID int `json:"publisherId,omitempty"` + MediaID string `json:"mediaId"` + AccountID int `json:"accountId"` } From 42ae15a6c8574590c9d47a1782a8a316cdf854a8 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 15 Feb 2021 15:14:50 +0900 Subject: [PATCH 13/25] Remove currency lock JPY --- adapters/unicorn/unicorn.go | 4 +--- .../unicorntest/exemplary/banner-app-without-ext.json | 5 ++--- .../exemplary/banner-app-without-placementid.json | 11 ++++++----- .../unicorn/unicorntest/exemplary/banner-app.json | 1 + adapters/unicorn/unicorntest/supplemental/204.json | 1 + adapters/unicorn/unicorntest/supplemental/400.json | 1 + adapters/unicorn/unicorntest/supplemental/500.json | 1 + .../unicorntest/supplemental/ccpa-is-enabled.json | 1 + .../unicorntest/supplemental/coppa-is-enabled.json | 1 + .../unicorntest/supplemental/gdpr-is-enabled.json | 1 + .../unicorntest/supplemental/no-imp-ext-prebid.json | 1 + .../unicorn/unicorntest/supplemental/no-imp-ext.json | 1 + .../supplemental/no-storedrequest-imp.json | 1 + 13 files changed, 19 insertions(+), 11 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 5d8a38ebf4d..9aff47b6b75 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -14,8 +14,7 @@ import ( ) const ( - unicornDefaultCurrency = "JPY" - unicornAuctionType = 1 + unicornAuctionType = 1 ) // UnicornAdapter describes a Smaato prebid server adapter. @@ -79,7 +78,6 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * } request.Imp = imp - request.Cur = []string{unicornDefaultCurrency} request.Source.Ext, err = setSourceExt() if err != nil { diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json index b789d4974a0..97cd93d8ce1 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json @@ -84,7 +84,6 @@ "ver": "1.9.0" }, "at": 1, - "cur": ["JPY"], "device": { "connectiontype": 1, "ext": { @@ -168,7 +167,7 @@ "id": "1", "impid": "29D2F33E-F865-40DA-9320-16EF77935254", "iurl": "https://example.com/banner.png", - "price": 73.283, + "price": 78.3, "w": 300 } ], @@ -189,7 +188,7 @@ "Bid": { "id": "1", "impid": "29D2F33E-F865-40DA-9320-16EF77935254", - "price": 73.283, + "price": 78.3, "adm": "awesome domain", "adid": "uoNYbq1L_-123456", "adomain": ["example.com"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json index 3effaa4c4d7..ad6fd974d2b 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json @@ -27,6 +27,7 @@ } } ], + "cur": ["USD"], "app": { "publisher": { "id": "test" @@ -94,7 +95,7 @@ "ver": "1.9.0" }, "at": 1, - "cur": ["JPY"], + "cur": ["USD"], "device": { "connectiontype": 1, "ext": { @@ -166,7 +167,7 @@ }, "body": { "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", - "cur": "JPY", + "cur": "USD", "ext": {}, "id": "CFD24FB1-916F-467D-8825-34892B315DB7", "seatbid": [ @@ -185,7 +186,7 @@ "id": "1", "impid": "29D2F33E-F865-40DA-9320-16EF77935254", "iurl": "https://example.com/banner.png", - "price": 73.283, + "price": 0.783, "w": 300 } ], @@ -200,13 +201,13 @@ ], "expectedBidResponses": [ { - "Currency": "JPY", + "Currency": "USD", "bids": [ { "Bid": { "id": "1", "impid": "29D2F33E-F865-40DA-9320-16EF77935254", - "price": 73.283, + "price": 0.783, "adm": "awesome domain", "adid": "uoNYbq1L_-123456", "adomain": ["example.com"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app.json b/adapters/unicorn/unicorntest/exemplary/banner-app.json index c4364b6959e..f3808102f71 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app.json @@ -28,6 +28,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/204.json b/adapters/unicorn/unicorntest/supplemental/204.json index e76859976a7..6e2e90c1f34 100644 --- a/adapters/unicorn/unicorntest/supplemental/204.json +++ b/adapters/unicorn/unicorntest/supplemental/204.json @@ -28,6 +28,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/400.json b/adapters/unicorn/unicorntest/supplemental/400.json index 38fbc52cb84..9df2f1d5c9d 100644 --- a/adapters/unicorn/unicorntest/supplemental/400.json +++ b/adapters/unicorn/unicorntest/supplemental/400.json @@ -28,6 +28,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/500.json b/adapters/unicorn/unicorntest/supplemental/500.json index 03793d0fa73..d4e1a027312 100644 --- a/adapters/unicorn/unicorntest/supplemental/500.json +++ b/adapters/unicorn/unicorntest/supplemental/500.json @@ -28,6 +28,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json index 4805c246fbd..37d84f027aa 100644 --- a/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json @@ -33,6 +33,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json index aa324efa994..2efdbb3ce2b 100644 --- a/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json @@ -31,6 +31,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json index 448c1e657f5..4bb2a7a9f20 100644 --- a/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json @@ -33,6 +33,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json index 3bc56e6fca7..62598b2c515 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json @@ -22,6 +22,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json index c0cf25d4dd4..bdd0f47765d 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json @@ -15,6 +15,7 @@ "secure": 1 } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" diff --git a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json index 901ee8f4ec8..8506f9da511 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json +++ b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json @@ -24,6 +24,7 @@ } } ], + "cur": ["JPY"], "app": { "publisher": { "id": "test" From 019800de8e8f4508d533cac4d04b570d6d2d72ec Mon Sep 17 00:00:00 2001 From: faithnh Date: Thu, 18 Feb 2021 14:49:59 +0900 Subject: [PATCH 14/25] fix comment, fix test code 500.json --- adapters/unicorn/unicorn.go | 2 +- adapters/unicorn/unicorntest/supplemental/500.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 9aff47b6b75..c938cca30e4 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -17,7 +17,7 @@ const ( unicornAuctionType = 1 ) -// UnicornAdapter describes a Smaato prebid server adapter. +// UnicornAdapter describes a UNICORN prebid server adapter. type UnicornAdapter struct { endpoint string } diff --git a/adapters/unicorn/unicorntest/supplemental/500.json b/adapters/unicorn/unicorntest/supplemental/500.json index d4e1a027312..9df2f1d5c9d 100644 --- a/adapters/unicorn/unicorntest/supplemental/500.json +++ b/adapters/unicorn/unicorntest/supplemental/500.json @@ -159,14 +159,14 @@ } }, "mockResponse": { - "status": 400, + "status": 500, "body": {} } } ], "expectedMakeBidsErrors": [ { - "value": "Unexpected http status code: 400", + "value": "Unexpected http status code: 500", "comparison": "literal" } ] From 7be6aa9a7ccd8481ae8ff66d1d44abb0d9170872 Mon Sep 17 00:00:00 2001 From: faithnh Date: Thu, 18 Feb 2021 15:09:43 +0900 Subject: [PATCH 15/25] Remove set AT --- adapters/unicorn/unicorn.go | 6 ------ .../unicorntest/exemplary/banner-app-without-ext.json | 1 + .../exemplary/banner-app-without-placementid.json | 1 + adapters/unicorn/unicorntest/exemplary/banner-app.json | 1 + adapters/unicorn/unicorntest/supplemental/204.json | 1 + adapters/unicorn/unicorntest/supplemental/400.json | 1 + adapters/unicorn/unicorntest/supplemental/500.json | 1 + .../unicorn/unicorntest/supplemental/ccpa-is-enabled.json | 1 + .../unicorn/unicorntest/supplemental/coppa-is-enabled.json | 1 + .../unicorn/unicorntest/supplemental/gdpr-is-enabled.json | 1 + .../unicorn/unicorntest/supplemental/no-imp-ext-prebid.json | 1 + adapters/unicorn/unicorntest/supplemental/no-imp-ext.json | 1 + .../unicorntest/supplemental/no-storedrequest-imp.json | 1 + 13 files changed, 12 insertions(+), 6 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index c938cca30e4..ded9139e7b2 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -13,10 +13,6 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -const ( - unicornAuctionType = 1 -) - // UnicornAdapter describes a UNICORN prebid server adapter. type UnicornAdapter struct { endpoint string @@ -70,8 +66,6 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * } } - request.AT = unicornAuctionType - imp, err := setImps(request, requestInfo) if err != nil { return nil, []error{err} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json index 97cd93d8ce1..fb571afbda1 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json index ad6fd974d2b..eb04e12aec9 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app.json b/adapters/unicorn/unicorntest/exemplary/banner-app.json index f3808102f71..802377b2b61 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/204.json b/adapters/unicorn/unicorntest/supplemental/204.json index 6e2e90c1f34..f708caca472 100644 --- a/adapters/unicorn/unicorntest/supplemental/204.json +++ b/adapters/unicorn/unicorntest/supplemental/204.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/400.json b/adapters/unicorn/unicorntest/supplemental/400.json index 9df2f1d5c9d..f9d1b793859 100644 --- a/adapters/unicorn/unicorntest/supplemental/400.json +++ b/adapters/unicorn/unicorntest/supplemental/400.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/500.json b/adapters/unicorn/unicorntest/supplemental/500.json index 9df2f1d5c9d..f9d1b793859 100644 --- a/adapters/unicorn/unicorntest/supplemental/500.json +++ b/adapters/unicorn/unicorntest/supplemental/500.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json index 37d84f027aa..6bc396c67f1 100644 --- a/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/ccpa-is-enabled.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "regs": { "ext": { "us_privacy": "1YNN" diff --git a/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json index 2efdbb3ce2b..1c33ce2e805 100644 --- a/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/coppa-is-enabled.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "regs": { "coppa": 1 }, diff --git a/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json index 4bb2a7a9f20..3c9222d8cc2 100644 --- a/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json +++ b/adapters/unicorn/unicorntest/supplemental/gdpr-is-enabled.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "regs": { "ext": { "gdpr": 1 diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json index 62598b2c515..081483c0c71 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json index bdd0f47765d..bab6e8d9603 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { diff --git a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json index 8506f9da511..ccade902f1b 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json +++ b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json @@ -1,5 +1,6 @@ { "mockBidRequest": { + "at": 1, "imp": [ { "banner": { From 8b9dcd1c5a9a318d595f056a17976d17dee0b82d Mon Sep 17 00:00:00 2001 From: faithnh Date: Fri, 19 Feb 2021 13:05:45 +0900 Subject: [PATCH 16/25] change maintener email address --- static/bidder-info/unicorn.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/bidder-info/unicorn.yaml b/static/bidder-info/unicorn.yaml index fb36a99abe9..f1b5a4e7f3e 100644 --- a/static/bidder-info/unicorn.yaml +++ b/static/bidder-info/unicorn.yaml @@ -1,5 +1,5 @@ maintainer: - email: service+prebid.js@bulbit.jp + email: prebid@unicorn.inc capabilities: app: mediaTypes: From f067facc76343359974cc35ef5da1a8cbb0b7b66 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 22 Feb 2021 13:54:48 +0900 Subject: [PATCH 17/25] support fpd --- adapters/unicorn/unicorn.go | 5 + .../exemplary/banner-app_with_fpd.json | 244 ++++++++++++++++++ .../exemplary/banner-app_with_no_fpd.json | 238 +++++++++++++++++ 3 files changed, 487 insertions(+) create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index ded9139e7b2..4f5497fc335 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -20,9 +20,14 @@ type UnicornAdapter struct { // unicornImpExt is imp ext for UNICORN type unicornImpExt struct { + Context *unicornImpExtContext `json:"context,omitempty"` Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` } +type unicornImpExtContext struct { + Data interface{} `json:"data,omitempty"` +} + // unicornSourceExt is source ext for UNICORN type unicornSourceExt struct { Stype string `json:"stype"` diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json new file mode 100644 index 00000000000..870da3db48f --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json @@ -0,0 +1,244 @@ +{ + "mockBidRequest": { + "at": 1, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + }, + "context": { + "data": { + "firstPartyData1": "firstPartyData1", + "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + } + } + } + } + ], + "cur": ["JPY"], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + }, + "context": { + "data": { + "firstPartyData1": "firstPartyData1", + "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + } + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "http://localhost:4000", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json b/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json new file mode 100644 index 00000000000..8dce4ca5fec --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json @@ -0,0 +1,238 @@ +{ + "mockBidRequest": { + "at": 1, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + }, + "context": { + "data": {} + } + } + } + ], + "cur": ["JPY"], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://localhost:4000", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + }, + "context": { + "data": {} + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "Bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "http://localhost:4000", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} From 8cb49061d0066e588dc5609939ca3c2b80a97f03 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 22 Feb 2021 13:56:56 +0900 Subject: [PATCH 18/25] apply fmt --- adapters/unicorn/unicorn.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 4f5497fc335..b9554ce8334 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -20,12 +20,12 @@ type UnicornAdapter struct { // unicornImpExt is imp ext for UNICORN type unicornImpExt struct { - Context *unicornImpExtContext `json:"context,omitempty"` - Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` + Context *unicornImpExtContext `json:"context,omitempty"` + Bidder openrtb_ext.ExtImpUnicorn `json:"bidder"` } type unicornImpExtContext struct { - Data interface{} `json:"data,omitempty"` + Data interface{} `json:"data,omitempty"` } // unicornSourceExt is source ext for UNICORN From 74b363a948d045b237051e40f32d7754651a9656 Mon Sep 17 00:00:00 2001 From: faithnh Date: Mon, 22 Feb 2021 14:05:00 +0900 Subject: [PATCH 19/25] fix fpd format on testcode --- .../unicorntest/exemplary/banner-app_with_fpd.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json index 870da3db48f..4ea06d4e45e 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json @@ -28,8 +28,8 @@ }, "context": { "data": { - "firstPartyData1": "firstPartyData1", - "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + "firstPartyData1": ["firstPartyData1"], + "uuid": ["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"] } } } @@ -149,8 +149,8 @@ }, "context": { "data": { - "firstPartyData1": "firstPartyData1", - "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + "firstPartyData1": ["firstPartyData1"], + "uuid": ["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"] } } }, From 3b1f698d2ec158ae67ab380b9b3fcc35ccdbe2fa Mon Sep 17 00:00:00 2001 From: faithnh Date: Wed, 24 Feb 2021 14:05:01 +0900 Subject: [PATCH 20/25] fix PR problem ( Except for #discussion_r580592627) --- adapters/unicorn/unicorn.go | 77 ++---- adapters/unicorn/unicorn_test.go | 2 +- .../exemplary/banner-app-with-ip.json | 236 ++++++++++++++++++ .../exemplary/banner-app-with-ipv6.json | 236 ++++++++++++++++++ .../exemplary/banner-app-without-ext.json | 6 +- .../banner-app-without-placementid.json | 6 +- .../unicorntest/exemplary/banner-app.json | 6 +- .../exemplary/banner-app_with_fpd.json | 6 +- .../exemplary/banner-app_with_no_fpd.json | 6 +- .../unicorn/unicorntest/supplemental/204.json | 4 +- .../unicorn/unicorntest/supplemental/400.json | 8 +- .../unicorn/unicorntest/supplemental/500.json | 4 +- .../supplemental/no-imp-ext-prebid.json | 2 +- .../supplemental/no-storedrequest-imp.json | 2 +- 14 files changed, 517 insertions(+), 84 deletions(-) create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app-with-ip.json create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app-with-ipv6.json diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index b9554ce8334..66ec4d13225 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -13,8 +13,8 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -// UnicornAdapter describes a UNICORN prebid server adapter. -type UnicornAdapter struct { +// adapter describes a UNICORN prebid server adapter. +type adapter struct { endpoint string } @@ -28,28 +28,22 @@ type unicornImpExtContext struct { Data interface{} `json:"data,omitempty"` } -// unicornSourceExt is source ext for UNICORN -type unicornSourceExt struct { - Stype string `json:"stype"` - Bidder string `json"bidder"` -} - // unicornExt is ext for UNICORN type unicornExt struct { Prebid *openrtb_ext.ExtImpPrebid `json:"prebid,omitempty"` AccountID int64 `json:"accountId,omitempty"` } -// Builder builds a new instance of the Foo adapter for the given bidder with the given config. +// Builder builds a new instance of the UNICORN adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { - bidder := &UnicornAdapter{ + bidder := &adapter{ endpoint: config.Endpoint, } return bidder, nil } // MakeRequests makes the HTTP requests which should be made to fetch bids. -func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { +func (a *adapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var extRegs openrtb_ext.ExtRegs if request.Regs != nil { if request.Regs.COPPA == 1 { @@ -71,17 +65,12 @@ func (a *UnicornAdapter) MakeRequests(request *openrtb.BidRequest, requestInfo * } } - imp, err := setImps(request, requestInfo) + err := modifyImps(request, requestInfo) if err != nil { return nil, []error{err} } - request.Imp = imp - - request.Source.Ext, err = setSourceExt() - if err != nil { - return nil, []error{err} - } + request.Source.Ext = setSourceExt() request.Ext, err = setExt(request) if err != nil { @@ -126,7 +115,7 @@ func getHeaders(request *openrtb.BidRequest) http.Header { return headers } -func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]openrtb.Imp, error) { +func modifyImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) error { for i := 0; i < len(request.Imp); i++ { imp := &request.Imp[i] @@ -134,7 +123,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo err := json.Unmarshal(imp.Ext, &ext) if err != nil { - return nil, &errortypes.BadInput{ + return &errortypes.BadInput{ Message: fmt.Sprintf("Error while decoding imp[%d].ext: %s", i, err), } } @@ -145,7 +134,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo } else { placementID, err = getStoredRequestImpID(imp) if err != nil { - return nil, &errortypes.BadInput{ + return &errortypes.BadInput{ Message: fmt.Sprintf("Error get StoredRequestImpID from imp[%d]: %s", i, err), } } @@ -155,7 +144,7 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo imp.Ext, err = json.Marshal(ext) if err != nil { - return nil, &errortypes.BadInput{ + return &errortypes.BadInput{ Message: fmt.Sprintf("Error while encoding imp[%d].ext: %s", i, err), } } @@ -164,50 +153,21 @@ func setImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo imp.Secure = &secure imp.TagID = placementID } - return request.Imp, nil + return nil } func getStoredRequestImpID(imp *openrtb.Imp) (string, error) { - var impExt map[string]json.RawMessage - - err := json.Unmarshal(imp.Ext, &impExt) + v, err := jsonparser.GetString(imp.Ext, "prebid", "storedrequest", "id") if err != nil { - return "", fmt.Errorf("Error while decoding ext because: %s", err) + return "", fmt.Errorf("stored request id not found: %s", err) } - rawPrebidExt, ok := impExt[openrtb_ext.PrebidExtKey] - - if !ok { - return "", fmt.Errorf("ext.prebid is null") - } - - var prebidExt openrtb_ext.ExtImpPrebid - - err = json.Unmarshal(rawPrebidExt, &prebidExt) - - if err != nil { - return "", fmt.Errorf("cannot decoding ext.prebid because: %s", err) - } - - if prebidExt.StoredRequest == nil { - return "", fmt.Errorf("ext.prebid.storedrequest is null") - } - - return prebidExt.StoredRequest.ID, nil + return v, nil } -func setSourceExt() (json.RawMessage, error) { - siteExt, err := json.Marshal(unicornSourceExt{ - Stype: "prebid_server_uncn", - Bidder: "unicorn", - }) - if err != nil { - return nil, &errortypes.BadInput{ - Message: fmt.Sprintf("Error while encoding source.ext, err: %s", err), - } - } - return siteExt, nil +func setSourceExt() json.RawMessage { + return json.RawMessage(`{"stype": "prebid_server_uncn", "bidder": "unicorn"}`) } func setExt(request *openrtb.BidRequest) (json.RawMessage, error) { @@ -234,7 +194,7 @@ func setExt(request *openrtb.BidRequest) (json.RawMessage, error) { } // MakeBids unpacks the server's response into Bids. -func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { +func (a *adapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { if responseData.StatusCode == http.StatusNoContent { return nil, nil @@ -263,6 +223,7 @@ func (a *UnicornAdapter) MakeBids(request *openrtb.BidRequest, requestData *adap bidResponse.Currency = response.Cur for _, seatBid := range response.SeatBid { for _, bid := range seatBid.Bid { + bid := bid var bidType openrtb_ext.BidType for _, imp := range request.Imp { if imp.ID == bid.ImpID { diff --git a/adapters/unicorn/unicorn_test.go b/adapters/unicorn/unicorn_test.go index 5254ee9ae9c..1a0d67d29f7 100644 --- a/adapters/unicorn/unicorn_test.go +++ b/adapters/unicorn/unicorn_test.go @@ -10,7 +10,7 @@ import ( func TestJsonSamples(t *testing.T) { bidder, buildErr := Builder(openrtb_ext.BidderUnicorn, config.Adapter{ - Endpoint: "http://localhost:4000"}) + Endpoint: "https://ds.uncn.jp"}) if buildErr != nil { t.Fatalf("Builder returned unexpected error %v", buildErr) diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-with-ip.json b/adapters/unicorn/unicorntest/exemplary/banner-app-with-ip.json new file mode 100644 index 00000000000..2d38a990db3 --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-with-ip.json @@ -0,0 +1,236 @@ +{ + "mockBidRequest": { + "at": 1, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "cur": ["JPY"], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "ip": "12.1.2.3", + "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://ds.uncn.jp", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "ip": "12.1.2.3", + "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "https://ds.uncn.jp", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-with-ipv6.json b/adapters/unicorn/unicorntest/exemplary/banner-app-with-ipv6.json new file mode 100644 index 00000000000..595741a0aa1 --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-with-ipv6.json @@ -0,0 +1,236 @@ +{ + "mockBidRequest": { + "at": 1, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "cur": ["JPY"], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "source": { + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "device": { + "make": "Apple", + "osv": "14.4", + "ipv6": "2400:2410:9120:3400:15f3:8c50:3a0:6820", + "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://ds.uncn.jp", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "ipv6": "2400:2410:9120:3400:15f3:8c50:3a0:6820", + "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "bidder": "unicorn", + "stype": "prebid_server_uncn" + }, + "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "https://ds.uncn.jp", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json index fb571afbda1..8b5423a5556 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-ext.json @@ -69,7 +69,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -129,7 +129,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -140,7 +140,7 @@ } }, "mockResponse": { - "url": "http://localhost:4000", + "url": "https://ds.uncn.jp", "status": 200, "headers": { "Content-Type": ["application/json"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json index eb04e12aec9..c05d3b6f536 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-without-placementid.json @@ -80,7 +80,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -148,7 +148,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -159,7 +159,7 @@ } }, "mockResponse": { - "url": "http://localhost:4000", + "url": "https://ds.uncn.jp", "status": 200, "headers": { "Content-Type": ["application/json"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app.json b/adapters/unicorn/unicorntest/exemplary/banner-app.json index 802377b2b61..b29c1e1d625 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app.json @@ -81,7 +81,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -149,7 +149,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -160,7 +160,7 @@ } }, "mockResponse": { - "url": "http://localhost:4000", + "url": "https://ds.uncn.jp", "status": 200, "headers": { "Content-Type": ["application/json"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json index 4ea06d4e45e..0a6fb420adc 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app_with_fpd.json @@ -87,7 +87,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -161,7 +161,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -172,7 +172,7 @@ } }, "mockResponse": { - "url": "http://localhost:4000", + "url": "https://ds.uncn.jp", "status": 200, "headers": { "Content-Type": ["application/json"], diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json b/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json index 8dce4ca5fec..022246382f8 100644 --- a/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json +++ b/adapters/unicorn/unicorntest/exemplary/banner-app_with_no_fpd.json @@ -84,7 +84,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -155,7 +155,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -166,7 +166,7 @@ } }, "mockResponse": { - "url": "http://localhost:4000", + "url": "https://ds.uncn.jp", "status": 200, "headers": { "Content-Type": ["application/json"], diff --git a/adapters/unicorn/unicorntest/supplemental/204.json b/adapters/unicorn/unicorntest/supplemental/204.json index f708caca472..a05864090ea 100644 --- a/adapters/unicorn/unicorntest/supplemental/204.json +++ b/adapters/unicorn/unicorntest/supplemental/204.json @@ -81,7 +81,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -149,7 +149,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" diff --git a/adapters/unicorn/unicorntest/supplemental/400.json b/adapters/unicorn/unicorntest/supplemental/400.json index f9d1b793859..6578082ca19 100644 --- a/adapters/unicorn/unicorntest/supplemental/400.json +++ b/adapters/unicorn/unicorntest/supplemental/400.json @@ -81,7 +81,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -149,7 +149,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" @@ -160,14 +160,14 @@ } }, "mockResponse": { - "status": 500, + "status": 400, "body": {} } } ], "expectedMakeBidsErrors": [ { - "value": "Unexpected http status code: 500", + "value": "Unexpected http status code: 400", "comparison": "literal" } ] diff --git a/adapters/unicorn/unicorntest/supplemental/500.json b/adapters/unicorn/unicorntest/supplemental/500.json index f9d1b793859..c0811be4b24 100644 --- a/adapters/unicorn/unicorntest/supplemental/500.json +++ b/adapters/unicorn/unicorntest/supplemental/500.json @@ -81,7 +81,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "http://localhost:4000", + "uri": "https://ds.uncn.jp", "body": { "app": { "bundle": "net.ada.test", @@ -149,7 +149,7 @@ ], "source": { "ext": { - "Bidder": "unicorn", + "bidder": "unicorn", "stype": "prebid_server_uncn" }, "tid": "A4B3EA9F-FF57-4716-AC85-6CBF6A46CFBD" diff --git a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json index 081483c0c71..2e6ce79a176 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json +++ b/adapters/unicorn/unicorntest/supplemental/no-imp-ext-prebid.json @@ -61,7 +61,7 @@ } }, "expectedMakeRequestsErrors" : [{ - "value": "Error get StoredRequestImpID from imp[0]: ext.prebid is null", + "value": "Error get StoredRequestImpID from imp[0]: stored request id not found: Key path not found", "comparison": "literal" }] } diff --git a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json index ccade902f1b..d903effd466 100644 --- a/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json +++ b/adapters/unicorn/unicorntest/supplemental/no-storedrequest-imp.json @@ -63,7 +63,7 @@ } }, "expectedMakeRequestsErrors" : [{ - "value": "Error get StoredRequestImpID from imp[0]: ext.prebid.storedrequest is null", + "value": "Error get StoredRequestImpID from imp[0]: stored request id not found: Key path not found", "comparison": "literal" }] } From 1080b560db06b29e050463aca4d863dbcc238481 Mon Sep 17 00:00:00 2001 From: faithnh Date: Wed, 24 Feb 2021 14:32:25 +0900 Subject: [PATCH 21/25] Remove comment on adapter --- adapters/unicorn/unicorn.go | 1 - 1 file changed, 1 deletion(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 66ec4d13225..644b052935e 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -13,7 +13,6 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -// adapter describes a UNICORN prebid server adapter. type adapter struct { endpoint string } From 435bf6e705db537fcf1a4ef91d3ff4c57bbc1f91 Mon Sep 17 00:00:00 2001 From: faithnh Date: Thu, 25 Feb 2021 15:32:59 +0900 Subject: [PATCH 22/25] fix PR problem --- adapters/unicorn/unicorn.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 644b052935e..cfdd31707a1 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -228,8 +228,7 @@ func (a *adapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.Re if imp.ID == bid.ImpID { if imp.Banner != nil { bidType = openrtb_ext.BidTypeBanner - } - if imp.Native != nil { + } else if imp.Native != nil { bidType = openrtb_ext.BidTypeNative } } From c27da8b1c27ab005ceff968efbbf39df97e6bf29 Mon Sep 17 00:00:00 2001 From: faithnh Date: Fri, 26 Feb 2021 11:02:45 +0900 Subject: [PATCH 23/25] fix PR problem again --- adapters/unicorn/unicorn.go | 13 +- .../exemplary/banner-app-no-source.json | 228 ++++++++++++++++++ 2 files changed, 238 insertions(+), 3 deletions(-) create mode 100644 adapters/unicorn/unicorntest/exemplary/banner-app-no-source.json diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index cfdd31707a1..72269e5aa73 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -64,12 +64,19 @@ func (a *adapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapter } } - err := modifyImps(request, requestInfo) + err := modifyImps(request) if err != nil { return nil, []error{err} } - request.Source.Ext = setSourceExt() + var modifiableSource *openrtb.Source + if request.Source != nil { + modifiableSource = request.Source + } else { + modifiableSource = &openrtb.Source{} + } + modifiableSource.Ext = setSourceExt() + request.Source = modifiableSource request.Ext, err = setExt(request) if err != nil { @@ -114,7 +121,7 @@ func getHeaders(request *openrtb.BidRequest) http.Header { return headers } -func modifyImps(request *openrtb.BidRequest, requestInfo *adapters.ExtraRequestInfo) error { +func modifyImps(request *openrtb.BidRequest) error { for i := 0; i < len(request.Imp); i++ { imp := &request.Imp[i] diff --git a/adapters/unicorn/unicorntest/exemplary/banner-app-no-source.json b/adapters/unicorn/unicorntest/exemplary/banner-app-no-source.json new file mode 100644 index 00000000000..c37c2095d48 --- /dev/null +++ b/adapters/unicorn/unicorntest/exemplary/banner-app-no-source.json @@ -0,0 +1,228 @@ +{ + "mockBidRequest": { + "at": 1, + "imp": [ + { + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "api": [5] + }, + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1, + "ext": { + "prebid": { + "storedrequest": { + "id": "test_unicorn" + } + }, + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + } + } + ], + "cur": ["JPY"], + "app": { + "publisher": { + "id": "test" + }, + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "bundle": "net.ada.test", + "ver": "1.9.0" + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "device": { + "make": "Apple", + "osv": "14.4", + "connectiontype": 1, + "os": "iOS", + "w": 320, + "model": "Simulator", + "ifa": "00000000-0000-0000-0000-000000000000", + "devtime": 1612413327, + "h": 568, + "pxratio": 2, + "ext": { + "atts": 0 + } + }, + "user": { + "gender": "O" + }, + "ext": { + "prebid": { + "targeting": {}, + "cache": { + "bids": {} + }, + "storedrequest": { + "id": "test" + } + } + } + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://ds.uncn.jp", + "body": { + "app": { + "bundle": "net.ada.test", + "ext": { + "prebid": { + "source": "prebid-mobile", + "version": "1.9.0" + } + }, + "publisher": { + "id": "test" + }, + "ver": "1.9.0" + }, + "at": 1, + "cur": ["JPY"], + "device": { + "connectiontype": 1, + "ext": { + "atts": 0 + }, + "h": 568, + "ifa": "00000000-0000-0000-0000-000000000000", + "make": "Apple", + "model": "Simulator", + "os": "iOS", + "osv": "14.4", + "pxratio": 2, + "w": 320 + }, + "ext": { + "prebid": { + "bidder": null, + "is_rewarded_inventory": 0, + "storedrequest": { + "id": "test" + } + }, + "accountId": 199578 + }, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "imp": [ + { + "banner": { + "api": [5], + "format": [ + { + "h": 250, + "w": 300 + } + ] + }, + "ext": { + "bidder": { + "accountId": 199578, + "publisherId": 123456, + "mediaId": "test_media", + "placementId": "test_placement" + } + }, + "tagid": "test_placement", + "id": "29D2F33E-F865-40DA-9320-16EF77935254", + "secure": 1 + } + ], + "source": { + "ext": { + "bidder": "unicorn", + "stype": "prebid_server_uncn" + } + }, + "user": { + "gender": "O" + } + } + }, + "mockResponse": { + "url": "https://ds.uncn.jp", + "status": 200, + "headers": { + "Content-Type": ["application/json"], + "Date": ["Thu, 04 Feb 2021 06:36:31 GMT"], + "Vary": ["Accept-Encoding"] + }, + "body": { + "bidid": "f1248280-24ec-4fbc-bdf5-6a866e7dcea4", + "cur": "JPY", + "ext": {}, + "id": "CFD24FB1-916F-467D-8825-34892B315DB7", + "seatbid": [ + { + "bid": [ + { + "adid": "uoNYbq1L_-123456", + "adm": "awesome domain", + "adomain": ["example.com"], + "attr": [], + "bundle": "example.com", + "cid": "7314", + "crid": "-123456", + "ext": {}, + "h": 250, + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "iurl": "https://example.com/banner.png", + "price": 73.283, + "w": 300 + } + ], + "group": 0, + "seat": "274" + } + ], + "units": 0 + } + } + } + ], + "expectedBidResponses": [ + { + "Currency": "JPY", + "bids": [ + { + "Bid": { + "id": "1", + "impid": "29D2F33E-F865-40DA-9320-16EF77935254", + "price": 73.283, + "adm": "awesome domain", + "adid": "uoNYbq1L_-123456", + "adomain": ["example.com"], + "bundle": "example.com", + "iurl": "https://example.com/banner.png", + "cid": "7314", + "crid": "-123456", + "w": 300, + "h": 250, + "ext": {} + }, + "type": "banner", + "BidType": "banner", + "BidVideo": null, + "DealPriority": 0 + } + ] + } + ] +} From fb58a7ee99d689075713ebb414a0f6cfd7b1412c Mon Sep 17 00:00:00 2001 From: faithnh Date: Tue, 2 Mar 2021 08:25:06 +0900 Subject: [PATCH 24/25] Fixed copying Source problem --- adapters/unicorn/unicorn.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 72269e5aa73..06be746e844 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -69,14 +69,14 @@ func (a *adapter) MakeRequests(request *openrtb.BidRequest, requestInfo *adapter return nil, []error{err} } - var modifiableSource *openrtb.Source + var modifiableSource openrtb.Source if request.Source != nil { - modifiableSource = request.Source + modifiableSource = *request.Source } else { - modifiableSource = &openrtb.Source{} + modifiableSource = openrtb.Source{} } modifiableSource.Ext = setSourceExt() - request.Source = modifiableSource + request.Source = &modifiableSource request.Ext, err = setExt(request) if err != nil { From deaf6c029d92bb95d7a851add43b9bae7f3a5098 Mon Sep 17 00:00:00 2001 From: faithnh Date: Wed, 3 Mar 2021 17:39:56 +0900 Subject: [PATCH 25/25] Fix review problem --- adapters/unicorn/unicorn.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/adapters/unicorn/unicorn.go b/adapters/unicorn/unicorn.go index 06be746e844..52441e1a882 100644 --- a/adapters/unicorn/unicorn.go +++ b/adapters/unicorn/unicorn.go @@ -134,11 +134,8 @@ func modifyImps(request *openrtb.BidRequest) error { } } - var placementID string - if ext.Bidder.PlacementID != "" { - placementID = ext.Bidder.PlacementID - } else { - placementID, err = getStoredRequestImpID(imp) + if ext.Bidder.PlacementID == "" { + ext.Bidder.PlacementID, err = getStoredRequestImpID(imp) if err != nil { return &errortypes.BadInput{ Message: fmt.Sprintf("Error get StoredRequestImpID from imp[%d]: %s", i, err), @@ -146,8 +143,6 @@ func modifyImps(request *openrtb.BidRequest) error { } } - ext.Bidder.PlacementID = placementID - imp.Ext, err = json.Marshal(ext) if err != nil { return &errortypes.BadInput{ @@ -157,7 +152,7 @@ func modifyImps(request *openrtb.BidRequest) error { secure := int8(1) imp.Secure = &secure - imp.TagID = placementID + imp.TagID = ext.Bidder.PlacementID } return nil } @@ -235,8 +230,6 @@ func (a *adapter) MakeBids(request *openrtb.BidRequest, requestData *adapters.Re if imp.ID == bid.ImpID { if imp.Banner != nil { bidType = openrtb_ext.BidTypeBanner - } else if imp.Native != nil { - bidType = openrtb_ext.BidTypeNative } } }