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

Refactor EEAC map to be more in line with the nonstandard publisher map #1514

Merged
merged 1 commit into from
Sep 30, 2020
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
15 changes: 11 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,16 @@ type GDPR struct {
UsersyncIfAmbiguous bool `mapstructure:"usersync_if_ambiguous"`
Timeouts GDPRTimeouts `mapstructure:"timeouts_ms"`
NonStandardPublishers []string `mapstructure:"non_standard_publishers,flow"`
NonStandardPublisherMap map[string]int
NonStandardPublisherMap map[string]struct{}
TCF1 TCF1 `mapstructure:"tcf1"`
TCF2 TCF2 `mapstructure:"tcf2"`
AMPException bool `mapstructure:"amp_exception"`
// EEACountries (EEA = European Economic Area) are a list of countries where we should assume GDPR applies.
// If the gdpr flag is unset in a request, but geo.country is set, we will assume GDPR applies if and only
// if the country matches one on this list. If both the GDPR flag and country are not set, we default
// to UsersyncIfAmbiguous
EEACountries []string `mapstructure:"eea_countries"`
EEACountries []string `mapstructure:"eea_countries"`
EEACountriesMap map[string]struct{}
}

func (cfg *GDPR) validate(errs configErrors) configErrors {
Expand Down Expand Up @@ -608,9 +609,15 @@ func New(v *viper.Viper) (*Configuration, error) {

// To look for a request's publisher_id in the NonStandardPublishers list in
// O(1) time, we fill this hash table located in the NonStandardPublisherMap field of GDPR
c.GDPR.NonStandardPublisherMap = make(map[string]int)
var s struct{}
c.GDPR.NonStandardPublisherMap = make(map[string]struct{})
for i := 0; i < len(c.GDPR.NonStandardPublishers); i++ {
c.GDPR.NonStandardPublisherMap[c.GDPR.NonStandardPublishers[i]] = 1
c.GDPR.NonStandardPublisherMap[c.GDPR.NonStandardPublishers[i]] = s
}

c.GDPR.EEACountriesMap = make(map[string]struct{})
for i := 0; i < len(c.GDPR.EEACountriesMap); i++ {
c.GDPR.NonStandardPublisherMap[c.GDPR.EEACountries[i]] = s
}

// To look for a request's app_id in O(1) time, we fill this hash table located in the
Expand Down
8 changes: 1 addition & 7 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type exchange struct {
currencyConverter *currencies.RateConverter
UsersyncIfAmbiguous bool
privacyConfig config.Privacy
eeaCountries map[string]struct{}
}

// Container to pass out response ext data from the GetAllBids goroutines back into the main thread
Expand All @@ -80,11 +79,6 @@ type bidResponseWrapper struct {
func NewExchange(client *http.Client, cache prebid_cache_client.Client, cfg *config.Configuration, metricsEngine pbsmetrics.MetricsEngine, infos adapters.BidderInfos, gDPR gdpr.Permissions, currencyConverter *currencies.RateConverter) Exchange {
e := new(exchange)

e.eeaCountries = make(map[string]struct{}, len(cfg.GDPR.EEACountries))
var s struct{}
for _, c := range cfg.GDPR.EEACountries {
e.eeaCountries[c] = s
}
e.adapterMap = newAdapterMap(client, cfg, infos, metricsEngine)
e.cache = cache
e.cacheTime = time.Duration(cfg.CacheURL.ExpectedTimeMillis) * time.Millisecond
Expand Down Expand Up @@ -141,7 +135,7 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque
if geo != nil {
// If we have a country set, and it is on the list, we assume GDPR applies if not set on the request.
// Otherwise we assume it does not apply as long as it appears "valid" (is 3 characters long).
if _, found := e.eeaCountries[strings.ToUpper(geo.Country)]; found {
if _, found := e.privacyConfig.GDPR.EEACountriesMap[strings.ToUpper(geo.Country)]; found {
usersyncIfAmbiguous = false
} else if len(geo.Country) == 3 {
// The country field is formatted properly as a three character country code
Expand Down
14 changes: 7 additions & 7 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,12 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
t.Fatalf("%s: Failed to parse aliases", filename)
}

var s struct{}
eeac := make(map[string]struct{})
for _, c := range []string{"FIN", "FRA", "GUF"} {
eeac[c] = s
}

privacyConfig := config.Privacy{
CCPA: config.CCPA{
Enforce: spec.EnforceCCPA,
Expand All @@ -1291,6 +1297,7 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
},
GDPR: config.GDPR{
UsersyncIfAmbiguous: !spec.AssumeGDPRApplies,
EEACountriesMap: eeac,
},
}

Expand Down Expand Up @@ -1409,12 +1416,6 @@ func newExchangeForTests(t *testing.T, filename string, expectations map[string]
}
}

var s struct{}
eeac := make(map[string]struct{})
for _, c := range []string{"FIN", "FRA", "GUF"} {
eeac[c] = s
}

return &exchange{
adapterMap: adapters,
me: metricsConf.NewMetricsEngine(&config.Configuration{}, openrtb_ext.BidderList()),
Expand All @@ -1424,7 +1425,6 @@ func newExchangeForTests(t *testing.T, filename string, expectations map[string]
currencyConverter: currencies.NewRateConverter(&http.Client{}, "", time.Duration(0)),
UsersyncIfAmbiguous: privacyConfig.GDPR.UsersyncIfAmbiguous,
privacyConfig: privacyConfig,
eeaCountries: eeac,
}
}

Expand Down
4 changes: 2 additions & 2 deletions gdpr/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestAllowPersonalInfo(t *testing.T) {
assertBoolsEqual(t, true, allowPI)

// Assert that an item that otherwise would not be allowed PI access, gets approved because it is found in the GDPR.NonStandardPublishers array
perms.cfg.NonStandardPublisherMap = map[string]int{"appNexusAppID": 1}
perms.cfg.NonStandardPublisherMap = map[string]struct{}{"appNexusAppID": {}}
allowPI, _, _, err = perms.PersonalInfoAllowed(context.Background(), openrtb_ext.BidderAppnexus, "appNexusAppID", "BOS2bx5OS2bx5ABABBAAABoAAAABBwAA")
assertNilErr(t, err)
assertBoolsEqual(t, true, allowPI)
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestAllowPersonalInfoWhitelistTCF2(t *testing.T) {
},
}
// Assert that an item that otherwise would not be allowed PI access, gets approved because it is found in the GDPR.NonStandardPublishers array
perms.cfg.NonStandardPublisherMap = map[string]int{"appNexusAppID": 1}
perms.cfg.NonStandardPublisherMap = map[string]struct{}{"appNexusAppID": {}}
allowPI, allowGeo, allowID, err := perms.PersonalInfoAllowed(context.Background(), openrtb_ext.BidderAppnexus, "appNexusAppID", "COzTVhaOzTVhaGvAAAENAiCIAP_AAH_AAAAAAEEUACCKAAA")
assert.NoErrorf(t, err, "Error processing PersonalInfoAllowed")
assert.EqualValuesf(t, true, allowPI, "AllowPI failure")
Expand Down