diff --git a/go.mod b/go.mod index 95df10bfc7..0480d5e46c 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,6 @@ require ( git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3 git.pubmatic.com/vastunwrap v0.0.0-00010101000000-000000000000 github.com/PubMatic-OpenWrap/fastxml v0.0.0-20241125102315-0d8f851a6e52 - github.com/beevik/etree/110 v0.0.0-00010101000000-000000000000 github.com/diegoholiveira/jsonlogic/v3 v3.5.3 github.com/go-sql-driver/mysql v1.7.1 github.com/golang/mock v1.6.0 @@ -89,6 +88,7 @@ require ( github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect + github.com/yudai/pp v2.0.1+incompatible // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/sys v0.18.0 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect diff --git a/go.sum b/go.sum index b5d85f1ecb..9dd291e296 100644 --- a/go.sum +++ b/go.sum @@ -519,6 +519,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= +github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/modules/pubmatic/openwrap/adapters/bidders.go b/modules/pubmatic/openwrap/adapters/bidders.go index 2bf2ac892f..293870fa02 100644 --- a/modules/pubmatic/openwrap/adapters/bidders.go +++ b/modules/pubmatic/openwrap/adapters/bidders.go @@ -380,23 +380,21 @@ func builderBeachfront(params BidderParameters) (json.RawMessage, error) { func builderSmaato(params BidderParameters) (json.RawMessage, error) { jsonStr := bytes.Buffer{} jsonStr.WriteByte('{') - var fields []string - if publisherID, ok := getString(params.FieldMap["publisherId"]); !ok { + publisherID, ok := getString(params.FieldMap["publisherId"]) + if !ok { return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "publisherId") - } else { - fields = append(fields, fmt.Sprintf(`"publisherId":"%s"`, publisherID)) } + fmt.Fprintf(&jsonStr, `"publisherId":"%s"`, publisherID) if adspaceID, ok := getString(params.FieldMap["adspaceId"]); ok { - fields = append(fields, fmt.Sprintf(`"adspaceId":"%s"`, adspaceID)) + fmt.Fprintf(&jsonStr, `,"adspaceId":"%s"`, adspaceID) } if adbreakID, ok := getString(params.FieldMap["adbreakId"]); ok { - fields = append(fields, fmt.Sprintf(`"adbreakId":"%s"`, adbreakID)) + fmt.Fprintf(&jsonStr, `,"adbreakId":"%s"`, adbreakID) } - jsonStr.WriteString(strings.Join(fields, ",")) jsonStr.WriteByte('}') return jsonStr.Bytes(), nil } diff --git a/modules/pubmatic/openwrap/adapters/bidders_test.go b/modules/pubmatic/openwrap/adapters/bidders_test.go index 7a87611fec..74ed8f9c77 100644 --- a/modules/pubmatic/openwrap/adapters/bidders_test.go +++ b/modules/pubmatic/openwrap/adapters/bidders_test.go @@ -2001,6 +2001,19 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) { args args want json.RawMessage }{ + { + name: "all_missing", + args: args{ + reqID: "", + width: nil, + height: nil, + fieldMap: map[string]interface{}{}, + slotKey: "", + adapterName: string(openrtb_ext.BidderSmaato), + bidderCode: string(openrtb_ext.BidderSmaato), + }, + want: nil, + }, { name: "publisherId missing", args: args{ @@ -2009,6 +2022,7 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) { height: nil, fieldMap: map[string]interface{}{ "adspaceId": "1234", + "adbreakId": "4567", }, slotKey: "", adapterName: string(openrtb_ext.BidderSmaato), @@ -2032,64 +2046,51 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) { want: json.RawMessage(`{"publisherId": "1234"}`), }, { - name: "publisherId & adspaceId both are missing", - args: args{ - reqID: "", - width: nil, - height: nil, - fieldMap: map[string]interface{}{}, - slotKey: "", - adapterName: string(openrtb_ext.BidderSmaato), - bidderCode: string(openrtb_ext.BidderSmaato), - }, - want: nil, - }, - { - name: "publisherId_adspaceId_both_are_present", + name: "adbreakId missing", args: args{ width: nil, height: nil, fieldMap: map[string]interface{}{ "publisherId": "1234", - "adspaceId": "3456", }, slotKey: "", adapterName: string(openrtb_ext.BidderSmaato), bidderCode: string(openrtb_ext.BidderSmaato), }, - want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`), + want: json.RawMessage(`{"publisherId": "1234"}`), }, { - name: "All_params_are_present", + name: "publisherId_adspaceId__present", args: args{ + width: nil, height: nil, fieldMap: map[string]interface{}{ "publisherId": "1234", "adspaceId": "3456", - "adbreakId": "7899", }, slotKey: "", adapterName: string(openrtb_ext.BidderSmaato), bidderCode: string(openrtb_ext.BidderSmaato), }, - want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456","adbreakId": "7899"}`), + want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`), }, { - name: "publisherId_and_adbreakId_present", + name: "publisherId_adbreakId__present", args: args{ + width: nil, height: nil, fieldMap: map[string]interface{}{ "publisherId": "1234", - "adbreakId": "7899", + "adbreakId": "3456", }, slotKey: "", adapterName: string(openrtb_ext.BidderSmaato), bidderCode: string(openrtb_ext.BidderSmaato), }, - want: json.RawMessage(`{"publisherId": "1234","adbreakId": "7899"}`), + want: json.RawMessage(`{"publisherId": "1234","adbreakId": "3456"}`), }, { name: "adspaceId_and_adbreakId_present", @@ -2107,18 +2108,20 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) { want: nil, }, { - name: "adbreakId_present", + name: "all_params_are_present", args: args{ width: nil, height: nil, fieldMap: map[string]interface{}{ - "adbreakId": "7899", + "publisherId": "1234", + "adspaceId": "3456", + "adbreakId": "7899", }, slotKey: "", adapterName: string(openrtb_ext.BidderSmaato), bidderCode: string(openrtb_ext.BidderSmaato), }, - want: nil, + want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456","adbreakId": "7899"}`), }, } for _, tt := range tests {