mirror of
https://github.com/cubixle/iabtcfv2.git
synced 2026-04-24 18:34:43 +01:00
fix IsVendorAllowedForFlexiblePurposes / IsVendorAllowedForFlexiblePurposesLI
add unit test
This commit is contained in:
@@ -257,3 +257,15 @@ func TestDecodePublisherTC(t *testing.T) {
|
||||
t.Errorf("Encode() should produce the same string: in = %s, out = %s", str, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublisherRestrictionFlexibleVendor(t *testing.T) {
|
||||
str := "CPStgrQPStgrQAGABCDEB9CsAP_AAH_AAAqIH-NN7S__a2Pj-359Q_t0eY1f9953v-UhjhaZk6QF0bPDsL8V4mM6vE3opioKuBYEO3LAIQRlHKHcBQGAaokRoTPsbk2MLpAAJ7PEmgMbEmdIGHV9m93DnZKYz3w-2r6T_u4NRP_M5MfpP41v3Wt5tl06qXTTVz8YhLP1cAABAAAAQPiAIEBAUAgAEMAEQAFCIQAAQpiQAAAABBCABAAAAIiAAQVwAZIIEAAARAAAQAABAQgwAAAAAABCAAAACwQCAACAQAAgAEAAAAEJAIBACAEAAAEAJABACACECAggAAAwDAgAACCABABAAACJDAAAMIIASABgBEAABEgAGAAACAoMgFgBMAEcAMsAfYBWwExAJsAWwAz4BygD4hEAkAZYBTwDqgHyAQ6AkQBNgDPgHKCQAIDfxAAEAEgSBUAAgABYAFQAMgAcAA8ACAAGUANAA1AB5AEQARQAmABvADmAHoAP0AiACJAEsAJoAUoAtwBhwDKAMsAaoA-wB-gEUAKeAbQA3AB8gEOgJEATEAmwBTQC2AGSAM-AaQA1iByYHKBQAYAigBfAO3CAAwASAGiAU-GgGgBcAGWAQUAp8BaAFpAOqAfIBDoCRAE2AMYAZ8A5QOABAb-KgGABMAC4AI4AZcBaAFpASCAmIBNgCmwFsAM-AcoOgZAALAAqABkADgAIIAYgBlADQANQAeAA-gCIAIoATAAuABiADMAG8AOYAegA_ACIAEsAJgATQAowBSgC3AGGAMoAaIA-wB-gEUAKfAWgBaQC8gG4AOoAh0BIICRAE2AKagWwBbIDGAGSAMsAZmAz4BpADWIHJgcoPADAAqAEUAL4AjIDfwHbjgAIAJCEBYABYAGQAYgBMAC4AGIAMwAbwA9ACOAH2ARQAoYBT4C0ALSAdQBIICRAE2AKagWwBbIDPiIAMAFQAvgCMkoEAACAAFgAZAA4AB8AGIAPAAiABMAC4AGIAMwAbYBEAESAKMAUoAtwBqgEnAKfAWgBaQDcAHUAPkAh0BIgCbAFsAMsAZ8A0gBrBMAEARkBv5SBQAAsACoAGQAOAAggBiAGUANAA1AB5AEQARQAmABSADEAGYAOYAfgBEACjAFKALcAZQA0QBqgD7AKGAVsAvIBtADcAIdASIAk4BNgC2AGMAMkAZYAz4BpADWIHJgcoVACAAqAB8AL4Bv5QAGACQAk4BOw.YAAAAAAAAAAA"
|
||||
tcData, err := Decode(str)
|
||||
if err != nil {
|
||||
t.Errorf("fail to decode tcstring: %s", err)
|
||||
return
|
||||
}
|
||||
if !tcData.IsVendorAllowedForFlexiblePurposesLI(916, 4) {
|
||||
t.Errorf("flexible vendor 916 should be allowed to purpose 4 even with publisher restriction because consent is established on purpose 4 for this vendor")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,12 +161,18 @@ func (c *CoreString) IsVendorAllowedForFlexiblePurposes(id int, purposeIds ...in
|
||||
}
|
||||
|
||||
for _, r := range pr {
|
||||
if r.IsVendorIncluded(id) {
|
||||
if r.RestrictionType == RestrictionTypeNotAllowed {
|
||||
if !r.IsVendorIncluded(id) {
|
||||
continue
|
||||
}
|
||||
switch r.RestrictionType {
|
||||
case RestrictionTypeNotAllowed:
|
||||
return false
|
||||
case RestrictionTypeRequireConsent:
|
||||
if !c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p) {
|
||||
return false
|
||||
} else if r.RestrictionType == RestrictionTypeRequireLI && (!c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p)) {
|
||||
return false
|
||||
} else if !c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p) {
|
||||
}
|
||||
case RestrictionTypeRequireLI:
|
||||
if !c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -194,12 +200,18 @@ func (c *CoreString) IsVendorAllowedForFlexiblePurposesLI(id int, purposeIds ...
|
||||
}
|
||||
|
||||
for _, r := range pr {
|
||||
if r.IsVendorIncluded(id) {
|
||||
if r.RestrictionType == RestrictionTypeNotAllowed {
|
||||
if !r.IsVendorIncluded(id) {
|
||||
continue
|
||||
}
|
||||
switch r.RestrictionType {
|
||||
case RestrictionTypeNotAllowed:
|
||||
return false
|
||||
case RestrictionTypeRequireConsent:
|
||||
if !c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p) {
|
||||
return false
|
||||
} else if r.RestrictionType == RestrictionTypeRequireConsent && (!c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p)) {
|
||||
return false
|
||||
} else if !c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p) {
|
||||
}
|
||||
case RestrictionTypeRequireLI:
|
||||
if !c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user