From 8e45ed9932b2051b48a044335ab443188989aed5 Mon Sep 17 00:00:00 2001 From: mtuchkova Date: Fri, 31 Dec 2021 11:30:26 +0200 Subject: [PATCH] Update tests --- .../model/request/amp/AmpRequest.groovy | 3 +- .../model/request/amp/ConsentType.groovy | 23 +++++ .../functional/tests/privacy/CcpaSpec.groovy | 67 ++++++++++++- .../functional/tests/privacy/GdprSpec.groovy | 93 +++++++++++++++++-- .../tests/privacy/PrivacyBaseSpec.groovy | 11 ++- 5 files changed, 178 insertions(+), 19 deletions(-) create mode 100644 src/test/groovy/org/prebid/server/functional/model/request/amp/ConsentType.groovy diff --git a/src/test/groovy/org/prebid/server/functional/model/request/amp/AmpRequest.groovy b/src/test/groovy/org/prebid/server/functional/model/request/amp/AmpRequest.groovy index 60312a627d2..b4b8db9c7ae 100644 --- a/src/test/groovy/org/prebid/server/functional/model/request/amp/AmpRequest.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/request/amp/AmpRequest.groovy @@ -22,8 +22,9 @@ class AmpRequest { String curl Integer account String gdprConsent + String consentString String targeting - Integer consentType + ConsentType consentType Boolean gdprApplies String addtlConsent diff --git a/src/test/groovy/org/prebid/server/functional/model/request/amp/ConsentType.groovy b/src/test/groovy/org/prebid/server/functional/model/request/amp/ConsentType.groovy new file mode 100644 index 00000000000..d9d1c8481a2 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/model/request/amp/ConsentType.groovy @@ -0,0 +1,23 @@ +package org.prebid.server.functional.model.request.amp + +import com.fasterxml.jackson.annotation.JsonValue + +enum ConsentType { + + TCF_1("1"), + TCF_2("2"), + US_PRIVACY("3"), + BOGUS("4") + + @JsonValue + final String value + + ConsentType(String value) { + this.value = value + } + + @Override + String toString() { + value + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/CcpaSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/CcpaSpec.groovy index d24ed241a38..b2cdab132dd 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/CcpaSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/CcpaSpec.groovy @@ -6,14 +6,17 @@ import org.prebid.server.functional.model.config.AccountConfig import org.prebid.server.functional.model.config.AccountPrivacyConfig import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.db.StoredRequest -import org.prebid.server.functional.model.request.amp.AmpRequest import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.testcontainers.PBSTest import org.prebid.server.functional.util.privacy.BogusConsent import org.prebid.server.functional.util.privacy.CcpaConsent +import org.prebid.server.functional.util.privacy.TcfConsent import spock.lang.PendingFeature +import static org.prebid.server.functional.model.request.amp.ConsentType.BOGUS import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED +import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS @PBSTest class CcpaSpec extends PrivacyBaseSpec { @@ -194,9 +197,8 @@ class CcpaSpec extends PrivacyBaseSpec { } } - def "PBS should not emit error for amp request when gdpr_consent contains invalid ccpa consent"() { + def "PBS should emit error for amp request when consent_string contains invalid ccpa consent"() { given: "Default AmpRequest with invalid ccpa consent" - def invalidCcpa = new BogusConsent() def ampRequest = getCcpaAmpRequest(invalidCcpa) def ampStoredRequest = BidRequest.defaultBidRequest.tap { site.publisher.id = ampRequest.account @@ -209,7 +211,62 @@ class CcpaSpec extends PrivacyBaseSpec { when: "PBS processes amp request" def response = defaultPbsService.sendAmpRequest(ampRequest) - then: "Response should not contain error" - assert !response.ext?.errors + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == + ["Amp request parameter consent_string has invalid format for consent " + + "type usPrivacy: $invalidCcpa" as String] + + where: + invalidCcpa << [new BogusConsent(), new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .build()] + } + + def "PBS should emit error for amp request with gdprConsent when consent_type is invalid"() { + given: "Default AmpRequest with invalid ccpa type" + def validCcpa = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) + def ampRequest = getCcpaAmpRequest(validCcpa).tap { + consentType = BOGUS + } + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == ["Invalid consent_type param passed"] + } + + def "PBS should emit error for amp request when set not appropriate tcf consent"() { + given: "Default AmpRequest with gdpr_consent" + def tcfConsent = new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .build() + def ampRequest = getCcpaAmpRequest(null).tap { + gdprConsent = tcfConsent + } + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == + ["Amp request parameter gdpr_consent has invalid format for consent type usPrivacy: $tcfConsent" as String] } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GdprSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GdprSpec.groovy index edbbbbb3332..09573d3453b 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GdprSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GdprSpec.groovy @@ -2,13 +2,17 @@ package org.prebid.server.functional.tests.privacy import org.prebid.server.functional.model.bidder.BidderName import org.prebid.server.functional.model.db.StoredRequest -import org.prebid.server.functional.model.request.amp.AmpRequest import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.testcontainers.PBSTest import org.prebid.server.functional.util.privacy.BogusConsent +import org.prebid.server.functional.util.privacy.CcpaConsent import org.prebid.server.functional.util.privacy.TcfConsent import spock.lang.PendingFeature +import static org.prebid.server.functional.model.request.amp.ConsentType.BOGUS +import static org.prebid.server.functional.model.request.amp.ConsentType.TCF_1 +import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS @PBSTest @@ -164,9 +168,9 @@ class GdprSpec extends PrivacyBaseSpec { } } - def "PBS should not emit error for amp request when gdpr_consent is #description"() { - given: "Default AmpRequest" - def ampRequest = AmpRequest.defaultAmpRequest + def "PBS should emit error for amp request when gdpr_consent is invalid"() { + given: "Default AmpRequest with invalid gdpr_consent" + def ampRequest = getGdprAmpRequest(invalidTcfConsent) def ampStoredRequest = BidRequest.defaultBidRequest.tap { site.publisher.id = ampRequest.account } @@ -178,12 +182,83 @@ class GdprSpec extends PrivacyBaseSpec { when: "PBS processes amp request" def response = defaultPbsService.sendAmpRequest(ampRequest) - then: "Response should not contain error" - assert !response.ext?.errors + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == + ["Amp request parameter gdpr_consent has invalid format for consent type tcfV2: $invalidTcfConsent" as String] where: - description | request - "not specified" | AmpRequest.defaultAmpRequest - "invalid tcf consent" | getGdprAmpRequest(new BogusConsent()) + invalidTcfConsent << [new BogusConsent(), new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED)] + } + + def "PBS should emit error for amp request when consent_type is tcf1"() { + given: "Default AmpRequest with consent_type = tcf1" + def consentString = new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .build() + def ampRequest = getGdprAmpRequest(consentString).tap { + consentType = TCF_1 + } + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == ["Consent type tcfV1 is no longer supported"] + } + + def "PBS should emit error for amp request with consentString when consent_type is bogus"() { + given: "Default AmpRequest with invalid consent_type" + def consentString = new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .build() + def ampRequest = getGdprAmpRequest(consentString).tap { + consentType = BOGUS + } + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == ["Invalid consent_type param passed"] + } + + def "PBS should emit error for amp request when set not appropriate ccpa consent"() { + given: "Default AmpRequest" + def ccpaConsent = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) + def ampRequest = getGdprAmpRequest(null).tap { + consentString = ccpaConsent + } + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Response should contain error" + assert response.ext?.errors[ErrorType.PREBID]*.code == [999] + assert response.ext?.errors[ErrorType.PREBID]*.message == + ["Amp request parameter consent_string has invalid format for consent type tcfV2: $ccpaConsent" as String] } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy index d02bc0cd040..7c010848da0 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy @@ -12,6 +12,9 @@ import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.ConsentString +import static org.prebid.server.functional.model.request.amp.ConsentType.TCF_2 +import static org.prebid.server.functional.model.request.amp.ConsentType.US_PRIVACY + @PBSTest abstract class PrivacyBaseSpec extends BaseSpec { @@ -29,10 +32,10 @@ abstract class PrivacyBaseSpec extends BaseSpec { } } - protected static AmpRequest getCcpaAmpRequest(ConsentString consentString) { + protected static AmpRequest getCcpaAmpRequest(ConsentString consentStringVal) { AmpRequest.defaultAmpRequest.tap { - gdprConsent = consentString - consentType = 3 + consentString = consentStringVal + consentType = US_PRIVACY } } @@ -46,7 +49,7 @@ abstract class PrivacyBaseSpec extends BaseSpec { protected static AmpRequest getGdprAmpRequest(ConsentString consentString) { AmpRequest.defaultAmpRequest.tap { gdprConsent = consentString - consentType = 2 + consentType = TCF_2 gdprApplies = true } }