Skip to content

Commit

Permalink
Merge pull request #19 from prebid/liTransparency
Browse files Browse the repository at this point in the history
Add support for PurposesLITransparency
  • Loading branch information
hhhjort authored May 13, 2020
2 parents b8a3577 + f77e879 commit f829aa7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vendorconsent/tcf2/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ func (c ConsentMetadata) PurposeAllowed(id consentconstants.Purpose) bool {
return isSet(c.data, uint(id)+151)
}

func (c ConsentMetadata) PurposeLITransparency(id consentconstants.Purpose) bool {
// Purposes are stored in bits 176 - 199. The interface contract only defines behavior for ints in the range [1, 24]...
// so in the valid range, this won't even overflow a uint8.
if id > 24 {
return false
}
return isSet(c.data, uint(id)+175)
}

func (c ConsentMetadata) PurposeOneTreatment() bool {
return isSet(c.data, 200)
}
Expand Down
16 changes: 16 additions & 0 deletions vendorconsent/tcf2/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ func TestTCF2Fields(t *testing.T) {
assertBoolsEqual(t, true, consent.SpecialFeatureOptIn(1))
assertBoolsEqual(t, false, consent.SpecialFeatureOptIn(2))
}

func TestLITransparency(t *testing.T) {
baseConsent, err := Parse(decode(t, "COx3XOeOx3XOeLkAAAENAfCIAAAAAHgAAIAAAAAAAAAA"))
assertNilError(t, err)
consent := baseConsent.(ConsentMetadata)

assertBoolsEqual(t, false, consent.PurposeLITransparency(1))
assertBoolsEqual(t, true, consent.PurposeLITransparency(2))
assertBoolsEqual(t, true, consent.PurposeLITransparency(3))
assertBoolsEqual(t, true, consent.PurposeLITransparency(4))
assertBoolsEqual(t, true, consent.PurposeLITransparency(5))
assertBoolsEqual(t, false, consent.PurposeLITransparency(6))
assertBoolsEqual(t, false, consent.PurposeLITransparency(7))
assertBoolsEqual(t, false, consent.PurposeLITransparency(28))

}

0 comments on commit f829aa7

Please sign in to comment.