Skip to content

Commit

Permalink
Always use fallback GVL for TCF1 (#1657)
Browse files Browse the repository at this point in the history
* Update TCF2 GVL subdomain and always use fallback GVL for TCF1

* Add config test coverage for invalid TCF1 FetchGVL and AMP Exception

* Delete obselete test
  • Loading branch information
bsardo authored Jan 28, 2021
1 parent 01645db commit ef06fac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 348 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (cfg *GDPR) validate(errs []error) []error {
errs = append(errs, fmt.Errorf("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)"))
}
if cfg.TCF1.FetchGVL == true {
glog.Warning("gdpr.tcf1.fetch_gvl is deprecated and will be removed in a future version, at which point TCF1 will always use the fallback GVL")
errs = append(errs, fmt.Errorf("gdpr.tcf1.fetch_gvl has been discontinued and must be removed from your config. TCF1 will always use the fallback GVL going forward"))
}
return errs
}
Expand Down Expand Up @@ -910,7 +910,7 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("gdpr.timeouts_ms.init_vendorlist_fetches", 0)
v.SetDefault("gdpr.timeouts_ms.active_vendorlist_fetch", 0)
v.SetDefault("gdpr.non_standard_publishers", []string{""})
v.SetDefault("gdpr.tcf1.fetch_gvl", true)
v.SetDefault("gdpr.tcf1.fetch_gvl", false)
v.SetDefault("gdpr.tcf1.fallback_gvl_path", "./static/tcf1/fallback_gvl.json")
v.SetDefault("gdpr.tcf2.enabled", true)
v.SetDefault("gdpr.tcf2.purpose1.enabled", true)
Expand Down
46 changes: 37 additions & 9 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,51 @@ func TestNegativeRequestSize(t *testing.T) {
assertOneError(t, cfg.validate(), "cfg.max_request_size must be >= 0. Got -1")
}

func TestNegativeVendorID(t *testing.T) {
cfg := newDefaultConfig(t)
cfg.GDPR.HostVendorID = -1
assertOneError(t, cfg.validate(), "gdpr.host_vendor_id must be in the range [0, 65535]. Got -1")
}

func TestNegativePrometheusTimeout(t *testing.T) {
cfg := newDefaultConfig(t)
cfg.Metrics.Prometheus.Port = 8001
cfg.Metrics.Prometheus.TimeoutMillisRaw = 0
assertOneError(t, cfg.validate(), "metrics.prometheus.timeout_ms must be positive if metrics.prometheus.port is defined. Got timeout=0 and port=8001")
}

func TestOverflowedVendorID(t *testing.T) {
func TestInvalidHostVendorID(t *testing.T) {
tests := []struct {
description string
vendorID int
wantErrorMsg string
}{
{
description: "Negative GDPR.HostVendorID",
vendorID: -1,
wantErrorMsg: "gdpr.host_vendor_id must be in the range [0, 65535]. Got -1",
},
{
description: "Overflowed GDPR.HostVendorID",
vendorID: (0xffff) + 1,
wantErrorMsg: "gdpr.host_vendor_id must be in the range [0, 65535]. Got 65536",
},
}

for _, tt := range tests {
cfg := newDefaultConfig(t)
cfg.GDPR.HostVendorID = tt.vendorID
errs := cfg.validate()

assert.Equal(t, 1, len(errs), tt.description)
assert.EqualError(t, errs[0], tt.wantErrorMsg, tt.description)
}
}

func TestInvalidFetchGVL(t *testing.T) {
cfg := newDefaultConfig(t)
cfg.GDPR.TCF1.FetchGVL = true
assertOneError(t, cfg.validate(), "gdpr.tcf1.fetch_gvl has been discontinued and must be removed from your config. TCF1 will always use the fallback GVL going forward")
}

func TestInvalidAMPException(t *testing.T) {
cfg := newDefaultConfig(t)
cfg.GDPR.HostVendorID = (0xffff) + 1
assertOneError(t, cfg.validate(), "gdpr.host_vendor_id must be in the range [0, 65535]. Got 65536")
cfg.GDPR.AMPException = true
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 TestNegativeCurrencyConverterFetchInterval(t *testing.T) {
Expand Down
19 changes: 9 additions & 10 deletions gdpr/vendorlist-fetching.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@ type saveVendors func(uint16, api.VendorList)

func newVendorListFetcher(initCtx context.Context, cfg config.GDPR, client *http.Client, urlMaker func(uint16, uint8) string, tcfSpecVersion uint8) func(ctx context.Context, id uint16) (vendorlist.VendorList, error) {
var fallback api.VendorList
if tcfSpecVersion == tcf1SpecVersion && len(cfg.TCF1.FallbackGVLPath) > 0 {
fallback = loadFallbackGVL(cfg.TCF1.FallbackGVLPath)
}

// If we are not going to try fetching the GVL dynamically, we have a simple fetcher.
if !cfg.TCF1.FetchGVL && tcfSpecVersion == tcf1SpecVersion {
if fallback != nil {
return func(ctx context.Context, vendorListVersion uint16) (vendorlist.VendorList, error) {
return fallback, nil
}
}
if tcfSpecVersion == tcf1SpecVersion && len(cfg.TCF1.FallbackGVLPath) == 0 {
return func(ctx context.Context, vendorListVersion uint16) (vendorlist.VendorList, error) {
return nil, makeVendorListNotFoundError(vendorListVersion)
}
}

if tcfSpecVersion == tcf1SpecVersion {
fallback = loadFallbackGVL(cfg.TCF1.FallbackGVLPath)

return func(ctx context.Context, vendorListVersion uint16) (vendorlist.VendorList, error) {
return fallback, nil
}
}

cacheSave, cacheLoad := newVendorListCache(fallback)

preloadContext, cancel := context.WithTimeout(initCtx, cfg.Timeouts.InitTimeout())
Expand Down
Loading

0 comments on commit ef06fac

Please sign in to comment.