Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TCF Policy Version 5. #3339

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ private TCStringParsingResult toValidResult(String consentString, TCStringParsin
}

final int tcfPolicyVersion = tcString.getTcfPolicyVersion();
// disable support for tcf policy version > 4
if (tcfPolicyVersion > 4) {
// disable support for tcf policy version > 5
if (tcfPolicyVersion > 5) {
warnings.add("Parsing consent string: %s failed. TCF policy version %d is not supported".formatted(
consentString, tcfPolicyVersion));
return TCStringParsingResult.of(TCStringEmpty.create(), warnings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public VersionedVendorListService(VendorListService vendorListServiceV2, VendorL
public Future<Map<Integer, Vendor>> forConsent(TCString consent) {
final int tcfPolicyVersion = consent.getTcfPolicyVersion();
final int vendorListVersion = consent.getVendorListVersion();
if (tcfPolicyVersion < 4) {
return vendorListServiceV2.forVersion(vendorListVersion);
} else if (tcfPolicyVersion == 4) {
return vendorListServiceV3.forVersion(vendorListVersion);
if (tcfPolicyVersion > 5) {
return Future.failedFuture(new PreBidException(
"Invalid tcf policy version: %d".formatted(tcfPolicyVersion)));
}

return Future.failedFuture(new PreBidException("Invalid tcf policy version: %d".formatted(tcfPolicyVersion)));
return tcfPolicyVersion < 4
? vendorListServiceV2.forVersion(vendorListVersion)
: vendorListServiceV3.forVersion(vendorListVersion);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.functional.model.mock.services.vendorlist

import com.fasterxml.jackson.annotation.JsonValue

enum GvlSpecificationVersion {

V2(2), V3(3)

@JsonValue
private final Integer value

GvlSpecificationVersion(Integer value) {
this.value = value
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.prebid.server.functional.model.mock.services.vendorlist

import org.prebid.server.functional.util.PBSUtils

import java.time.Clock
import java.time.ZonedDateTime

import static org.prebid.server.functional.model.mock.services.vendorlist.GvlSpecificationVersion.V2
import static org.prebid.server.functional.util.privacy.TcfConsent.VENDOR_LIST_VERSION

class VendorListResponse {

Integer gvlSpecificationVersion
GvlSpecificationVersion gvlSpecificationVersion
Integer vendorListVersion
Integer tcfPolicyVersion
ZonedDateTime lastUpdated
Map<Integer, Vendor> vendors

static VendorListResponse getDefaultVendorListResponse() {
new VendorListResponse().tap {
it.gvlSpecificationVersion = 2
it.gvlSpecificationVersion = V2
it.vendorListVersion = VENDOR_LIST_VERSION
it.lastUpdated = ZonedDateTime.now(Clock.systemUTC()).minusWeeks(2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDO
import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS
import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.DEVICE_ACCESS
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V2
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V3
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V4
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V5

class GdprAmpSpec extends PrivacyBaseSpec {

Expand Down Expand Up @@ -356,7 +357,7 @@ class GdprAmpSpec extends PrivacyBaseSpec {
serverContainer.stop()

where:
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V3]
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5]
}

def "PBS amp with invalid consent.tcfPolicyVersion parameter should reject request and include proper warning"() {
Expand Down Expand Up @@ -442,7 +443,7 @@ class GdprAmpSpec extends PrivacyBaseSpec {
vendorListResponse.reset()

where:
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V3]
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5]
}

def "PBS amp should update activity controls fetch bids metrics when tcf requirement disallow request"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDO
import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS
import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.DEVICE_ACCESS
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V2
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V3
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V4
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V5

class GdprAuctionSpec extends PrivacyBaseSpec {

Expand Down Expand Up @@ -310,7 +311,7 @@ class GdprAuctionSpec extends PrivacyBaseSpec {
serverContainer.stop()

where:
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V3]
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5]
}

def "PBS auction should reject request with proper warning when incoming consent.tcfPolicyVersion have invalid parameter"() {
Expand Down Expand Up @@ -385,7 +386,7 @@ class GdprAuctionSpec extends PrivacyBaseSpec {
vendorListResponse.reset()

where:
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V3]
tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5]
}

def "PBS should apply gdpr and emit metrics when host and device.geo.country contains same eea-country"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class TcfConsent implements ConsentString {
enum TcfPolicyVersion {

TCF_POLICY_V2(2),
TCF_POLICY_V3(4)
TCF_POLICY_V4(4),
TCF_POLICY_V5(5),

final int value

Expand All @@ -151,11 +152,11 @@ class TcfConsent implements ConsentString {
}

int getVendorListVersion() {
(this == TCF_POLICY_V3) ? 3 : 2
(this < TCF_POLICY_V4) ? 2 : 3
}

int getReversedListVersion() {
(this == TCF_POLICY_V3) ? 2 : 3
(this < TCF_POLICY_V4) ? 3 : 2
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void resolveTcfContextShouldTreatTcfConsentWithTcfPolicyVersionGreaterTha

final String vendorConsent = TCStringEncoder.newBuilder()
.version(2)
.tcfPolicyVersion(5)
.tcfPolicyVersion(6)
.encode();

// when
Expand All @@ -260,7 +260,7 @@ public void resolveTcfContextShouldTreatTcfConsentWithTcfPolicyVersionGreaterTha
null);

// then
final String expectedWarning = "Parsing consent string: %s failed. TCF policy version 5 is not supported"
final String expectedWarning = "Parsing consent string: %s failed. TCF policy version 6 is not supported"
.formatted(vendorConsent);
assertThat(result).isSucceeded();
assertThat(result.result().getConsent()).isInstanceOf(TCStringEmpty.class);
Expand Down Expand Up @@ -634,17 +634,20 @@ public void resultForBidderNamesShouldReturnTcfResponseFromTcf2ServiceWhenConsen

@Test
public void isConsentStringValidShouldReturnTrueWhenStringIsValid() {
// when and then
assertThat(TcfDefinerService.isConsentStringValid("CPBCa-mPBCa-mAAAAAENA0CAAEAAAAAAACiQAaQAwAAgAgABoAAAAAA"))
.isTrue();
}

@Test
public void isConsentStringValidShouldReturnFalseWhenStringIsNull() {
// when and then
assertThat(TcfDefinerService.isConsentStringValid(null)).isFalse();
}

@Test
public void isConsentStringValidShouldReturnFalseWhenStringNotValid() {
// when and then
assertThat(TcfDefinerService.isConsentStringValid("invalid")).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public void versionedVendorListServiceShouldTreatTcfPolicyLessThanFourAsVendorLi
@Test
public void versionedVendorListServiceShouldTreatTcfPolicyFourAsVendorListSpecificationThree() {
// given
final int tcfPolicyVersion = ThreadLocalRandom.current().nextInt(4, 6);
final TCString consent = TCStringEncoder.newBuilder()
.version(2)
.tcfPolicyVersion(4)
.tcfPolicyVersion(tcfPolicyVersion)
.vendorListVersion(12)
.toTCString();

Expand All @@ -64,7 +65,7 @@ public void versionedVendorListServiceShouldTreatTcfPolicyFourAsVendorListSpecif
@Test
public void versionedVendorListServiceShouldTreatTcfPolicyGreaterThanFourAsInvalidVersion() {
// given
final int tcfPolicyVersion = ThreadLocalRandom.current().nextInt(5, 63);
final int tcfPolicyVersion = ThreadLocalRandom.current().nextInt(6, 63);
final TCString consent = TCStringEncoder.newBuilder()
.version(2)
.tcfPolicyVersion(tcfPolicyVersion)
Expand Down
Loading