Skip to content

Commit

Permalink
Add TCF1 consent string unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo committed Jun 1, 2021
1 parent 274c354 commit 7683071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 2 additions & 5 deletions gdpr/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ func (p *permissionsImpl) allowSync(ctx context.Context, vendorID uint16, consen
return false, nil
}

if parsedConsent.Version() != 2 {
return false, nil
}

if !p.cfg.TCF2.Purpose1.Enabled {
return true, nil
}
Expand All @@ -137,11 +133,12 @@ func (p *permissionsImpl) allowActivities(ctx context.Context, vendorID uint16,
return false, false, false, err
}

// vendor will be nil if not a valid TCF2 consent string
if vendor == nil {
return false, false, false, nil
}

if parsedConsent.Version() != 2 || !p.cfg.TCF2.Enabled {
if !p.cfg.TCF2.Enabled {
return true, false, false, nil
}

Expand Down
18 changes: 18 additions & 0 deletions gdpr/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,21 @@ func TestAllowActivitiesBidRequests(t *testing.T) {
assert.EqualValuesf(t, td.passID, passID, "PassID failure on %s", td.description)
}
}

func TestTCF1Consent(t *testing.T) {
bidderAllowedByConsent := openrtb_ext.BidderAppnexus
tcf1Consent := "BOS2bx5OS2bx5ABABBAAABoAAAABBwAA"

perms := permissionsImpl{
vendorIDs: map[openrtb_ext.BidderName]uint16{
openrtb_ext.BidderAppnexus: 2,
},
}

bidReq, passGeo, passID, err := perms.AuctionActivitiesAllowed(context.Background(), bidderAllowedByConsent, "", SignalYes, tcf1Consent, false)

assert.Nil(t, err, "TCF1 consent - no error returned")
assert.Equal(t, false, bidReq, "TCF1 consent - bid request not allowed")
assert.Equal(t, false, passGeo, "TCF1 consent - passing geo not allowed")
assert.Equal(t, false, passID, "TCF1 consent - passing id not allowed")
}

0 comments on commit 7683071

Please sign in to comment.