From b3795a0a440f6a0845d2b8dd2554e3804c5b7ea7 Mon Sep 17 00:00:00 2001 From: Markiyan Mykush <95693607+marki1an@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:41:40 +0200 Subject: [PATCH] Test: `consented_providers_settings` (#3577) --- .../auction/ConsentedProvidersSettings.groovy | 12 +++ .../model/request/auction/UserExt.groovy | 7 ++ .../server/functional/tests/AmpSpec.groovy | 80 ++++++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/org/prebid/server/functional/model/request/auction/ConsentedProvidersSettings.groovy diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/ConsentedProvidersSettings.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/ConsentedProvidersSettings.groovy new file mode 100644 index 00000000000..aa7bd511cb2 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/ConsentedProvidersSettings.groovy @@ -0,0 +1,12 @@ +package org.prebid.server.functional.model.request.auction + +import com.fasterxml.jackson.databind.PropertyNamingStrategies +import com.fasterxml.jackson.databind.annotation.JsonNaming +import groovy.transform.ToString + +@ToString(includeNames = true, ignoreNulls = true) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy) +class ConsentedProvidersSettings { + + String consentedProviders +} diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/UserExt.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/UserExt.groovy index e547d8f37ed..af07e197c28 100644 --- a/src/test/groovy/org/prebid/server/functional/model/request/auction/UserExt.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/UserExt.groovy @@ -1,8 +1,12 @@ package org.prebid.server.functional.model.request.auction +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.PropertyNamingStrategies +import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.ToString @ToString(includeNames = true, ignoreNulls = true) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy) class UserExt { String consent @@ -11,6 +15,9 @@ class UserExt { UserTime time UserExtData data UserExtPrebid prebid + ConsentedProvidersSettings consentedProvidersSettings + @JsonProperty("ConsentedProvidersSettings") + ConsentedProvidersSettings consentedProvidersSettingsCamelCase static UserExt getFPDUserExt() { new UserExt(data: UserExtData.FPDUserExtData) diff --git a/src/test/groovy/org/prebid/server/functional/tests/AmpSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AmpSpec.groovy index ac3ba146010..96a78df89a8 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AmpSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AmpSpec.groovy @@ -4,9 +4,12 @@ import org.prebid.server.functional.model.db.StoredRequest import org.prebid.server.functional.model.db.StoredResponse import org.prebid.server.functional.model.request.amp.AmpRequest import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.request.auction.ConsentedProvidersSettings import org.prebid.server.functional.model.request.auction.DistributionChannel import org.prebid.server.functional.model.request.auction.Site import org.prebid.server.functional.model.request.auction.StoredAuctionResponse +import org.prebid.server.functional.model.request.auction.User +import org.prebid.server.functional.model.request.auction.UserExt import org.prebid.server.functional.model.response.auction.SeatBid import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.util.PBSUtils @@ -56,7 +59,7 @@ class AmpSpec extends BaseSpec { assert exception.responseBody == "Invalid request format: request.${channel.value.toLowerCase()} must not exist in AMP stored requests." where: - channel << [DistributionChannel.APP, DistributionChannel.DOOH] + channel << [DistributionChannel.APP, DistributionChannel.DOOH] } def "PBS should return info from the stored response when it's defined in the stored request"() { @@ -180,4 +183,79 @@ class AmpSpec extends BaseSpec { assert bidderRequest.imp[0]?.banner?.format[0]?.weight == ampStoredRequest.imp[0].banner.format[0].weight assert bidderRequest.regs?.gdpr == ampStoredRequest.regs.gdpr } + + def "PBS should pass addtl_consent to user.ext.{consented_providers_settings/ConsentedProvidersSettings}.consented_providers"() { + given: "Default amp request with addtlConsent" + def randomAddtlConsent = PBSUtils.randomString + def ampRequest = AmpRequest.defaultAmpRequest.tap { + addtlConsent = randomAddtlConsent + } + + and: "Save storedRequest into DB" + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + user = new User(ext: new UserExt( + consentedProvidersSettingsCamelCase: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString), + consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString))) + } + def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + defaultPbsService.sendAmpRequest(ampRequest) + + then: "Bidder request should contain addtl consent" + def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id) + assert bidderRequest.user.ext.consentedProvidersSettingsCamelCase.consentedProviders == randomAddtlConsent + assert bidderRequest.user.ext.consentedProvidersSettings.consentedProviders == randomAddtlConsent + } + + def "PBS should process original user.ext.{consented_providers_settings/ConsentedProvidersSettings}.consented_providers when ampRequest doesn't contain addtl_consent"() { + given: "Default amp request with addtlConsent" + def ampRequest = AmpRequest.defaultAmpRequest.tap { + addtlConsent = null + } + + and: "Save storedRequest into DB" + def consentProvidersKebabCase = PBSUtils.randomString + def consentProviders = PBSUtils.randomString + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + user = new User(ext: new UserExt( + consentedProvidersSettingsCamelCase: new ConsentedProvidersSettings(consentedProviders: consentProvidersKebabCase), + consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: consentProviders))) + } + def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + defaultPbsService.sendAmpRequest(ampRequest) + + then: "Bidder request should contain requested consent" + def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id) + assert bidderRequest.user.ext.consentedProvidersSettingsCamelCase.consentedProviders == consentProvidersKebabCase + assert bidderRequest.user.ext.consentedProvidersSettings.consentedProviders == consentProviders + } + + def "PBS should left user.ext.{consented_providers_settings/ConsentedProvidersSettings}.consented_providers empty when addtl_consent and original fields are empty"() { + given: "Default amp request with addtlConsent" + def ampRequest = AmpRequest.defaultAmpRequest.tap { + addtlConsent = null + } + + and: "Save storedRequest into DB" + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + user = new User(ext: new UserExt( + consentedProvidersSettingsCamelCase: new ConsentedProvidersSettings(consentedProviders: null), + consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: null))) + } + def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + defaultPbsService.sendAmpRequest(ampRequest) + + then: "Bidder request shouldn't contain consent" + def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id) + assert !bidderRequest.user.ext.consentedProvidersSettingsCamelCase.consentedProviders + assert !bidderRequest.user.ext.consentedProvidersSettings.consentedProviders + } }