diff --git a/adapters/ogury/ogury.go b/adapters/ogury/ogury.go index b7b0ad1139..6210f04c30 100644 --- a/adapters/ogury/ogury.go +++ b/adapters/ogury/ogury.go @@ -8,10 +8,10 @@ import ( "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/openrtb_ext" + "github.com/prebid/prebid-server/v3/adapters" + "github.com/prebid/prebid-server/v3/config" + "github.com/prebid/prebid-server/v3/errortypes" + "github.com/prebid/prebid-server/v3/openrtb_ext" ) type oguryAdapter struct { @@ -28,9 +28,16 @@ func Builder(_ openrtb_ext.BidderName, config config.Adapter, _ config.Server) ( func (a oguryAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { headers := setHeaders(request) + request.Imp = filterValidImps(request) + if len(request.Imp) == 0 { + return nil, []error{&errortypes.BadInput{ + Message: "Invalid request. assetKey/adUnitId or request.site.publisher.id required", + }} + } + var errors []error - var impExt, impExtBidderHoist map[string]json.RawMessage for i, imp := range request.Imp { + var impExt, impExtBidderHoist map[string]json.RawMessage // extract ext if err := json.Unmarshal(imp.Ext, &impExt); err != nil { return nil, append(errors, &errortypes.BadInput{ @@ -38,21 +45,19 @@ func (a oguryAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *ad }) } // find Ogury bidder params - bidder, ok := impExt["bidder"] - if ok { + if bidder, ok := impExt[openrtb_ext.PrebidExtBidderKey]; ok { if err := json.Unmarshal(bidder, &impExtBidderHoist); err != nil { return nil, append(errors, &errortypes.BadInput{ - Message: "Bidder extension not provided or can't be unmarshalled", + Message: "Ogury bidder extension not provided or can't be unmarshalled", }) } - } impExtOut := make(map[string]any, len(impExt)-1+len(impExtBidderHoist)) // extract Ogury "bidder" params from imp.ext.bidder to imp.ext for key, value := range impExt { - if key != "bidder" { + if key != openrtb_ext.PrebidExtBidderKey { impExtOut[key] = value } } @@ -66,14 +71,14 @@ func (a oguryAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *ad Message: "Error while marshaling Imp.Ext bidder exension", }) } + request.Imp[i].Ext = ext // save adUnitCode - request.Imp[i].TagID = imp.ID - if impExtOut["gpid"] == "" { - impExtOut["gpid"] = imp.ID + if adUnitCode := getAdUnitCode(impExt); adUnitCode != "" { + request.Imp[i].TagID = adUnitCode + } else { + request.Imp[i].TagID = imp.ID } - - request.Imp[i].Ext = ext } // currency conversion @@ -111,6 +116,51 @@ func (a oguryAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *ad } +func filterValidImps(request *openrtb2.BidRequest) (validImps []openrtb2.Imp) { + for _, imp := range request.Imp { + var impExt adapters.ExtImpBidder + var impExtOgury openrtb_ext.ImpExtOgury + + if err := json.Unmarshal(imp.Ext, &impExt); err != nil { + continue + } + if err := json.Unmarshal(impExt.Bidder, &impExtOgury); err != nil { + continue + } + if impExtOgury.AssetKey != "" && impExtOgury.AdUnitID != "" { + validImps = append(validImps, imp) + } + } + + // if we have imp with assetKey/adUnitId then we want to serve them + if len(validImps) > 0 { + return validImps + } + + // no assetKey/adUnitId imps then we serve everything if publisher.ID exists + if request.Site != nil && request.Site.Publisher.ID != "" { + return request.Imp + } + + // else no valid imp + return nil +} + +func getAdUnitCode(ext map[string]json.RawMessage) string { + var prebidExt openrtb_ext.ExtImpPrebid + v, ok := ext["prebid"] + if !ok { + return "" + } + + err := json.Unmarshal(v, &prebidExt) + if err != nil { + return "" + } + + return prebidExt.AdUnitCode +} + func setHeaders(request *openrtb2.BidRequest) http.Header { headers := http.Header{} headers.Add("Content-Type", "application/json;charset=utf-8") @@ -144,21 +194,10 @@ func getMediaTypeForBid(impressions []openrtb2.Imp, bid openrtb2.Bid) (openrtb_e } func (a oguryAdapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { - if responseData.StatusCode == http.StatusNoContent { + if adapters.IsResponseStatusCodeNoContent(responseData) { return nil, nil } - - if responseData.StatusCode == http.StatusBadRequest { - err := &errortypes.BadInput{ - Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", - } - return nil, []error{err} - } - - if responseData.StatusCode != http.StatusOK { - err := &errortypes.BadServerResponse{ - Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), - } + if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { return nil, []error{err} } diff --git a/adapters/ogury/ogury_test.go b/adapters/ogury/ogury_test.go index 4add931218..504be6ccaa 100644 --- a/adapters/ogury/ogury_test.go +++ b/adapters/ogury/ogury_test.go @@ -3,9 +3,9 @@ package ogury import ( "testing" - "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/v3/adapters/adapterstest" + "github.com/prebid/prebid-server/v3/config" + "github.com/prebid/prebid-server/v3/openrtb_ext" ) func TestJsonSamples(t *testing.T) { diff --git a/adapters/ogury/ogurytest/exemplary/banner_asset_ad_unit.json b/adapters/ogury/ogurytest/exemplary/banner_asset_ad_unit.json index c3fd79ca7b..66e68b88ff 100644 --- a/adapters/ogury/ogurytest/exemplary/banner_asset_ad_unit.json +++ b/adapters/ogury/ogurytest/exemplary/banner_asset_ad_unit.json @@ -9,6 +9,9 @@ }, "ext": { "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code" + }, "bidder": { "assetKey": "OGY", "adUnitId": "123" @@ -27,14 +30,17 @@ "imp": [ { "id":"test-imp-id", - "tagid": "test-imp-id", + "tagid": "ad-unit-code", "banner": { "format": [{"w": 128, "h": 100}] }, "ext": { "gpid": "global position id", "assetKey": "OGY", - "adUnitId": "123" + "adUnitId": "123", + "prebid": { + "adunitcode": "ad-unit-code" + } } } ] @@ -85,4 +91,3 @@ } ] } - diff --git a/adapters/ogury/ogurytest/exemplary/banner_multi_imp_with_params.json b/adapters/ogury/ogurytest/exemplary/banner_multi_imp_with_params.json new file mode 100644 index 0000000000..bbadc27397 --- /dev/null +++ b/adapters/ogury/ogurytest/exemplary/banner_multi_imp_with_params.json @@ -0,0 +1,141 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code" + }, + "bidder": { + "assetKey": "OGY", + "adUnitId": "123" + } + } + }, + { + "id": "test-imp-id-2", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": {"bidder": {}} + }, + { + "id": "test-imp-id-3", + "banner": { + "format": [{"w": 1, "h": 1}] + }, + "ext": { + "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code-2" + }, + "bidder": { + "assetKey": "OGY3", + "adUnitId": "1234" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://ogury.example.com", + "body": { + "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, + "imp": [ + { + "id":"test-imp-id", + "tagid": "ad-unit-code", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "assetKey": "OGY", + "adUnitId": "123", + "prebid": { + "adunitcode": "ad-unit-code" + } + } + }, + { + "id":"test-imp-id-3", + "tagid": "ad-unit-code-2", + "banner": { + "format": [{"w": 1, "h": 1}] + }, + "ext": { + "gpid": "global position id", + "assetKey": "OGY3", + "adUnitId": "1234", + "prebid": { + "adunitcode": "ad-unit-code-2" + } + } + } + ] + }, + "impIDs":["test-imp-id", "test-imp-id-3"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "seat", + "bid": [{ + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.5, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/ogury/ogurytest/exemplary/banner_multi_imp_without_ogury_params.json b/adapters/ogury/ogurytest/exemplary/banner_multi_imp_without_ogury_params.json new file mode 100644 index 0000000000..62cc253ecb --- /dev/null +++ b/adapters/ogury/ogurytest/exemplary/banner_multi_imp_without_ogury_params.json @@ -0,0 +1,113 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code" + }, + "bidder": {} + } + }, + { + "id": "test-imp-id-2", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": {"bidder": {}} + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://ogury.example.com", + "body": { + "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, + "imp": [ + { + "id":"test-imp-id", + "tagid": "ad-unit-code", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code" + } + } + }, + { + "id": "test-imp-id-2", + "tagid": "test-imp-id-2", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": {} + } + ] + }, + "impIDs":["test-imp-id", "test-imp-id-2"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "seat", + "bid": [{ + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.5, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/ogury/ogurytest/exemplary/banner_publisher.json b/adapters/ogury/ogurytest/exemplary/banner_publisher.json index ae92a576b0..1d8e2fd5a6 100644 --- a/adapters/ogury/ogurytest/exemplary/banner_publisher.json +++ b/adapters/ogury/ogurytest/exemplary/banner_publisher.json @@ -1,6 +1,11 @@ { "mockBidRequest": { "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, "imp": [ { "id": "test-imp-id", @@ -8,8 +13,8 @@ "format": [{"w": 128, "h": 100}] }, "ext": { - "bidder": { - "publisherId": "pub123" + "prebid": { + "adunitcode": "ad-unit-code" } } } @@ -22,15 +27,22 @@ "uri": "http://ogury.example.com", "body": { "id": "test-request-id", + "site": { + "publisher": { + "id": "pub123" + } + }, "imp": [ { "id":"test-imp-id", - "tagid": "test-imp-id", + "tagid": "ad-unit-code", "banner": { "format": [{"w": 128, "h": 100}] }, "ext": { - "publisherId": "pub123" + "prebid": { + "adunitcode": "ad-unit-code" + } } } ] @@ -81,4 +93,3 @@ } ] } - diff --git a/adapters/ogury/ogurytest/supplemental/banner_invalid_request.json b/adapters/ogury/ogurytest/supplemental/banner_invalid_request.json new file mode 100644 index 0000000000..aac99257c2 --- /dev/null +++ b/adapters/ogury/ogurytest/supplemental/banner_invalid_request.json @@ -0,0 +1,24 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "bidder": {} + } + } + ] + }, + + "httpCalls": [], + "expectedBidResponses": [], + "expectedMakeRequestsErrors": [{ + "value": "Invalid request. assetKey/adUnitId or request.site.publisher.id required", + "comparison": "literal" + }] +} diff --git a/adapters/ogury/ogurytest/supplemental/banner_with_arbitary_bidder_param.json b/adapters/ogury/ogurytest/supplemental/banner_with_arbitary_bidder_param.json index bb5c8ba8d9..b1e4ec2674 100644 --- a/adapters/ogury/ogurytest/supplemental/banner_with_arbitary_bidder_param.json +++ b/adapters/ogury/ogurytest/supplemental/banner_with_arbitary_bidder_param.json @@ -9,6 +9,9 @@ }, "ext": { "gpid": "global position id", + "prebid": { + "adunitcode": "ad-unit-code" + }, "bidder": { "assetKey": "OGY", "adUnitId": "123", @@ -28,7 +31,7 @@ "imp": [ { "id":"test-imp-id", - "tagid": "test-imp-id", + "tagid": "ad-unit-code", "banner": { "format": [{"w": 128, "h": 100}] }, @@ -36,7 +39,10 @@ "gpid": "global position id", "assetKey": "OGY", "adUnitId": "123", - "testcampaign": "test123" + "testcampaign": "test123", + "prebid": { + "adunitcode": "ad-unit-code" + } } } ] diff --git a/adapters/ogury/ogurytest/supplemental/banner_without_ad_unit_code.json b/adapters/ogury/ogurytest/supplemental/banner_without_ad_unit_code.json new file mode 100644 index 0000000000..6ac73bc221 --- /dev/null +++ b/adapters/ogury/ogurytest/supplemental/banner_without_ad_unit_code.json @@ -0,0 +1,87 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "bidder": { + "assetKey": "OGY", + "adUnitId": "123" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://ogury.example.com", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "tagid": "test-imp-id", + "banner": { + "format": [{"w": 128, "h": 100}] + }, + "ext": { + "gpid": "global position id", + "assetKey": "OGY", + "adUnitId": "123" + } + } + ] + }, + "impIDs":["test-imp-id"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "cur": "USD", + "seatbid": [ + { + "seat": "seat", + "bid": [{ + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.500000, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "some-UUID", + "impid": "test-imp-id", + "price": 0.5, + "adm": "adm string", + "crid": "crid_10", + "h": 100, + "w": 128 + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/ogury/param_test.go b/adapters/ogury/param_test.go index 2bc27e4796..f4c7c83445 100644 --- a/adapters/ogury/param_test.go +++ b/adapters/ogury/param_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v3/openrtb_ext" ) func TestValidParams(t *testing.T) { @@ -21,11 +21,9 @@ func TestValidParams(t *testing.T) { } var validParams = []string{ + `{}`, `{"adUnitId": "12", "assetKey": "OGY"}`, - `{"publisherId": "00000000-0000-0000-0000-000000000000"}`, - `{"publisherId": "00000000-0000-0000-0000-000000000000", "assetKey": "ogy"}`, - `{"publisherId": "00000000-0000-0000-0000-000000000000", "adUnitId": "12"}`, - `{"publisherId": "00000000-0000-0000-0000-000000000000", "assetKey": "ogy asset", "adUnitId": "1"}`, + `{"adUnitId": "123", "assetKey": "OGY", "thirdParam": "something"}`, } func TestInvalidParams(t *testing.T) { @@ -49,5 +47,4 @@ var invalidParams = []string{ `{"assetKey": "ogy asset"}`, `{"adUnitId": 12, "assetKey": "OGY"}`, `{"adUnitId": "45test", "assetKey": false}`, - `{"publisherId": true}`, } diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index c37907180c..4af5bff3a9 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -145,6 +145,7 @@ import ( "github.com/prebid/prebid-server/v3/adapters/nativo" "github.com/prebid/prebid-server/v3/adapters/nextmillennium" "github.com/prebid/prebid-server/v3/adapters/nobid" + "github.com/prebid/prebid-server/v3/adapters/ogury" "github.com/prebid/prebid-server/v3/adapters/oms" "github.com/prebid/prebid-server/v3/adapters/onetag" "github.com/prebid/prebid-server/v3/adapters/openweb" diff --git a/openrtb_ext/imp_ogury.go b/openrtb_ext/imp_ogury.go index 62f853b536..295bd7d26d 100644 --- a/openrtb_ext/imp_ogury.go +++ b/openrtb_ext/imp_ogury.go @@ -1,7 +1,6 @@ package openrtb_ext type ImpExtOgury struct { - AdUnitID string `json:"adUnitId,omitempty"` - AssetKey string `json:"assetKey,omitempty"` - PublisherID string `json:"publisherId,omitempty"` + AdUnitID string `json:"adUnitId,omitempty"` + AssetKey string `json:"assetKey,omitempty"` } diff --git a/static/bidder-params/ogury.json b/static/bidder-params/ogury.json index 1097509b54..fd77fbe849 100644 --- a/static/bidder-params/ogury.json +++ b/static/bidder-params/ogury.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Ogury Adapter Params", "description": "A schema which validates params accepted by the Ogury adapter", "type": "object", @@ -14,17 +14,17 @@ "type": "string", "minLength": 1, "description": "Ogury provided id for you placement." - }, - "publisherId": { - "type": "string", - "format": "uuid", - "description": "Ogury provided publisher id." } }, - "anyOf": [ - { "required": ["assetKey", "adUnitId"] }, - { "required": ["publisherId"] } + "allOf": [ + { + "if": { "required": ["assetKey"] }, + "then": { "required": ["adUnitId"] } + }, + { + "if": { "required": ["adUnitId"] }, + "then": { "required": ["assetKey"] } + } ] } -