diff --git a/adapters/metax/metax.go b/adapters/metax/metax.go new file mode 100644 index 00000000000..d10c426434c --- /dev/null +++ b/adapters/metax/metax.go @@ -0,0 +1,194 @@ +package metax + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" + "strconv" + "text/template" + + "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v2/adapters" + "github.com/prebid/prebid-server/v2/config" + "github.com/prebid/prebid-server/v2/errortypes" + "github.com/prebid/prebid-server/v2/macros" + "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/ptrutil" +) + +type adapter struct { + template *template.Template +} + +func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + errs := make([]error, 0, len(request.Imp)) + + // split impressions + reqDatas := make([]*adapters.RequestData, 0, len(request.Imp)) + for _, imp := range request.Imp { + metaxExt, err := parseBidderExt(&imp) + if err != nil { + errs = append(errs, err) + continue + } + + if err := preprocessImp(&imp); err != nil { + errs = append(errs, err) + continue + } + + endpoint, err := a.getEndpoint(metaxExt) + if err != nil { + errs = append(errs, err) + continue + } + + requestCopy := *request + requestCopy.Imp = []openrtb2.Imp{imp} + reqJSON, err := json.Marshal(requestCopy) + if err != nil { + errs = append(errs, err) + return nil, errs + } + + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + reqDatas = append(reqDatas, &adapters.RequestData{ + Method: "POST", + Uri: endpoint, + Body: reqJSON, + Headers: headers, + ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp), + }) + } + + return reqDatas, errs +} + +func (a *adapter) MakeBids(bidReq *openrtb2.BidRequest, reqData *adapters.RequestData, respData *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if adapters.IsResponseStatusCodeNoContent(respData) { + return nil, nil + } + + if err := adapters.CheckResponseStatusCodeForErrors(respData); err != nil { + return nil, []error{err} + } + + var bidResp openrtb2.BidResponse + if err := json.Unmarshal(respData.Body, &bidResp); err != nil { + return nil, []error{err} + } + + // additional no content check + if len(bidResp.SeatBid) == 0 || len(bidResp.SeatBid[0].Bid) == 0 { + return nil, nil + } + + resp := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid[0].Bid)) + if len(bidResp.Cur) != 0 { + resp.Currency = bidResp.Cur + } + for _, sb := range bidResp.SeatBid { + for i := range sb.Bid { + bid := &sb.Bid[i] + bidType, err := getBidType(bid) + if err != nil { + return nil, []error{err} + } + resp.Bids = append(resp.Bids, &adapters.TypedBid{ + Bid: bid, + BidType: bidType, + }) + } + } + return resp, nil +} + +func (a *adapter) getEndpoint(ext *openrtb_ext.ExtImpMetaX) (string, error) { + params := macros.EndpointTemplateParams{ + PublisherID: strconv.Itoa(ext.PublisherID), + AdUnit: strconv.Itoa(ext.Adunit), + } + return macros.ResolveMacros(a.template, params) +} + +func parseBidderExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpMetaX, error) { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { + return nil, err + } + + var metaxExt openrtb_ext.ExtImpMetaX + if err := json.Unmarshal(bidderExt.Bidder, &metaxExt); err != nil { + return nil, errors.New("Wrong MetaX bidder ext") + } + + return &metaxExt, nil +} + +func preprocessImp(imp *openrtb2.Imp) error { + if imp == nil { + return errors.New("imp is nil") + } + + if imp.Banner != nil { + imp.Banner = assignBannerSize(imp.Banner) + } + + return nil +} + +func assignBannerSize(banner *openrtb2.Banner) *openrtb2.Banner { + if banner.W != nil && banner.H != nil { + return banner + } + + if len(banner.Format) == 0 { + return banner + } + + return assignBannerWidthAndHeight(banner, banner.Format[0].W, banner.Format[0].H) +} + +func assignBannerWidthAndHeight(banner *openrtb2.Banner, w, h int64) *openrtb2.Banner { + bannerCopy := *banner + bannerCopy.W = ptrutil.ToPtr(w) + bannerCopy.H = ptrutil.ToPtr(h) + return &bannerCopy +} + +func getBidType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { + switch bid.MType { + case openrtb2.MarkupBanner: + return openrtb_ext.BidTypeBanner, nil + case openrtb2.MarkupVideo: + return openrtb_ext.BidTypeVideo, nil + case openrtb2.MarkupNative: + return openrtb_ext.BidTypeNative, nil + case openrtb2.MarkupAudio: + return openrtb_ext.BidTypeAudio, nil + default: + return "", &errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unsupported MType %d", bid.MType), + } + } +} + +// Builder builds a new instance of the MetaX adapter for the given bidder with the given config. +func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { + if config.Endpoint == "" { + return nil, errors.New("endpoint is empty") + } + + templ, err := template.New("endpointTemplate").Parse(config.Endpoint) + if err != nil { + return nil, fmt.Errorf("unable to parse endpoint: %v", err) + } + + bidder := &adapter{ + template: templ, + } + return bidder, nil +} diff --git a/adapters/metax/metax_test.go b/adapters/metax/metax_test.go new file mode 100644 index 00000000000..765f3004c81 --- /dev/null +++ b/adapters/metax/metax_test.go @@ -0,0 +1,214 @@ +package metax + +import ( + "encoding/json" + "testing" + + "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v2/adapters" + "github.com/prebid/prebid-server/v2/adapters/adapterstest" + "github.com/prebid/prebid-server/v2/config" + "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/ptrutil" + "github.com/stretchr/testify/assert" +) + +func TestJsonSamples(t *testing.T) { + bidder, buildErr := Builder( + openrtb_ext.BidderMetaX, + config.Adapter{ + Endpoint: "https://hb.metaxads.com/prebid?sid={{.PublisherID}}&adunit={{.AdUnit}}&source=prebid-server", + }, + config.Server{ + ExternalUrl: "http://hosturl.com", + GvlID: 1301, + DataCenter: "2", + }, + ) + + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } + + adapterstest.RunJSONBidderTest(t, "metaxtest", bidder) +} + +func TestParseBidderExt(t *testing.T) { + data := ` +{ + "bidder": { + "publisherId": 1000, + "adunit": 200 + } +}` + imp := &openrtb2.Imp{ + Ext: json.RawMessage([]byte(data)), + } + metaxExt, err := parseBidderExt(imp) + assert.Nil(t, err) + assert.Equal(t, 1000, metaxExt.PublisherID) + assert.Equal(t, 200, metaxExt.Adunit) +} + +func TestPreprocessImp(t *testing.T) { + assert.NotNil(t, preprocessImp(nil)) + + imp1 := &openrtb2.Imp{ + Banner: &openrtb2.Banner{ + Format: []openrtb2.Format{ + {W: 300, H: 250}, + {W: 728, H: 90}, + }, + }, + } + err1 := preprocessImp(imp1) + assert.Nil(t, err1) + + imp2 := &openrtb2.Imp{ + Video: &openrtb2.Video{ + W: ptrutil.ToPtr(int64(1920)), + H: ptrutil.ToPtr(int64(1920)), + }, + } + err2 := preprocessImp(imp2) + assert.Nil(t, err2) +} + +func TestAssignBannerSize(t *testing.T) { + b1 := &openrtb2.Banner{ + Format: []openrtb2.Format{ + {W: 300, H: 250}, + {W: 728, H: 90}, + }, + } + b1n := assignBannerSize(b1) + assert.Equal(t, b1n.W, ptrutil.ToPtr(int64(300))) + assert.Equal(t, b1n.H, ptrutil.ToPtr(int64(250))) + assert.NotSame(t, b1, b1n) + + b2 := &openrtb2.Banner{ + Format: []openrtb2.Format{ + {W: 300, H: 250}, + {W: 728, H: 90}, + }, + W: ptrutil.ToPtr(int64(336)), + H: ptrutil.ToPtr(int64(280)), + } + b2n := assignBannerSize(b2) + assert.Equal(t, b2n.W, ptrutil.ToPtr(int64(336))) + assert.Equal(t, b2n.H, ptrutil.ToPtr(int64(280))) + assert.Same(t, b2, b2n) + + b3 := &openrtb2.Banner{ + W: ptrutil.ToPtr(int64(336)), + H: ptrutil.ToPtr(int64(280)), + } + b3n := assignBannerSize(b3) + assert.Equal(t, b3n.W, ptrutil.ToPtr(int64(336))) + assert.Equal(t, b3n.H, ptrutil.ToPtr(int64(280))) + assert.Same(t, b3, b3n) + + b4 := &openrtb2.Banner{ + Format: []openrtb2.Format{ + {W: 300, H: 250}, + {W: 728, H: 90}, + }, + W: ptrutil.ToPtr(int64(336)), + } + b4n := assignBannerSize(b4) + assert.Equal(t, b4n.W, ptrutil.ToPtr(int64(300))) + assert.Equal(t, b4n.H, ptrutil.ToPtr(int64(250))) + assert.NotSame(t, b4, b4n) + + b5 := &openrtb2.Banner{} + b5n := assignBannerSize(b5) + assert.Nil(t, b5n.W) + assert.Nil(t, b5n.H) + assert.Same(t, b5, b5n) +} + +func TestGetBidType(t *testing.T) { + tests := []struct { + bid *openrtb2.Bid + bidtype openrtb_ext.BidType + }{ + {&openrtb2.Bid{AdM: "", MType: openrtb2.MarkupBanner}, openrtb_ext.BidTypeBanner}, + {&openrtb2.Bid{AdM: "", MType: openrtb2.MarkupVideo}, openrtb_ext.BidTypeVideo}, + {&openrtb2.Bid{AdM: "", MType: openrtb2.MarkupNative}, openrtb_ext.BidTypeNative}, + {&openrtb2.Bid{AdM: "", MType: openrtb2.MarkupAudio}, openrtb_ext.BidTypeAudio}, + {&openrtb2.Bid{AdM: "", MType: 0}, ""}, + } + + for _, test := range tests { + bidType, err := getBidType(test.bid) + assert.Equal(t, test.bidtype, bidType) + if bidType == "" { + assert.NotNil(t, err) + } + } +} + +func TestBuilder(t *testing.T) { + serverCfg := config.Server{} + + cfg1 := config.Adapter{Endpoint: "https://hb.metaxads.com/prebid"} + builder1, err1 := Builder("test", cfg1, serverCfg) + assert.NotNil(t, builder1) + assert.Nil(t, err1) + + // empty endpoint + cfg2 := config.Adapter{Endpoint: ""} + builder2, err2 := Builder("test2", cfg2, serverCfg) + assert.Nil(t, builder2) + assert.NotNil(t, err2) + + // invalid endpoint + cfg3 := config.Adapter{Endpoint: "https://hb.metaxads.com/prebid?a={{}}"} + builder3, err3 := Builder("test3", cfg3, serverCfg) + assert.Nil(t, builder3) + assert.NotNil(t, err3) +} + +func TestMakeRequests(t *testing.T) { + builder1, _ := Builder("metax", config.Adapter{Endpoint: "https://hb.metaxads.com/prebid?sid={{.PublisherId}}"}, config.Server{}) + reqDatas1, err1 := builder1.MakeRequests(&openrtb2.BidRequest{ + Imp: []openrtb2.Imp{ + { + Ext: []byte(` + { + "bidder": { + "publisherId": 100, + "adunit": 2 + } + } + `), + }, + }, + Ext: []byte(`{invalid json}`), + }, &adapters.ExtraRequestInfo{}) + assert.Equal(t, 0, len(reqDatas1)) + assert.Equal(t, 1, len(err1)) + + builder2, _ := Builder( + "metax", + config.Adapter{Endpoint: "https://hb.metaxads.com/prebid?sid={{.PublisherID}}&adunit={{.AdUnit}}&source=prebid-server"}, + config.Server{}, + ) + reqDatas2, err2 := builder2.MakeRequests(&openrtb2.BidRequest{ + Imp: []openrtb2.Imp{ + { + Ext: []byte(` + { + "bidder": { + "publisherId": 100, + "adunit": 2 + } + } + `), + }, + }, + Ext: []byte(`{invalid json}`), + }, &adapters.ExtraRequestInfo{}) + assert.Equal(t, 0, len(reqDatas2)) + assert.Equal(t, 1, len(err2)) +} diff --git a/adapters/metax/metaxtest/exemplary/app-formats.json b/adapters/metax/metaxtest/exemplary/app-formats.json new file mode 100644 index 00000000000..013436f20bb --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/app-formats.json @@ -0,0 +1,156 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "native": { + "request": "{json string 1}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "native": { + "request": "{json string 1}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/metax/metaxtest/exemplary/app-imps.json b/adapters/metax/metaxtest/exemplary/app-imps.json new file mode 100644 index 00000000000..cc77a34baaf --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/app-imps.json @@ -0,0 +1,351 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "imp-1", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + }, + { + "id": "imp-2", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + }, + { + "id": "imp-3", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "imp-1", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "imp-1" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "bid-1", + "impid": "imp-1", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + } + ] + } + ] + } + } + }, + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "imp-2", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "imp-2" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "bid-2", + "impid": "imp-2", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + } + ] + } + ] + } + } + }, + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "imp-3", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "imp-3" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "bid-3", + "impid": "imp-3", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "bid-1", + "impid": "imp-1", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + }, + "type": "video" + } + ] + }, + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "bid-2", + "impid": "imp-2", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + }, + "type": "video" + } + ] + }, + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "bid-3", + "impid": "imp-3", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} + + + diff --git a/adapters/metax/metaxtest/exemplary/no-bid.json b/adapters/metax/metaxtest/exemplary/no-bid.json new file mode 100644 index 00000000000..3eb1b79a2eb --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/no-bid.json @@ -0,0 +1,92 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 204, + "body": { + } + } + } + ], + "expectedBidResponses": [] +} diff --git a/adapters/metax/metaxtest/exemplary/no-seat-bid.json b/adapters/metax/metaxtest/exemplary/no-seat-bid.json new file mode 100644 index 00000000000..fe166b1b634 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/no-seat-bid.json @@ -0,0 +1,99 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [] + } + ] + } + } + } + ], + "expectedBidResponses": [] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/exemplary/no-seat.json b/adapters/metax/metaxtest/exemplary/no-seat.json new file mode 100644 index 00000000000..ea83df7f83a --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/no-seat.json @@ -0,0 +1,94 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [] + } + } + } + ], + "expectedBidResponses": [] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/exemplary/simple-app-audio.json b/adapters/metax/metaxtest/exemplary/simple-app-audio.json new file mode 100644 index 00000000000..5bd6a102fb7 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-app-audio.json @@ -0,0 +1,110 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "audio": { + "mimes": [ + "audio/mp4" + ], + "protocols": [ + 9, + 10 + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "audio": { + "mimes": [ + "audio/mp4" + ], + "protocols": [ + 9, + 10 + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "mtype": 3 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "mtype": 3 + }, + "type": "audio" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/exemplary/simple-app-banner.json b/adapters/metax/metaxtest/exemplary/simple-app-banner.json new file mode 100644 index 00000000000..329e00a2f59 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-app-banner.json @@ -0,0 +1,122 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/metax/metaxtest/exemplary/simple-app-native.json b/adapters/metax/metaxtest/exemplary/simple-app-native.json new file mode 100644 index 00000000000..52b4305ad70 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-app-native.json @@ -0,0 +1,99 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":2,\"contextsubtype\":20,\"plcmttype\":11,\"plcmtcnt\":1,\"aurlsupport\":1,\"durlsupport\":1,\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"len\":140}},{\"id\":128,\"required\":0,\"img\":{\"wmin\":836,\"hmin\":627,\"type\":3}}]}" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":2,\"contextsubtype\":20,\"plcmttype\":11,\"plcmtcnt\":1,\"aurlsupport\":1,\"durlsupport\":1,\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"len\":140}},{\"id\":128,\"required\":0,\"img\":{\"wmin\":836,\"hmin\":627,\"type\":3}}]}" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "native-json", + "crid": "test-crid", + "mtype": 4 + } + ] + } + ] + } + } + }], + + "expectedBidResponses": [{ + "currency": "USD", + "bids": [{ + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "native-json", + "crid": "test-crid", + "mtype": 4 + }, + "type": "native" + }] + }] +} diff --git a/adapters/metax/metaxtest/exemplary/simple-app-video.json b/adapters/metax/metaxtest/exemplary/simple-app-video.json new file mode 100644 index 00000000000..4f4272ee3db --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-app-video.json @@ -0,0 +1,130 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + }, + "type": "video" + } + ] + } + ] +} diff --git a/adapters/metax/metaxtest/exemplary/simple-site-audio.json b/adapters/metax/metaxtest/exemplary/simple-site-audio.json new file mode 100644 index 00000000000..ebc240ec9f4 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-site-audio.json @@ -0,0 +1,110 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "audio": { + "mimes": [ + "audio/mp4" + ], + "protocols": [ + 9, + 10 + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "audio": { + "mimes": [ + "audio/mp4" + ], + "protocols": [ + 9, + 10 + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "mtype": 3 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "mtype": 3 + }, + "type": "audio" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/exemplary/simple-site-banner.json b/adapters/metax/metaxtest/exemplary/simple-site-banner.json new file mode 100644 index 00000000000..cc631fac8a7 --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-site-banner.json @@ -0,0 +1,122 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 1 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/metax/metaxtest/exemplary/simple-site-native.json b/adapters/metax/metaxtest/exemplary/simple-site-native.json new file mode 100644 index 00000000000..5955b1b86af --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-site-native.json @@ -0,0 +1,99 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":2,\"contextsubtype\":20,\"plcmttype\":11,\"plcmtcnt\":1,\"aurlsupport\":1,\"durlsupport\":1,\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"len\":140}},{\"id\":128,\"required\":0,\"img\":{\"wmin\":836,\"hmin\":627,\"type\":3}}]}" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":2,\"contextsubtype\":20,\"plcmttype\":11,\"plcmtcnt\":1,\"aurlsupport\":1,\"durlsupport\":1,\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"len\":140}},{\"id\":128,\"required\":0,\"img\":{\"wmin\":836,\"hmin\":627,\"type\":3}}]}" + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "native-json", + "crid": "test-crid", + "mtype": 4 + } + ] + } + ] + } + } + }], + + "expectedBidResponses": [{ + "currency": "USD", + "bids": [{ + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "native-json", + "crid": "test-crid", + "mtype": 4 + }, + "type": "native" + }] + }] +} diff --git a/adapters/metax/metaxtest/exemplary/simple-site-video.json b/adapters/metax/metaxtest/exemplary/simple-site-video.json new file mode 100644 index 00000000000..d6084603a0e --- /dev/null +++ b/adapters/metax/metaxtest/exemplary/simple-site-video.json @@ -0,0 +1,130 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json;charset=utf-8" + ] + }, + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "video": { + "mimes": [ + "video/mp4" + ], + "protocols": [ + 2, + 3, + 5, + 6 + ], + "w": 1024, + "h": 576 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 1024, + "h": 576, + "mtype": 2 + }, + "type": "video" + } + ] + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/invalid-adunit-error.json b/adapters/metax/metaxtest/supplemental/invalid-adunit-error.json new file mode 100644 index 00000000000..35ce462a422 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/invalid-adunit-error.json @@ -0,0 +1,35 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": "abc" + } + } + } + ], + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "Wrong MetaX bidder ext", + "comparison": "literal" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/invalid-ext-bidder.json b/adapters/metax/metaxtest/supplemental/invalid-ext-bidder.json new file mode 100644 index 00000000000..7016e7dc08e --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/invalid-ext-bidder.json @@ -0,0 +1,32 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": "bad string" + } + } + ], + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "Wrong MetaX bidder ext", + "comparison": "literal" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/invalid-ext.json b/adapters/metax/metaxtest/supplemental/invalid-ext.json new file mode 100644 index 00000000000..54d6d9f2c05 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/invalid-ext.json @@ -0,0 +1,30 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": "" + } + ], + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "json: cannot unmarshal*", + "comparison": "regex" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/invalid-publisher-error.json b/adapters/metax/metaxtest/supplemental/invalid-publisher-error.json new file mode 100644 index 00000000000..2a16200f1c1 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/invalid-publisher-error.json @@ -0,0 +1,35 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "abc", + "adunit": 100000 + } + } + } + ], + "app": { + "bundle": "com.prebid" + }, + "device": { + "ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3" + } + }, + "expectedMakeRequestsErrors": [ + { + "value": "Wrong MetaX bidder ext", + "comparison": "literal" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/resp-bad-json.json b/adapters/metax/metaxtest/supplemental/resp-bad-json.json new file mode 100644 index 00000000000..cc51b14e050 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/resp-bad-json.json @@ -0,0 +1,80 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": "this is not a valid json" + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "json: cannot unmarshal*", + "comparison": "regex" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/resp-bad-markuptype.json b/adapters/metax/metaxtest/supplemental/resp-bad-markuptype.json new file mode 100644 index 00000000000..dae139bd452 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/resp-bad-markuptype.json @@ -0,0 +1,100 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "metax", + "bid": [ + { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "some-test-ad", + "crid": "test-crid", + "w": 728, + "h": 90, + "mtype": 0 + } + ] + } + ], + "cur": "USD" + } + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unsupported MType 0", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/supplemental/status-400.json b/adapters/metax/metaxtest/supplemental/status-400.json new file mode 100644 index 00000000000..63a86a5388b --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/status-400.json @@ -0,0 +1,80 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 400, + "body": "invalid params" + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: 400. Run with request.debug = 1 for more info", + "comparison": "literal" + } + ] +} diff --git a/adapters/metax/metaxtest/supplemental/status-500.json b/adapters/metax/metaxtest/supplemental/status-500.json new file mode 100644 index 00000000000..79841569eb4 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/status-500.json @@ -0,0 +1,80 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 500, + "body": "Internal Server Error" + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: 500. Run with request.debug = 1 for more info", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/metax/metaxtest/supplemental/status-503.json b/adapters/metax/metaxtest/supplemental/status-503.json new file mode 100644 index 00000000000..3c8220ee598 --- /dev/null +++ b/adapters/metax/metaxtest/supplemental/status-503.json @@ -0,0 +1,80 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ] + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hb.metaxads.com/prebid?sid=10000000&adunit=100000&source=prebid-server", + "body": { + "id": "test-request-id", + "site": { + "page": "prebid.org" + }, + "user": { + "buyeruid": "be5e209ad46927520000000000000000" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 728, + "h": 90 + } + ], + "w": 728, + "h": 90 + }, + "ext": { + "bidder": { + "publisherId": 10000000, + "adunit": 100000 + } + } + } + ] + }, + "impIDs": [ + "test-imp-id" + ] + }, + "mockResponse": { + "status": 503, + "body": "" + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: 503. Run with request.debug = 1 for more info", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/metax/params_test.go b/adapters/metax/params_test.go new file mode 100644 index 00000000000..5ffb45308e1 --- /dev/null +++ b/adapters/metax/params_test.go @@ -0,0 +1,60 @@ +package metax + +import ( + "encoding/json" + "testing" + + "github.com/prebid/prebid-server/v2/openrtb_ext" +) + +// This file actually intends to test static/bidder-params/metax.json +// +// These also validate the format of the external API: request.imp[i].ext.prebid.bidder.metax + +// TestValidParams makes sure that the metax schema accepts all imp.ext fields which we intend to support. +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.BidderMetaX, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected metax params: %s", validParam) + } + } +} + +// TestInvalidParams makes sure that the metax 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.BidderMetaX, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema allowed unexpected params: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"publisherId": 10000000, "adunit": 100000}`, +} + +var invalidParams = []string{ + ``, + `null`, + `undefined`, + `0`, + `{}`, + `[]`, + `{"publisherId": ""}`, + `{"adunit": ""}`, + `{"publisherId": "", "adunit": ""}`, + `{"publisherId": "10000000", "adunit": "100000"}`, + `{"publisherId": 0, "adunit": 0}`, + `{"publisherId": 10000000, "adunit": 0}`, + `{"publisherId": 0, "adunit": 100000}`, +} diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index 173f134567f..b79d03a8afd 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -129,6 +129,7 @@ import ( "github.com/prebid/prebid-server/v2/adapters/marsmedia" "github.com/prebid/prebid-server/v2/adapters/mediago" "github.com/prebid/prebid-server/v2/adapters/medianet" + "github.com/prebid/prebid-server/v2/adapters/metax" "github.com/prebid/prebid-server/v2/adapters/mgid" "github.com/prebid/prebid-server/v2/adapters/mgidX" "github.com/prebid/prebid-server/v2/adapters/minutemedia" @@ -352,6 +353,7 @@ func newAdapterBuilders() map[openrtb_ext.BidderName]adapters.Builder { openrtb_ext.BidderMediafuse: appnexus.Builder, openrtb_ext.BidderMediaGo: mediago.Builder, openrtb_ext.BidderMedianet: medianet.Builder, + openrtb_ext.BidderMetaX: metax.Builder, openrtb_ext.BidderMgid: mgid.Builder, openrtb_ext.BidderMgidX: mgidX.Builder, openrtb_ext.BidderMinuteMedia: minutemedia.Builder, diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index bc422e4ab87..46d70c7f998 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -147,6 +147,7 @@ var coreBidderNames []BidderName = []BidderName{ BidderMediafuse, BidderMediaGo, BidderMedianet, + BidderMetaX, BidderMgid, BidderMgidX, BidderMinuteMedia, @@ -467,6 +468,7 @@ const ( BidderMediafuse BidderName = "mediafuse" BidderMediaGo BidderName = "mediago" BidderMedianet BidderName = "medianet" + BidderMetaX BidderName = "metax" BidderMgid BidderName = "mgid" BidderMgidX BidderName = "mgidX" BidderMinuteMedia BidderName = "minutemedia" diff --git a/openrtb_ext/imp_metax.go b/openrtb_ext/imp_metax.go new file mode 100644 index 00000000000..ab54505fbf3 --- /dev/null +++ b/openrtb_ext/imp_metax.go @@ -0,0 +1,7 @@ +package openrtb_ext + +// ExtImpMetaX defines the contract for bidrequest.imp[i].ext.prebid.bidder.metax +type ExtImpMetaX struct { + PublisherID int `json:"publisherId"` + Adunit int `json:"adunit"` +} diff --git a/static/bidder-info/metax.yaml b/static/bidder-info/metax.yaml new file mode 100644 index 00000000000..d9867322d01 --- /dev/null +++ b/static/bidder-info/metax.yaml @@ -0,0 +1,18 @@ +# The MetaX Bidding adapter requires setup before beginning. Please contact us at +endpoint: "https://hb.metaxads.com/prebid?sid={{.PublisherID}}&adunit={{.AdUnit}}&source=prebid-server" +maintainer: + email: "prebid@metaxsoft.com" +gvlVendorID: 1301 +capabilities: + app: + mediaTypes: + - banner + - video + - native + - audio + site: + mediaTypes: + - banner + - video + - native + - audio diff --git a/static/bidder-params/metax.json b/static/bidder-params/metax.json new file mode 100644 index 00000000000..3c336c2be3e --- /dev/null +++ b/static/bidder-params/metax.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "MetaX Adapter Params", + "description": "A schema which validates params accepted by the MetaX adapter", + "type": "object", + "properties": { + "publisherId": { + "type": "integer", + "description": "An ID which identifies the publisher", + "minimum": 1 + }, + "adunit": { + "type": "integer", + "description": "An ID which identifies the adunit", + "minimum": 1 + } + }, + "required": ["publisherId", "adunit"] +}