Skip to content

Commit

Permalink
fix test cases and handle only valid values from max req
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-saurabh-narkhede committed Apr 17, 2024
1 parent ccf2b36 commit 21b7c16
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 34 deletions.
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/beforevalidationhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
DebugMessages: []string{`new imp: {"1":{"ImpID":"1","TagID":"adunit","Div":"","SlotName":"adunit","AdUnitName":"adunit","Secure":0,"BidFloor":0.01,"BidFloorCur":"USD","IsRewardInventory":null,"Banner":true,"Video":{"mimes":["video/3gpp2","video/quicktime","video/mp4","video/x-m4v","video/3gpp"],"startdelay":0,"protocols":[2,3,5,6,7,8,11,12,13,14],"w":300,"h":250,"placement":2,"linearity":1,"boxingallowed":1,"playbackend":1,"delivery":[2],"pos":0,"companionad":[{"format":[{"w":300,"h":250}],"pos":0,"vcm":1}],"api":[7],"companiontype":[1,2,3]},"Native":null,"IncomingSlots":["300x250","300x250v","700x900","728x90"],"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"},"VASTTagFlag":false,"VASTTagFlags":null}},"NonMapped":{},"NewExt":{"skadn":{"sourceapp":"406719683","versions":["2.0","2.1","2.2","3.0","4.0"],"skadnetids":["cstr6suwn9.skadnetwork","7ug5zh24hu.skadnetwork","uw77j35x4d.skadnetwork","c6k4g5qg8m.skadnetwork","hs6bdukanm.skadnetwork","yclnxrl5pm.skadnetwork","3sh42y64q3.skadnetwork","cj5566h2ga.skadnetwork","klf5c3l5u5.skadnetwork","8s468mfl3y.skadnetwork","2u9pt9hc89.skadnetwork","7rz58n8ntl.skadnetwork","ppxm28t8ap.skadnetwork","mtkv5xtk9e.skadnetwork","cg4yq2srnc.skadnetwork","wzmmz9fp6w.skadnetwork","k674qkevps.skadnetwork","v72qych5uu.skadnetwork","578prtvx9j.skadnetwork","3rd42ekr43.skadnetwork","g28c52eehv.skadnetwork","2fnua5tdw4.skadnetwork","9nlqeag3gk.skadnetwork","5lm9lj6jb7.skadnetwork","97r2b46745.skadnetwork","e5fvkxwrpn.skadnetwork","4pfyvq9l8r.skadnetwork","tl55sbb4fm.skadnetwork","t38b2kh725.skadnetwork","prcb7njmu6.skadnetwork","mlmmfzh3r3.skadnetwork","9t245vhmpl.skadnetwork","9rd848q2bz.skadnetwork","4fzdc2evr5.skadnetwork","4468km3ulz.skadnetwork","m8dbw4sv7c.skadnetwork","ejvt5qm6ak.skadnetwork","5lm9lj6jb7.skadnetwork","44jx6755aq.skadnetwork","6g9af3uyq4.skadnetwork","u679fj5vs4.skadnetwork","rx5hdcabgc.skadnetwork","275upjj5gd.skadnetwork","p78axxw29g.skadnetwork"],"productpage":1,"version":"2.0"},"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"site":"12313","adtag":"45343"}}}},"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}}`, `new request.ext: {"prebid":{"bidadjustmentfactors":{"appnexus":1},"bidderparams":{"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]":"5","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}`},
AnalyticsTags: hookanalytics.Analytics{},
},
wantBidRequest: json.RawMessage(`{"id":"{BID_ID}","imp":[{"id":"1","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900,"api":[5,6,7]},"video":{"mimes":["video/3gpp2","video/quicktime","video/mp4","video/x-m4v","video/3gpp"],"startdelay":0,"protocols":[2,3,5,6,7,8,11,12,13,14],"w":300,"h":250,"placement":2,"linearity":1,"boxingallowed":1,"playbackend":1,"delivery":[2],"pos":0,"companionad":[{"format":[{"w":300,"h":250}],"pos":0,"vcm":1}],"api":[7],"companiontype":[1,2,3]},"displaymanager":"PubMatic_OpenWrap_SDK","displaymanagerver":"3.1.0","tagid":"adunit","bidfloor":0.01,"bidfloorcur":"USD","clickbrowser":1,"secure":0,"exp":14400,"ext":{"skadn":{"sourceapp":"406719683","versions":["2.0","2.1","2.2","3.0","4.0"],"skadnetids":["cstr6suwn9.skadnetwork","7ug5zh24hu.skadnetwork","uw77j35x4d.skadnetwork","c6k4g5qg8m.skadnetwork","hs6bdukanm.skadnetwork","yclnxrl5pm.skadnetwork","3sh42y64q3.skadnetwork","cj5566h2ga.skadnetwork","klf5c3l5u5.skadnetwork","8s468mfl3y.skadnetwork","2u9pt9hc89.skadnetwork","7rz58n8ntl.skadnetwork","ppxm28t8ap.skadnetwork","mtkv5xtk9e.skadnetwork","cg4yq2srnc.skadnetwork","wzmmz9fp6w.skadnetwork","k674qkevps.skadnetwork","v72qych5uu.skadnetwork","578prtvx9j.skadnetwork","3rd42ekr43.skadnetwork","g28c52eehv.skadnetwork","2fnua5tdw4.skadnetwork","9nlqeag3gk.skadnetwork","5lm9lj6jb7.skadnetwork","97r2b46745.skadnetwork","e5fvkxwrpn.skadnetwork","4pfyvq9l8r.skadnetwork","tl55sbb4fm.skadnetwork","t38b2kh725.skadnetwork","prcb7njmu6.skadnetwork","mlmmfzh3r3.skadnetwork","9t245vhmpl.skadnetwork","9rd848q2bz.skadnetwork","4fzdc2evr5.skadnetwork","4468km3ulz.skadnetwork","m8dbw4sv7c.skadnetwork","ejvt5qm6ak.skadnetwork","5lm9lj6jb7.skadnetwork","44jx6755aq.skadnetwork","6g9af3uyq4.skadnetwork","u679fj5vs4.skadnetwork","rx5hdcabgc.skadnetwork","275upjj5gd.skadnetwork","p78axxw29g.skadnetwork"],"productpage":1,"version":"2.0"},"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"site":"12313","adtag":"45343"}}}}}],"app":{"id":"{NETWORK_APP_ID}","name":"DrawHappyAngel","bundle":"com.newstory.DrawHappyAngel","domain":"abc.com","cat":["IAB9-30"],"ver":"0.5.4","paid":1,"publisher":{"id":"5890","name":"New Story Inc.","ext":{"installed_sdk":{"id":"MOLOCO_BIDDING","sdk_version":{"major":1,"minor":0,"micro":0},"adapter_version":{"major":1,"minor":0,"micro":0}}}},"keywords":"k1=v1","ext":{"orientation":1}},"device":{"geo":{"lat":40.7429,"lon":-73.9392,"type":2,"ipservice":3,"country":"USA","region":"ny","metro":"501","zip":"11101","utcoffset":-480,"ext":{"org":"Myanmar Broadband Telecom Co.","isp":"Myanmar Broadband Telecom Co."}},"ua":"Mozilla/5.0 (Linux; Android 13; 22101316C Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.230 Mobile Safari/537.36","ip":"38.158.207.171","devicetype":4,"make":"xiaomi","model":"22101316c","os":"android","osv":"13.0.0","hwv":"ruby","h":2400,"w":1080,"ppi":440,"pxratio":2.75,"js":1,"language":"en","carrier":"MYTEL","mccmnc":"311-480","connectiontype":5,"ifa":"497a10d6-c4dd-4e04-a986-c32b7180d462","ext":{"atts":3}},"user":{"customdata":"7D75D25F-FAC9-443D-B2D1-B17FEE11E027","yob":2000,"gender":"M","data":[{"id":"1","name":"PubMatic_SDK","segment":[{"id":"seg_id","name":"segment_sdk","ext":{"segtax":90}}]}],"ext":{"gdpr":0}},"at":1,"tmax":3000,"bcat":["IAB26-4","IAB26-2","IAB25-6","IAB25-5","IAB25-4","IAB25-3","IAB25-1","IAB25-7","IAB8-18","IAB26-3","IAB26-1","IAB8-5","IAB25-2","IAB11-4"],"source":{"tid":"{BID_ID}","ext":{"schain":{"ver":"1.0","complete":1,"nodes":[{"asi":"applovin.com","sid":"53bf468f18c5a0e2b7d4e3f748c677c1","rid":"494dbe15a3ce08c54f4e456363f35a022247f997","hp":1}]},"omidpn":"Pubmatic","omidpv":"3.1.0"}},"regs":{"coppa":1,"ext":{"ccpa":0,"gdpr":1,"consent":"0","tcf_consent_string":"{TCF_STRING}","gpp":"gpp_string","gpp_sid":[7],"us_privacy":"uspConsentString"}},"ext":{"prebid":{"bidadjustmentfactors":{"appnexus":1},"bidderparams":{"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]":"5","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}}`),
wantBidRequest: json.RawMessage(`{"id":"{BID_ID}","imp":[{"id":"1","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900,"api":[5,6,7]},"video":{"mimes":["video/3gpp2","video/quicktime","video/mp4","video/x-m4v","video/3gpp"],"startdelay":0,"protocols":[2,3,5,6,7,8,11,12,13,14],"w":300,"h":250,"placement":2,"linearity":1,"boxingallowed":1,"playbackend":1,"delivery":[2],"pos":0,"companionad":[{"format":[{"w":300,"h":250}],"pos":0,"vcm":1}],"api":[7],"companiontype":[1,2,3]},"displaymanager":"PubMatic_OpenWrap_SDK","displaymanagerver":"3.1.0","tagid":"adunit","bidfloor":0.01,"bidfloorcur":"USD","clickbrowser":1,"secure":0,"exp":14400,"ext":{"skadn":{"sourceapp":"406719683","versions":["2.0","2.1","2.2","3.0","4.0"],"skadnetids":["cstr6suwn9.skadnetwork","7ug5zh24hu.skadnetwork","uw77j35x4d.skadnetwork","c6k4g5qg8m.skadnetwork","hs6bdukanm.skadnetwork","yclnxrl5pm.skadnetwork","3sh42y64q3.skadnetwork","cj5566h2ga.skadnetwork","klf5c3l5u5.skadnetwork","8s468mfl3y.skadnetwork","2u9pt9hc89.skadnetwork","7rz58n8ntl.skadnetwork","ppxm28t8ap.skadnetwork","mtkv5xtk9e.skadnetwork","cg4yq2srnc.skadnetwork","wzmmz9fp6w.skadnetwork","k674qkevps.skadnetwork","v72qych5uu.skadnetwork","578prtvx9j.skadnetwork","3rd42ekr43.skadnetwork","g28c52eehv.skadnetwork","2fnua5tdw4.skadnetwork","9nlqeag3gk.skadnetwork","5lm9lj6jb7.skadnetwork","97r2b46745.skadnetwork","e5fvkxwrpn.skadnetwork","4pfyvq9l8r.skadnetwork","tl55sbb4fm.skadnetwork","t38b2kh725.skadnetwork","prcb7njmu6.skadnetwork","mlmmfzh3r3.skadnetwork","9t245vhmpl.skadnetwork","9rd848q2bz.skadnetwork","4fzdc2evr5.skadnetwork","4468km3ulz.skadnetwork","m8dbw4sv7c.skadnetwork","ejvt5qm6ak.skadnetwork","5lm9lj6jb7.skadnetwork","44jx6755aq.skadnetwork","6g9af3uyq4.skadnetwork","u679fj5vs4.skadnetwork","rx5hdcabgc.skadnetwork","275upjj5gd.skadnetwork","p78axxw29g.skadnetwork"],"productpage":1,"version":"2.0"},"data":{"pbadslot":"adunit"},"prebid":{"bidder":{"appnexus":{"placementId":0,"site":"12313","adtag":"45343"}}}}}],"app":{"id":"{NETWORK_APP_ID}","name":"DrawHappyAngel","bundle":"com.newstory.DrawHappyAngel","domain":"abc.com","cat":["IAB9-30"],"ver":"0.5.4","paid":1,"publisher":{"id":"5890","name":"New Story Inc.","ext":{"installed_sdk":{"id":"MOLOCO_BIDDING","sdk_version":{"major":1,"minor":0,"micro":0},"adapter_version":{"major":1,"minor":0,"micro":0}}}},"keywords":"k1=v1","ext":{"orientation":1}},"device":{"geo":{"city":"Queens","lat":40.7429,"lon":-73.9392,"type":2,"ipservice":3,"country":"USA","region":"ny","metro":"501","zip":"11101","utcoffset":-480,"ext":{"org":"Myanmar Broadband Telecom Co.","isp":"Myanmar Broadband Telecom Co."}},"ua":"Mozilla/5.0 (Linux; Android 13; 22101316C Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.230 Mobile Safari/537.36","ip":"38.158.207.171","devicetype":4,"make":"xiaomi","model":"22101316c","os":"android","osv":"13.0.0","hwv":"ruby","h":2400,"w":1080,"ppi":440,"pxratio":2.75,"js":1,"language":"en","carrier":"MYTEL","mccmnc":"311-480","connectiontype":5,"ifa":"497a10d6-c4dd-4e04-a986-c32b7180d462","ext":{"atts":3}},"user":{"customdata":"7D75D25F-FAC9-443D-B2D1-B17FEE11E027","yob":2000,"gender":"M","data":[{"id":"1","name":"PubMatic_SDK","segment":[{"id":"seg_id","name":"segment_sdk","ext":{"segtax":90}}]}],"ext":{"gdpr":0}},"at":1,"tmax":3000,"bcat":["IAB26-4","IAB26-2","IAB25-6","IAB25-5","IAB25-4","IAB25-3","IAB25-1","IAB25-7","IAB8-18","IAB26-3","IAB26-1","IAB8-5","IAB25-2","IAB11-4"],"source":{"tid":"{BID_ID}","ext":{"schain":{"ver":"1.0","complete":1,"nodes":[{"asi":"applovin.com","sid":"53bf468f18c5a0e2b7d4e3f748c677c1","rid":"494dbe15a3ce08c54f4e456363f35a022247f997","hp":1}]},"omidpn":"Pubmatic","omidpv":"3.1.0"}},"regs":{"coppa":1,"ext":{"ccpa":0,"gdpr":1,"consent":"0","tcf_consent_string":"{TCF_STRING}","gpp":"gpp_string","gpp_sid":[7],"us_privacy":"uspConsentString"}},"ext":{"prebid":{"bidadjustmentfactors":{"appnexus":1},"bidderparams":{"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]":"5","[PROFILE_ID]":"1234","[PROFILE_VERSION]":"1","[UNIX_TIMESTAMP]":"0","[WRAPPER_IMPRESSION_ID]":""}}}}`),
wantErr: false,
doMutate: true,
},
Expand Down
78 changes: 61 additions & 17 deletions modules/pubmatic/openwrap/max.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/openrtb/v20/openrtb2"
)

func getSignalData(requestBody []byte) string {
Expand All @@ -22,7 +22,12 @@ func addSignalDataInRequest(signal string, maxRequest *openrtb2.BidRequest, clie
return
}

var sdkRequest openrtb2.BidRequest
sdkRequest := openrtb2.BidRequest{
Regs: &openrtb2.Regs{
COPPA: -1,
},
}

if err := json.Unmarshal([]byte(signal), &sdkRequest); err != nil {
return
}
Expand Down Expand Up @@ -50,9 +55,17 @@ func updateImpression(sdkImpression openrtb2.Imp, maxImpression *openrtb2.Imp) {
return
}

maxImpression.DisplayManager = sdkImpression.DisplayManager
maxImpression.DisplayManagerVer = sdkImpression.DisplayManagerVer
maxImpression.ClickBrowser = sdkImpression.ClickBrowser
if sdkImpression.DisplayManager != "" {
maxImpression.DisplayManager = sdkImpression.DisplayManager
}

if sdkImpression.DisplayManagerVer != "" {
maxImpression.DisplayManagerVer = sdkImpression.DisplayManagerVer
}

if sdkImpression.ClickBrowser != nil {
maxImpression.ClickBrowser = sdkImpression.ClickBrowser
}

if sdkImpression.Video != nil {
maxImpression.Video = sdkImpression.Video
Expand Down Expand Up @@ -81,8 +94,13 @@ func updateDevice(sdkDevice *openrtb2.Device, maxRequest *openrtb2.BidRequest) {
maxRequest.Device = &openrtb2.Device{}
}

maxRequest.Device.MCCMNC = sdkDevice.MCCMNC
maxRequest.Device.ConnectionType = sdkDevice.ConnectionType
if sdkDevice.MCCMNC != "" {
maxRequest.Device.MCCMNC = sdkDevice.MCCMNC
}

if sdkDevice.ConnectionType != nil {
maxRequest.Device.ConnectionType = sdkDevice.ConnectionType
}

maxRequest.Device.Ext = setIfKeysExists(sdkDevice.Ext, maxRequest.Device.Ext, "atts")

Expand All @@ -94,8 +112,13 @@ func updateDevice(sdkDevice *openrtb2.Device, maxRequest *openrtb2.BidRequest) {
maxRequest.Device.Geo = &openrtb2.Geo{}
}

maxRequest.Device.Geo.City = sdkDevice.Geo.City
maxRequest.Device.Geo.UTCOffset = sdkDevice.Geo.UTCOffset
if sdkDevice.Geo.City != "" {
maxRequest.Device.Geo.City = sdkDevice.Geo.City
}

if sdkDevice.Geo.UTCOffset != 0 {
maxRequest.Device.Geo.UTCOffset = sdkDevice.Geo.UTCOffset
}
}

func updateApp(sdkApp *openrtb2.App, maxRequest *openrtb2.BidRequest) {
Expand All @@ -107,9 +130,17 @@ func updateApp(sdkApp *openrtb2.App, maxRequest *openrtb2.BidRequest) {
maxRequest.App = &openrtb2.App{}
}

maxRequest.App.Paid = sdkApp.Paid
maxRequest.App.Keywords = sdkApp.Keywords
maxRequest.App.Domain = sdkApp.Domain
if sdkApp.Paid != nil {
maxRequest.App.Paid = sdkApp.Paid
}

if sdkApp.Keywords != "" {
maxRequest.App.Keywords = sdkApp.Keywords
}

if sdkApp.Domain != "" {
maxRequest.App.Domain = sdkApp.Domain
}
}

func updateRegs(sdkRegs *openrtb2.Regs, maxRequest *openrtb2.BidRequest) {
Expand All @@ -121,7 +152,9 @@ func updateRegs(sdkRegs *openrtb2.Regs, maxRequest *openrtb2.BidRequest) {
maxRequest.Regs = &openrtb2.Regs{}
}

maxRequest.Regs.COPPA = sdkRegs.COPPA
if sdkRegs.COPPA != -1 {
maxRequest.Regs.COPPA = sdkRegs.COPPA
}
maxRequest.Regs.Ext = setIfKeysExists(sdkRegs.Ext, maxRequest.Regs.Ext, "gdpr", "gpp", "gpp_sid", "us_privacy")
}

Expand All @@ -146,10 +179,21 @@ func updateUser(sdkUser *openrtb2.User, maxRequest *openrtb2.BidRequest) {
maxRequest.User = &openrtb2.User{}
}

maxRequest.User.Yob = sdkUser.Yob
maxRequest.User.Gender = sdkUser.Gender
maxRequest.User.Keywords = sdkUser.Keywords
maxRequest.User.Data = sdkUser.Data
if sdkUser.Yob != 0 {
maxRequest.User.Yob = sdkUser.Yob
}

if sdkUser.Gender != "" {
maxRequest.User.Gender = sdkUser.Gender
}

if sdkUser.Keywords != "" {
maxRequest.User.Keywords = sdkUser.Keywords
}

if sdkUser.Data != nil {
maxRequest.User.Data = sdkUser.Data
}

maxRequest.User.Ext = setIfKeysExists(sdkUser.Ext, maxRequest.User.Ext, "consent", "eids")
}
Expand Down
Loading

0 comments on commit 21b7c16

Please sign in to comment.