diff --git a/v2_parsed_consent.go b/v2_parsed_consent.go index 17cca34..e2fb606 100644 --- a/v2_parsed_consent.go +++ b/v2_parsed_consent.go @@ -285,6 +285,19 @@ func (p *V2ParsedConsent) PurposeAllowed(ps int) bool { return true } +// EverySpecialFeaturesOptInGiven returns true iff every feature number in specialFeatures exists in +// the V2ParsedConsent, otherwise false. +func (p *V2ParsedConsent) EverySpecialFeaturesOptInGiven(specialFeatures []int) bool { + for _, specialFeature := range specialFeatures { + if !p.SpecialFeaturesOptIn[specialFeature] { + return false + } + } + return true +} + + + // VendorAllowed returns true if the ParsedConsent contains affirmative consent // for VendorID |v|. func (p *V2ParsedConsent) VendorAllowed(v int) bool { diff --git a/v2_parsed_consent_test.go b/v2_parsed_consent_test.go index 8d6a4cd..bda4b54 100644 --- a/v2_parsed_consent_test.go +++ b/v2_parsed_consent_test.go @@ -100,9 +100,48 @@ func (p *V2ParsedConsentSuite) TestPurposeAllowed(c *check.C) { } } -func (v *V2ParsedConsentSuite) TestVendorAllowed(c *check.C) { - var tcs = []struct { - vendor int +func (v *V2ParsedConsentSuite) TestEverySpecialFeatureOptInGiven(c *check.C) { + var tcs = []struct{ + specialFeatures []int + specialFeatureOptIn map[int]bool + exp bool + }{ + { + specialFeatures: []int{1, 2, 3}, + specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: true}, + exp: true, + }, + { + specialFeatures: []int{1, 2, 3}, + specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: false}, + exp: false, + }, + { + specialFeatures: []int{1, 2, 3}, + specialFeatureOptIn: map[int]bool{1: true, 2: true}, + exp: false, + }, + { + specialFeatures: []int{1, 2}, + specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: true}, + exp: true, + }, + } + + for _, tc := range tcs { + c.Log(tc) + + var pc = &iabconsent.V2ParsedConsent{ + SpecialFeaturesOptIn: tc.specialFeatureOptIn, + } + + c.Check(pc.EverySpecialFeaturesOptInGiven(tc.specialFeatures), check.Equals, tc.exp) + } +} + +func (v *V2ParsedConsentSuite) TestVendorAllowed(c *check.C) { + var tcs = []struct{ + vendor int isRange bool entries []*iabconsent.RangeEntry vendors map[int]bool