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

Always sync when GDPR globally enabled and allow host cookie sync … #1656

Merged
merged 4 commits into from
Jan 21, 2021
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 endpoints/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestCacheVideoOnly(t *testing.T) {
t.Fatal(err.Error())
}
syncers := usersyncers.NewSyncerMap(cfg)
gdprPerms := gdpr.NewPermissions(nil, config.GDPR{
gdprPerms := gdpr.NewPermissions(context.Background(), config.GDPR{
HostVendorID: 0,
}, nil, nil)
prebid_cache_client.InitPrebidCache(server.URL)
Expand Down
15 changes: 11 additions & 4 deletions gdpr/gdpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ const (

// NewPermissions gets an instance of the Permissions for use elsewhere in the project.
func NewPermissions(ctx context.Context, cfg config.GDPR, vendorIDs map[openrtb_ext.BidderName]uint16, client *http.Client) Permissions {
// If the host doesn't buy into the IAB GDPR consent framework, then save some cycles and let all syncs happen.
if cfg.HostVendorID == 0 {
return AlwaysAllow{}
if !cfg.Enabled {
return &AlwaysAllow{}
}

return &permissionsImpl{
permissionsImpl := &permissionsImpl{
cfg: cfg,
vendorIDs: vendorIDs,
fetchVendorList: map[uint8]func(ctx context.Context, id uint16) (vendorlist.VendorList, error){
tcf1SpecVersion: newVendorListFetcher(ctx, cfg, client, vendorListURLMaker, tcf1SpecVersion),
tcf2SpecVersion: newVendorListFetcher(ctx, cfg, client, vendorListURLMaker, tcf2SpecVersion)},
}

if cfg.HostVendorID == 0 {
return &AllowHostCookies{
permissionsImpl: permissionsImpl,
}
}

return permissionsImpl
}

// An ErrorMalformedConsent will be returned by the Permissions interface if
Expand Down
50 changes: 50 additions & 0 deletions gdpr/gdpr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gdpr

import (
"context"
"net/http"
"testing"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"

"github.com/stretchr/testify/assert"
)

func TestNewPermissions(t *testing.T) {
tests := []struct {
description string
gdprEnabled bool
hostVendorID int
wantType Permissions
}{
{
gdprEnabled: false,
hostVendorID: 32,
wantType: &AlwaysAllow{},
},
{
gdprEnabled: true,
hostVendorID: 0,
wantType: &AllowHostCookies{},
},
{
gdprEnabled: true,
hostVendorID: 32,
wantType: &permissionsImpl{},
},
}

for _, tt := range tests {

config := config.GDPR{
Enabled: tt.gdprEnabled,
HostVendorID: tt.hostVendorID,
}
vendorIDs := map[openrtb_ext.BidderName]uint16{}

perms := NewPermissions(context.Background(), config, vendorIDs, &http.Client{})

assert.IsType(t, tt.wantType, perms, tt.description)
}
}
10 changes: 10 additions & 0 deletions gdpr/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ func (p *permissionsImpl) parseVendor(ctx context.Context, vendorID uint16, cons
return
}

// AllowHostCookies represents a GDPR permissions policy with host cookie syncing always allowed
type AllowHostCookies struct {
*permissionsImpl
}

// HostCookiesAllowed always returns true
func (p *AllowHostCookies) HostCookiesAllowed(ctx context.Context, consent string) (bool, error) {
return true, nil
}

// Exporting to allow for easy test setups
type AlwaysAllow struct{}

Expand Down