Skip to content

Commit

Permalink
update user object only when topics available
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate committed Jan 11, 2024
1 parent c73d388 commit 898a1e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 11 additions & 7 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2035,10 +2035,6 @@ func setAuctionTypeImplicitly(r *openrtb_ext.RequestWrapper) {

// (100);v=chrome.1:1:20, (200);v=chrome.1:1:40, (300);v=chrome.1:1:60, ();p=P
func setSecBrowsingTopcisImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper, cfg *config.Configuration) {
if r.User == nil {
r.User = &openrtb2.User{}
}

topicsDomain := "TOPICS_DOMAIN"
if cfg != nil {
topicsDomain = cfg.Auction.PrivacySandbox.TopicsDomain
Expand All @@ -2052,9 +2048,9 @@ func setSecBrowsingTopcisImplicitly(httpReq *http.Request, r *openrtb_ext.Reques
// segtax-segclass-name-segIds
userData := map[int]map[string]map[string]map[string]struct{}{}
secBrowsingTopicsArr := strings.Split(secBrowsingTopics, ",")
c := 0
selectedFields := 0
for _, seg := range secBrowsingTopicsArr {
if c >= 10 {
if selectedFields >= 10 {
break
}

Expand Down Expand Up @@ -2115,7 +2111,15 @@ func setSecBrowsingTopcisImplicitly(httpReq *http.Request, r *openrtb_ext.Reques
}
}

c++
selectedFields++
}

if selectedFields == 0 {
return
}

if r.User == nil {
r.User = &openrtb2.User{}
}

type extData struct {
Expand Down
12 changes: 6 additions & 6 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6203,7 +6203,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
r: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{}},
cfg: &config.Configuration{Auction: config.Auction{PrivacySandbox: config.PrivacySandbox{TopicsDomain: "TOPICS_DOMAIN"}}},
},
wantUser: &openrtb2.User{},
wantUser: nil,
},
{
name: "Sec-Browsing-Topics with empty value, request.user.data empty, no change in user data",
Expand All @@ -6216,7 +6216,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
r: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{}},
cfg: &config.Configuration{Auction: config.Auction{PrivacySandbox: config.PrivacySandbox{TopicsDomain: "TOPICS_DOMAIN"}}},
},
wantUser: &openrtb2.User{},
wantUser: nil,
},
{
name: "Sec-Browsing-Topics with invalid value, request.user.data empty, no change in user data",
Expand All @@ -6229,7 +6229,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
r: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{}},
cfg: &config.Configuration{Auction: config.Auction{PrivacySandbox: config.PrivacySandbox{TopicsDomain: "TOPICS_DOMAIN"}}},
},
wantUser: &openrtb2.User{},
wantUser: nil,
},
{
name: "Sec-Browsing-Topics with finish padding, request.user.data empty, no change in user data",
Expand All @@ -6242,7 +6242,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
r: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{}},
cfg: &config.Configuration{Auction: config.Auction{PrivacySandbox: config.PrivacySandbox{TopicsDomain: "TOPICS_DOMAIN"}}},
},
wantUser: &openrtb2.User{},
wantUser: nil,
},
{
name: "Sec-Browsing-Topics with one valid field, request.user.data empty, valid field data added to req.user.data",
Expand Down Expand Up @@ -6897,7 +6897,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
setSecBrowsingTopcisImplicitly(tt.args.httpReq, tt.args.r, tt.args.cfg)

// sequence is not garunteed in request.user.data as we're using a map
if tt.wantUser.Data != nil {
if tt.wantUser != nil && tt.wantUser.Data != nil {
sort.Slice(tt.wantUser.Data, func(i, j int) bool {
return string(tt.wantUser.Data[i].Ext) < string(tt.wantUser.Data[j].Ext)
})
Expand All @@ -6908,7 +6908,7 @@ func Test_setSecBrowsingTopcisImplicitly(t *testing.T) {
})
}
}
if tt.args.r.User.Data != nil {
if tt.args.r.User != nil && tt.args.r.User.Data != nil {
sort.Slice(tt.args.r.User.Data, func(i, j int) bool {
return string(tt.args.r.User.Data[i].Ext) < string(tt.args.r.User.Data[j].Ext)
})
Expand Down

0 comments on commit 898a1e8

Please sign in to comment.