From 879d17b04b95a9eebff69bedce17d4ca7c988a46 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Sun, 26 Apr 2020 17:55:17 +0800 Subject: [PATCH 01/11] sometests --- adapters/yeahmobi/params_test.go | 47 +++++ adapters/yeahmobi/yeahmobi.go | 164 ++++++++++++++++++ adapters/yeahmobi/yeahmobi_test.go | 10 ++ .../yeahmobitest/exemplary/simple-banner.json | 85 +++++++++ .../yeahmobitest/params/race/banner.json | 5 + config/config.go | 1 + exchange/adapter_map.go | 2 + openrtb_ext/bidders.go | 2 + openrtb_ext/imp_yeahmobi.go | 7 + static/bidder-info/yeahmobi.yaml | 8 + static/bidder-params/yeahmobi.json | 21 +++ 11 files changed, 352 insertions(+) create mode 100644 adapters/yeahmobi/params_test.go create mode 100644 adapters/yeahmobi/yeahmobi.go create mode 100644 adapters/yeahmobi/yeahmobi_test.go create mode 100644 adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json create mode 100644 adapters/yeahmobi/yeahmobitest/params/race/banner.json create mode 100644 openrtb_ext/imp_yeahmobi.go create mode 100644 static/bidder-info/yeahmobi.yaml create mode 100644 static/bidder-params/yeahmobi.json diff --git a/adapters/yeahmobi/params_test.go b/adapters/yeahmobi/params_test.go new file mode 100644 index 00000000000..0d8c0a567be --- /dev/null +++ b/adapters/yeahmobi/params_test.go @@ -0,0 +1,47 @@ +package yeahmobi + +import ( + "encoding/json" + "github.com/prebid/prebid-server/openrtb_ext" + "testing" +) + +func TestValidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, validParam := range validParams { + if err := validator.Validate(openrtb_ext.BidderYeahmobi, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected yeahmobi params: %s", validParam) + } + } +} + +// TestInvalidParams makes sure that the yeahmobi schema rejects all the imp.ext fields we don't support. +func TestInvalidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, invalidParam := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderYeahmobi, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema allowed unexpected params: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"pubId": "11233", "zoneId": "sin"}`, + `{"pubId": "11244", "zoneId": "iad"}`, +} + +var invalidParams = []string{ + `{"pubId": "11233"}`, + `{"zoneId": "aaa"}`, + `{"pubId": 123, "zoneId": "sin"}`, + `{"pubId": "", "zoneId": "iad"}`, + `{"pubId": "11233", "zoneId": ""}`, +} \ No newline at end of file diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go new file mode 100644 index 00000000000..6d689637c87 --- /dev/null +++ b/adapters/yeahmobi/yeahmobi.go @@ -0,0 +1,164 @@ +package yeahmobi + +import ( + "encoding/json" + "errors" + "fmt" + "github.com/golang/glog" + "github.com/mxmCherry/openrtb" + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/macros" + "github.com/prebid/prebid-server/openrtb_ext" + "net/http" + "text/template" +) + +type YeahmobiAdapter struct { + EndpointTemplate template.Template +} + +func NewYeahmobiBidder(endpointTemplate string) adapters.Bidder { + tpl, err := template.New("endpointTemplate").Parse(endpointTemplate) + if err != nil { + glog.Fatal("Unknow url template") + return nil + } + return &YeahmobiAdapter{EndpointTemplate: *tpl} +} + +func (adapter *YeahmobiAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + var adapterRequests []*adapters.RequestData + + adapterRequest, errors := adapter.makeRequest(request) + if adapterRequest != nil { + adapterRequests = append(adapterRequests, adapterRequest) + } + + return adapterRequests, errors +} + +// Update the request object to include custom value +// site.id +func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) { + var errs []error + + yeahmobiExt, errs := getYeahmobiExt(request) + + if yeahmobiExt == nil { + glog.Fatal("invalid ExtImpYeahmobi value") + return nil, errs + } + + endPoint, err := adapter.getEndpoint(yeahmobiExt) + + if err != nil { + return nil, append(errs, err) + } + reqBody, err := json.Marshal(request) + + if err != nil { + errs = append(errs, err) + } + + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + + return &adapters.RequestData{ + Method: "POST", + Uri: endPoint, + Body: reqBody, + Headers: headers, + }, errs +} + +func getYeahmobiExt(request *openrtb.BidRequest) (*openrtb_ext.ExtImpYeahmobi, []error) { + var extImpYeahmobi openrtb_ext.ExtImpYeahmobi + var errs []error + + for _, imp := range request.Imp { + var extBidder adapters.ExtImpBidder + err := json.Unmarshal(imp.Ext, &extBidder) + if err != nil { + errs = append(errs, err) + continue + } + err = json.Unmarshal(extBidder.Bidder, &extImpYeahmobi) + if err != nil { + errs = append(errs, err) + continue + } + + } + + return &extImpYeahmobi, errs + +} + +func (adapter *YeahmobiAdapter) getEndpoint(ext *openrtb_ext.ExtImpYeahmobi) (string, error) { + if ext.ZoneId == "" { + return "", errors.New("param of zone not config") + } + + return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + ext.ZoneId + "-bid.yeahtargeter.com"}) +} + +// MakeBids make the bids for the bid response. +func (a *YeahmobiAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if response.StatusCode == http.StatusNoContent { + return nil, nil + } + + if response.StatusCode == http.StatusBadRequest { + return nil, []error{&errortypes.BadInput{ + Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode), + }} + } + + if response.StatusCode != http.StatusOK { + return nil, []error{&errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode), + }} + } + + var bidResp openrtb.BidResponse + + if err := json.Unmarshal(response.Body, &bidResp); err != nil { + return nil, []error{err} + } + + bidResponse := adapters.NewBidderResponseWithBidsCapacity(1) + + for _, sb := range bidResp.SeatBid { + for i := range sb.Bid { + var mediaType = getBidType(sb.Bid[i].ImpID, internalRequest.Imp) + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ + Bid: &sb.Bid[i], + BidType: mediaType, + }) + } + } + return bidResponse, nil + +} + +func getBidType(impId string, imps []openrtb.Imp) openrtb_ext.BidType { + bidType := openrtb_ext.BidTypeBanner + for _, imp := range imps { + if imp.ID == impId { + if imp.Banner != nil { + break + } + if imp.Video != nil { + bidType = openrtb_ext.BidTypeVideo + break + } + if imp.Native != nil { + bidType = openrtb_ext.BidTypeNative + break + } + + } + } + return bidType +} diff --git a/adapters/yeahmobi/yeahmobi_test.go b/adapters/yeahmobi/yeahmobi_test.go new file mode 100644 index 00000000000..51b4cf13533 --- /dev/null +++ b/adapters/yeahmobi/yeahmobi_test.go @@ -0,0 +1,10 @@ +package yeahmobi + +import ( + "github.com/prebid/prebid-server/adapters/adapterstest" + "testing" +) + +func TestJsonSamples(t *testing.T) { + adapterstest.RunJSONBidderTest(t, "yeahmobitest", NewYeahmobiBidder("https://{{.Host}}/prebid/bid")) +} diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json new file mode 100644 index 00000000000..72c5c4c70b9 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json @@ -0,0 +1,85 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.700, + "adm": "some-ads", + "crid": "crid_10", + "h": 90, + "w": 728 + }] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.7, + "adm": "some-ads", + "crid": "crid_10", + "w": 728, + "h": 90 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/params/race/banner.json b/adapters/yeahmobi/yeahmobitest/params/race/banner.json new file mode 100644 index 00000000000..7dc4c43515e --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/params/race/banner.json @@ -0,0 +1,5 @@ +{ + "pubId": "222", + "zoneId": "sin" + } + \ No newline at end of file diff --git a/config/config.go b/config/config.go index 2ea91bfa24b..b02288d76f4 100644 --- a/config/config.go +++ b/config/config.go @@ -747,6 +747,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.yieldmo.endpoint", "https://ads.yieldmo.com/exchange/prebid-server") v.SetDefault("adapters.yieldone.endpoint", "https://y.one.impact-ad.jp/hbs_imp") v.SetDefault("adapters.zeroclickfraud.endpoint", "http://{{.Host}}/openrtb2?sid={{.SourceId}}") + v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") v.SetDefault("max_request_size", 1024*256) v.SetDefault("analytics.file.filename", "") diff --git a/exchange/adapter_map.go b/exchange/adapter_map.go index 698824c3fe2..7ade4796b88 100644 --- a/exchange/adapter_map.go +++ b/exchange/adapter_map.go @@ -2,6 +2,7 @@ package exchange import ( "fmt" + "github.com/prebid/prebid-server/adapters/yeahmobi" "net/http" "strings" @@ -142,6 +143,7 @@ func newAdapterMap(client *http.Client, cfg *config.Configuration, infos adapter openrtb_ext.BidderYieldmo: yieldmo.NewYieldmoBidder(cfg.Adapters[string(openrtb_ext.BidderYieldmo)].Endpoint), openrtb_ext.BidderYieldone: yieldone.NewYieldoneBidder(cfg.Adapters[string(openrtb_ext.BidderYieldone)].Endpoint), openrtb_ext.BidderZeroClickFraud: zeroclickfraud.NewZeroClickFraudBidder(cfg.Adapters[string(openrtb_ext.BidderZeroClickFraud)].Endpoint), + openrtb_ext.BidderYeahmobi: yeahmobi.NewYeahmobiBidder(cfg.Adapters[string(openrtb_ext.BidderYeahmobi)].Endpoint), } legacyBidders := map[openrtb_ext.BidderName]adapters.Adapter{ diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 5b0046ce096..72e9175d70b 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -85,6 +85,7 @@ const ( BidderYieldmo BidderName = "yieldmo" BidderYieldone BidderName = "yieldone" BidderZeroClickFraud BidderName = "zeroclickfraud" + BidderYeahmobi BidderName = "yeahmobi" ) // BidderMap stores all the valid OpenRTB 2.x Bidders in the project. This map *must not* be mutated. @@ -151,6 +152,7 @@ var BidderMap = map[string]BidderName{ "yieldmo": BidderYieldmo, "yieldone": BidderYieldone, "zeroclickfraud": BidderZeroClickFraud, + "yeahmobi": BidderYeahmobi, } // BidderList returns the values of the BidderMap diff --git a/openrtb_ext/imp_yeahmobi.go b/openrtb_ext/imp_yeahmobi.go new file mode 100644 index 00000000000..5eb7fd339b5 --- /dev/null +++ b/openrtb_ext/imp_yeahmobi.go @@ -0,0 +1,7 @@ +package openrtb_ext + +// ExtImpYeahmobi defines the contract for bidrequest.imp[i].ext.yeahmobi +type ExtImpYeahmobi struct { + PubId string `json:"pubId"` + ZoneId string `json:"zoneId"` +} diff --git a/static/bidder-info/yeahmobi.yaml b/static/bidder-info/yeahmobi.yaml new file mode 100644 index 00000000000..063b09d0f75 --- /dev/null +++ b/static/bidder-info/yeahmobi.yaml @@ -0,0 +1,8 @@ +maintainer: + email: "junping.zhao@yeahmobi.com" +capabilities: + app: + mediaTypes: + - banner + - video + - native \ No newline at end of file diff --git a/static/bidder-params/yeahmobi.json b/static/bidder-params/yeahmobi.json new file mode 100644 index 00000000000..fe26fa7255a --- /dev/null +++ b/static/bidder-params/yeahmobi.json @@ -0,0 +1,21 @@ + +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Yeahmobi Adapter Params", + "description": "A schema which validates params accepted by the Yeahmobi adapter", + + "type": "object", + "properties": { + "pubId": { + "type": "string", + "description": "Publisher ID", + "minLength": 1 + }, + "zoneId": { + "type": "string", + "description": "Zone Id", + "minLength": 1 + } + }, + "required": ["pubId", "zoneId"] +} \ No newline at end of file From b9197127264c75b2386f26f0531799aff1d15484 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Wed, 29 Apr 2020 11:09:27 +0800 Subject: [PATCH 02/11] endpoint --- adapters/yeahmobi/yeahmobi.go | 6 ++---- .../yeahmobitest/exemplary/simple-banner.json | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index 6d689637c87..c8b566d864b 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -38,15 +38,13 @@ func (adapter *YeahmobiAdapter) MakeRequests(request *openrtb.BidRequest, reqInf return adapterRequests, errors } -// Update the request object to include custom value -// site.id func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) { var errs []error yeahmobiExt, errs := getYeahmobiExt(request) if yeahmobiExt == nil { - glog.Fatal("invalid ExtImpYeahmobi value") + glog.Fatal("Invalid ExtImpYeahmobi value") return nil, errs } @@ -97,7 +95,7 @@ func getYeahmobiExt(request *openrtb.BidRequest) (*openrtb_ext.ExtImpYeahmobi, [ func (adapter *YeahmobiAdapter) getEndpoint(ext *openrtb_ext.ExtImpYeahmobi) (string, error) { if ext.ZoneId == "" { - return "", errors.New("param of zone not config") + return "", errors.New("param of zoneId not config") } return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + ext.ZoneId + "-bid.yeahtargeter.com"}) diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json index 72c5c4c70b9..7499a7874e7 100644 --- a/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-banner.json @@ -49,11 +49,9 @@ "bid": [{ "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", "impid": "test-imp-id", - "price": 0.700, + "price": 1.2, "adm": "some-ads", - "crid": "crid_10", - "h": 90, - "w": 728 + "crid": "crid_testid" }] } ], @@ -71,11 +69,9 @@ "bid": { "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", "impid": "test-imp-id", - "price": 0.7, + "price": 1.2, "adm": "some-ads", - "crid": "crid_10", - "w": 728, - "h": 90 + "crid": "crid_testid" }, "type": "banner" } From 751a589cb3c0f1f9796245f733ce6f454eb5c89e Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Wed, 29 Apr 2020 17:33:59 +0800 Subject: [PATCH 03/11] native request transform --- adapters/yeahmobi/yeahmobi.go | 17 +++++++++++++++++ config/config.go | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index c8b566d864b..c0ec14bab66 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -50,6 +50,8 @@ func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapt endPoint, err := adapter.getEndpoint(yeahmobiExt) + transform(request) + if err != nil { return nil, append(errs, err) } @@ -70,6 +72,21 @@ func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapt }, errs } +func transform(request *openrtb.BidRequest) { + for i, imp := range request.Imp { + if imp.Native != nil { + var nativeRequest map[string]interface{} + err := json.Unmarshal([]byte(request.Imp[i].Native.Request), &nativeRequest) + if err == nil { + if nativeRequest["native"] != nil { + continue + } + request.Imp[i].Native.Request = "{\"native\":" + request.Imp[i].Native.Request + "}" + } + } + } +} + func getYeahmobiExt(request *openrtb.BidRequest) (*openrtb_ext.ExtImpYeahmobi, []error) { var extImpYeahmobi openrtb_ext.ExtImpYeahmobi var errs []error diff --git a/config/config.go b/config/config.go index b02288d76f4..03923fe1da8 100644 --- a/config/config.go +++ b/config/config.go @@ -747,7 +747,8 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.yieldmo.endpoint", "https://ads.yieldmo.com/exchange/prebid-server") v.SetDefault("adapters.yieldone.endpoint", "https://y.one.impact-ad.jp/hbs_imp") v.SetDefault("adapters.zeroclickfraud.endpoint", "http://{{.Host}}/openrtb2?sid={{.SourceId}}") - v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") + //v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") + v.SetDefault("adapters.yeahmobi.endpoint", "http://10.101.35.49:9090/prebid") v.SetDefault("max_request_size", 1024*256) v.SetDefault("analytics.file.filename", "") From e0a09c516d690c3f0b82f15b6d6a550c11f414e7 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Wed, 29 Apr 2020 17:35:11 +0800 Subject: [PATCH 04/11] remove debug code --- config/config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 03923fe1da8..b02288d76f4 100644 --- a/config/config.go +++ b/config/config.go @@ -747,8 +747,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.yieldmo.endpoint", "https://ads.yieldmo.com/exchange/prebid-server") v.SetDefault("adapters.yieldone.endpoint", "https://y.one.impact-ad.jp/hbs_imp") v.SetDefault("adapters.zeroclickfraud.endpoint", "http://{{.Host}}/openrtb2?sid={{.SourceId}}") - //v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") - v.SetDefault("adapters.yeahmobi.endpoint", "http://10.101.35.49:9090/prebid") + v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") v.SetDefault("max_request_size", 1024*256) v.SetDefault("analytics.file.filename", "") From ebd21bffcde6c30b82d7f94e33fc05e36c4272f6 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Wed, 29 Apr 2020 17:53:42 +0800 Subject: [PATCH 05/11] adapter without syncers --- adapters/yeahmobi/params_test.go | 2 +- openrtb_ext/bidders.go | 2 +- openrtb_ext/imp_yeahmobi.go | 2 +- usersync/usersyncers/syncer_test.go | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/adapters/yeahmobi/params_test.go b/adapters/yeahmobi/params_test.go index 0d8c0a567be..997bf93a53f 100644 --- a/adapters/yeahmobi/params_test.go +++ b/adapters/yeahmobi/params_test.go @@ -44,4 +44,4 @@ var invalidParams = []string{ `{"pubId": 123, "zoneId": "sin"}`, `{"pubId": "", "zoneId": "iad"}`, `{"pubId": "11233", "zoneId": ""}`, -} \ No newline at end of file +} diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 72e9175d70b..9d1c3c0343e 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -85,7 +85,7 @@ const ( BidderYieldmo BidderName = "yieldmo" BidderYieldone BidderName = "yieldone" BidderZeroClickFraud BidderName = "zeroclickfraud" - BidderYeahmobi BidderName = "yeahmobi" + BidderYeahmobi BidderName = "yeahmobi" ) // BidderMap stores all the valid OpenRTB 2.x Bidders in the project. This map *must not* be mutated. diff --git a/openrtb_ext/imp_yeahmobi.go b/openrtb_ext/imp_yeahmobi.go index 5eb7fd339b5..6c1c045d705 100644 --- a/openrtb_ext/imp_yeahmobi.go +++ b/openrtb_ext/imp_yeahmobi.go @@ -3,5 +3,5 @@ package openrtb_ext // ExtImpYeahmobi defines the contract for bidrequest.imp[i].ext.yeahmobi type ExtImpYeahmobi struct { PubId string `json:"pubId"` - ZoneId string `json:"zoneId"` + ZoneId string `json:"zoneId"` } diff --git a/usersync/usersyncers/syncer_test.go b/usersync/usersyncers/syncer_test.go index c84b3d9b6b9..5d2f5d9ab75 100644 --- a/usersync/usersyncers/syncer_test.go +++ b/usersync/usersyncers/syncer_test.go @@ -79,6 +79,7 @@ func TestNewSyncerMap(t *testing.T) { openrtb_ext.BidderKubient: true, openrtb_ext.BidderPubnative: true, openrtb_ext.BidderKidoz: true, + openrtb_ext.BidderYeahmobi: true, } for bidder, config := range cfg.Adapters { From 43e0781a3e0dcf29126de0fbffe2f1e412523234 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Thu, 7 May 2020 17:11:06 +0800 Subject: [PATCH 06/11] native test & resolve some issues --- adapters/yeahmobi/yeahmobi.go | 18 +++-- .../yeahmobitest/exemplary/simple-native.json | 76 +++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index c0ec14bab66..0d3bcc91061 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -11,6 +11,7 @@ import ( "github.com/prebid/prebid-server/macros" "github.com/prebid/prebid-server/openrtb_ext" "net/http" + "net/url" "text/template" ) @@ -21,7 +22,7 @@ type YeahmobiAdapter struct { func NewYeahmobiBidder(endpointTemplate string) adapters.Bidder { tpl, err := template.New("endpointTemplate").Parse(endpointTemplate) if err != nil { - glog.Fatal("Unknow url template") + glog.Fatal("Unable parse url template %s", err.Error()) return nil } return &YeahmobiAdapter{EndpointTemplate: *tpl} @@ -30,12 +31,12 @@ func NewYeahmobiBidder(endpointTemplate string) adapters.Bidder { func (adapter *YeahmobiAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var adapterRequests []*adapters.RequestData - adapterRequest, errors := adapter.makeRequest(request) - if adapterRequest != nil { + adapterRequest, errs := adapter.makeRequest(request) + if errs != nil { adapterRequests = append(adapterRequests, adapterRequest) } - return adapterRequests, errors + return adapterRequests, errs } func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) { @@ -78,10 +79,13 @@ func transform(request *openrtb.BidRequest) { var nativeRequest map[string]interface{} err := json.Unmarshal([]byte(request.Imp[i].Native.Request), &nativeRequest) if err == nil { - if nativeRequest["native"] != nil { + _, exists := nativeRequest["native"] + if exists { continue } - request.Imp[i].Native.Request = "{\"native\":" + request.Imp[i].Native.Request + "}" + nativeCopy := *request.Imp[i].Native; + nativeCopy.Request = "{\"native\":" + request.Imp[i].Native.Request + "}" + request.Imp[i].Native = &nativeCopy } } } @@ -115,7 +119,7 @@ func (adapter *YeahmobiAdapter) getEndpoint(ext *openrtb_ext.ExtImpYeahmobi) (st return "", errors.New("param of zoneId not config") } - return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + ext.ZoneId + "-bid.yeahtargeter.com"}) + return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + url.QueryEscape(ext.ZoneId) + "-bid.yeahtargeter.com"}) } // MakeBids make the bids for the bid response. diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json new file mode 100644 index 00000000000..ed86d2199b8 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json @@ -0,0 +1,76 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + "httpcalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", + "ver": "1.1" + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + + }, + "type": "native" + } + ] + } + ] +} From 65e5db27955035d981f575946d5647c9de2ee74b Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Thu, 7 May 2020 18:56:13 +0800 Subject: [PATCH 07/11] native json test --- adapters/yeahmobi/yeahmobi.go | 7 +++---- .../yeahmobi/yeahmobitest/exemplary/simple-native.json | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index 0d3bcc91061..adeef637379 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -22,7 +22,7 @@ type YeahmobiAdapter struct { func NewYeahmobiBidder(endpointTemplate string) adapters.Bidder { tpl, err := template.New("endpointTemplate").Parse(endpointTemplate) if err != nil { - glog.Fatal("Unable parse url template %s", err.Error()) + glog.Fatal("Unable parse url template err:" + err.Error()) return nil } return &YeahmobiAdapter{EndpointTemplate: *tpl} @@ -32,7 +32,7 @@ func (adapter *YeahmobiAdapter) MakeRequests(request *openrtb.BidRequest, reqInf var adapterRequests []*adapters.RequestData adapterRequest, errs := adapter.makeRequest(request) - if errs != nil { + if errs == nil { adapterRequests = append(adapterRequests, adapterRequest) } @@ -83,7 +83,7 @@ func transform(request *openrtb.BidRequest) { if exists { continue } - nativeCopy := *request.Imp[i].Native; + nativeCopy := *request.Imp[i].Native nativeCopy.Request = "{\"native\":" + request.Imp[i].Native.Request + "}" request.Imp[i].Native = &nativeCopy } @@ -118,7 +118,6 @@ func (adapter *YeahmobiAdapter) getEndpoint(ext *openrtb_ext.ExtImpYeahmobi) (st if ext.ZoneId == "" { return "", errors.New("param of zoneId not config") } - return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + url.QueryEscape(ext.ZoneId) + "-bid.yeahtargeter.com"}) } diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json index ed86d2199b8..c2e6dc8d209 100644 --- a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json @@ -28,7 +28,13 @@ "id": "test-imp-id", "native": { "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", - "ver": "1.1" + "ver": "1.2" + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } } } ] From 59d226d399bd75e1265b4a1c51f05889175a0032 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Fri, 8 May 2020 11:11:59 +0800 Subject: [PATCH 08/11] optimized code --- adapters/yeahmobi/yeahmobi.go | 6 +----- config/config.go | 2 +- exchange/adapter_map.go | 4 ++-- openrtb_ext/bidders.go | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index adeef637379..66c3dc7c062 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -2,7 +2,6 @@ package yeahmobi import ( "encoding/json" - "errors" "fmt" "github.com/golang/glog" "github.com/mxmCherry/openrtb" @@ -107,7 +106,7 @@ func getYeahmobiExt(request *openrtb.BidRequest) (*openrtb_ext.ExtImpYeahmobi, [ errs = append(errs, err) continue } - + break } return &extImpYeahmobi, errs @@ -115,9 +114,6 @@ func getYeahmobiExt(request *openrtb.BidRequest) (*openrtb_ext.ExtImpYeahmobi, [ } func (adapter *YeahmobiAdapter) getEndpoint(ext *openrtb_ext.ExtImpYeahmobi) (string, error) { - if ext.ZoneId == "" { - return "", errors.New("param of zoneId not config") - } return macros.ResolveMacros(adapter.EndpointTemplate, macros.EndpointTemplateParams{Host: "gw-" + url.QueryEscape(ext.ZoneId) + "-bid.yeahtargeter.com"}) } diff --git a/config/config.go b/config/config.go index b02288d76f4..33853d86a2d 100644 --- a/config/config.go +++ b/config/config.go @@ -744,10 +744,10 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.verizonmedia.disabled", true) v.SetDefault("adapters.visx.endpoint", "https://t.visx.net/s2s_bid?wrapperType=s2s_prebid_standard") v.SetDefault("adapters.vrtcal.endpoint", "http://rtb.vrtcal.com/bidder_prebid.vap?ssp=1804") + v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") v.SetDefault("adapters.yieldmo.endpoint", "https://ads.yieldmo.com/exchange/prebid-server") v.SetDefault("adapters.yieldone.endpoint", "https://y.one.impact-ad.jp/hbs_imp") v.SetDefault("adapters.zeroclickfraud.endpoint", "http://{{.Host}}/openrtb2?sid={{.SourceId}}") - v.SetDefault("adapters.yeahmobi.endpoint", "https://{{.Host}}/prebid/bid") v.SetDefault("max_request_size", 1024*256) v.SetDefault("analytics.file.filename", "") diff --git a/exchange/adapter_map.go b/exchange/adapter_map.go index 7ade4796b88..46a4fe4b09d 100644 --- a/exchange/adapter_map.go +++ b/exchange/adapter_map.go @@ -2,7 +2,6 @@ package exchange import ( "fmt" - "github.com/prebid/prebid-server/adapters/yeahmobi" "net/http" "strings" @@ -65,6 +64,7 @@ import ( "github.com/prebid/prebid-server/adapters/verizonmedia" "github.com/prebid/prebid-server/adapters/visx" "github.com/prebid/prebid-server/adapters/vrtcal" + "github.com/prebid/prebid-server/adapters/yeahmobi" "github.com/prebid/prebid-server/adapters/yieldmo" "github.com/prebid/prebid-server/adapters/yieldone" "github.com/prebid/prebid-server/adapters/zeroclickfraud" @@ -140,10 +140,10 @@ func newAdapterMap(client *http.Client, cfg *config.Configuration, infos adapter openrtb_ext.BidderVerizonMedia: verizonmedia.NewVerizonMediaBidder(client, cfg.Adapters[string(openrtb_ext.BidderVerizonMedia)].Endpoint), openrtb_ext.BidderVisx: visx.NewVisxBidder(cfg.Adapters[string(openrtb_ext.BidderVisx)].Endpoint), openrtb_ext.BidderVrtcal: vrtcal.NewVrtcalBidder(cfg.Adapters[string(openrtb_ext.BidderVrtcal)].Endpoint), + openrtb_ext.BidderYeahmobi: yeahmobi.NewYeahmobiBidder(cfg.Adapters[string(openrtb_ext.BidderYeahmobi)].Endpoint), openrtb_ext.BidderYieldmo: yieldmo.NewYieldmoBidder(cfg.Adapters[string(openrtb_ext.BidderYieldmo)].Endpoint), openrtb_ext.BidderYieldone: yieldone.NewYieldoneBidder(cfg.Adapters[string(openrtb_ext.BidderYieldone)].Endpoint), openrtb_ext.BidderZeroClickFraud: zeroclickfraud.NewZeroClickFraudBidder(cfg.Adapters[string(openrtb_ext.BidderZeroClickFraud)].Endpoint), - openrtb_ext.BidderYeahmobi: yeahmobi.NewYeahmobiBidder(cfg.Adapters[string(openrtb_ext.BidderYeahmobi)].Endpoint), } legacyBidders := map[openrtb_ext.BidderName]adapters.Adapter{ diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 9d1c3c0343e..fd1555bb3ba 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -82,10 +82,10 @@ const ( BidderVerizonMedia BidderName = "verizonmedia" BidderVisx BidderName = "visx" BidderVrtcal BidderName = "vrtcal" + BidderYeahmobi BidderName = "yeahmobi" BidderYieldmo BidderName = "yieldmo" BidderYieldone BidderName = "yieldone" BidderZeroClickFraud BidderName = "zeroclickfraud" - BidderYeahmobi BidderName = "yeahmobi" ) // BidderMap stores all the valid OpenRTB 2.x Bidders in the project. This map *must not* be mutated. @@ -149,10 +149,10 @@ var BidderMap = map[string]BidderName{ "verizonmedia": BidderVerizonMedia, "visx": BidderVisx, "vrtcal": BidderVrtcal, + "yeahmobi": BidderYeahmobi, "yieldmo": BidderYieldmo, "yieldone": BidderYieldone, "zeroclickfraud": BidderZeroClickFraud, - "yeahmobi": BidderYeahmobi, } // BidderList returns the values of the BidderMap From 0558b6ea36a9671600a78361835aa13a9929aab0 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Fri, 8 May 2020 16:10:26 +0800 Subject: [PATCH 09/11] add more test cases --- adapters/yeahmobi/yeahmobi.go | 7 +- .../yeahmobitest/exemplary/no-bid.json | 51 +++++++++++ .../exemplary/simple-native-1.1.json | 82 +++++++++++++++++ .../yeahmobitest/exemplary/simple-video.json | 89 +++++++++++++++++++ .../supplemental/bad_imp_ext.json | 21 +++++ .../supplemental/bad_imp_ext_bidder.json | 23 +++++ .../supplemental/bad_response.json | 55 ++++++++++++ .../yeahmobitest/supplemental/status_400.json | 55 ++++++++++++ .../yeahmobitest/supplemental/status_500.json | 55 ++++++++++++ 9 files changed, 433 insertions(+), 5 deletions(-) create mode 100644 adapters/yeahmobi/yeahmobitest/exemplary/no-bid.json create mode 100644 adapters/yeahmobi/yeahmobitest/exemplary/simple-native-1.1.json create mode 100644 adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json create mode 100644 adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext.json create mode 100644 adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext_bidder.json create mode 100644 adapters/yeahmobi/yeahmobitest/supplemental/bad_response.json create mode 100644 adapters/yeahmobi/yeahmobitest/supplemental/status_400.json create mode 100644 adapters/yeahmobi/yeahmobitest/supplemental/status_500.json diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index 66c3dc7c062..fa74adc008c 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -47,18 +47,15 @@ func (adapter *YeahmobiAdapter) makeRequest(request *openrtb.BidRequest) (*adapt glog.Fatal("Invalid ExtImpYeahmobi value") return nil, errs } - endPoint, err := adapter.getEndpoint(yeahmobiExt) - - transform(request) - if err != nil { return nil, append(errs, err) } + transform(request) reqBody, err := json.Marshal(request) if err != nil { - errs = append(errs, err) + return nil, append(errs, err) } headers := http.Header{} diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/no-bid.json b/adapters/yeahmobi/yeahmobitest/exemplary/no-bid.json new file mode 100644 index 00000000000..723cc40e664 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/exemplary/no-bid.json @@ -0,0 +1,51 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 204, + "body": {} + } + } + ], + + "expectedBidResponses": [] + +} diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native-1.1.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native-1.1.json new file mode 100644 index 00000000000..7e93eb68246 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native-1.1.json @@ -0,0 +1,82 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + "httpcalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + + }, + "type": "native" + } + ] + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json new file mode 100644 index 00000000000..b040d31b5f6 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json @@ -0,0 +1,89 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "video": { + "w": 300, + "h": 250, + "mimes": [ + "video/mp4" + ] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "video": { + "w": 300, + "h": 250, + "mimes": [ + "video/mp4" + ] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some-ads", + "crid": "crid_testid" + }] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some-ads", + "crid": "crid_testid" + }, + "type": "video" + } + ] + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext.json b/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext.json new file mode 100644 index 00000000000..444e1e7a8d8 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext.json @@ -0,0 +1,21 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": "aaa" + } + ] + }, + + "expectedMakeRequestsErrors": [ + { + "value": "json: cannot unmarshal string into Go value of type adapters.ExtImpBidder", + "comparison": "literal" + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext_bidder.json b/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext_bidder.json new file mode 100644 index 00000000000..89697d37141 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/supplemental/bad_imp_ext_bidder.json @@ -0,0 +1,23 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": "aa" + } + } + ] + }, + + "expectedMakeRequestsErrors": [ + { + "value": "json: cannot unmarshal string into Go value of type openrtb_ext.ExtImpYeahmobi", + "comparison": "literal" + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/supplemental/bad_response.json b/adapters/yeahmobi/yeahmobitest/supplemental/bad_response.json new file mode 100644 index 00000000000..22939466309 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/supplemental/bad_response.json @@ -0,0 +1,55 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": "{\"id\":test-request-id" + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "json: cannot unmarshal string into Go value of type openrtb.BidResponse" + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/supplemental/status_400.json b/adapters/yeahmobi/yeahmobitest/supplemental/status_400.json new file mode 100644 index 00000000000..74bb869218c --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/supplemental/status_400.json @@ -0,0 +1,55 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 400, + "body": {} + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "Unexpected status code: 400." + } + ] +} diff --git a/adapters/yeahmobi/yeahmobitest/supplemental/status_500.json b/adapters/yeahmobi/yeahmobitest/supplemental/status_500.json new file mode 100644 index 00000000000..2d3264de897 --- /dev/null +++ b/adapters/yeahmobi/yeahmobitest/supplemental/status_500.json @@ -0,0 +1,55 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://gw-sin-bid.yeahtargeter.com/prebid/bid", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 300, "h": 50}] + }, + "ext": { + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ] + } + }, + "mockResponse": { + "status": 500, + "body": {} + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "Unexpected status code: 500." + } + ] +} From 7bd0db0d1d874e3639178edf2fbd61aa59fcaed3 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Tue, 12 May 2020 11:19:42 +0800 Subject: [PATCH 10/11] optimized code of native request transform --- adapters/yeahmobi/yeahmobi.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index fa74adc008c..f1891e132bd 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -73,15 +73,23 @@ func transform(request *openrtb.BidRequest) { for i, imp := range request.Imp { if imp.Native != nil { var nativeRequest map[string]interface{} + nativeCopyRequest := make(map[string]interface{}) err := json.Unmarshal([]byte(request.Imp[i].Native.Request), &nativeRequest) + //just ignore the bad native request if err == nil { _, exists := nativeRequest["native"] if exists { continue } - nativeCopy := *request.Imp[i].Native - nativeCopy.Request = "{\"native\":" + request.Imp[i].Native.Request + "}" - request.Imp[i].Native = &nativeCopy + + nativeCopyRequest["native"] = nativeRequest + nativeReqByte, err := json.Marshal(nativeCopyRequest) + //just ignore the bad native request + if err != nil { + continue + } + + request.Imp[i].Native.Request = string(nativeReqByte) } } } From 29bda25ea72a4e157f30e3a3632cd78379b31608 Mon Sep 17 00:00:00 2001 From: "junping.zhao" Date: Tue, 12 May 2020 11:37:58 +0800 Subject: [PATCH 11/11] fix test case --- adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json index c2e6dc8d209..894e835bc07 100644 --- a/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-native.json @@ -27,7 +27,7 @@ { "id": "test-imp-id", "native": { - "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", + "request": "{\"native\":{\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"img\":{\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"],\"type\":3,\"wmin\":128},\"required\":1},{\"data\":{\"len\":120,\"type\":2},\"id\":7,\"required\":1}],\"context\":1,\"plcmtcnt\":1,\"plcmttype\":4,\"ver\":\"1.2\"}}", "ver": "1.2" }, "ext": {