Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDPR: Convert bidder name to string to accommodate analytics #3554

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func setDerivedConfig(account *config.Account) {
if pc.VendorExceptions == nil {
continue
}
pc.VendorExceptionMap = make(map[openrtb_ext.BidderName]struct{})
pc.VendorExceptionMap = make(map[string]struct{})
for _, v := range pc.VendorExceptions {
pc.VendorExceptionMap[v] = struct{}{}
}
Expand Down
8 changes: 4 additions & 4 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestGetAccount(t *testing.T) {
func TestSetDerivedConfig(t *testing.T) {
tests := []struct {
description string
purpose1VendorExceptions []openrtb_ext.BidderName
purpose1VendorExceptions []string
feature1VendorExceptions []openrtb_ext.BidderName
basicEnforcementVendors []string
enforceAlgo string
Expand All @@ -134,11 +134,11 @@ func TestSetDerivedConfig(t *testing.T) {
},
{
description: "One purpose 1 vendor exception",
purpose1VendorExceptions: []openrtb_ext.BidderName{"appnexus"},
purpose1VendorExceptions: []string{"appnexus"},
},
{
description: "Multiple purpose 1 vendor exceptions",
purpose1VendorExceptions: []openrtb_ext.BidderName{"appnexus", "rubicon"},
purpose1VendorExceptions: []string{"appnexus", "rubicon"},
},
{
description: "Nil feature 1 vendor exceptions",
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestSetDerivedConfig(t *testing.T) {

setDerivedConfig(&account)

purpose1ExceptionMapKeys := make([]openrtb_ext.BidderName, 0)
purpose1ExceptionMapKeys := make([]string, 0)
for k := range account.GDPR.Purpose1.VendorExceptionMap {
purpose1ExceptionMapKeys = append(purpose1ExceptionMapKeys, k)
}
Expand Down
6 changes: 3 additions & 3 deletions config/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (a *AccountGDPR) PurposeEnforcingVendors(purpose consentconstants.Purpose)
}

// PurposeVendorExceptions returns the vendor exception map for a given purpose.
func (a *AccountGDPR) PurposeVendorExceptions(purpose consentconstants.Purpose) (value map[openrtb_ext.BidderName]struct{}, exists bool) {
func (a *AccountGDPR) PurposeVendorExceptions(purpose consentconstants.Purpose) (value map[string]struct{}, exists bool) {
c, exists := a.PurposeConfigs[purpose]

if exists && c.VendorExceptionMap != nil {
Expand Down Expand Up @@ -262,8 +262,8 @@ type AccountGDPRPurpose struct {
EnforcePurpose *bool `mapstructure:"enforce_purpose" json:"enforce_purpose,omitempty"`
EnforceVendors *bool `mapstructure:"enforce_vendors" json:"enforce_vendors,omitempty"`
// Array of vendor exceptions that is used to create the hash table VendorExceptionMap so vendor names can be instantly accessed
VendorExceptions []openrtb_ext.BidderName `mapstructure:"vendor_exceptions" json:"vendor_exceptions"`
VendorExceptionMap map[openrtb_ext.BidderName]struct{}
VendorExceptions []string `mapstructure:"vendor_exceptions" json:"vendor_exceptions"`
VendorExceptionMap map[string]struct{}
}

// AccountGDPRSpecialFeature represents account-specific GDPR special feature configuration
Expand Down
42 changes: 19 additions & 23 deletions config/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,48 +476,40 @@ func TestPurposeVendorExceptions(t *testing.T) {
tests := []struct {
description string
givePurposeConfigNil bool
givePurpose1ExceptionMap map[openrtb_ext.BidderName]struct{}
givePurpose2ExceptionMap map[openrtb_ext.BidderName]struct{}
givePurpose1ExceptionMap map[string]struct{}
givePurpose2ExceptionMap map[string]struct{}
givePurpose consentconstants.Purpose
wantExceptionMap map[openrtb_ext.BidderName]struct{}
wantExceptionMapSet bool
wantExceptionMap map[string]struct{}
}{
{
description: "Purpose config is nil",
givePurposeConfigNil: true,
givePurpose: 1,
// wantExceptionMap: map[openrtb_ext.BidderName]struct{}{},
wantExceptionMap: nil,
wantExceptionMapSet: false,
wantExceptionMap: nil,
},
{
description: "Nil - exception map not defined for purpose",
givePurpose: 1,
// wantExceptionMap: map[openrtb_ext.BidderName]struct{}{},
wantExceptionMap: nil,
wantExceptionMapSet: false,
description: "Nil - exception map not defined for purpose",
givePurpose: 1,
wantExceptionMap: nil,
},
{
description: "Empty - exception map empty for purpose",
givePurpose: 1,
givePurpose1ExceptionMap: map[openrtb_ext.BidderName]struct{}{},
wantExceptionMap: map[openrtb_ext.BidderName]struct{}{},
wantExceptionMapSet: true,
givePurpose1ExceptionMap: map[string]struct{}{},
wantExceptionMap: map[string]struct{}{},
},
{
description: "Nonempty - exception map with multiple entries for purpose",
givePurpose: 1,
givePurpose1ExceptionMap: map[openrtb_ext.BidderName]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
wantExceptionMap: map[openrtb_ext.BidderName]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
wantExceptionMapSet: true,
givePurpose1ExceptionMap: map[string]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
wantExceptionMap: map[string]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
},
{
description: "Nonempty - exception map with multiple entries for different purpose",
givePurpose: 2,
givePurpose1ExceptionMap: map[openrtb_ext.BidderName]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
givePurpose2ExceptionMap: map[openrtb_ext.BidderName]struct{}{"rubicon": {}, "appnexus": {}, "openx": {}},
wantExceptionMap: map[openrtb_ext.BidderName]struct{}{"rubicon": {}, "appnexus": {}, "openx": {}},
wantExceptionMapSet: true,
givePurpose1ExceptionMap: map[string]struct{}{"rubicon": {}, "appnexus": {}, "index": {}},
givePurpose2ExceptionMap: map[string]struct{}{"rubicon": {}, "appnexus": {}, "openx": {}},
wantExceptionMap: map[string]struct{}{"rubicon": {}, "appnexus": {}, "openx": {}},
},
}

Expand All @@ -538,7 +530,11 @@ func TestPurposeVendorExceptions(t *testing.T) {
value, present := accountGDPR.PurposeVendorExceptions(tt.givePurpose)

assert.Equal(t, tt.wantExceptionMap, value, tt.description)
assert.Equal(t, tt.wantExceptionMapSet, present, tt.description)
if tt.wantExceptionMap == nil {
assert.Equal(t, false, present)
} else {
assert.Equal(t, true, present)
}
}
}

Expand Down
38 changes: 19 additions & 19 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ func (t *TCF2) PurposeEnforcingVendors(purpose consentconstants.Purpose) (enforc

// PurposeVendorExceptions returns the vendor exception map for a given purpose if it exists, otherwise it returns
// an empty map of vendor exceptions
func (t *TCF2) PurposeVendorExceptions(purpose consentconstants.Purpose) (vendorExceptions map[openrtb_ext.BidderName]struct{}) {
func (t *TCF2) PurposeVendorExceptions(purpose consentconstants.Purpose) (vendorExceptions map[string]struct{}) {
c, exists := t.PurposeConfigs[purpose]

if exists && c.VendorExceptionMap != nil {
return c.VendorExceptionMap
}
return make(map[openrtb_ext.BidderName]struct{}, 0)
return make(map[string]struct{}, 0)
}

// FeatureOneEnforced checks if special feature one is enforced. If it is enforced, PBS will determine whether geo
Expand Down Expand Up @@ -417,8 +417,8 @@ type TCF2Purpose struct {
EnforcePurpose bool `mapstructure:"enforce_purpose"`
EnforceVendors bool `mapstructure:"enforce_vendors"`
// Array of vendor exceptions that is used to create the hash table VendorExceptionMap so vendor names can be instantly accessed
VendorExceptions []openrtb_ext.BidderName `mapstructure:"vendor_exceptions"`
VendorExceptionMap map[openrtb_ext.BidderName]struct{}
VendorExceptions []string `mapstructure:"vendor_exceptions"`
VendorExceptionMap map[string]struct{}
}

type TCF2SpecialFeature struct {
Expand Down Expand Up @@ -735,13 +735,13 @@ func New(v *viper.Viper, bidderInfos BidderInfos, normalizeBidderName func(strin
}
}

// To look for a purpose's vendor exceptions in O(1) time, for each purpose we fill this hash table with bidders
// located in the VendorExceptions field of the GDPR.TCF2.PurposeX struct defined in this file
// To look for a purpose's vendor exceptions in O(1) time, for each purpose we fill this hash table with bidders/analytics
// adapters located in the VendorExceptions field of the GDPR.TCF2.PurposeX struct defined in this file
for _, pc := range c.GDPR.TCF2.PurposeConfigs {
pc.VendorExceptionMap = make(map[openrtb_ext.BidderName]struct{})
pc.VendorExceptionMap = make(map[string]struct{})
for v := 0; v < len(pc.VendorExceptions); v++ {
bidderName := pc.VendorExceptions[v]
pc.VendorExceptionMap[bidderName] = struct{}{}
adapterName := pc.VendorExceptions[v]
pc.VendorExceptionMap[adapterName] = struct{}{}
}
}

Expand Down Expand Up @@ -1064,16 +1064,16 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("gdpr.tcf2.purpose8.enforce_vendors", true)
v.SetDefault("gdpr.tcf2.purpose9.enforce_vendors", true)
v.SetDefault("gdpr.tcf2.purpose10.enforce_vendors", true)
v.SetDefault("gdpr.tcf2.purpose1.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose2.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose3.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose4.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose5.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose6.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose7.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose8.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose9.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose10.vendor_exceptions", []openrtb_ext.BidderName{})
v.SetDefault("gdpr.tcf2.purpose1.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose2.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose3.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose4.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose5.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose6.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose7.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose8.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose9.vendor_exceptions", []string{})
v.SetDefault("gdpr.tcf2.purpose10.vendor_exceptions", []string{})
v.SetDefault("gdpr.amp_exception", false)
v.SetDefault("gdpr.eea_countries", []string{"ALA", "AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST",
"FIN", "FRA", "GUF", "DEU", "GIB", "GRC", "GLP", "GGY", "HUN", "ISL", "IRL", "IMN", "ITA", "JEY", "LVA",
Expand Down
Loading
Loading