Skip to content

Commit

Permalink
Convert GDPR default value string to signal type in GDPR permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo committed Jun 9, 2021
1 parent 1e2f1a7 commit c56359c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
10 changes: 8 additions & 2 deletions gdpr/gdpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ func NewPermissions(ctx context.Context, cfg config.GDPR, vendorIDs map[openrtb_
return &AlwaysAllow{}
}

gdprDefaultValue := SignalYes
if cfg.DefaultValue == "0" {
gdprDefaultValue = SignalNo
}

permissionsImpl := &permissionsImpl{
cfg: cfg,
vendorIDs: vendorIDs,
cfg: cfg,
gdprDefaultValue: gdprDefaultValue,
vendorIDs: vendorIDs,
fetchVendorList: map[uint8]func(ctx context.Context, id uint16) (vendorlist.VendorList, error){
tcf1SpecVersion: newVendorListFetcherTCF1(cfg),
tcf2SpecVersion: newVendorListFetcherTCF2(ctx, cfg, client, vendorListURLMaker)},
Expand Down
9 changes: 5 additions & 4 deletions gdpr/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const (
)

type permissionsImpl struct {
cfg config.GDPR
vendorIDs map[openrtb_ext.BidderName]uint16
fetchVendorList map[uint8]func(ctx context.Context, id uint16) (vendorlist.VendorList, error)
cfg config.GDPR
gdprDefaultValue Signal
vendorIDs map[openrtb_ext.BidderName]uint16
fetchVendorList map[uint8]func(ctx context.Context, id uint16) (vendorlist.VendorList, error)
}

func (p *permissionsImpl) HostCookiesAllowed(ctx context.Context, gdprSignal Signal, consent string) (bool, error) {
Expand Down Expand Up @@ -94,7 +95,7 @@ func (p *permissionsImpl) normalizeGDPR(gdprSignal Signal) Signal {
return gdprSignal
}

if p.cfg.DefaultValue == "0" {
if p.gdprDefaultValue == SignalNo {
return SignalNo
}

Expand Down
14 changes: 13 additions & 1 deletion gdpr/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func TestDisallowOnEmptyConsent(t *testing.T) {
HostVendorID: 3,
DefaultValue: "0",
},
vendorIDs: nil,
gdprDefaultValue: SignalNo,
vendorIDs: nil,
fetchVendorList: map[uint8]func(ctx context.Context, id uint16) (vendorlist.VendorList, error){
tcf1SpecVersion: failedListFetcher,
tcf2SpecVersion: failedListFetcher,
Expand Down Expand Up @@ -285,6 +286,11 @@ func TestAllowActivities(t *testing.T) {

for _, tt := range tests {
perms.cfg.DefaultValue = tt.gdprDefaultValue
if tt.gdprDefaultValue == "0" {
perms.gdprDefaultValue = SignalNo
} else {
perms.gdprDefaultValue = SignalYes
}

_, _, passID, err := perms.AuctionActivitiesAllowed(context.Background(), tt.bidderName, tt.publisherID, tt.gdpr, tt.consent, tt.weakVendorEnforcement)

Expand Down Expand Up @@ -707,6 +713,12 @@ func TestNormalizeGDPR(t *testing.T) {
},
}

if tt.gdprDefaultValue == "0" {
perms.gdprDefaultValue = SignalNo
} else {
perms.gdprDefaultValue = SignalYes
}

normalizedSignal := perms.normalizeGDPR(tt.giveSignal)

assert.Equal(t, tt.wantSignal, normalizedSignal, tt.description)
Expand Down

0 comments on commit c56359c

Please sign in to comment.