From dc9041a3a2d56f3e6387e6e5bc581391969d9237 Mon Sep 17 00:00:00 2001 From: pm-avinash-kapre <112699665+AvinashKapre@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:50:36 +0530 Subject: [PATCH] UOE-10974: Bug-fix- PubMatic-Secondary and pubmatic alias partners are not consuming PublisherID Configured at Partner Account Level (#885) --- .../openwrap/beforevalidationhook_test.go | 5 +- .../openwrap/bidderparams/pubmatic.go | 42 ++- .../openwrap/bidderparams/pubmatic_test.go | 297 +++++++++++++++++- 3 files changed, 322 insertions(+), 22 deletions(-) diff --git a/modules/pubmatic/openwrap/beforevalidationhook_test.go b/modules/pubmatic/openwrap/beforevalidationhook_test.go index bc14a7bbfb2..a31dcc803ed 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook_test.go +++ b/modules/pubmatic/openwrap/beforevalidationhook_test.go @@ -3967,6 +3967,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { models.BidderCode: "pub2-alias", models.IsAlias: "1", models.TIMEOUT: "200", + models.PubID: "301", models.KEY_GEN_PATTERN: "_AU_@_W_x_H_", models.SERVER_SIDE_FLAG: "1", models.VENDORID: "130", @@ -4011,10 +4012,10 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { Reject: false, NbrCode: 0, ChangeSet: hookstage.ChangeSet[hookstage.BeforeValidationRequestPayload]{}, - DebugMessages: []string{`new imp: {"123":{"ImpID":"123","TagID":"adunit","Div":"","SlotName":"adunit","AdUnitName":"adunit","Secure":0,"BidFloor":4.3,"BidFloorCur":"USD","IsRewardInventory":null,"Banner":true,"Video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"Native":null,"IncomingSlots":["700x900","728x90","300x250","640x480"],"Type":"video","Bidders":{"appnexus":{"PartnerID":2,"PrebidBidderCode":"appnexus","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"placementId":0,"site":"12313","adtag":"45343"},"VASTTagFlags":null},"dm-alias":{"PartnerID":3,"PrebidBidderCode":"districtm","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"placementId":0,"site":"12313","adtag":"45343"},"VASTTagFlags":null},"pub2-alias":{"PartnerID":1,"PrebidBidderCode":"pubmatic2","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"publisherId":"5890","adSlot":"adunit@700x900","wrapper":{"version":1,"profile":1234}},"VASTTagFlags":null}},"NonMapped":{},"NewExt":{"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"site":"12313","adtag":"45343"},"dm-alias":{"placementId":0,"site":"12313","adtag":"45343"},"pub2-alias":{"publisherId":"5890","adSlot":"adunit@700x900","wrapper":{"version":1,"profile":1234}}}}},"BidCtx":{},"BannerAdUnitCtx":{"MatchedSlot":"","IsRegex":false,"MatchedRegex":"","SelectedSlotAdUnitConfig":null,"AppliedSlotAdUnitConfig":null,"UsingDefaultConfig":false,"AllowedConnectionTypes":null},"VideoAdUnitCtx":{"MatchedSlot":"","IsRegex":false,"MatchedRegex":"","SelectedSlotAdUnitConfig":null,"AppliedSlotAdUnitConfig":null,"UsingDefaultConfig":false,"AllowedConnectionTypes":null},"BidderError":"","IsAdPodRequest":false,"AdpodConfig":null,"ImpAdPodCfg":null,"BidIDToAPRC":null,"AdserverURL":"","BidIDToDur":null}}`, `new request.ext: {"prebid":{"aliases":{"dm-alias":"appnexus","pub2-alias":"pubmatic"},"aliasgvlids":{"dm-alias":99,"pub2-alias":130},"bidadjustmentfactors":{"appnexus":1,"dm-alias":1,"pub2-alias":1},"bidderparams":{"pub2-alias":{"wiid":""},"pubmatic":{"wiid":""}},"debug":true,"floors":{"enforcement":{"enforcepbs":true},"enabled":true},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":5,"increment":0.05},{"min":5,"max":10,"increment":0.1},{"min":10,"max":20,"increment":0.5}]},"mediatypepricegranularity":{},"includewinners":true,"includebidderkeys":true},"macros":{"[PLATFORM]":"3","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}`}, + DebugMessages: []string{`new imp: {"123":{"ImpID":"123","TagID":"adunit","Div":"","SlotName":"adunit","AdUnitName":"adunit","Secure":0,"BidFloor":4.3,"BidFloorCur":"USD","IsRewardInventory":null,"Banner":true,"Video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"Native":null,"IncomingSlots":["700x900","728x90","300x250","640x480"],"Type":"video","Bidders":{"appnexus":{"PartnerID":2,"PrebidBidderCode":"appnexus","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"placementId":0,"adtag":"45343","site":"12313"},"VASTTagFlags":null},"dm-alias":{"PartnerID":3,"PrebidBidderCode":"districtm","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"placementId":0,"site":"12313","adtag":"45343"},"VASTTagFlags":null},"pub2-alias":{"PartnerID":1,"PrebidBidderCode":"pubmatic2","MatchedSlot":"adunit@700x900","KGP":"_AU_@_W_x_H_","KGPV":"","IsRegex":false,"Params":{"publisherId":"301","adSlot":"adunit@700x900"},"VASTTagFlags":null}},"NonMapped":{},"NewExt":{"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"adtag":"45343","site":"12313"},"dm-alias":{"placementId":0,"site":"12313","adtag":"45343"},"pub2-alias":{"publisherId":"301","adSlot":"adunit@700x900"}}}},"BidCtx":{},"BannerAdUnitCtx":{"MatchedSlot":"","IsRegex":false,"MatchedRegex":"","SelectedSlotAdUnitConfig":null,"AppliedSlotAdUnitConfig":null,"UsingDefaultConfig":false,"AllowedConnectionTypes":null},"VideoAdUnitCtx":{"MatchedSlot":"","IsRegex":false,"MatchedRegex":"","SelectedSlotAdUnitConfig":null,"AppliedSlotAdUnitConfig":null,"UsingDefaultConfig":false,"AllowedConnectionTypes":null},"BidderError":"","IsAdPodRequest":false,"AdpodConfig":null,"ImpAdPodCfg":null,"BidIDToAPRC":null,"AdserverURL":"","BidIDToDur":null}}`, `new request.ext: {"prebid":{"aliases":{"dm-alias":"appnexus","pub2-alias":"pubmatic"},"aliasgvlids":{"dm-alias":99,"pub2-alias":130},"bidadjustmentfactors":{"appnexus":1,"dm-alias":1,"pub2-alias":1},"bidderparams":{"pub2-alias":{"wiid":""},"pubmatic":{"wiid":""}},"debug":true,"floors":{"enforcement":{"enforcepbs":true},"enabled":true},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":5,"increment":0.05},{"min":5,"max":10,"increment":0.1},{"min":10,"max":20,"increment":0.5}]},"mediatypepricegranularity":{},"includewinners":true,"includebidderkeys":true},"macros":{"[PLATFORM]":"3","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}`}, AnalyticsTags: hookanalytics.Analytics{}, }, - bidRequest: json.RawMessage(`{"id":"123-456-789","imp":[{"id":"123","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900},"video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"tagid":"adunit","bidfloor":4.3,"bidfloorcur":"USD","ext":{"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"adtag":"45343","site":"12313"},"dm-alias":{"placementId":0,"site":"12313","adtag":"45343"},"pub2-alias":{"publisherId":"5890","adSlot":"adunit@700x900","wrapper":{"version":1,"profile":1234}}}}}}],"site":{"domain":"test.com","page":"www.test.com","publisher":{"id":"5890"}},"device":{"ua":"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/52.0.2743.82Safari/537.36","ip":"123.145.167.10"},"user":{"id":"119208432","buyeruid":"1rwe432","yob":1980,"gender":"F","customdata":"7D75D25F-FAC9-443D-B2D1-B17FEE11E027","geo":{"country":"US","region":"CA","metro":"90001","city":"Alamo"}},"wseat":["Wseat_0","Wseat_1"],"bseat":["Bseat_0","Bseat_1"],"cur":["cur_0","cur_1"],"wlang":["Wlang_0","Wlang_1"],"bcat":["bcat_0","bcat_1"],"badv":["badv_0","badv_1"],"bapp":["bapp_0","bapp_1"],"source":{"tid":"123-456-789","ext":{"omidpn":"MyIntegrationPartner","omidpv":"7.1"}},"ext":{"prebid":{"aliases":{"dm-alias":"appnexus","pub2-alias":"pubmatic"},"aliasgvlids":{"dm-alias":99,"pub2-alias":130},"bidadjustmentfactors":{"appnexus":1,"dm-alias":1,"pub2-alias":1},"bidderparams":{"pubmatic":{"wiid":""},"pub2-alias":{"wiid":""}},"debug":true,"floors":{"enforcement":{"enforcepbs":true},"enabled":true},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":5,"increment":0.05},{"min":5,"max":10,"increment":0.1},{"min":10,"max":20,"increment":0.5}]},"mediatypepricegranularity":{},"includewinners":true,"includebidderkeys":true},"macros":{"[PLATFORM]":"3","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}}`), + bidRequest: json.RawMessage(`{"id":"123-456-789","imp":[{"id":"123","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900},"video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"tagid":"adunit","bidfloor":4.3,"bidfloorcur":"USD","ext":{"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"site":"12313","adtag":"45343"},"dm-alias":{"placementId":0,"site":"12313","adtag":"45343"},"pub2-alias":{"publisherId":"301","adSlot":"adunit@700x900"}}}}}],"site":{"domain":"test.com","page":"www.test.com","publisher":{"id":"5890"}},"device":{"ua":"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/52.0.2743.82Safari/537.36","ip":"123.145.167.10"},"user":{"id":"119208432","buyeruid":"1rwe432","yob":1980,"gender":"F","customdata":"7D75D25F-FAC9-443D-B2D1-B17FEE11E027","geo":{"country":"US","region":"CA","metro":"90001","city":"Alamo"}},"wseat":["Wseat_0","Wseat_1"],"bseat":["Bseat_0","Bseat_1"],"cur":["cur_0","cur_1"],"wlang":["Wlang_0","Wlang_1"],"bcat":["bcat_0","bcat_1"],"badv":["badv_0","badv_1"],"bapp":["bapp_0","bapp_1"],"source":{"tid":"123-456-789","ext":{"omidpn":"MyIntegrationPartner","omidpv":"7.1"}},"ext":{"prebid":{"aliases":{"dm-alias":"appnexus","pub2-alias":"pubmatic"},"aliasgvlids":{"dm-alias":99,"pub2-alias":130},"bidadjustmentfactors":{"appnexus":1,"dm-alias":1,"pub2-alias":1},"bidderparams":{"pub2-alias":{"wiid":""},"pubmatic":{"wiid":""}},"debug":true,"floors":{"enforcement":{"enforcepbs":true},"enabled":true},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":5,"increment":0.05},{"min":5,"max":10,"increment":0.1},{"min":10,"max":20,"increment":0.5}]},"mediatypepricegranularity":{},"includewinners":true,"includebidderkeys":true},"macros":{"[PLATFORM]":"3","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}}`), error: false, doMutate: true, nilCurrencyConversion: false, diff --git a/modules/pubmatic/openwrap/bidderparams/pubmatic.go b/modules/pubmatic/openwrap/bidderparams/pubmatic.go index e79858bb0d5..9b90a7b2b94 100644 --- a/modules/pubmatic/openwrap/bidderparams/pubmatic.go +++ b/modules/pubmatic/openwrap/bidderparams/pubmatic.go @@ -3,7 +3,6 @@ package bidderparams import ( "encoding/json" "fmt" - "strconv" "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/cache" @@ -12,16 +11,9 @@ import ( ) func PreparePubMaticParamsV25(rctx models.RequestCtx, cache cache.Cache, bidRequest openrtb2.BidRequest, imp openrtb2.Imp, impExt models.ImpExtension, partnerID int) (string, string, bool, []byte, error) { - wrapExt := fmt.Sprintf(`{"%s":%d,"%s":%d}`, models.SS_PM_VERSION_ID, rctx.DisplayID, models.SS_PM_PROFILE_ID, rctx.ProfileID) - - // change profile id for pubmatic2 - if secondaryProfileID, ok := rctx.PartnerConfigMap[partnerID][models.KEY_PROFILE_ID]; ok { - wrapExt = fmt.Sprintf(`{"%s":0,"%s":%s}`, models.SS_PM_VERSION_ID, models.SS_PM_PROFILE_ID, secondaryProfileID) - } - extImpPubMatic := openrtb_ext.ExtImpPubmatic{ - PublisherId: strconv.Itoa(rctx.PubID), - WrapExt: json.RawMessage(wrapExt), + PublisherId: getPubMaticPublisherID(rctx, partnerID), + WrapExt: getPubMaticWrapperExt(rctx, partnerID), Keywords: getImpExtPubMaticKeyWords(impExt, rctx.PartnerConfigMap[partnerID][models.BidderCode]), Floors: getApplovinBidFloors(rctx, imp), SendBurl: rctx.SendBurl, @@ -149,3 +141,33 @@ func getMatchingSlotAndPattern(rctx models.RequestCtx, cache cache.Cache, slots } return matchedSlot, matchedPattern, isRegexSlot } + +func getPubMaticPublisherID(rctx models.RequestCtx, partnerID int) string { + //Pubmatic secondary flow send account level pubID + if pubID, ok := rctx.PartnerConfigMap[partnerID][models.KEY_PUBLISHER_ID]; ok { + return pubID + } + //PubMatic alias flow + if pubID, ok := rctx.PartnerConfigMap[partnerID][models.PubID]; ok { + return pubID + } + //PubMatic primary flow + return rctx.PubIDStr +} + +func getPubMaticWrapperExt(rctx models.RequestCtx, partnerID int) json.RawMessage { + wrapExt := fmt.Sprintf(`{"%s":%d,"%s":%d}`, models.SS_PM_VERSION_ID, rctx.DisplayID, models.SS_PM_PROFILE_ID, rctx.ProfileID) + + // change profile id for pubmatic2 + if secondaryProfileID, ok := rctx.PartnerConfigMap[partnerID][models.KEY_PROFILE_ID]; ok { + wrapExt = fmt.Sprintf(`{"%s":%s}`, models.SS_PM_PROFILE_ID, secondaryProfileID) + } + + //Pubmatic alias flow do not send wrapExt + if isAlias, ok := rctx.PartnerConfigMap[partnerID][models.IsAlias]; ok && isAlias == "1" { + if pubID, ok := rctx.PartnerConfigMap[partnerID][models.PubID]; ok && pubID != rctx.PubIDStr { + return nil + } + } + return json.RawMessage(wrapExt) +} diff --git a/modules/pubmatic/openwrap/bidderparams/pubmatic_test.go b/modules/pubmatic/openwrap/bidderparams/pubmatic_test.go index 1efdf6150e4..604a7c6e40c 100644 --- a/modules/pubmatic/openwrap/bidderparams/pubmatic_test.go +++ b/modules/pubmatic/openwrap/bidderparams/pubmatic_test.go @@ -1,6 +1,7 @@ package bidderparams import ( + "encoding/json" "testing" "github.com/golang/mock/gomock" @@ -254,6 +255,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 1, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -320,23 +322,25 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ 1: { - models.PREBID_PARTNER_NAME: "pubmatic", - models.BidderCode: "pubmatic", + models.PREBID_PARTNER_NAME: "pubmatic2", + models.BidderCode: "pubmatic2", models.TIMEOUT: "200", models.KEY_GEN_PATTERN: "_AU_@_DIV_@_W_x_H_", models.SERVER_SIDE_FLAG: "1", models.KEY_PROFILE_ID: "1323", + models.KEY_PUBLISHER_ID: "301", }, }, }, cache: mockCache, impExt: models.ImpExtension{ Bidder: map[string]*models.BidderExtension{ - "pubmatic": { + "pubmatic2": { KeyWords: []models.KeyVal{ { Key: "test_key1", @@ -377,7 +381,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { matchedSlot: "/Test_Adunit1234@Div1@200x300", matchedPattern: "", isRegexSlot: false, - params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`), + params: []byte(`{"publisherId":"301","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`), wantErr: false, }, }, @@ -387,23 +391,91 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ 1: { - models.PREBID_PARTNER_NAME: "pubmatic", - models.BidderCode: "pubmatic", + models.PREBID_PARTNER_NAME: "pubmatic2", + models.BidderCode: "pubmatic2", models.TIMEOUT: "200", models.KEY_GEN_PATTERN: "_RE_@_W_x_H_", models.SERVER_SIDE_FLAG: "1", models.KEY_PROFILE_ID: "1323", + models.KEY_PUBLISHER_ID: "301", }, }, }, cache: mockCache, impExt: models.ImpExtension{ Bidder: map[string]*models.BidderExtension{ - "pubmatic": { + "pubmatic2": { + KeyWords: []models.KeyVal{ + { + Key: "test_key1", + Values: []string{"test_value1", "test_value2"}, + }, + { + Key: "test_key2", + Values: []string{"test_value1", "test_value2"}, + }, + }, + }, + }, + }, + imp: getTestImp("/Test_Adunit1234", true, false), + partnerID: 1, + }, + setup: func() { + mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{ + "/test_adunit1234@200x300": { + PartnerId: 1, + AdapterId: 1, + SlotName: "/Test_Adunit1234@200x300", + SlotMappings: map[string]interface{}{ + "site": "12313", + "adtag": "45343", + "slotName": "/Test_Adunit1234@200x300", + }, + }, + }) + mockCache.EXPECT().GetSlotToHashValueMapFromCacheV25(gomock.Any(), gomock.Any()).Return(models.SlotMappingInfo{ + OrderedSlotList: []string{"test", "test1"}, + }) + }, + want: want{ + matchedSlot: "/Test_Adunit1234@200x300", + matchedPattern: "", + isRegexSlot: false, + params: []byte(`{"publisherId":"301","adSlot":"/Test_Adunit1234@200x300","wrapper":{"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`), + wantErr: false, + }, + }, + { + name: "exact_matched_slot_found_adslot_updated_from_PubMatic_alias_flow_for_prebids2s_regex", + args: args{ + rctx: models.RequestCtx{ + IsTestRequest: 0, + PubID: 5890, + PubIDStr: "5890", + ProfileID: 123, + DisplayID: 1, + PartnerConfigMap: map[int]map[string]string{ + 1: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubmatic_alias", + models.TIMEOUT: "200", + models.KEY_GEN_PATTERN: "_RE_@_W_x_H_", + models.SERVER_SIDE_FLAG: "1", + models.IsAlias: "1", + models.PubID: "301", + }, + }, + }, + cache: mockCache, + impExt: models.ImpExtension{ + Bidder: map[string]*models.BidderExtension{ + "pubmatic_alias": { KeyWords: []models.KeyVal{ { Key: "test_key1", @@ -441,7 +513,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { matchedSlot: "/Test_Adunit1234@200x300", matchedPattern: "", isRegexSlot: false, - params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`), + params: []byte(`{"publisherId":"301","adSlot":"/Test_Adunit1234@200x300","keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`), wantErr: false, }, }, @@ -451,6 +523,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -514,6 +587,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -583,6 +657,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -649,6 +724,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -721,6 +797,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -787,6 +864,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -853,6 +931,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -919,6 +998,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -985,6 +1065,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -1051,6 +1132,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 1, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -1122,6 +1204,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 2, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -1171,6 +1254,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 2, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, DisplayID: 1, PartnerConfigMap: map[int]map[string]string{ @@ -1220,6 +1304,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { rctx: models.RequestCtx{ IsTestRequest: 0, PubID: 5890, + PubIDStr: "5890", ProfileID: 123, ProfileIDStr: "123", DisplayID: 1, @@ -1231,7 +1316,6 @@ func TestPreparePubMaticParamsV25(t *testing.T) { models.TIMEOUT: "200", models.KEY_GEN_PATTERN: "_AU_@_DIV_@_W_x_H_", models.SERVER_SIDE_FLAG: "1", - models.KEY_PROFILE_ID: "1323", }, }, AppLovinMax: models.AppLovinMax{ @@ -1288,7 +1372,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) { matchedSlot: "/Test_Adunit1234@Div1@200x300", matchedPattern: "", isRegexSlot: false, - params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}],"floors":[1.5,1.2,2.2],"sendburl":true}`), + params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}],"floors":[1.5,1.2,2.2],"sendburl":true}`), wantErr: false, }, }, @@ -1437,3 +1521,196 @@ func TestGetMatchingSlotAndPattern(t *testing.T) { }) } } + +func TestGetPubMaticPublisherID(t *testing.T) { + type args struct { + rctx models.RequestCtx + partnerID int + } + tests := []struct { + name string + args args + want string + }{ + { + name: "pubmatic partner", + args: args{ + partnerID: 789, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 789: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubmatic", + models.PubID: "5890", + }, + }, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: "5890", + }, + { + name: "pubmatic secondary partner", + args: args{ + partnerID: 123, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 123: { + models.PREBID_PARTNER_NAME: "pubmatic2", + models.BidderCode: "pubmatic2", + models.KEY_PUBLISHER_ID: "301", + models.PubID: "5890", + }, + }, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: "301", + }, + { + name: "pubmatic alias partner", + args: args{ + partnerID: 456, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 456: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubm_alias", + models.PubID: "301", + models.IsAlias: "1", + }, + }, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: "301", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := getPubMaticPublisherID(tt.args.rctx, tt.args.partnerID) + assert.Equal(t, tt.want, got) + }) + } +} + +func TestGetPubMaticWrapperExt(t *testing.T) { + type args struct { + rctx models.RequestCtx + partnerID int + } + tests := []struct { + name string + args args + want json.RawMessage + }{ + { + name: "pubmatic partner", + args: args{ + partnerID: 789, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 789: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubmatic", + models.PubID: "5890", + }, + }, + DisplayID: 1, + ProfileID: 1234, + PubID: 5890, + }, + }, + want: json.RawMessage(`{"version":1,"profile":1234}`), + }, + { + name: "pubmatic secondary partner", + args: args{ + partnerID: 123, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 123: { + models.PREBID_PARTNER_NAME: "pubmatic2", + models.BidderCode: "pubmatic2", + models.KEY_PROFILE_ID: "222", + }, + }, + DisplayID: 1, + ProfileID: 1234, + }, + }, + want: json.RawMessage(`{"profile":222}`), + }, + { + name: "pubmatic alias partner with pubID different from incoming request pubID", + args: args{ + partnerID: 456, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 456: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubm_alias", + models.PubID: "301", + models.IsAlias: "1", + }, + }, + DisplayID: 1, + ProfileID: 1234, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: nil, + }, + { + name: "pubmatic alias partner with pubID same as incoming request pubID", + args: args{ + partnerID: 456, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 456: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubm_alias", + models.PubID: "5890", + models.IsAlias: "1", + }, + }, + DisplayID: 1, + ProfileID: 1234, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: json.RawMessage(`{"version":1,"profile":1234}`), + }, + { + name: "pubmatic alias partner with no pubID in partner config", + args: args{ + partnerID: 456, + rctx: models.RequestCtx{ + PartnerConfigMap: map[int]map[string]string{ + 456: { + models.PREBID_PARTNER_NAME: "pubmatic", + models.BidderCode: "pubm_alias", + models.IsAlias: "1", + }, + }, + DisplayID: 1, + ProfileID: 1234, + PubID: 5890, + PubIDStr: "5890", + }, + }, + want: json.RawMessage(`{"version":1,"profile":1234}`), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := getPubMaticWrapperExt(tt.args.rctx, tt.args.partnerID) + assert.Equal(t, tt.want, got) + }) + } +}