Skip to content

Commit

Permalink
Rename GDPR UserSyncIfAmbiguous to DefaultValue (prebid#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo authored and sachin-pubmatic committed Aug 2, 2021
1 parent 73482d6 commit 2be3ddb
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 149 deletions.
13 changes: 11 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestDefaults(t *testing.T) {
var fullConfig = []byte(`
gdpr:
host_vendor_id: 15
usersync_if_ambiguous: true
default_value: "0"
non_standard_publishers: ["siteID","fake-site-id","appID","agltb3B1Yi1pbmNyDAsSA0FwcBiJkfIUDA"]
ccpa:
enforce: true
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestFullConfig(t *testing.T) {
cmpInts(t, "http_client_cache.max_idle_connections_per_host", cfg.CacheClient.MaxIdleConnsPerHost, 2)
cmpInts(t, "http_client_cache.idle_connection_timeout_seconds", cfg.CacheClient.IdleConnTimeout, 3)
cmpInts(t, "gdpr.host_vendor_id", cfg.GDPR.HostVendorID, 15)
cmpBools(t, "gdpr.usersync_if_ambiguous", cfg.GDPR.UsersyncIfAmbiguous, true)
cmpStrings(t, "gdpr.default_value", cfg.GDPR.DefaultValue, "0")

//Assert the NonStandardPublishers was correctly unmarshalled
cmpStrings(t, "gdpr.non_standard_publishers", cfg.GDPR.NonStandardPublishers[0], "siteID")
Expand Down Expand Up @@ -460,6 +460,9 @@ func TestUnmarshalAdapterExtraInfo(t *testing.T) {

func TestValidConfig(t *testing.T) {
cfg := Configuration{
GDPR: GDPR{
DefaultValue: "1",
},
StoredRequests: StoredRequests{
Files: FileFetcherConfig{Enabled: true},
InMemoryCache: InMemoryCache{
Expand Down Expand Up @@ -650,6 +653,12 @@ func TestInvalidAMPException(t *testing.T) {
assertOneError(t, cfg.validate(), "gdpr.amp_exception has been discontinued and must be removed from your config. If you need to disable GDPR for AMP, you may do so per-account (gdpr.integration_enabled.amp) or at the host level for the default account (account_defaults.gdpr.integration_enabled.amp)")
}

func TestInvalidGDPRDefaultValue(t *testing.T) {
cfg := newDefaultConfig(t)
cfg.GDPR.DefaultValue = "2"
assertOneError(t, cfg.validate(), "gdpr.default_value must be 0 or 1")
}

func TestNegativeCurrencyConverterFetchInterval(t *testing.T) {
cfg := Configuration{
CurrencyConverter: CurrencyConverter{
Expand Down
6 changes: 3 additions & 3 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (deps *cookieSyncDeps) Endpoint(w http.ResponseWriter, r *http.Request, _ h
}

parsedReq := &cookieSyncRequest{}
if err := parseRequest(parsedReq, bodyBytes, deps.gDPR.UsersyncIfAmbiguous); err != nil {
if err := parseRequest(parsedReq, bodyBytes, deps.gDPR.DefaultValue); err != nil {
co.Status = http.StatusBadRequest
co.Errors = append(co.Errors, err)
http.Error(w, co.Errors[len(co.Errors)-1].Error(), co.Status)
Expand Down Expand Up @@ -188,7 +188,7 @@ func (deps *cookieSyncDeps) Endpoint(w http.ResponseWriter, r *http.Request, _ h
enc.Encode(csResp)
}

func parseRequest(parsedReq *cookieSyncRequest, bodyBytes []byte, usersyncIfAmbiguous bool) error {
func parseRequest(parsedReq *cookieSyncRequest, bodyBytes []byte, gdprDefaultValue string) error {
if err := json.Unmarshal(bodyBytes, parsedReq); err != nil {
return fmt.Errorf("JSON parsing failed: %s", err.Error())
}
Expand All @@ -200,7 +200,7 @@ func parseRequest(parsedReq *cookieSyncRequest, bodyBytes []byte, usersyncIfAmbi
if parsedReq.GDPR == nil {
var gdpr = new(int)
*gdpr = 1
if usersyncIfAmbiguous {
if gdprDefaultValue == "0" {
*gdpr = 0
}
parsedReq.GDPR = gdpr
Expand Down
4 changes: 2 additions & 2 deletions endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCCPA(t *testing.T) {
}

for _, test := range testCases {
gdpr := config.GDPR{UsersyncIfAmbiguous: true}
gdpr := config.GDPR{DefaultValue: "0"}
ccpa := config.CCPA{Enforce: test.enforceCCPA}
rr := doConfigurablePost(test.requestBody, nil, true, syncersForTest(), gdpr, ccpa)
assert.Equal(t, http.StatusOK, rr.Code, test.description+":httpResponseCode")
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestCookieSyncNoBidders(t *testing.T) {
}

func TestCookieSyncNoCookiesBrokenGDPR(t *testing.T) {
rr := doConfigurablePost(`{"bidders":["appnexus", "audienceNetwork", "random"],"gdpr_consent":"GLKHGKGKKGK"}`, nil, true, map[openrtb_ext.BidderName]usersync.Usersyncer{}, config.GDPR{UsersyncIfAmbiguous: true}, config.CCPA{})
rr := doConfigurablePost(`{"bidders":["appnexus", "audienceNetwork", "random"],"gdpr_consent":"GLKHGKGKKGK"}`, nil, true, map[openrtb_ext.BidderName]usersync.Usersyncer{}, config.GDPR{DefaultValue: "0"}, config.CCPA{})
assert.Equal(t, rr.Header().Get("Content-Type"), "application/json; charset=utf-8")
assert.Equal(t, http.StatusOK, rr.Code)
assert.ElementsMatch(t, []string{"appnexus", "audienceNetwork"}, parseSyncs(t, rr.Body.Bytes()))
Expand Down
37 changes: 22 additions & 15 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,13 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
eeac[c] = s
}

var gdprDefaultValue string
if spec.AssumeGDPRApplies {
gdprDefaultValue = "1"
} else {
gdprDefaultValue = "0"
}

privacyConfig := config.Privacy{
CCPA: config.CCPA{
Enforce: spec.EnforceCCPA,
Expand All @@ -1653,9 +1660,9 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
Enforce: spec.EnforceLMT,
},
GDPR: config.GDPR{
Enabled: spec.GDPREnabled,
UsersyncIfAmbiguous: !spec.AssumeGDPRApplies,
EEACountriesMap: eeac,
Enabled: spec.GDPREnabled,
DefaultValue: gdprDefaultValue,
EEACountriesMap: eeac,
},
}
bidIdGenerator := &mockBidIDGenerator{}
Expand Down Expand Up @@ -1797,18 +1804,18 @@ func newExchangeForTests(t *testing.T, filename string, expectations map[string]
}

return &exchange{
adapterMap: bidderAdapters,
me: metricsConf.NewMetricsEngine(&config.Configuration{}, openrtb_ext.CoreBidderNames()),
cache: &wellBehavedCache{},
cacheTime: 0,
gDPR: &permissionsMock{allowAllBidders: true},
currencyConverter: currency.NewRateConverter(&http.Client{}, "", time.Duration(0)),
UsersyncIfAmbiguous: privacyConfig.GDPR.UsersyncIfAmbiguous,
privacyConfig: privacyConfig,
categoriesFetcher: categoriesFetcher,
bidderInfo: bidderInfos,
externalURL: "http://localhost",
bidIDGenerator: bidIDGenerator,
adapterMap: bidderAdapters,
me: metricsConf.NewMetricsEngine(&config.Configuration{}, openrtb_ext.CoreBidderNames()),
cache: &wellBehavedCache{},
cacheTime: 0,
gDPR: &permissionsMock{allowAllBidders: true},
currencyConverter: currency.NewRateConverter(&http.Client{}, "", time.Duration(0)),
gdprDefaultValue: privacyConfig.GDPR.DefaultValue,
privacyConfig: privacyConfig,
categoriesFetcher: categoriesFetcher,
bidderInfo: bidderInfos,
externalURL: "http://localhost",
bidIDGenerator: bidIDGenerator,
}
}

Expand Down
18 changes: 9 additions & 9 deletions exchange/targeting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ func runTargetingAuction(t *testing.T, mockBids map[openrtb_ext.BidderName][]*op
}

ex := &exchange{
adapterMap: buildAdapterMap(mockBids, server.URL, server.Client()),
me: &metricsConf.DummyMetricsEngine{},
cache: &wellBehavedCache{},
cacheTime: time.Duration(0),
gDPR: gdpr.AlwaysAllow{},
currencyConverter: currency.NewRateConverter(&http.Client{}, "", time.Duration(0)),
UsersyncIfAmbiguous: false,
categoriesFetcher: categoriesFetcher,
bidIDGenerator: &mockBidIDGenerator{false, false},
adapterMap: buildAdapterMap(mockBids, server.URL, server.Client()),
me: &metricsConf.DummyMetricsEngine{},
cache: &wellBehavedCache{},
cacheTime: time.Duration(0),
gDPR: gdpr.AlwaysAllow{},
currencyConverter: currency.NewRateConverter(&http.Client{}, "", time.Duration(0)),
gdprDefaultValue: "1",
categoriesFetcher: categoriesFetcher,
bidIDGenerator: &mockBidIDGenerator{false, false},
}

imps := buildImps(t, mockBids)
Expand Down
4 changes: 2 additions & 2 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func cleanOpenRTBRequests(ctx context.Context,
requestExt *openrtb_ext.ExtRequest,
gDPR gdpr.Permissions,
metricsEngine metrics.MetricsEngine,
usersyncIfAmbiguous bool,
gdprDefaultValue string,
privacyConfig config.Privacy,
account *config.Account) (allowedBidderRequests []BidderRequest, privacyLabels metrics.PrivacyLabels, errs []error) {

Expand Down Expand Up @@ -87,7 +87,7 @@ func cleanOpenRTBRequests(ctx context.Context,
if err != nil {
errs = append(errs, err)
}
gdprEnforced := gdprSignal == gdpr.SignalYes || (gdprSignal == gdpr.SignalAmbiguous && !usersyncIfAmbiguous)
gdprEnforced := gdprSignal == gdpr.SignalYes || (gdprSignal == gdpr.SignalAmbiguous && gdprDefaultValue == "1")

ccpaEnforcer, err := extractCCPA(req.BidRequest, privacyConfig, &req.Account, aliases, integrationTypeMap[req.LegacyLabels.RType])
if err != nil {
Expand Down
Loading

0 comments on commit 2be3ddb

Please sign in to comment.