diff --git a/adapters/ortbbidder/bidderparams/config.go b/adapters/ortbbidder/bidderparams/config.go index eea6f87d209..36aa8282997 100644 --- a/adapters/ortbbidder/bidderparams/config.go +++ b/adapters/ortbbidder/bidderparams/config.go @@ -18,9 +18,6 @@ type BidderConfig struct { // setRequestParams sets the bidder specific requestParams func (bcfg *BidderConfig) setRequestParams(bidderName string, requestParams map[string]BidderParamMapper) { - if bcfg.bidderConfigMap == nil { - bcfg.bidderConfigMap = make(map[string]*config) - } if _, found := bcfg.bidderConfigMap[bidderName]; !found { bcfg.bidderConfigMap[bidderName] = &config{} } diff --git a/adapters/ortbbidder/bidderparams/config_test.go b/adapters/ortbbidder/bidderparams/config_test.go index 9ba737ecd96..f4b80ee7843 100644 --- a/adapters/ortbbidder/bidderparams/config_test.go +++ b/adapters/ortbbidder/bidderparams/config_test.go @@ -16,7 +16,6 @@ func TestSetRequestParams(t *testing.T) { } type want struct { bidderCfg *BidderConfig - err error } tests := []struct { name string @@ -24,35 +23,6 @@ func TestSetRequestParams(t *testing.T) { args args want want }{ - { - name: "bidderConfigMap_is_nil", - fields: fields{ - bidderConfig: &BidderConfig{ - bidderConfigMap: nil, - }, - }, - args: args{ - bidderName: "test", - requestParams: map[string]BidderParamMapper{ - "adunit": { - Location: "ext.adunit", - }, - }, - }, - want: want{ - bidderCfg: &BidderConfig{ - bidderConfigMap: map[string]*config{ - "test": { - requestParams: map[string]BidderParamMapper{ - "adunit": { - Location: "ext.adunit", - }, - }, - }, - }, - }, - }, - }, { name: "bidderName_not_found", fields: fields{ diff --git a/adapters/ortbbidder/ortbbidder.go b/adapters/ortbbidder/ortbbidder.go index 3e57c85b655..12420c4e75c 100644 --- a/adapters/ortbbidder/ortbbidder.go +++ b/adapters/ortbbidder/ortbbidder.go @@ -64,12 +64,12 @@ func (o *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte if o.bidderParamsConfig == nil { return nil, []error{newBadInputError(errNilBidderParamCfg.Error())} } - requestParams := o.bidderParamsConfig.GetRequestParams(o.bidderName.String()) requestBuilder := newRequestBuilder(o.adapterInfo.extraInfo.RequestMode, o.Endpoint) err := requestBuilder.parseRequest(request) if err != nil { return nil, []error{newBadInputError(err.Error())} } + requestParams := o.bidderParamsConfig.GetRequestParams(o.bidderName.String()) return requestBuilder.makeRequest(o.endpointTemplate, requestParams) } diff --git a/adapters/ortbbidder/ortbbidder_test.go b/adapters/ortbbidder/ortbbidder_test.go index 88892939666..51852955842 100644 --- a/adapters/ortbbidder/ortbbidder_test.go +++ b/adapters/ortbbidder/ortbbidder_test.go @@ -33,6 +33,15 @@ func TestMakeRequests(t *testing.T) { args args want want }{ + { + name: "request_is_nil", + args: args{ + bidderCfg: &bidderparams.BidderConfig{}, + }, + want: want{ + errors: []error{newBadInputError(errImpMissing.Error())}, + }, + }, { name: "bidderParamsConfig_is_nil", args: args{ @@ -98,7 +107,7 @@ func TestMakeRequests(t *testing.T) { { Method: http.MethodPost, Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), + Body: []byte(`{"id":"reqid","imp":[{"id":"imp1","tagid":"tag1"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -107,7 +116,7 @@ func TestMakeRequests(t *testing.T) { { Method: http.MethodPost, Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp1","tagid":"tag1"}]}`), + Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -137,8 +146,8 @@ func TestMakeRequests(t *testing.T) { requestData: []*adapters.RequestData{ { Method: http.MethodPost, - Uri: "http://", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), + Uri: "http://localhost.com", + Body: []byte(`{"id":"reqid","imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp1","tagid":"tag1"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -146,8 +155,8 @@ func TestMakeRequests(t *testing.T) { }, { Method: http.MethodPost, - Uri: "http://localhost.com", - Body: []byte(`{"id":"reqid","imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp1","tagid":"tag1"}]}`), + Uri: "http://", + Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -228,7 +237,6 @@ func TestMakeRequests(t *testing.T) { }) } } - func TestMakeBids(t *testing.T) { type args struct { request *openrtb2.BidRequest @@ -611,473 +619,3 @@ func TestIsORTBBidder(t *testing.T) { }) } } - -func TestMakeRequest(t *testing.T) { - type fields struct { - endpointTemplate *template.Template - } - type args struct { - rawRequest json.RawMessage - bidderParamMapper map[string]bidderparams.BidderParamMapper - supportSingleImpInRequest bool - } - type want struct { - requestData []*adapters.RequestData - errs []error - } - tests := []struct { - name string - fields fields - args args - want want - }{ - { - name: "nil_request", - fields: fields{}, - args: args{ - rawRequest: nil, - }, - want: want{ - requestData: nil, - errs: []error{newBadInputError("failed to unmarshal request, err:expect { or n, but found \x00")}, - }, - }, - { - name: "no_imp_object", - fields: fields{}, - args: args{ - rawRequest: json.RawMessage(`{}`), - }, - want: want{ - requestData: nil, - errs: []error{newBadInputError("imp object not found in request")}, - }, - }, - { - name: "invalid_imp_object", - fields: fields{}, - args: args{ - rawRequest: json.RawMessage(`{"imp":["invalid"]}`), - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "", - Body: json.RawMessage(`{"imp":["invalid"]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - errs: []error{newBadInputError("invalid imp object found at index:0")}, - }, - }, - // { - // name: "multiRequestMode_replace_macros_to_form_endpoint_url", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "multiRequestMode_macros_value_absent_in_bidder_params", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Option("missingkey=default").Parse(`http://{{.host}}/publisher/{{.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http:///publisher/", - // Body: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "multiRequestMode_macro_replacement_failure", - // fields: fields{ - // endpointTemplate: func() *template.Template { - // errorFunc := template.FuncMap{ - // "errorFunc": func() (string, error) { - // return "", errors.New("intentional error") - // }, - // } - // t := template.Must(template.New("endpointTemplate").Funcs(errorFunc).Parse(`{{errorFunc}}`)) - // return t - // }(), - // }, - // args: args{ - // supportSingleImpInRequest: false, - // rawRequest: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), - // }, - // want: want{ - // requestData: nil, - // errs: []error{newBadInputError("failed to replace macros in endpoint, err:template: endpointTemplate:1:2: " + - // "executing \"endpointTemplate\" at : error calling errorFunc: intentional error")}, - // }, - // }, - // { - // name: "multiRequestMode_first_imp_bidder_params_has_high_priority_while_replacing_macros_in_endpoint", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"host":"imp2.host.com"}},"id":"imp_2"}]}`), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher", - // Body: json.RawMessage(`{"imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"host":"imp2.host.com"}},"id":"imp_2"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "map_bidder_params_in_single_imp", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"device":{"pubid":5890},"host":"localhost.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "multiRequestMode_map_bidder_params_in_multi_imp", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"tagid":"valid_tag_id"}},"id":"imp_2"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // tagMapper := bidderparams.BidderParamMapper{} - // tagMapper.SetLocation("imp.#.tagid") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // "tagid": tagMapper, - // } - // }(), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"device":{"pubid":5890},"host":"localhost.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"},{"ext":{"bidder":{}},"id":"imp_2","tagid":"valid_tag_id"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "multiRequestMode_first_imp_bidder_param_has_high_pririty", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"ext":{"pubid":1111}}},"id":"imp_2"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"device":{"pubid":5890},"host":"localhost.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"},{"ext":{"bidder":{}},"id":"imp_2"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "bidder_param_mapping_absent", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // bidderParamMapper: nil, - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "singleRequestMode_single_imp_request", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111},"host":"imp1.host.com"}},"id":"imp_1"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // supportSingleImpInRequest: true, - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp1.host.com/publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "singleRequestMode_multi_imps_request", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111},"host":"imp1.host.com"}},"id":"imp_1"},{"ext":{"bidder":{"ext":{"pubid":2222},"host":"imp2.host.com"}},"id":"imp_2"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // supportSingleImpInRequest: true, - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp2.host.com/publisher/2222", - // Body: json.RawMessage(`{"device":{"pubid":2222},"host":"imp2.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_2"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // { - // Method: http.MethodPost, - // Uri: "http://imp1.host.com/publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "singleRequestMode_multi_imps_request_with_one_invalid_imp", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111},"host":"imp1.host.com"}},"id":"imp_1"},"invalid-imp"]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // supportSingleImpInRequest: true, - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp1.host.com/publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: []error{newBadInputError("invalid imp object found at index:1")}, - // }, - // }, - // { - // name: "singleRequestMode_one_imp_updates_request_level_param_but_another_imp_does_not_update", - // fields: fields{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // args: args{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111}}},"id":"imp_1"},{"ext":{"bidder":{"ext":{"pubid":2222},"host":"imp2.host.com"}},"id":"imp_2"}]}`), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{} - // hostMapper.SetLocation("host") - // extMapper := bidderparams.BidderParamMapper{} - // extMapper.SetLocation("device") - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // supportSingleImpInRequest: true, - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp2.host.com/publisher/2222", - // Body: json.RawMessage(`{"device":{"pubid":2222},"host":"imp2.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_2"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // { - // Method: http.MethodPost, - // Uri: "http:///publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "singleRequestMode_macro_replacement_failure", - // fields: fields{ - // endpointTemplate: func() *template.Template { - // errorFunc := template.FuncMap{ - // "errorFunc": func() (string, error) { - // return "", errors.New("intentional error") - // }, - // } - // t := template.Must(template.New("endpointTemplate").Funcs(errorFunc).Parse(`{{errorFunc}}`)) - // return t - // }(), - // }, - // args: args{ - // supportSingleImpInRequest: true, - // rawRequest: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), - // }, - // want: want{ - // requestData: nil, - // errs: []error{newBadInputError("failed to replace macros in endpoint, err:template: endpointTemplate:1:2: " + - // "executing \"endpointTemplate\" at : error calling errorFunc: intentional error")}, - // }, - // }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // o := adapterInfo{ - // endpointTemplate: tt.fields.endpointTemplate, - // } - // requestData, errs := o.makeRequest(tt.args.rawRequest, tt.args.bidderParamMapper, tt.args.supportSingleImpInRequest) - // assert.Equalf(t, tt.want.requestData, requestData, "mismatched requestData") - // assert.Equalf(t, tt.want.errs, errs, "mismatched errs") - }) - } -} diff --git a/adapters/ortbbidder/requestBuilder.go b/adapters/ortbbidder/requestBuilder.go index 3e9f6d14b26..f198d220ad4 100644 --- a/adapters/ortbbidder/requestBuilder.go +++ b/adapters/ortbbidder/requestBuilder.go @@ -39,11 +39,6 @@ func (reqBuilder *requestBuilder) parseRequest(request *openrtb2.BidRequest) (er if !ok { return errImpMissing } - for impIndex := range reqBuilder.imps { - imp := reqBuilder.imps[impIndex].(map[string]any) - delete(imp, "id") - } - return } @@ -157,7 +152,6 @@ func (reqBuilder *multiRequestModeBuilder) makeRequest(endpointTemplate *templat requestData []*adapters.RequestData foundValidImp bool ) - // reqBuilder.requestNode[impKey] = reqBuilder.imps // iterate through imps in reverse order to ensure setRequestParams prioritizes // the parameters from imp[0].ext.bidder over those from imp[1..N].ext.bidder. for impIndex := len(reqBuilder.imps) - 1; impIndex >= 0; impIndex-- { diff --git a/adapters/ortbbidder/requestBuilder_test.go b/adapters/ortbbidder/requestBuilder_test.go index 31ecb2bf642..7dada8b95db 100644 --- a/adapters/ortbbidder/requestBuilder_test.go +++ b/adapters/ortbbidder/requestBuilder_test.go @@ -11,231 +11,9 @@ import ( "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v2/adapters" "github.com/prebid/prebid-server/v2/adapters/ortbbidder/bidderparams" - "github.com/prebid/prebid-server/v2/config" "github.com/stretchr/testify/assert" ) -func TestMakeRequests_(t *testing.T) { - type args struct { - request *openrtb2.BidRequest - requestInfo *adapters.ExtraRequestInfo - adapterInfo adapterInfo - bidderCfg *bidderparams.BidderConfig - } - type want struct { - requestData []*adapters.RequestData - errors []error - } - tests := []struct { - name string - args args - want want - }{ - { - name: "request_is_nil", - args: args{ - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - errors: []error{newBadInputError(errImpMissing.Error())}, - }, - }, - { - name: "bidderParamsConfig_is_nil", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{{ID: "imp1", TagID: "tag1"}}, - }, - adapterInfo: adapterInfo{config.Adapter{Endpoint: "http://test_bidder.com"}, extraAdapterInfo{RequestMode: "single"}, "testbidder", nil}, - bidderCfg: nil, - }, - want: want{ - errors: []error{newBadInputError("found nil bidderParamsConfig")}, - }, - }, - { - name: "bidderParamsConfig_not_contains_bidder_param_data", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{{ID: "imp1", TagID: "tag1"}}, - }, - adapterInfo: func() adapterInfo { - endpoint := "http://test_bidder.com" - template, _ := template.New("endpointTemplate").Parse(endpoint) - return adapterInfo{config.Adapter{Endpoint: endpoint}, extraAdapterInfo{RequestMode: "single"}, "testbidder", template} - }(), - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp1","tagid":"tag1"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - errors: nil, - }, - }, - { - name: "single_requestmode_to_form_requestdata", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{ - {ID: "imp1", TagID: "tag1"}, - {ID: "imp2", TagID: "tag2"}, - }, - }, - adapterInfo: func() adapterInfo { - endpoint := "http://test_bidder.com" - template, _ := template.New("endpointTemplate").Parse(endpoint) - return adapterInfo{config.Adapter{Endpoint: endpoint}, extraAdapterInfo{RequestMode: "single"}, "testbidder", template} - }(), - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - { - Method: http.MethodPost, - Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp1","tagid":"tag1"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - }, - }, - { - name: "single_requestmode_validate_endpoint_macro", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{ - {ID: "imp1", TagID: "tag1", Ext: json.RawMessage(`{"bidder": {"host": "localhost.com"}}`)}, - {ID: "imp2", TagID: "tag2"}, - }, - }, - adapterInfo: func() adapterInfo { - endpoint := "http://{{.host}}" - template, _ := template.New("endpointTemplate").Parse(endpoint) - return adapterInfo{config.Adapter{Endpoint: endpoint}, extraAdapterInfo{RequestMode: "single"}, "testbidder", template} - }(), - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "http://", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp2","tagid":"tag2"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - { - Method: http.MethodPost, - Uri: "http://localhost.com", - Body: []byte(`{"id":"reqid","imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp1","tagid":"tag1"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - }, - }, - { - name: "multi_requestmode_to_form_requestdata", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{ - {ID: "imp1", TagID: "tag1"}, - {ID: "imp2", TagID: "tag2"}, - }, - }, - adapterInfo: func() adapterInfo { - endpoint := "http://test_bidder.com" - template, _ := template.New("endpointTemplate").Parse(endpoint) - return adapterInfo{config.Adapter{Endpoint: endpoint}, extraAdapterInfo{RequestMode: ""}, "testbidder", template} - }(), - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "http://test_bidder.com", - Body: []byte(`{"id":"reqid","imp":[{"id":"imp1","tagid":"tag1"},{"id":"imp2","tagid":"tag2"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - }, - }, - { - name: "multi_requestmode_validate_endpoint_macros", - args: args{ - request: &openrtb2.BidRequest{ - ID: "reqid", - Imp: []openrtb2.Imp{ - {ID: "imp1", TagID: "tag1", Ext: json.RawMessage(`{"bidder": {"host": "localhost.com"}}`)}, - {ID: "imp2", TagID: "tag2"}, - }, - }, - adapterInfo: func() adapterInfo { - endpoint := "http://{{.host}}" - template, _ := template.New("endpointTemplate").Parse(endpoint) - return adapterInfo{config.Adapter{Endpoint: endpoint}, extraAdapterInfo{RequestMode: ""}, "testbidder", template} - }(), - bidderCfg: &bidderparams.BidderConfig{}, - }, - want: want{ - requestData: []*adapters.RequestData{ - { - Method: http.MethodPost, - Uri: "http://localhost.com", - Body: []byte(`{"id":"reqid","imp":[{"ext":{"bidder":{"host":"localhost.com"}},"id":"imp1","tagid":"tag1"},{"id":"imp2","tagid":"tag2"}]}`), - Headers: http.Header{ - "Content-Type": {"application/json;charset=utf-8"}, - "Accept": {"application/json"}, - }, - }, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - adapter := &adapter{adapterInfo: tt.args.adapterInfo, bidderParamsConfig: tt.args.bidderCfg} - requestData, errors := adapter.MakeRequests(tt.args.request, tt.args.requestInfo) - assert.Equalf(t, tt.want.requestData, requestData, "mismatched requestData") - assert.Equalf(t, tt.want.errors, errors, "mismatched errors") - }) - } -} - func TestParseRequest(t *testing.T) { type args struct { request *openrtb2.BidRequest @@ -292,7 +70,6 @@ func TestParseRequest(t *testing.T) { t.Run(tt.name, func(t *testing.T) { reqBuilder := &requestBuilder{} err := reqBuilder.parseRequest(tt.args.request) - assert.Equalf(t, tt.want.err, err, "mismatched error") assert.Equalf(t, string(tt.want.rawRequest), string(reqBuilder.rawRequest), "mismatched rawRequest") assert.Equalf(t, tt.want.requestNode, reqBuilder.requestNode, "mismatched requestNode") @@ -712,8 +489,8 @@ func Test_singleRequestModeBuilder_makeRequest(t *testing.T) { requestData: []*adapters.RequestData{ { Method: http.MethodPost, - Uri: "http://imp2.host.com/publisher/2222", - Body: json.RawMessage(`{"device":{"pubid":2222},"host":"imp2.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_2"}]}`), + Uri: "http://imp1.host.com/publisher/1111", + Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -721,8 +498,8 @@ func Test_singleRequestModeBuilder_makeRequest(t *testing.T) { }, { Method: http.MethodPost, - Uri: "http://imp1.host.com/publisher/1111", - Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), + Uri: "http://imp2.host.com/publisher/2222", + Body: json.RawMessage(`{"device":{"pubid":2222},"host":"imp2.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_2"}]}`), Headers: http.Header{ "Content-Type": {"application/json;charset=utf-8"}, "Accept": {"application/json"}, @@ -918,157 +695,114 @@ func Test_multiRequestModeBuilder_makeRequest(t *testing.T) { args args want want }{ - // { - // name: "no_imp_object_in_builder", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // rawRequest: json.RawMessage(`{}`), - // }, - // }, - // args: args{ - // endpointTemplate: nil, - // }, - // want: want{ - // requestData: nil, - // errs: nil, - // }, - // }, - // { - // name: "invalid_imp_object", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // rawRequest: json.RawMessage(`{"imp":["invalid"]}`), - // imps: []any{"invalid"}, - // }, - // }, - // args: args{}, - // want: want{ - // requestData: nil, - // errs: []error{newBadInputError("invalid imp object found at index:0")}, - // }, - // }, - // { - // name: "replace_macros_to_form_endpoint_url", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // imps: []any{ - // map[string]any{ - // "id": "imp_1", - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 5890, - // }, - // "host": "localhost.com", - // }, - // }, - // }, - // }, - // requestNode: map[string]any{ - // "imp": []any{ - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 5890, - // }, - // "host": "localhost.com", - // }, - // }, - // "id": "imp_1", - // }, - // }, - // }, - // hasMacrosInEndpoint: true, - // }, - // }, - // args: args{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://localhost.com/publisher/5890", - // Body: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, - // { - // name: "buildEndpoint_returns_error", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // hasMacrosInEndpoint: true, - // rawRequest: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), - // requestNode: map[string]any{ - // "imp": []any{ - // map[string]any{ - // "ext": map[string]any{}, - // "id": "imp_1", - // }, - // }, - // }, - // imps: []any{ - // map[string]any{ - // "ext": map[string]any{}, - // "id": "imp_1", - // }, - // }, - // }, - // }, - // args: args{ - // endpointTemplate: func() *template.Template { - // errorFunc := template.FuncMap{ - // "errorFunc": func() (string, error) { - // return "", errors.New("intentional error") - // }, - // } - // t := template.Must(template.New("endpointTemplate").Funcs(errorFunc).Parse(`{{errorFunc}}`)) - // return t - // }(), - // }, - // want: want{ - // requestData: nil, - // errs: []error{newBadInputError("failed to replace macros in endpoint, err:template: endpointTemplate:1:2: " + - // "executing \"endpointTemplate\" at : error calling errorFunc: intentional error")}, - // }, - // }, { - name: "multiRequestMode_map_bidder_params_in_multi_imp", + name: "no_imp_object_in_builder", fields: fields{ requestBuilder: &requestBuilder{ - hasMacrosInEndpoint: true, - rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"tagid":"valid_tag_id"}},"id":"imp_2"}]}`), - requestNode: map[string]any{ - "imp": []any{ - map[string]any{ - "ext": map[string]any{ - "bidder": map[string]any{ - "ext": map[string]any{ - "pubid": 5890, - }, - "host": "localhost.com", - }, - }, - "id": "imp_1", - }, - map[string]any{ - "ext": map[string]any{ - "bidder": map[string]any{ - "tagid": "valid_tag_id", + rawRequest: json.RawMessage(`{}`), + }, + }, + args: args{ + endpointTemplate: nil, + }, + want: want{ + requestData: nil, + errs: nil, + }, + }, + { + name: "invalid_imp_object", + fields: fields{ + requestBuilder: &requestBuilder{ + rawRequest: json.RawMessage(`{"imp":["invalid"]}`), + imps: []any{"invalid"}, + }, + }, + args: args{}, + want: want{ + requestData: nil, + errs: []error{newBadInputError("invalid imp object found at index:0")}, + }, + }, + { + name: "replace_macros_to_form_endpoint_url", + fields: fields{ + requestBuilder: &requestBuilder{ + rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), + imps: []any{ + map[string]any{ + "id": "imp_1", + "ext": map[string]any{ + "bidder": map[string]any{ + "ext": map[string]any{ + "pubid": 5890, }, + "host": "localhost.com", }, - "id": "imp_2", }, }, }, + requestNode: map[string]any{}, + hasMacrosInEndpoint: true, + }, + }, + args: args{ + endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), + }, + want: want{ + requestData: []*adapters.RequestData{ + { + Method: http.MethodPost, + Uri: "http://localhost.com/publisher/5890", + Body: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"}]}`), + Headers: http.Header{ + "Content-Type": {"application/json;charset=utf-8"}, + "Accept": {"application/json"}, + }, + }, + }, + errs: nil, + }, + }, + { + name: "buildEndpoint_returns_error", + fields: fields{ + requestBuilder: &requestBuilder{ + hasMacrosInEndpoint: true, + rawRequest: json.RawMessage(`{"imp":[{"ext":{},"id":"imp_1"}]}`), + requestNode: map[string]any{}, + imps: []any{ + map[string]any{ + "ext": map[string]any{}, + "id": "imp_1", + }, + }, + }, + }, + args: args{ + endpointTemplate: func() *template.Template { + errorFunc := template.FuncMap{ + "errorFunc": func() (string, error) { + return "", errors.New("intentional error") + }, + } + t := template.Must(template.New("endpointTemplate").Funcs(errorFunc).Parse(`{{errorFunc}}`)) + return t + }(), + }, + want: want{ + requestData: nil, + errs: []error{newBadInputError("failed to replace macros in endpoint, err:template: endpointTemplate:1:2: " + + "executing \"endpointTemplate\" at : error calling errorFunc: intentional error")}, + }, + }, + { + name: "map_bidder_params_in_multi_imp", + fields: fields{ + requestBuilder: &requestBuilder{ + hasMacrosInEndpoint: true, + rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":5890},"host":"localhost.com"}},"id":"imp_1"},{"ext":{"bidder":{"tagid":"valid_tag_id"}},"id":"imp_2"}]}`), + requestNode: map[string]any{}, imps: []any{ map[string]any{ "ext": map[string]any{ @@ -1120,167 +854,66 @@ func Test_multiRequestModeBuilder_makeRequest(t *testing.T) { errs: nil, }, }, - // { - // name: "multi_imps_request_with_one_invalid_imp", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // hasMacrosInEndpoint: true, - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111},"host":"imp1.host.com"}},"id":"imp_1"},"invalid-imp"]}`), - // requestNode: map[string]any{ - // "imp": []any{ - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 1111, - // }, - // "host": "imp1.host.com", - // }, - // }, - // "id": "imp_1", - // }, - // "invalid", - // }, - // }, - // imps: []any{ - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 1111, - // }, - // "host": "imp1.host.com", - // }, - // }, - // "id": "imp_1", - // }, - // "invalid", - // }, - // }, - // }, - // args: args{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{Location: "host"} - // extMapper := bidderparams.BidderParamMapper{Location: "device"} - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp1.host.com/publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: []error{newBadInputError("invalid imp object found at index:1")}, - // }, - // }, - // { - // name: "one_imp_updates_request_level_param_but_another_imp_does_not_update", - // fields: fields{ - // requestBuilder: &requestBuilder{ - // hasMacrosInEndpoint: true, - // rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111}}},"id":"imp_1"},{"ext":{"bidder":{"ext":{"pubid":2222},"host":"imp2.host.com"}},"id":"imp_2"}]}`), - // requestNode: map[string]any{ - // "imp": []any{ - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 1111, - // }, - // }, - // }, - // "id": "imp_1", - // }, - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 2222, - // }, - // "host": "imp2.host.com", - // }, - // }, - // "id": "imp_2", - // }, - // }, - // }, - // imps: []any{ - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 1111, - // }, - // }, - // }, - // "id": "imp_1", - // }, - // map[string]any{ - // "ext": map[string]any{ - // "bidder": map[string]any{ - // "ext": map[string]any{ - // "pubid": 2222, - // }, - // "host": "imp2.host.com", - // }, - // }, - // "id": "imp_2", - // }, - // }, - // }, - // }, - // args: args{ - // endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), - // bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { - // hostMapper := bidderparams.BidderParamMapper{Location: "host"} - // extMapper := bidderparams.BidderParamMapper{Location: "device"} - // return map[string]bidderparams.BidderParamMapper{ - // "host": hostMapper, - // "ext": extMapper, - // } - // }(), - // }, - // want: want{ - // requestData: []*adapters.RequestData{ - // { - // Method: http.MethodPost, - // Uri: "http://imp2.host.com/publisher/2222", - // Body: json.RawMessage(`{"device":{"pubid":2222},"host":"imp2.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_2"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // { - // Method: http.MethodPost, - // Uri: "http:///publisher/1111", - // Body: json.RawMessage(`{"device":{"pubid":1111},"imp":[{"ext":{"bidder":{}},"id":"imp_1"}]}`), - // Headers: http.Header{ - // "Content-Type": {"application/json;charset=utf-8"}, - // "Accept": {"application/json"}, - // }, - // }, - // }, - // errs: nil, - // }, - // }, + { + name: "multi_imps_request_with_one_invalid_imp", + fields: fields{ + requestBuilder: &requestBuilder{ + hasMacrosInEndpoint: true, + rawRequest: json.RawMessage(`{"imp":[{"ext":{"bidder":{"ext":{"pubid":1111},"host":"imp1.host.com"}},"id":"imp_1"},"invalid-imp"]}`), + requestNode: map[string]any{}, + imps: []any{ + map[string]any{ + "ext": map[string]any{ + "bidder": map[string]any{ + "ext": map[string]any{ + "pubid": 1111, + }, + "host": "imp1.host.com", + }, + }, + "id": "imp_1", + }, + "invalid", + }, + }, + }, + args: args{ + endpointTemplate: template.Must(template.New("endpointTemplate").Parse(`http://{{.host}}/publisher/{{.ext.pubid}}`)), + bidderParamMapper: func() map[string]bidderparams.BidderParamMapper { + hostMapper := bidderparams.BidderParamMapper{Location: "host"} + extMapper := bidderparams.BidderParamMapper{Location: "device"} + tagMapper := bidderparams.BidderParamMapper{Location: "imp.#.tagid"} + return map[string]bidderparams.BidderParamMapper{ + "host": hostMapper, + "ext": extMapper, + "tagid": tagMapper, + } + }(), + }, + want: want{ + requestData: []*adapters.RequestData{ + { + Method: http.MethodPost, + Uri: "http://imp1.host.com/publisher/1111", + Body: json.RawMessage(`{"device":{"pubid":1111},"host":"imp1.host.com","imp":[{"ext":{"bidder":{}},"id":"imp_1"},"invalid"]}`), + Headers: http.Header{ + "Content-Type": {"application/json;charset=utf-8"}, + "Accept": {"application/json"}, + }, + }, + }, + errs: []error{newBadInputError("invalid imp object found at index:1")}, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { builder := &multiRequestModeBuilder{ requestBuilder: tt.fields.requestBuilder, } + if builder.requestNode != nil { + builder.requestNode[impKey] = builder.imps + } requestData, errs := builder.makeRequest(tt.args.endpointTemplate, tt.args.bidderParamMapper) assert.Equalf(t, tt.want.requestData, requestData, "mismatched requestData") assert.Equalf(t, tt.want.errs, errs, "mismatched errs")