diff --git a/pom.xml b/pom.xml index 1012e1493ab..f9f2e5b8117 100644 --- a/pom.xml +++ b/pom.xml @@ -615,6 +615,7 @@ ${project.version} 5 + false false diff --git a/src/test/groovy/org/prebid/server/functional/model/bidder/BidderName.groovy b/src/test/groovy/org/prebid/server/functional/model/bidder/BidderName.groovy index 1061cf4a348..1ebb874c6a7 100644 --- a/src/test/groovy/org/prebid/server/functional/model/bidder/BidderName.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/bidder/BidderName.groovy @@ -14,7 +14,7 @@ enum BidderName { ALIAS_UPPER_CASE("ALIAS"), GENERIC_CAMEL_CASE("GeNerIc"), GENERIC("generic"), - GENER_X("gener_x"), + GENER_X("gener-x"), MAGNITE("magnite"), APPNEXUS("appnexus"), MAGNITE_ALIAS("magniteAlias"), diff --git a/src/test/groovy/org/prebid/server/functional/model/bidder/GeneralBidderAdapter.groovy b/src/test/groovy/org/prebid/server/functional/model/bidder/GeneralBidderAdapter.groovy index b583363974c..98a8187cf2e 100644 --- a/src/test/groovy/org/prebid/server/functional/model/bidder/GeneralBidderAdapter.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/bidder/GeneralBidderAdapter.groovy @@ -11,4 +11,6 @@ class GeneralBidderAdapter extends Generic { String demandSource @JsonProperty("bc") BidderName bidderCode + @JsonProperty("placement_id") + String placementId } diff --git a/src/test/groovy/org/prebid/server/functional/model/config/AppVideoHtml.groovy b/src/test/groovy/org/prebid/server/functional/model/config/AppVideoHtml.groovy index 6486e292ed5..602893b2808 100644 --- a/src/test/groovy/org/prebid/server/functional/model/config/AppVideoHtml.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/config/AppVideoHtml.groovy @@ -1,6 +1,5 @@ package org.prebid.server.functional.model.config -import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.ToString diff --git a/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingActionOverride.groovy b/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingActionOverride.groovy index de8eae06d04..eb7434fe46e 100644 --- a/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingActionOverride.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingActionOverride.groovy @@ -6,8 +6,8 @@ import groovy.transform.ToString import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.AUDIO_BATTR import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BADV -import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BANNER_BATTR +import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BCAT import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BTYPE import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.VIDEO_BATTR diff --git a/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingAttributeConfig.groovy b/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingAttributeConfig.groovy index 9e622472024..0255dd9bfa6 100644 --- a/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingAttributeConfig.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/config/Ortb2BlockingAttributeConfig.groovy @@ -6,8 +6,8 @@ import groovy.transform.ToString import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.AUDIO_BATTR import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BADV -import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BANNER_BATTR +import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BCAT import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BTYPE import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.VIDEO_BATTR diff --git a/src/test/groovy/org/prebid/server/functional/model/db/StoredProfileRequest.groovy b/src/test/groovy/org/prebid/server/functional/model/db/StoredProfileRequest.groovy index 8b04143d368..4112f18ac8a 100644 --- a/src/test/groovy/org/prebid/server/functional/model/db/StoredProfileRequest.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/db/StoredProfileRequest.groovy @@ -6,13 +6,13 @@ import jakarta.persistence.Convert import jakarta.persistence.Entity import jakarta.persistence.Id import jakarta.persistence.Table +import org.prebid.server.functional.model.db.typeconverter.BidRequestConfigTypeConverter import org.prebid.server.functional.model.db.typeconverter.ProfileMergePrecedenceConvert import org.prebid.server.functional.model.db.typeconverter.ProfileTypeConvert -import org.prebid.server.functional.model.db.typeconverter.BidRequestConfigTypeConverter import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.profile.ProfileMergePrecedence -import org.prebid.server.functional.model.request.profile.RequestProfile import org.prebid.server.functional.model.request.profile.ProfileType +import org.prebid.server.functional.model.request.profile.RequestProfile @Entity @Table(name = "profiles") diff --git a/src/test/groovy/org/prebid/server/functional/model/db/StoredResponse.groovy b/src/test/groovy/org/prebid/server/functional/model/db/StoredResponse.groovy index ebfc31f3c6d..278dd1e9227 100644 --- a/src/test/groovy/org/prebid/server/functional/model/db/StoredResponse.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/db/StoredResponse.groovy @@ -7,8 +7,8 @@ import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.Id import jakarta.persistence.Table -import org.prebid.server.functional.model.db.typeconverter.StoredAuctionResponseConfigTypeConverter import org.prebid.server.functional.model.db.typeconverter.BidResponseConfigTypeConverter +import org.prebid.server.functional.model.db.typeconverter.StoredAuctionResponseConfigTypeConverter import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.SeatBid diff --git a/src/test/groovy/org/prebid/server/functional/model/mock/services/vendorlist/VendorListResponse.groovy b/src/test/groovy/org/prebid/server/functional/model/mock/services/vendorlist/VendorListResponse.groovy index 9e54f4ce7e6..24ad5385bcf 100644 --- a/src/test/groovy/org/prebid/server/functional/model/mock/services/vendorlist/VendorListResponse.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/mock/services/vendorlist/VendorListResponse.groovy @@ -1,6 +1,7 @@ package org.prebid.server.functional.model.mock.services.vendorlist import org.prebid.server.functional.util.PBSUtils + import java.time.Clock import java.time.ZonedDateTime diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/FetchStatus.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/AnalyticTagStatus.groovy similarity index 93% rename from src/test/groovy/org/prebid/server/functional/model/request/auction/FetchStatus.groovy rename to src/test/groovy/org/prebid/server/functional/model/request/auction/AnalyticTagStatus.groovy index 6eec49cf39d..3f6dcaf412e 100644 --- a/src/test/groovy/org/prebid/server/functional/model/request/auction/FetchStatus.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/AnalyticTagStatus.groovy @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue import groovy.transform.ToString @ToString -enum FetchStatus { +enum AnalyticTagStatus { NONE, SUCCESS, TIMEOUT, INPROGRESS, ERROR, SUCCESS_ALLOW, SUCCESS_BLOCK, SKIPPED, RUN diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/Bidder.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/Bidder.groovy index 5ea7a7d3270..6561be81498 100644 --- a/src/test/groovy/org/prebid/server/functional/model/request/auction/Bidder.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/Bidder.groovy @@ -5,8 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty import groovy.transform.ToString import org.prebid.server.functional.model.bidder.AppNexus import org.prebid.server.functional.model.bidder.Generic -import org.prebid.server.functional.model.bidder.Openx import org.prebid.server.functional.model.bidder.Magnite +import org.prebid.server.functional.model.bidder.Openx @ToString(includeNames = true, ignoreNulls = true) class Bidder { @@ -15,7 +15,7 @@ class Bidder { @JsonProperty("ALIAS") Generic aliasUpperCase Generic generic - @JsonProperty("gener_x") + @JsonProperty("gener-x") Generic generX @JsonProperty("GeNerIc") Generic genericCamelCase diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/ExtPrebidFloors.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/ExtPrebidFloors.groovy index c0c80038f5c..0ef7a96e7c6 100644 --- a/src/test/groovy/org/prebid/server/functional/model/request/auction/ExtPrebidFloors.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/ExtPrebidFloors.groovy @@ -12,7 +12,7 @@ class ExtPrebidFloors { Boolean enabled Location location - FetchStatus fetchStatus + AnalyticTagStatus fetchStatus Boolean skipped Currency floorMinCur BigDecimal floorMin diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticResult.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticResult.groovy index a8b737a848a..57d62801746 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticResult.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticResult.groovy @@ -4,11 +4,11 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import org.prebid.server.functional.model.request.auction.FetchStatus +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus import org.prebid.server.functional.model.request.auction.Imp -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS_BLOCK +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS_BLOCK @ToString(includeNames = true, ignoreNulls = true) @JsonNaming(PropertyNamingStrategies.LowerCaseStrategy) @@ -16,7 +16,7 @@ import static org.prebid.server.functional.model.request.auction.FetchStatus.SUC class AnalyticResult { String name - FetchStatus status + AnalyticTagStatus status List results static AnalyticResult buildFromImp(Imp imp) { diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticTagStatus.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticTagStatus.groovy new file mode 100644 index 00000000000..f7575677ce3 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticTagStatus.groovy @@ -0,0 +1,13 @@ +package org.prebid.server.functional.model.response.auction + +import com.fasterxml.jackson.annotation.JsonValue + +enum AnalyticTagStatus { + + NONE, LOOKUP, CONTROL, SUCCESS, ERROR, SUCCESS_ALLOW, SUCCESS_BLOCK, SKIPPED, RUN + + @JsonValue + String getValue() { + name().toLowerCase().replace('_', '-') + } +} diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivity.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivity.groovy index 6fd41583617..2ee172e41e3 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivity.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivity.groovy @@ -3,13 +3,13 @@ package org.prebid.server.functional.model.response.auction import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.ToString -import org.prebid.server.functional.model.request.auction.FetchStatus +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus @ToString(includeNames = true, ignoreNulls = true) @JsonNaming(PropertyNamingStrategies.LowerCaseStrategy) class AnalyticsTagActivity { ModuleActivityName name - FetchStatus status + AnalyticTagStatus status List results } diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivityResult.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivityResult.groovy index a439d6411c2..59d0948519c 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivityResult.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/AnalyticsTagActivityResult.groovy @@ -3,13 +3,13 @@ package org.prebid.server.functional.model.response.auction import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.ToString -import org.prebid.server.functional.model.request.auction.FetchStatus +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus @ToString(includeNames = true, ignoreNulls = true) @JsonNaming(PropertyNamingStrategies.LowerCaseStrategy) class AnalyticsTagActivityResult { - FetchStatus status + AnalyticTagStatus status AnalyticsTagActivityValue values AppliedTo appliedTo } diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/ErrorType.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/ErrorType.groovy index 81dcd788b7d..04ac22ee511 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/ErrorType.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/ErrorType.groovy @@ -6,6 +6,7 @@ enum ErrorType { GENERAL("general"), GENERIC("generic"), + GENER_X("gener-x"), GENERIC_CAMEL_CASE("GeNerIc"), MAGNITE("magnite"), APPNEXUS("appnexus"), diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/ImpResult.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/ImpResult.groovy index 8740e415f47..e12db6d5404 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/ImpResult.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/ImpResult.groovy @@ -4,14 +4,14 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.annotation.JsonNaming import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import org.prebid.server.functional.model.request.auction.FetchStatus +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus @ToString(includeNames = true, ignoreNulls = true) @JsonNaming(PropertyNamingStrategies.LowerCaseStrategy) @EqualsAndHashCode class ImpResult { - FetchStatus status + AnalyticTagStatus status ModuleValue values AppliedTo appliedTo } diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleActivityName.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleActivityName.groovy index 8711bd395c6..10705cc6dcf 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleActivityName.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleActivityName.groovy @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue enum ModuleActivityName { - ORTB2_BLOCKING('enforce-blocking'), + PB_ORTB2_BLOCKING('enforce-blocking'), REJECT_RICHMEDIA('reject-richmedia'), AB_TESTING('core-module-abtests') diff --git a/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleValue.groovy b/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleValue.groovy index d0368344098..eed7c8da6d1 100644 --- a/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleValue.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/response/auction/ModuleValue.groovy @@ -3,8 +3,8 @@ package org.prebid.server.functional.model.response.auction import com.fasterxml.jackson.annotation.JsonProperty import groovy.transform.EqualsAndHashCode import groovy.transform.ToString -import org.prebid.server.functional.model.config.ModuleName import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.config.ModuleName @ToString(includeNames = true, ignoreNulls = true) @EqualsAndHashCode diff --git a/src/test/groovy/org/prebid/server/functional/repository/HibernateRepositoryService.groovy b/src/test/groovy/org/prebid/server/functional/repository/HibernateRepositoryService.groovy index cd1b9706f79..48ab82f6126 100644 --- a/src/test/groovy/org/prebid/server/functional/repository/HibernateRepositoryService.groovy +++ b/src/test/groovy/org/prebid/server/functional/repository/HibernateRepositoryService.groovy @@ -3,9 +3,9 @@ package org.prebid.server.functional.repository import org.hibernate.SessionFactory import org.hibernate.cfg.Configuration import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.db.StoredImp import org.prebid.server.functional.model.db.StoredProfileImp import org.prebid.server.functional.model.db.StoredProfileRequest -import org.prebid.server.functional.model.db.StoredImp import org.prebid.server.functional.model.db.StoredRequest import org.prebid.server.functional.model.db.StoredResponse import org.prebid.server.functional.repository.dao.AccountDao diff --git a/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy b/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy index d8b1a05ff31..4a71e447a91 100644 --- a/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy +++ b/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy @@ -38,7 +38,6 @@ import org.slf4j.LoggerFactory import java.time.Duration import java.time.Instant -import java.time.ZoneId import java.time.format.DateTimeFormatter import static io.restassured.RestAssured.given @@ -61,7 +60,6 @@ import static org.prebid.server.functional.model.config.Endpoint.VTRACK import static org.prebid.server.functional.testcontainers.Dependencies.influxdbContainer import static org.prebid.server.functional.util.SystemProperties.DEFAULT_TIMEOUT - class PrebidServerService implements ObjectMapperWrapper { static final String UIDS_COOKIE_NAME = "uids" @@ -468,7 +466,6 @@ class PrebidServerService implements ObjectMapperWrapper { [] } - Boolean isContainMetricByValue(String value) { try { PBSUtils.waitUntil({ sendInfluxMetricsRequest()[value] != null }) diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/Dependencies.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/Dependencies.groovy index 22b8e9cecae..a70cbb1b4f0 100644 --- a/src/test/groovy/org/prebid/server/functional/testcontainers/Dependencies.groovy +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/Dependencies.groovy @@ -5,8 +5,8 @@ import org.prebid.server.functional.util.SystemProperties import org.testcontainers.containers.InfluxDBContainer import org.testcontainers.containers.MySQLContainer import org.testcontainers.containers.Network -import org.testcontainers.containers.localstack.LocalStackContainer import org.testcontainers.containers.PostgreSQLContainer +import org.testcontainers.containers.localstack.LocalStackContainer import org.testcontainers.lifecycle.Startables import org.testcontainers.utility.DockerImageName diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/PbsConfig.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/PbsConfig.groovy index c873c1a03f3..b768d9ee057 100644 --- a/src/test/groovy/org/prebid/server/functional/testcontainers/PbsConfig.groovy +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/PbsConfig.groovy @@ -1,6 +1,5 @@ package org.prebid.server.functional.testcontainers - import org.testcontainers.containers.MySQLContainer import org.testcontainers.containers.PostgreSQLContainer diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/PbsServiceFactory.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/PbsServiceFactory.groovy index 60ca02ad762..1842df91ccc 100644 --- a/src/test/groovy/org/prebid/server/functional/testcontainers/PbsServiceFactory.groovy +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/PbsServiceFactory.groovy @@ -1,73 +1,80 @@ package org.prebid.server.functional.testcontainers import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.testcontainers.container.NetworkServiceContainer +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.container.PrebidServerContainer -import org.prebid.server.functional.util.SystemProperties import org.testcontainers.images.builder.Transferable +import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.LRU +import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.PERSISTENT +import static org.prebid.server.functional.util.SystemProperties.DEBUG_ENABLED +import static org.prebid.server.functional.util.SystemProperties.MAX_CONTAINER import static org.prebid.server.functional.util.SystemProperties.USE_FIXED_CONTAINER_PORTS -// TODO make container instance into a POGO and add the ability for any given container to live through stopContainers() class PbsServiceFactory { - private static final Map, PrebidServerContainer> containers = [:] - private static final int MAX_CONTAINER_COUNT = maxContainerCount + private static final int MAX_CONTAINER_COUNT = USE_FIXED_CONTAINER_PORTS ? 1 : MAX_CONTAINER - private final NetworkServiceContainer networkServiceContainer + private static final Map containers = + new LinkedHashMap<>(16, 0.75f, true) - PbsServiceFactory(NetworkServiceContainer networkServiceContainer) { - this.networkServiceContainer = networkServiceContainer + // Will be removed in 5.0 + @Deprecated(forRemoval = true) + static PrebidServerService getService(Map config, + Map additionalFiles = [:], + ContainerPolicy policy = LRU) { + getService(new PbsContainerConfig(config, additionalFiles), policy) } - static PrebidServerService getService(Map config, Map additionalFiles = [:]) { - if (containers.containsKey(config)) { - def container = containers.get(config) - container.refresh() - return new PrebidServerService(container) + static PrebidServerService getService(PbsContainerConfig config, + ContainerPolicy policy = LRU) { + def cached = containers.remove(config) + if (cached) { + cached.container.refresh() + cached.persistent |= policy == PERSISTENT } else { - if (containers.size() == 1 && MAX_CONTAINER_COUNT == 1) { - def container = containers.entrySet().first() - remove([(container.key): container.value]) - } else if (containers.size() >= MAX_CONTAINER_COUNT) { - def container = containers.find { !it.key.isEmpty() } - remove([(container.key): container.value]) - } - def pbsContainer = new PrebidServerContainer(config) - if (!additionalFiles.isEmpty()) { - additionalFiles.each { k, v -> pbsContainer.withCopyToContainer(v, k) } - } - pbsContainer.start() - containers.put(config, pbsContainer) - return new PrebidServerService(pbsContainer) + evictIfNeeded() + def container = new PrebidServerContainer(config, DEBUG_ENABLED) + container.start() + cached = new CachedContainer( + container: container, + persistent: policy == PERSISTENT) } + containers[config] = cached + new PrebidServerService(cached.container) } - private static PrebidServerContainer getContainer(Map config) { - containers.get(config) + private static void evictIfNeeded() { + if (containers.size() < MAX_CONTAINER_COUNT) { + return + } + + def eldest = containers.find { !it.value.persistent } + if (!eldest) { + throw new IllegalStateException("All container slots are persistent") + } + + eldest.value.container.stop() + containers.remove(eldest.key) } - static void stopContainers() { - def containers = containers.findAll { it.key != [:] } - remove(containers) + // Will be removed in 5.0 + @Deprecated(forRemoval = true) + static void removeContainer(Map config) { + removeContainer(new PbsContainerConfig(config)) } - static void removeContainer(Map config) { - def container = containers.get(config) - container.stop() - containers.remove(config) + static void removeContainer(PbsContainerConfig config) { + containers.remove(config)?.container?.stop() } - private static void remove(Map, PrebidServerContainer> map) { - map.each { key, value -> - value.stop() - containers.remove(key) - } + private static class CachedContainer { + PrebidServerContainer container + boolean persistent } - private static int getMaxContainerCount() { - USE_FIXED_CONTAINER_PORTS - ? 1 - : SystemProperties.getPropertyOrDefault("tests.max-container-count", 5) + enum ContainerPolicy { + PERSISTENT, + LRU } } diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/container/PbsContainerConfig.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/container/PbsContainerConfig.groovy new file mode 100644 index 00000000000..cf73f4e70cf --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/container/PbsContainerConfig.groovy @@ -0,0 +1,46 @@ +package org.prebid.server.functional.testcontainers.container + +import groovy.transform.EqualsAndHashCode +import org.testcontainers.images.builder.Transferable + +@EqualsAndHashCode +class PbsContainerConfig { + + final Map extraProperties + final Map additionalFiles + + PbsContainerConfig(Map extraProperties = [:], Map additionalFiles = [:]) { + this.extraProperties = normalizeProperties(extraProperties) + this.additionalFiles = additionalFiles.asImmutable() + } + + PbsContainerConfig plus(Map properties) { + if (properties.values().any { it instanceof Transferable }) { + throw new IllegalArgumentException("Use withFiles() to add container files") + } + new PbsContainerConfig( + [:] << extraProperties << properties, + additionalFiles + ) + } + + PbsContainerConfig plus(PbsContainerConfig other) { + new PbsContainerConfig( + [:] << extraProperties << other.extraProperties, + [:] << additionalFiles << other.additionalFiles + ) + } + + PbsContainerConfig withFiles(Map files) { + new PbsContainerConfig( + extraProperties, + [:] << additionalFiles << files + ) + } + + private static Map normalizeProperties(Map properties) { + properties.collectEntries { + key, value -> [(key.toString()): value?.toString()] + }.asImmutable() + } +} diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/container/PrebidServerContainer.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/container/PrebidServerContainer.groovy index 5a177572122..a71fd0e24dc 100644 --- a/src/test/groovy/org/prebid/server/functional/testcontainers/container/PrebidServerContainer.groovy +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/container/PrebidServerContainer.groovy @@ -12,29 +12,32 @@ import static org.prebid.server.functional.testcontainers.PbsConfig.DEFAULT_ENV class PrebidServerContainer extends GenericContainer { - public static final String ADMIN_ENDPOINT_USERNAME = "admin" - public static final String ADMIN_ENDPOINT_PASSWORD = "admin" - public static final String APP_WORKDIR = "/app/prebid-server/" - public static final int PROMETHEUS_PORT = 8070 - - private static final int DEFAULT_PORT = 8080 - private static final int DEFAULT_ADMIN_PORT = 8060 - private static final int DEFAULT_DEBUG_PORT = 8000 - private static final int PORT = SystemProperties.getPropertyOrDefault("port", DEFAULT_PORT) - private static final int ADMIN_PORT = SystemProperties.getPropertyOrDefault("admin.port", DEFAULT_ADMIN_PORT) - private static final int DEBUG_PORT = SystemProperties.getPropertyOrDefault("debug.port", DEFAULT_DEBUG_PORT) + static final String ADMIN_ENDPOINT_USERNAME = "admin" + static final String ADMIN_ENDPOINT_PASSWORD = "admin" + static final String APP_WORKDIR = "/app/prebid-server/" + static final int PROMETHEUS_PORT = 8070 + + private static final int PORT = SystemProperties.getPropertyOrDefault("port", 8080) + private static final int ADMIN_PORT = SystemProperties.getPropertyOrDefault("admin.port", 8060) + private static final int DEBUG_PORT = SystemProperties.getPropertyOrDefault("debug.port", 8000) private static final String PBS_DOCKER_IMAGE_NAME = "prebid/prebid-server:latest" - PrebidServerContainer(Map customConfig) { + private final boolean debugEnabled + + PrebidServerContainer(PbsContainerConfig config, boolean debugEnabled = false) { super(PBS_DOCKER_IMAGE_NAME) - withExposedPorts(PORT, DEBUG_PORT, ADMIN_PORT, PROMETHEUS_PORT) + this.debugEnabled = debugEnabled + def ports = [PORT, ADMIN_PORT, PROMETHEUS_PORT] + if (debugEnabled) { + ports << DEBUG_PORT + } + withExposedPorts(*ports) withFixedPorts() withStartupAttempts(3) waitingFor(Wait.forHttp(STATUS.value) .forPort(PORT) .forStatusCode(200)) - withDebug() withNetwork(Dependencies.network) def commonConfig = [:] << DEFAULT_ENV << PbsConfig.defaultBiddersConfig @@ -46,23 +49,46 @@ class PrebidServerContainer extends GenericContainer { << PbsConfig.mySqlConfig << PbsConfig.targetingConfig withConfig(commonConfig) - withConfig(customConfig) + withConfig(config.extraProperties) + + config.additionalFiles.each { path, file -> + withCopyToContainer(file, path) + } + + if (debugEnabled) { + withDebug() + } } private void withFixedPorts() { - if (SystemProperties.USE_FIXED_CONTAINER_PORTS) { - addFixedExposedPort(PORT, PORT) - addFixedExposedPort(ADMIN_PORT, ADMIN_PORT) + if (!SystemProperties.USE_FIXED_CONTAINER_PORTS) { + return + } + addFixedExposedPort(PORT, PORT) + addFixedExposedPort(ADMIN_PORT, ADMIN_PORT) + if (debugEnabled) { addFixedExposedPort(DEBUG_PORT, DEBUG_PORT) } } - void withDebug() { - withEnv("JAVA_TOOL_OPTIONS", "-agentlib:jdwp=transport=dt_socket,address=*:$DEBUG_PORT,server=y,suspend=n") + private void withDebug() { + def options = [ + envMap.JAVA_TOOL_OPTIONS, + "-agentlib:jdwp=transport=dt_socket,address=*:$DEBUG_PORT,server=y,suspend=n" + ].findAll().join(' ') + withEnv("JAVA_TOOL_OPTIONS", options) } void withConfig(Map config) { - withEnv(normalizeProperties(config)) + withEnv(config.collectEntries { key, value -> + [(normalizeProperty(key)): value] + }) + } + + private static String normalizeProperty(String property) { + property.replace(".", "_") + .replace("[", "_") + .replace("]", "_") } int getPort() { @@ -77,50 +103,38 @@ class PrebidServerContainer extends GenericContainer { getMappedPort(PROMETHEUS_PORT) } + String getDebugAddress() { + debugEnabled ? "$host:${getMappedPort(DEBUG_PORT)}" : null + } + String getInfluxUri() { - return "http://$host:$Dependencies.influxdbContainer.firstMappedPort" + "http://$host:${Dependencies.influxdbContainer.firstMappedPort}" } String getRootUri() { - return "http://$host:$port" + "http://$host:$port" } String getAdminRootUri() { - return "http://$host:$adminPort" + "http://$host:$adminPort" } String getPrometheusRootUri() { - return "http://$host:$prometheusPort" - } - - private static Map normalizeProperties(Map properties) { - properties.collectEntries { [normalizeProperty(it.key), it.value] } as Map - } - - private static String normalizeProperty(String property) { - property.replace(".", "_") - .replace("[", "_") - .replace("]", "_") + "http://$host:$prometheusPort" } PrebidServerContainer withFolder(String containerPath) { - this.withCopyToContainer( + withCopyToContainer( Transferable.of(new byte[0], 010755), - containerPath + "/.keep" + "$containerPath/.keep" ) return this } - // This is a workaround for cases when container is killed mid-test due to OOM void refresh() { if (!running) { stop() start() } } - - @Override - void close() { - super.close() - } } diff --git a/src/test/groovy/org/prebid/server/functional/testcontainers/scaffolding/PrebidCache.groovy b/src/test/groovy/org/prebid/server/functional/testcontainers/scaffolding/PrebidCache.groovy index 121f9f2ab96..7094b6a5168 100644 --- a/src/test/groovy/org/prebid/server/functional/testcontainers/scaffolding/PrebidCache.groovy +++ b/src/test/groovy/org/prebid/server/functional/testcontainers/scaffolding/PrebidCache.groovy @@ -7,17 +7,16 @@ import org.prebid.server.functional.model.response.vtrack.TransferValue import org.prebid.server.functional.testcontainers.container.NetworkServiceContainer import org.prebid.server.functional.util.PBSUtils -import static java.lang.Integer.MAX_VALUE +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo +import static com.github.tomakehurst.wiremock.client.WireMock.get +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor +import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath import static com.github.tomakehurst.wiremock.client.WireMock.post import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo -import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse -import static com.github.tomakehurst.wiremock.client.WireMock.get -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor +import static java.lang.Integer.MAX_VALUE import static org.apache.hc.core5.http.HttpStatus.SC_INTERNAL_SERVER_ERROR import static org.apache.hc.core5.http.HttpStatus.SC_OK @@ -37,7 +36,6 @@ class PrebidCache extends NetworkScaffolding { } ''' - PrebidCache(NetworkServiceContainer wireMockContainer) { super(wireMockContainer, CACHE_ENDPOINT) } @@ -65,7 +63,6 @@ class PrebidCache extends NetworkScaffolding { .withRequestBody(matchingJsonPath("\$.puts[?(@.value.impid == '$impId')]")) } - List getRecordedRequests(String impId) { wireMockClient.find(getRequest(impId)).bodyAsString .collect { decode(it, BidCacheRequest) } diff --git a/src/test/groovy/org/prebid/server/functional/tests/AccountSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AccountSpec.groovy index e2730e46e52..3b913936b94 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AccountSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AccountSpec.groovy @@ -8,6 +8,7 @@ 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.Site import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import java.time.Instant @@ -16,12 +17,15 @@ import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED class AccountSpec extends BaseSpec { + private static final PbsContainerConfig ENFORCED_ACCOUNT_CONFIG = new PbsContainerConfig(['settings.enforce-valid-account': 'true']) + private static final PbsContainerConfig UNENFORCED_ACCOUNT_CONFIG = new PbsContainerConfig(['settings.enforce-valid-account': 'false']) + private static final PbsContainerConfig DISABLED_LOGGING_CONFIG = new PbsContainerConfig(['logging.sampling-rate': '0']) + def "PBS should reject request with inactive account"() { - given: "Start up time" + given: "Start time" def start = Instant.now() - and: "Pbs config with enforce-valid-account" - def pbsConfig = ["settings.enforce-valid-account": enforceValidAccount as String] + and: "PBS config with enforce-valid-account" def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Inactive account id" @@ -43,24 +47,20 @@ class AccountSpec extends BaseSpec { assert exception.statusCode == UNAUTHORIZED.code() assert exception.responseBody == warningMessage - and: "PBs should emit warning logs" + and: "PBS should emit warning logs" def logsByTime = pbsService.getLogsByTime(start) assert getLogsByText(logsByTime, warningMessage).size() == 1 - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - where: - enforceValidAccount << [true, false] + pbsConfig << [ENFORCED_ACCOUNT_CONFIG, UNENFORCED_ACCOUNT_CONFIG] } - def "PBS shouldn't emit warning in logs when reject request with inactive account amd sampling-rate is disabled"() { - given: "Start up time" + def "PBS shouldn't emit warning in logs when reject request with inactive account and sampling-rate is disabled"() { + given: "Start time" def start = Instant.now() - and: "Pbs config with logging.sampling-rate" - def pbsConfig = ["logging.sampling-rate": "0"] - def pbsService = pbsServiceFactory.getService(pbsConfig) + and: "PBS config with logging.sampling-rate" + def pbsService = pbsServiceFactory.getService(DISABLED_LOGGING_CONFIG) and: "Inactive account id" def accountId = PBSUtils.randomNumber @@ -81,19 +81,18 @@ class AccountSpec extends BaseSpec { assert exception.statusCode == UNAUTHORIZED.code() assert exception.responseBody == warningMessage - and: "PBs shouldn't emit warning logs" + and: "PBS shouldn't emit warning logs" def logsByTime = pbsService.getLogsByTime(start) assert !getLogsByText(logsByTime, warningMessage) - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) + cleanup: + pbsServiceFactory.removeContainer(DISABLED_LOGGING_CONFIG) } def "PBS should reject request with unknown account when settings.enforce-valid-account = true"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "true", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = ENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Non-existing account id" def accountId = PBSUtils.randomNumber @@ -116,10 +115,9 @@ class AccountSpec extends BaseSpec { } def "PBS should reject request without account when settings.enforce-valid-account = true"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "true", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = ENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default basic BidRequest without account" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -139,10 +137,9 @@ class AccountSpec extends BaseSpec { } def "PBS should not reject request with unknown account when settings.enforce-valid-account = false"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "false", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = UNENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default basic BidRequest with non-existing account id" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -164,10 +161,9 @@ class AccountSpec extends BaseSpec { } def "PBS AMP should reject request with unknown account when settings.enforce-valid-account = true"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "true", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = ENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default AMP request with non-existing account" def ampRequest = AmpRequest.defaultAmpRequest.tap { @@ -189,23 +185,21 @@ class AccountSpec extends BaseSpec { then: "Request should fail with an error" def exception = thrown(PrebidServerException) - def resolvedAccount = requestAccount ?: storedRequestAccount assert exception.statusCode == UNAUTHORIZED.code() - assert exception.responseBody == "Unauthorized account id: $resolvedAccount" + assert exception.responseBody == "Unauthorized account id: $accountId" where: - defaultAccountConfig || requestAccount || storedRequestAccount - null || PBSUtils.randomNumber || null - null || null || PBSUtils.randomNumber - AccountConfig.defaultAccountConfig || PBSUtils.randomNumber || null - AccountConfig.defaultAccountConfig || null || PBSUtils.randomNumber + defaultAccountConfig | accountId || requestAccount | storedRequestAccount + null | PBSUtils.randomNumber || accountId | null + null | PBSUtils.randomNumber || null | accountId + AccountConfig.defaultAccountConfig | PBSUtils.randomNumber || accountId | null + AccountConfig.defaultAccountConfig | PBSUtils.randomNumber || null | accountId } def "PBS AMP should reject request without account when settings.enforce-valid-account = true"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "true", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = ENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default AMP request without account" def ampRequest = AmpRequest.defaultAmpRequest.tap { @@ -235,10 +229,9 @@ class AccountSpec extends BaseSpec { } def "PBS AMP should not reject request with unknown account when settings.enforce-valid-account = false"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "false", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = UNENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default AMP request with non-existing account" def ampRequest = AmpRequest.defaultAmpRequest.tap { @@ -271,10 +264,9 @@ class AccountSpec extends BaseSpec { } def "PBS AMP should not reject request without account when settings.enforce-valid-account = false"() { - given: "Pbs config with enforce-valid-account and default-account-config" - def pbsService = pbsServiceFactory.getService( - ["settings.enforce-valid-account" : "false", - "settings.default-account-config": encode(defaultAccountConfig)]) + given: "PBS config with enforce-valid-account and default-account-config" + def config = UNENFORCED_ACCOUNT_CONFIG + ['settings.default-account-config': encode(defaultAccountConfig)] + def pbsService = pbsServiceFactory.getService(config) and: "Default AMP request without account" def ampRequest = AmpRequest.defaultAmpRequest.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/AliasSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AliasSpec.groovy index 9013978f76f..e942612b6e2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AliasSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AliasSpec.groovy @@ -1,21 +1,30 @@ package org.prebid.server.functional.tests import org.prebid.server.functional.model.bidder.AppNexus +import org.prebid.server.functional.model.bidder.BidderName import org.prebid.server.functional.model.bidder.Generic import org.prebid.server.functional.model.bidder.Openx +import org.prebid.server.functional.model.request.auction.Adrino +import org.prebid.server.functional.model.request.auction.Amx import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.request.auction.Targeting +import org.prebid.server.functional.model.response.auction.BidExt +import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST -import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS_UPPER_CASE +import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS import static org.prebid.server.functional.model.bidder.BidderName.BOGUS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.GENER_X import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.CompressionType.GZIP +import static org.prebid.server.functional.model.response.auction.ErrorType.ALIAS import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer import static org.prebid.server.functional.util.HttpUtil.CONTENT_ENCODING_HEADER @@ -26,17 +35,28 @@ class AliasSpec extends BaseSpec { "adapters.${OPENX.value}.endpoint" : "$networkServiceContainer.rootUri/${OPENX.value}/auction".toString(), "adapters.${APPNEXUS.value}.enabled" : "true", "adapters.${APPNEXUS.value}.endpoint": "$networkServiceContainer.rootUri/${APPNEXUS.value}/auction".toString()] - private static PrebidServerService pbsServiceWithAdditionalBidders - def setupSpec() { - pbsServiceWithAdditionalBidders = pbsServiceFactory.getService(ADDITIONAL_BIDDERS_CONFIG + GENERIC_ALIAS_CONFIG) - } + private static final Map AMX_CONFIG = ["adapters.${BidderName.AMX}.enabled" : "true", + "adapters.${BidderName.AMX}.endpoint": "$networkServiceContainer.rootUri/auction".toString()] + + private static final PbsContainerConfig GENERIC_HARD_ALIAS_CONFIG = new PbsContainerConfig( + ADDITIONAL_BIDDERS_CONFIG + GENERIC_ALIAS_CONFIG + AMX_CONFIG) + + private static final PbsContainerConfig AMX_HARD_ALIAS_CONFIG = new PbsContainerConfig(AMX_CONFIG + + ["adapters.${BidderName.AMX}.aliases.alias.enabled" : "true", + "adapters.${BidderName.AMX}.aliases.alias.meta-info.vendor-id": "0", + "adapters.${BidderName.AMX}.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()]) + private static final PbsContainerConfig GENERIC_COMPRESS_CONFIG = new PbsContainerConfig(["adapters.generic.endpoint-compression": GZIP.value]) - def cleanupSpec() { - pbsServiceFactory.removeContainer(ADDITIONAL_BIDDERS_CONFIG + GENERIC_ALIAS_CONFIG) + private static PrebidServerService pbsServiceWithGenericHardAlias = pbsServiceFactory.getService(GENERIC_HARD_ALIAS_CONFIG) + private static PrebidServerService pbsServiceWithAmxHardAlias = pbsServiceFactory.getService(AMX_HARD_ALIAS_CONFIG + GENERIC_COMPRESS_CONFIG) + + def setupSpec() { + pbsServiceWithGenericHardAlias = pbsServiceFactory.getService(GENERIC_HARD_ALIAS_CONFIG) + pbsServiceWithAmxHardAlias = pbsServiceFactory.getService(AMX_HARD_ALIAS_CONFIG + GENERIC_COMPRESS_CONFIG) } - def "PBS should be able to take alias from request"() { + def "PBS should route request-defined alias to its parent adapter"() { given: "Default bid request with alias" def bidRequest = BidRequest.defaultBidRequest.tap { ext.prebid.aliases = [(ALIAS.value): GENERIC] @@ -59,7 +79,7 @@ class AliasSpec extends BaseSpec { assert bidderRequests.size() == 2 } - def "PBS shouldn't apply aliases for bidder when aliases didn't provide proper config"() { + def "PBS should ignore request alias without matching bidder params"() { given: "Default bid request with alias" def bidRequest = BidRequest.defaultBidRequest.tap { ext.prebid.aliases = [(BOGUS.value): GENERIC] @@ -76,27 +96,23 @@ class AliasSpec extends BaseSpec { assert response.ext.debug.resolvedRequest.ext.prebid.aliases == bidRequest.ext.prebid.aliases } - def "PBS should apply compression type for bidder alias when adapters.BIDDER.endpoint-compression = gzip"() { - given: "PBS with adapter configuration" + def "PBS should inherit gzip compression for soft alias"() { + given: "Default bid request with soft alias" def compressionType = GZIP.value - def pbsService = pbsServiceFactory.getService( - ["adapters.generic.endpoint-compression": compressionType]) - - and: "Default bid request with alias" def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.aliases = [(ALIAS.value): GENERIC] - imp[0].ext.prebid.bidder.alias = new Generic() + ext.prebid.aliases = [(GENER_X.value): GENERIC] + imp[0].ext.prebid.bidder.generX = new Generic() } when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) + def response = pbsServiceWithAmxHardAlias.sendAuctionRequest(bidRequest) then: "Bidder request should contain header Content-Encoding = gzip" - assert response.ext?.debug?.httpcalls?.get(ALIAS.value)?.requestHeaders?.first() + assert response.ext?.debug?.httpcalls?.get(GENER_X.value)?.requestHeaders?.first() ?.get(CONTENT_ENCODING_HEADER)?.first() == compressionType } - def "PBS should return an error when GVL Id alias refers to unknown bidder alias"() { + def "PBS should reject alias GVL ID referencing unknown alias"() { given: "Default basic BidRequest with aliasgvlids and aliases" def bidderName = PBSUtils.randomString def validId = 1 @@ -113,7 +129,7 @@ class AliasSpec extends BaseSpec { "vendorId ${validId} refers to unknown bidder alias: ${bidderName.toLowerCase()}") } - def "PBS should return an error when GVL ID alias value is lower that one"() { + def "PBS should reject nonpositive GVL IDs for aliases"() { given: "Default basic BidRequest with aliasgvlids and aliases" def bidderName = PBSUtils.randomString def bidRequest = BidRequest.defaultBidRequest @@ -132,7 +148,7 @@ class AliasSpec extends BaseSpec { invalidId << [PBSUtils.randomNegativeNumber, 0] } - def "PBS should emit error when alias didn't participate in request"() { + def "PBS should reject soft alias referencing unknown parent bidder"() { given: "Default bid request with alias" def randomString = PBSUtils.randomString def bidRequest = BidRequest.defaultBidRequest.tap { @@ -149,27 +165,22 @@ class AliasSpec extends BaseSpec { "refers to unknown bidder: $BOGUS.value" } - def "PBS aliased bidder config should be independently from parent"() { + def "PBS should register configured hard alias independently of parent"() { given: "Default bid request with alias" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.alias = new Generic() } when: "PBS processes auction request" - pbsServiceWithAdditionalBidders.sendAuctionRequest(bidRequest) + pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) then: "Bidder request should contain request per-alies" def bidderRequests = bidder.getBidderRequests(bidRequest.id) assert bidderRequests.size() == 2 } - def "PBS should ignore aliases for requests with a base adapter"() { - given: "PBs server with aliases config" - def pbsConfig = ["adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri/openx/auction".toString()] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with openx and alias bidder" + def "PBS should prefer a material bidder over a conflicting soft alias"() { + given: "Default bid request with OpenX and request-defined alias" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.openx = Openx.defaultOpenx imp[0].ext.prebid.bidder.generic = new Generic() @@ -177,19 +188,16 @@ class AliasSpec extends BaseSpec { } when: "PBS processes auction request" - def bidResponse = pbsService.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) then: "PBS contain two http calls and the different url for both" def responseDebug = bidResponse.ext.debug assert responseDebug.httpcalls.size() == 2 assert responseDebug.httpcalls[OPENX.value]*.uri == ["$networkServiceContainer.rootUri/openx/auction"] assert responseDebug.httpcalls[GENERIC.value]*.uri == ["$networkServiceContainer.rootUri/auction"] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } - def "PBS should validate request as alias request and without any warnings when required properties in place"() { + def "PBS should accept valid material bidder params despite conflicting soft alias"() { given: "Default bid request with openx and alias bidder" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.appNexus = AppNexus.default @@ -198,7 +206,7 @@ class AliasSpec extends BaseSpec { } when: "PBS processes auction request" - def bidResponse = pbsServiceWithAdditionalBidders.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) then: "PBS contain http call for specific bidder" def responseDebug = bidResponse.ext.debug @@ -209,7 +217,7 @@ class AliasSpec extends BaseSpec { assert !bidResponse.ext.warnings } - def "PBS should validate request as alias request and emit proper warnings when validation fails for request"() { + def "PBS should reject invalid material bidder params despite conflicting soft alias"() { given: "Default bid request with openx and alias bidder" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.appNexus = new AppNexus() @@ -218,7 +226,7 @@ class AliasSpec extends BaseSpec { } when: "PBS processes auction request" - def bidResponse = pbsServiceWithAdditionalBidders.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) then: "PBS shouldn't contain http calls" assert !bidResponse.ext.debug.httpcalls @@ -237,28 +245,27 @@ class AliasSpec extends BaseSpec { "WARNING: request.imp[0].ext must contain at least one valid bidder"] } - def "PBS should invoke as aliases when alias is unknown and core bidder is specified"() { - given: "Default bid request with generic and alias bidder" + def "PBS should invoke both original bidder and request-defined alias"() { + given: "Bid request with original bidder and soft alias" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.generX = new Generic() ext.prebid.aliases = [(GENER_X.value): GENERIC] } when: "PBS processes auction request" - def bidResponse = defaultPbsService.sendAuctionRequest(bidRequest) + def response = defaultPbsService.sendAuctionRequest(bidRequest) - then: "PBS contain two http calls and the same url for both" - def responseDebug = bidResponse.ext.debug - assert responseDebug.httpcalls.size() == 2 - assert responseDebug.httpcalls[GENER_X.value]*.uri == responseDebug.httpcalls[GENERIC.value]*.uri + then: "PBS should send requests to both bidders" + assert response.ext.debug.httpcalls.size() == 2 + assert response.ext.debug.httpcalls[GENER_X.value]*.uri == ["$networkServiceContainer.rootUri/auction"] + assert response.ext.debug.httpcalls[GENERIC.value]*.uri == ["$networkServiceContainer.rootUri/auction"] - and: "Bidder request should contain request per-alies" - def bidderRequests = bidder.getBidderRequests(bidRequest.id) - assert bidderRequests.size() == 2 + and: "Bidder should receive two requests" + assert bidder.getBidderRequests(bidRequest.id).size() == 2 } - def "PBS should invoke aliases when alias is unknown and no core bidder is specified"() { - given: "Default bid request with generic and alias bidder" + def "PBS should invoke only request-defined alias when original bidder is absent"() { + given: "Bid request with soft alias and without original bidder" def bidRequest = BidRequest.defaultBidRequest.tap { imp[0].ext.prebid.bidder.generX = new Generic() imp[0].ext.prebid.bidder.generic = null @@ -266,11 +273,287 @@ class AliasSpec extends BaseSpec { } when: "PBS processes auction request" - def bidResponse = defaultPbsService.sendAuctionRequest(bidRequest) + def response = defaultPbsService.sendAuctionRequest(bidRequest) - then: "PBS contain two http calls and the same url for both" - def responseDebug = bidResponse.ext.debug - assert responseDebug.httpcalls.size() == 1 - assert responseDebug.httpcalls[GENER_X.value] + then: "PBS should send request only to alias" + assert response.ext.debug.httpcalls.size() == 1 + assert response.ext.debug.httpcalls[GENER_X.value]*.uri == ["$networkServiceContainer.rootUri/auction"] + + and: "Bidder should receive one request" + assert bidder.getBidderRequests(bidRequest.id).size() == 1 + } + + def "PBS should preserve uppercase soft alias in seat and targeting"() { + given: "Default bid request with alias" + def bidRequest = BidRequest.defaultBidRequest.tap { + ext.prebid.aliases = [(ALIAS.value): GENERIC] + ext.prebid.targeting = new Targeting() + imp[0].ext.prebid.bidder.tap { + generic = null + aliasUpperCase = new Generic() + } + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [GENERIC] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [ALIAS_UPPER_CASE] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${ALIAS_UPPER_CASE}"] + assert targeting["hb_size_${ALIAS_UPPER_CASE}"] + assert targeting["hb_bidder"] == ALIAS_UPPER_CASE.value + assert targeting["hb_bidder_${ALIAS_UPPER_CASE}"] == ALIAS_UPPER_CASE.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS_UPPER_CASE.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) + } + + def "PBS should reject invalid bidder parameters for generic and hard alias"() { + given: "Default basic generic BidRequest" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.tap { + it.generic.exampleProperty = PBSUtils.randomNumber + //Adrino hard coded bidder alias in generic.yaml + it.adrino = new Adrino(hash: PBSUtils.randomNumber) + } + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder should be dropped" + assert response.ext?.warnings[PREBID]*.code == [999, 999, 999] + assert response.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + + "\$.exampleProperty: integer found, string expected", + "WARNING: request.imp[0].ext.prebid.bidder.adrino was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.adrino failed validation.\n" + + "\$.hash: integer found, string expected", + "WARNING: request.imp[0].ext must contain at least one valid bidder"] + + and: "PBS should not call bidder" + assert bidder.getRequestCount(bidRequest.id) == 0 + + and: "targeting should be empty" + assert response.seatbid.isEmpty() + } + + def "PBS should retain parent adapter code for soft alias"() { + given: "Default bid request with alias" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.tap { + generic = null + alias = new Generic() + } + ext.prebid.aliases = [(ALIAS.value): GENERIC] + ext.prebid.targeting = new Targeting() + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [GENERIC] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [BidderName.ALIAS] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${BidderName.ALIAS}"] + assert targeting["hb_size_${BidderName.ALIAS}"] + assert targeting["hb_bidder"] == BidderName.ALIAS.value + assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS.value) + + and: "Bidder request should be valid and not contain aliases" + def bidderRequests = bidder.getBidderRequests(bidRequest.id).first + assert !bidderRequests.ext.prebid.aliases + } + + def "PBS should use alias adapter code for Generic hard alias"() { + given: "Default bid request with hard alias" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.tap { + generic = null + alias = new Generic() + } + ext.prebid.targeting = new Targeting() + } + + when: "PBS processes auction request" + def response = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [BidderName.ALIAS] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${BidderName.ALIAS}"] + assert targeting["hb_size_${BidderName.ALIAS}"] + assert targeting["hb_bidder"] == BidderName.ALIAS.value + assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) + } + + def "PBS should propagate demandSource for AMX hard alias"() { + given: "Default bid request with AMX hard alias" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.tap { + generic = null + alias = new Generic() + } + ext.prebid.targeting = new Targeting() + } + + and: "Bid response with bidder code" + def demandSource = PBSUtils.randomString + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest, BidderName.ALIAS).tap { + it.seatbid[0].bid[0].ext = new BidExt(demandSource: demandSource) + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = pbsServiceWithAmxHardAlias.sendAuctionRequest(bidRequest) + + then: "Response should contain demand source" + assert response.seatbid.bid.ext.prebid.meta.demandSource.flatten() == [demandSource] + + and: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [BidderName.ALIAS] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${BidderName.ALIAS}"] + assert targeting["hb_size_${BidderName.ALIAS}"] + assert targeting["hb_bidder"] == BidderName.ALIAS.value + assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) + } + + def "PBS should prefer AMX hard alias over conflicting soft alias"() { + given: "Bid request with AMX hard alias and conflicting soft alias" + def bidRequest = BidRequest.getDefaultBidRequest().tap { + imp[0].ext.prebid.bidder.alias = new Generic() + imp[0].ext.prebid.bidder.amx = null + imp[0].ext.prebid.bidder.generic = null + it.ext.prebid.aliases = [(ALIAS.value): GENERIC] + it.ext.prebid.targeting = new Targeting() + } + + when: "PBS processes auction request" + def response = pbsServiceWithAmxHardAlias.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [BidderName.ALIAS] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${BidderName.ALIAS}"] + assert targeting["hb_size_${BidderName.ALIAS}"] + assert targeting["hb_bidder"] == BidderName.ALIAS.value + assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) + } + + def "PBS should prefer Generic hard alias over conflicting soft alias"() { + given: "Bid request with Generic hard alias and conflicting soft alias" + def bidRequest = BidRequest.getDefaultBidRequest().tap { + imp[0].ext.prebid.bidder.alias = new Generic() + imp[0].ext.prebid.bidder.amx = null + imp[0].ext.prebid.bidder.generic = null + it.ext.prebid.aliases = [(ALIAS.value): AMX] + it.ext.prebid.targeting = new Targeting() + } + + when: "PBS processes auction request" + def response = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] + + and: "Response should contain seat bid" + assert response.seatbid.seat == [BidderName.ALIAS] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${BidderName.ALIAS}"] + assert targeting["hb_size_${BidderName.ALIAS}"] + assert targeting["hb_bidder"] == BidderName.ALIAS.value + assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(ALIAS.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) + } + + def "PBS should preserve material AMX bidder despite conflicting soft alias"() { + given: "Bid request with AMX material bidder and conflicting soft alias" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.amx = new Amx() + imp[0].ext.prebid.bidder.generic = null + ext.prebid.targeting = new Targeting() + ext.prebid.aliases = [(AMX.value): GENERIC] + } + + when: "PBS processes auction request" + def response = pbsServiceWithGenericHardAlias.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [AMX] + + and: "Response should contain seat" + assert response.seatbid.seat == [AMX] + + and: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${AMX}"] + assert targeting["hb_size_${AMX}"] + assert targeting["hb_bidder"] == AMX.value + assert targeting["hb_bidder_${AMX}"] == AMX.value + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(AMX.value) + + and: "Bidder request should be valid" + assert bidder.getBidderRequests(bidRequest.id) } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/AlternateBidderCodeSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AlternateBidderCodeSpec.groovy index 27bc35f3cc3..49c9435b876 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AlternateBidderCodeSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AlternateBidderCodeSpec.groovy @@ -18,6 +18,7 @@ import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import spock.lang.Shared @@ -41,8 +42,8 @@ class AlternateBidderCodeSpec extends BaseSpec { private static final String ERROR_BID_CODE_VALIDATION = "BidId `%s` validation messages: " + "Error: invalid bidder code %s was set by the adapter %s for the account %s" private static final String INVALID_BIDDER_CODE_LOGS = "invalid bidder code %s was set by the adapter %s for the account %s" - private static final Map AMX_CONFIG = ["adapters.amx.enabled" : "true", - "adapters.amx.endpoint": "$networkServiceContainer.rootUri/auction".toString()] + private static final PbsContainerConfig AMX_CONFIG = new PbsContainerConfig(["adapters.amx.enabled" : "true", + "adapters.amx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) @Shared private static final PrebidServerService pbsServiceWithAmxBidder = pbsServiceFactory.getService(AMX_CONFIG) @@ -634,7 +635,6 @@ class AlternateBidderCodeSpec extends BaseSpec { assert exception.responseBody == "Invalid request format: " + "request.ext.prebid.alternatebiddercodes.bidders.unknown is not a known bidder or alias" - where: requestedAlternateBidderCodes << [new AlternateBidderCodes(bidders: [(UNKNOWN): new CodesBidderConfig()]), new AlternateBidderCodes(enabled: true, bidders: [(UNKNOWN): new CodesBidderConfig()]), @@ -1159,9 +1159,6 @@ class AlternateBidderCodeSpec extends BaseSpec { and: "Alert.general metric shouldn't be updated" def metrics = pbsService.sendCollectedMetricsRequest() assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(AMX)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(config) } def "PBS should discard the bid and emit a response warning when request alternate bidder codes are enabled and the allowed bidder codes doesn't match the bidder's request"() { @@ -1330,9 +1327,6 @@ class AlternateBidderCodeSpec extends BaseSpec { and: "Bidder request should be valid" assert bidder.getBidderRequests(bidRequest.id) - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - where: allowedBidderCodes << [BOGUS, UNKNOWN] } @@ -1387,9 +1381,6 @@ class AlternateBidderCodeSpec extends BaseSpec { and: "PBS shouldn't emit validation metrics" def metrics = defaultPbsService.sendCollectedMetricsRequest() assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(GENERIC)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't discard bid when alternate bidder code allow and soft alias with case"() { @@ -1574,9 +1565,6 @@ class AlternateBidderCodeSpec extends BaseSpec { and: "PBS shouldn't emit validation metrics" def metrics = defaultPbsService.sendCollectedMetricsRequest() assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(GENERIC)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should populate two seat bid when different bidder response with same seat"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/AnalyticsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AnalyticsSpec.groovy index 0201c20fa20..3da64f6253f 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AnalyticsSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AnalyticsSpec.groovy @@ -11,31 +11,47 @@ import org.prebid.server.functional.model.request.auction.PrebidAnalytics import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.Dependencies import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.PubStackAnalytics import org.prebid.server.functional.util.PBSUtils import spock.lang.Ignore -import spock.lang.Shared class AnalyticsSpec extends BaseSpec { private static final String SCOPE_ID = UUID.randomUUID() - private static final Map ENABLED_DEBUG_LOG_MODE = ["logging.level.root": "debug"] + + private static final PbsContainerConfig PUBSTACK_CONFIG = new PbsContainerConfig(PbsConfig.getPubstackAnalyticsConfig(SCOPE_ID)) + private static final PbsContainerConfig DEBUG_LOG_CONFIG = new PbsContainerConfig(['logging.level.root': 'debug']) + private static final PbsContainerConfig LOG_ANALYTICS_ENABLED_CONFIG = DEBUG_LOG_CONFIG + + ['analytics.log.enabled' : 'true', + 'analytics.global.adapters': 'logAnalytics'] + private static final PbsContainerConfig LOG_ANALYTICS_DISABLED_CONFIG = DEBUG_LOG_CONFIG + + ['analytics.log.enabled' : 'false', + 'analytics.global.adapters': ''] private static final PubStackAnalytics analytics = new PubStackAnalytics(Dependencies.networkServiceContainer).tap { it.setResponse(PubStackResponse.getDefaultPubStackResponse(SCOPE_ID, Dependencies.networkServiceContainer.rootUri)) } - private static final PrebidServerService pbsService = pbsServiceFactory.getService(PbsConfig.getPubstackAnalyticsConfig(SCOPE_ID)) - private static final PrebidServerService pbsServiceWithLogAnalytics = pbsServiceFactory.getService( - ENABLED_DEBUG_LOG_MODE + ['analytics.log.enabled' : 'true', - 'analytics.global.adapters': 'logAnalytics']) - private static final PrebidServerService pbsServiceWithoutLogAnalytics = pbsServiceFactory.getService( - ENABLED_DEBUG_LOG_MODE + ['analytics.log.enabled' : 'true', - 'analytics.global.adapters': '']) + private static PrebidServerService pbsServiceWithLogAnalytics + private static PrebidServerService pbsServiceWithoutLogAnalytics + + def setupSpec() { + pbsServiceWithLogAnalytics = pbsServiceFactory.getService(LOG_ANALYTICS_ENABLED_CONFIG) + pbsServiceWithoutLogAnalytics = pbsServiceFactory.getService(LOG_ANALYTICS_DISABLED_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(LOG_ANALYTICS_ENABLED_CONFIG) + pbsServiceFactory.removeContainer(LOG_ANALYTICS_DISABLED_CONFIG) + } @Ignore("Currently impossible to make this test pass 100% of the time") def "PBS should send PubStack analytics when analytics.pubstack.enabled=true"() { - given: "Basic bid request" + given: "PBS with PubStack analytics" + def pbsService = pbsServiceFactory.getService(PUBSTACK_CONFIG) + + and: "Basic bid request" def bidRequest = BidRequest.defaultBidRequest and: "Initial request count" @@ -91,7 +107,7 @@ class AnalyticsSpec extends BaseSpec { assert !bidderRequest.ext.prebid.analytics then: "PBS shouldn't call log analytics" - def logsByValue = pbsServiceWithLogAnalytics.getLogsByValue(bidRequest.id) + def logsByValue = pbsServiceWithoutLogAnalytics.getLogsByValue(bidRequest.id) assert !logsByValue where: @@ -163,7 +179,7 @@ class AnalyticsSpec extends BaseSpec { assert !bidderRequest.ext.prebid.analytics and: "PBS shouldn't call log analytics" - def logsByValue = pbsServiceWithLogAnalytics.getLogsByValue(bidRequest.id) + def logsByValue = pbsServiceWithoutLogAnalytics.getLogsByValue(bidRequest.id) assert !logsByValue } diff --git a/src/test/groovy/org/prebid/server/functional/tests/AuctionSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/AuctionSpec.groovy index 166f49e4cf6..923d5b9687c 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/AuctionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/AuctionSpec.groovy @@ -12,9 +12,6 @@ import org.prebid.server.functional.model.request.auction.Device import org.prebid.server.functional.model.request.auction.DeviceExt import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.PrebidStoredRequest -import org.prebid.server.functional.model.request.auction.Renderer -import org.prebid.server.functional.model.request.auction.RendererData -import org.prebid.server.functional.model.request.auction.Sdk import org.prebid.server.functional.model.request.auction.User import org.prebid.server.functional.model.request.auction.UserExt import org.prebid.server.functional.model.request.auction.UserExtPrebid @@ -24,10 +21,9 @@ import org.prebid.server.functional.model.response.auction.Meta import org.prebid.server.functional.model.response.auction.Prebid import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo import org.prebid.server.functional.service.PrebidServerException -import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.HttpUtil import org.prebid.server.functional.util.PBSUtils -import spock.lang.Shared import static org.prebid.server.functional.model.AccountStatus.ACTIVE import static org.prebid.server.functional.model.AccountStatus.INACTIVE @@ -49,16 +45,20 @@ class AuctionSpec extends BaseSpec { private static final Integer DEFAULT_TIMEOUT = getRandomTimeout() private static final Integer MIN_BID_ID_LENGTH = 17 private static final Integer DEFAULT_UUID_LENGTH = 36 - private static final Map GENERIC_CONFIG = [ - "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url" : USER_SYNC_URL] - @Shared - PrebidServerService prebidServerService = pbsServiceFactory.getService(PBS_CONFIG) - + private static final String GENERIC_COOKIE_NAME = PBSUtils.randomString private static final String IMPS_REQUESTED_METRIC = 'imps_requested' private static final String IMPS_DROPPED_METRIC = 'imps_dropped' private static final Integer IMP_LIMIT = 1 - private static final Map PBS_CONFIG = ["auction.biddertmax.max" : MAX_TIMEOUT as String, - "auction.default-timeout-ms": DEFAULT_TIMEOUT as String] + + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig([ + 'auction.biddertmax.max' : MAX_TIMEOUT, + 'host-cookie.family' : GENERIC.value, + 'host-cookie.cookie-name' : GENERIC_COOKIE_NAME, + 'auction.default-timeout-ms': DEFAULT_TIMEOUT]) + private static final PbsContainerConfig BUYER_UID_CONFIG = PBS_CONFIG + ["adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url": USER_SYNC_URL] + private static final PbsContainerConfig RANDOM_BID_ID_ENABLED_CONFIG = new PbsContainerConfig(['auction.enforce-random-bid-id': 'true']) + private static final PbsContainerConfig RANDOM_BID_ID_DISABLED_CONFIG = new PbsContainerConfig(['auction.enforce-random-bid-id': 'false']) + private static final PbsContainerConfig RANDOM_BID_ID_DEFAULT_CONFIG = new PbsContainerConfig(['auction.enforce-random-bid-id': null]) def "PBS should return version in response header for auction request for #description"() { when: "PBS processes auction request" @@ -68,9 +68,9 @@ class AuctionSpec extends BaseSpec { assert response.headers["x-prebid"] == ["pbs-java/$PBS_VERSION"] where: - bidRequest || description - BidRequest.defaultBidRequest || "valid bid request" - new BidRequest() || "invalid bid request" + bidRequest | description + BidRequest.defaultBidRequest | "valid bid request" + new BidRequest() | "invalid bid request" } def "PBS should update account..requests.rejected.invalid-account metric when account is inactive"() { @@ -127,13 +127,15 @@ class AuctionSpec extends BaseSpec { def "PBS should populate bidder request buyeruid from buyeruids when buyeruids with appropriate bidder present in request"() { given: "Bid request with buyeruids" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) + def buyeruid = PBSUtils.randomString def bidRequest = BidRequest.defaultBidRequest.tap { user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(GENERIC): buyeruid]))) } when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request should contain buyeruid from the user.ext.prebid.buyeruids" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -145,13 +147,15 @@ class AuctionSpec extends BaseSpec { def "PBS shouldn't populate bidder request buyeruid from buyeruids when buyeruids without appropriate bidder present in request"() { given: "Bid request with buyeruids" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) + def buyeruid = PBSUtils.randomString def bidRequest = BidRequest.defaultBidRequest.tap { user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(APPNEXUS): buyeruid]))) } when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request shouldn't contain buyeruid from the user.ext.prebid.buyeruids" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -159,11 +163,8 @@ class AuctionSpec extends BaseSpec { } def "PBS should populate buyeruid from uids cookie when buyeruids with appropriate bidder but without value present in request"() { - given: "PBS config" - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.usersync.${REDIRECT.value}.url" : USER_SYNC_URL]) - - and: "Bid request with buyeruids" + given: "Bid request with buyeruids" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) def bidRequest = BidRequest.defaultBidRequest.tap { user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(GENERIC): ""]))) } @@ -173,7 +174,7 @@ class AuctionSpec extends BaseSpec { def cookieHeader = HttpUtil.getCookieHeader(uidsCookie) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookieHeader) + pbsService.sendAuctionRequest(bidRequest, cookieHeader) then: "Bidder request should contain buyeruid from the uids cookie" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -181,11 +182,8 @@ class AuctionSpec extends BaseSpec { } def "PBS shouldn't populate buyeruid from uids cookie when buyeruids with appropriate bidder but without value present in request"() { - given: "PBS config" - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.usersync.${REDIRECT.value}.url" : USER_SYNC_URL]) - - and: "Bid request with buyeruids" + given: "Bid request with buyeruids" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) def bidRequest = BidRequest.defaultBidRequest.tap { user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(GENERIC): ""]))) } @@ -194,7 +192,7 @@ class AuctionSpec extends BaseSpec { def cookieHeader = HttpUtil.getCookieHeader(null) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookieHeader) + pbsService.sendAuctionRequest(bidRequest, cookieHeader) then: "Bidder request shouldn't contain buyeruid from the uids cookie" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -202,7 +200,10 @@ class AuctionSpec extends BaseSpec { } def "PBS should take precedence buyeruids whenever present valid uid cookie"() { - given: "Bid request with buyeruids" + given: "PBS service" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) + + and: "Bid request with buyeruids" def buyeruid = PBSUtils.randomString def bidRequest = BidRequest.defaultBidRequest.tap { user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(GENERIC): buyeruid]))) @@ -213,7 +214,7 @@ class AuctionSpec extends BaseSpec { def cookieHeader = HttpUtil.getCookieHeader(uidsCookie) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookieHeader) + pbsService.sendAuctionRequest(bidRequest, cookieHeader) then: "Bidder request should contain buyeruid from the buyeruids" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -221,22 +222,18 @@ class AuctionSpec extends BaseSpec { } def "PBS should populate buyeruid from host cookie name config when host cookie family matched with requested bidder"() { - given: "PBS config" - def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_CONFIG - + ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name" : cookieName, - "adapters.generic.usersync.cookie-family-name": GENERIC.value]) + given: "PBS service" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) - and: "Bid request" + and: "Default bid request" def bidRequest = BidRequest.defaultBidRequest and: "Host cookie" def hostCookieUid = UUID.randomUUID().toString() - def cookies = HttpUtil.getCookieHeader(cookieName, hostCookieUid) + def cookies = HttpUtil.getCookieHeader(GENERIC_COOKIE_NAME, hostCookieUid) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookies) + pbsService.sendAuctionRequest(bidRequest, cookies) then: "Bidder request should contain buyeruid from cookieName" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -244,12 +241,13 @@ class AuctionSpec extends BaseSpec { } def "PBS shouldn't populate buyeruid from cookie name config when host cookie family not matched with requested cookie-family-name"() { - given: "PBS config" + given: "PBS service with host cookie config" def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_CONFIG - + ["host-cookie.family" : APPNEXUS.value, - "host-cookie.cookie-name" : cookieName, - "adapters.generic.usersync.cookie-family-name": GENERIC.value]) + def pbsConfig = BUYER_UID_CONFIG + + ['host-cookie.family' : APPNEXUS.value, + 'host-cookie.cookie-name' : cookieName, + 'adapters.generic.usersync.cookie-family-name': GENERIC.value] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Bid request" def bidRequest = BidRequest.defaultBidRequest @@ -259,21 +257,21 @@ class AuctionSpec extends BaseSpec { def cookies = HttpUtil.getCookieHeader(cookieName, hostCookieUid) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookies) + pbsService.sendAuctionRequest(bidRequest, cookies) then: "Bidder request shouldn't contain buyeruid from cookieName" def bidderRequest = bidder.getBidderRequest(bidRequest.id) assert !bidderRequest.user + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't populate buyeruid from cookie when cookie-name in cookie and config are diferent"() { - given: "PBS config" - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_CONFIG - + ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name" : PBSUtils.randomString, - "adapters.generic.usersync.cookie-family-name": GENERIC.value]) + given: "PBS service with buyer config" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) - and: "Bid request" + and: "Default bid request" def bidRequest = BidRequest.defaultBidRequest and: "Host cookie" @@ -281,7 +279,7 @@ class AuctionSpec extends BaseSpec { def cookies = HttpUtil.getCookieHeader(PBSUtils.randomString, hostCookieUid) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookies) + pbsService.sendAuctionRequest(bidRequest, cookies) then: "Bidder request shouldn't contain buyeruid from cookieName" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -312,11 +310,14 @@ class AuctionSpec extends BaseSpec { def bidRequest = BidRequest.defaultBidRequest and: "Default bidder response without bid" + def rendererName = PBSUtils.randomString + def rendererUrl = PBSUtils.randomString + def rendererVersion = PBSUtils.randomString def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { seatbid[0].bid[0].ext = new BidExt(prebid: new Prebid(meta: new Meta( - rendererName: PBSUtils.randomString, - rendererUrl: PBSUtils.randomString, - rendererVersion: PBSUtils.getRandomString()))) + rendererName: rendererName, + rendererUrl: rendererUrl, + rendererVersion: rendererVersion))) } and: "Set bidder response" @@ -326,21 +327,16 @@ class AuctionSpec extends BaseSpec { def response = defaultPbsService.sendAuctionRequest(bidRequest) then: "Bid response should contain meta value same in request" - assert response.seatbid[0].bid[0].ext.prebid.meta.rendererName == - bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererName - assert response.seatbid[0].bid[0].ext.prebid.meta.rendererUrl == - bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererUrl - assert response.seatbid[0].bid[0].ext.prebid.meta.rendererVersion == - bidResponse.seatbid[0].bid[0].ext.prebid.meta.rendererVersion + verifyAll(response.seatbid.bid.ext.prebid.meta.flatten()) { + it.rendererName == [rendererName] + it.rendererUrl == [rendererUrl] + it.rendererVersion == [rendererVersion] + } } def "PBS call to alias should populate bidder request buyeruid from family user.buyeruids when resolved name is present"() { - given: "Pbs config with alias" - def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_CONFIG - + ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name" : cookieName, - "adapters.generic.usersync.cookie-family-name": GENERIC.value]) + given: "PBS service with buyer config" + def pbsService = pbsServiceFactory.getService(BUYER_UID_CONFIG) and: "Alias bid request" def buyeruid = PBSUtils.randomString @@ -353,10 +349,10 @@ class AuctionSpec extends BaseSpec { and: "Host cookie" def hostCookieUid = UUID.randomUUID().toString() - def cookies = HttpUtil.getCookieHeader(cookieName, hostCookieUid) + def cookies = HttpUtil.getCookieHeader(GENERIC_COOKIE_NAME, hostCookieUid) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookies) + pbsService.sendAuctionRequest(bidRequest, cookies) then: "Bidder request should contain buyeruid from the user.ext.prebid.buyeruids" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -367,12 +363,14 @@ class AuctionSpec extends BaseSpec { } def "PBS call to alias should populate bidder request buyeruid from family user.buyeruids when it's contained in base bidder"() { - given: "Pbs config with alias" + given: "PBS service with buyer and alias config" def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_CONFIG + GENERIC_ALIAS_CONFIG - + ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name" : cookieName, - "adapters.generic.usersync.cookie-family-name": GENERIC.value]) + def pbsConfig = BUYER_UID_CONFIG + GENERIC_ALIAS_CONFIG + [ + 'host-cookie.family' : GENERIC.value, + 'host-cookie.cookie-name' : cookieName, + 'adapters.generic.usersync.cookie-family-name': GENERIC.value + ] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Alias bid request" def buyeruid = PBSUtils.randomString @@ -387,14 +385,14 @@ class AuctionSpec extends BaseSpec { def cookies = HttpUtil.getCookieHeader(cookieName, hostCookieUid) when: "PBS processes auction request" - prebidServerService.sendAuctionRequest(bidRequest, cookies) + pbsService.sendAuctionRequest(bidRequest, cookies) then: "Bidder request should contain buyeruid from the user.ext.prebid.buyeruids" def bidderRequest = bidder.getBidderRequest(bidRequest.id) assert bidderRequest?.user?.buyeruid == buyeruid - where: - bidderName << [GENERIC, GENERIC_CAMEL_CASE] + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should set device.ext.cdep from header when cookieDeprecation and Deprecation header is specified"() { @@ -491,8 +489,8 @@ class AuctionSpec extends BaseSpec { def defaultAccountConfigSettings = AccountConfig.defaultAccountConfig.tap { auction = new AccountAuctionConfig(privacySandbox: privacySandbox) } - def pbsService = pbsServiceFactory.getService(PBS_CONFIG + - ["settings.default-account-config": encode(defaultAccountConfigSettings)]) + def pbsConfig = PBS_CONFIG + ['settings.default-account-config': encode(defaultAccountConfigSettings)] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default basic BidRequest with generic bidder" def bidRequest = BidRequest.defaultBidRequest @@ -506,6 +504,9 @@ class AuctionSpec extends BaseSpec { then: "BidderRequest should have device.ext.cdep from sec-cookie-deprecation header" def bidderRequest = bidder.getBidderRequest(bidRequest.id) assert bidderRequest.device.ext.cdep == secCookieDeprecation[COOKIE_DEPRECATION_HEADER] + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't set device.ext.cdep from header when default account don't contain privacy sandbox and request account is empty"() { @@ -553,8 +554,7 @@ class AuctionSpec extends BaseSpec { def "PBS should override short bid.id with random uuid when enforce-random-bid-id is enabled"() { given: "PBS with enabled generate-bid-id" - def pbsConfig = ['auction.enforce-random-bid-id': 'true'] - def pbsService = pbsServiceFactory.getService(pbsConfig) + def pbsService = pbsServiceFactory.getService(RANDOM_BID_ID_ENABLED_CONFIG) and: "Default bid request" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -590,15 +590,11 @@ class AuctionSpec extends BaseSpec { and: "BidResponse should contain generated UUID" assert PBSUtils.isUUID(response.seatbid.first.bid.first.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } - def "PBS shouldn't override short bid.id when enforce-random-bid-id in default or disabled"() { - given: "PBS with disabled generate-bid-id" - def pbsConfig = ["auction.enforce-random-bid-id": enforceRandomBidId] - def pbsService = pbsServiceFactory.getService(pbsConfig) + def "PBS shouldn't override long enough bid.id with random uuid when enforce-random-bid-id is enabled"() { + given: "PBS with enabled generate-bid-id" + def pbsService = pbsServiceFactory.getService(RANDOM_BID_ID_ENABLED_CONFIG) and: "Default bid request" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -606,7 +602,7 @@ class AuctionSpec extends BaseSpec { } and: "Default bid response" - def originalBidId = PBSUtils.getRandomString(PBSUtils.getRandomNumber(1, MIN_BID_ID_LENGTH)) + def originalBidId = PBSUtils.getRandomString(PBSUtils.getRandomNumber(MIN_BID_ID_LENGTH, DEFAULT_UUID_LENGTH)) def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { seatbid.first.bid.first.id = originalBidId } @@ -630,17 +626,10 @@ class AuctionSpec extends BaseSpec { and: "BidResponse should contain original bid.id" assert response.seatbid.bid.id.flatten().sort() == [originalBidId] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - enforceRandomBidId << [null, 'false'] } - def "PBS shouldn't override long enough bid.id with random uuid when enforce-random-bid-id is enabled"() { - given: "PBS with enabled generate-bid-id" - def pbsConfig = ['auction.enforce-random-bid-id': 'true'] + def "PBS shouldn't override short bid.id when enforce-random-bid-id in default or disabled"() { + given: "PBS with disabled generate-bid-id" def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request" @@ -649,7 +638,7 @@ class AuctionSpec extends BaseSpec { } and: "Default bid response" - def originalBidId = PBSUtils.getRandomString(PBSUtils.getRandomNumber(MIN_BID_ID_LENGTH, DEFAULT_UUID_LENGTH)) + def originalBidId = PBSUtils.getRandomString(PBSUtils.getRandomNumber(1, MIN_BID_ID_LENGTH)) def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { seatbid.first.bid.first.id = originalBidId } @@ -674,8 +663,8 @@ class AuctionSpec extends BaseSpec { and: "BidResponse should contain original bid.id" assert response.seatbid.bid.id.flatten().sort() == [originalBidId] - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) + where: + pbsConfig << [RANDOM_BID_ID_DEFAULT_CONFIG, RANDOM_BID_ID_DISABLED_CONFIG] } def "PBS should drop extra impressions with warnings when number of impressions exceeds impression-limit"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/BaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/BaseSpec.groovy index b50f9772eef..567a7a76382 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/BaseSpec.groovy @@ -14,6 +14,7 @@ import org.prebid.server.functional.repository.dao.StoredResponseDao import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.Dependencies import org.prebid.server.functional.testcontainers.PbsServiceFactory +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.Bidder import org.prebid.server.functional.testcontainers.scaffolding.PrebidCache import org.prebid.server.functional.testcontainers.scaffolding.VendorList @@ -27,11 +28,12 @@ import static java.math.RoundingMode.DOWN import static java.math.RoundingMode.HALF_UP import static java.math.RoundingMode.UP import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer +import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.PERSISTENT import static org.prebid.server.functional.util.SystemProperties.DEFAULT_TIMEOUT abstract class BaseSpec extends Specification implements ObjectMapperWrapper { - protected static final PbsServiceFactory pbsServiceFactory = new PbsServiceFactory(networkServiceContainer) + protected static final PbsServiceFactory pbsServiceFactory = new PbsServiceFactory() protected static final Bidder bidder = new Bidder(networkServiceContainer) protected static final VendorList vendorList = new VendorList(networkServiceContainer) protected static final PrebidCache prebidCache = new PrebidCache(networkServiceContainer) @@ -50,8 +52,12 @@ abstract class BaseSpec extends Specification implements ObjectMapperWrapper { protected static final Map GENERIC_ALIAS_CONFIG = ["adapters.generic.aliases.alias.enabled" : "true", "adapters.generic.aliases.alias.meta-info.vendor-id": "0", "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] + protected static final Map EMPTY_CACHE_TTL_CONFIG = ["cache.default-ttl-seconds.banner": "", + "cache.default-ttl-seconds.video" : "", + "cache.default-ttl-seconds.native": "", + "cache.default-ttl-seconds.audio" : ""] - protected static final PrebidServerService defaultPbsService = pbsServiceFactory.getService([:]) + protected static final PrebidServerService defaultPbsService = pbsServiceFactory.getService(new PbsContainerConfig(), PERSISTENT) def setupSpec() { prebidCache.setResponse() diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidAdjustmentSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/BidAdjustmentSpec.groovy index 2c8837301bc..ba6be655c44 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidAdjustmentSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/BidAdjustmentSpec.groovy @@ -21,6 +21,7 @@ import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.CurrencyConversion import org.prebid.server.functional.util.CurrencyUtil import org.prebid.server.functional.util.PBSUtils @@ -66,16 +67,17 @@ class BidAdjustmentSpec extends BaseSpec { private static final CurrencyConversion currencyConversion = new CurrencyConversion(networkServiceContainer) private static final Map AMX_CONFIG = ["adapters.amx.enabled" : "true", "adapters.amx.endpoint": "$networkServiceContainer.rootUri/auction".toString()] + private static final PbsContainerConfig CURRENCY_CONFIG = new PbsContainerConfig(PbsConfig.currencyConverterConfig + AMX_CONFIG) private static PrebidServerService pbsService def setupSpec() { currencyConversion.setCurrencyConversionRatesResponse() - pbsService = pbsServiceFactory.getService(PbsConfig.currencyConverterConfig + AMX_CONFIG) + pbsService = pbsServiceFactory.getService(CURRENCY_CONFIG) } @Override def cleanupSpec() { - pbsServiceFactory.removeContainer(PbsConfig.currencyConverterConfig + AMX_CONFIG) + pbsServiceFactory.removeContainer(CURRENCY_CONFIG) } def "PBS should adjust bid price for matching bidder when request has per-bidder bid adjustment factors"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidExpResponseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/BidExpResponseSpec.groovy index 6ca55f4b7bc..01ed18bb664 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidExpResponseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/BidExpResponseSpec.groovy @@ -8,12 +8,14 @@ import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.PrebidCache import org.prebid.server.functional.model.request.auction.PrebidCacheSettings import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils +import static org.prebid.server.functional.model.response.auction.MediaType.AUDIO import static org.prebid.server.functional.model.response.auction.MediaType.BANNER -import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO import static org.prebid.server.functional.model.response.auction.MediaType.NATIVE -import static org.prebid.server.functional.model.response.auction.MediaType.AUDIO +import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO class BidExpResponseSpec extends BaseSpec { @@ -23,22 +25,46 @@ class BidExpResponseSpec extends BaseSpec { private static final def VIDEO_TTL_DEFAULT_CACHE = PBSUtils.randomNumber private static final def AUDIO_TTL_DEFAULT_CACHE = PBSUtils.randomNumber private static final def NATIVE_TTL_DEFAULT_CACHE = PBSUtils.randomNumber - private static final Map CACHE_TTL_HOST_CONFIG = ["cache.banner-ttl-seconds": BANNER_TTL_HOST_CACHE as String, - "cache.video-ttl-seconds" : VIDEO_TTL_HOST_CACHE as String] - private static final Map DEFAULT_CACHE_TTL_CONFIG = ["cache.default-ttl-seconds.banner": BANNER_TTL_DEFAULT_CACHE as String, - "cache.default-ttl-seconds.video" : VIDEO_TTL_DEFAULT_CACHE as String, - "cache.default-ttl-seconds.native": NATIVE_TTL_DEFAULT_CACHE as String, - "cache.default-ttl-seconds.audio" : AUDIO_TTL_DEFAULT_CACHE as String] - private static final Map EMPTY_CACHE_TTL_CONFIG = ["cache.default-ttl-seconds.banner": "", - "cache.default-ttl-seconds.video" : "", - "cache.default-ttl-seconds.native": "", - "cache.default-ttl-seconds.audio" : ""] - private static final Map EMPTY_CACHE_TTL_HOST_CONFIG = ["cache.banner-ttl-seconds": "", - "cache.video-ttl-seconds" : ""] - private static def pbsOnlyHostCacheTtlService = pbsServiceFactory.getService(CACHE_TTL_HOST_CONFIG + EMPTY_CACHE_TTL_CONFIG) - private static def pbsEmptyTtlService = pbsServiceFactory.getService(EMPTY_CACHE_TTL_CONFIG + EMPTY_CACHE_TTL_HOST_CONFIG) - private static def pbsHostAndDefaultCacheTtlService = pbsServiceFactory.getService(CACHE_TTL_HOST_CONFIG + DEFAULT_CACHE_TTL_CONFIG) + private static final PbsContainerConfig CACHE_TTL_HOST_CONFIG = new PbsContainerConfig([ + "cache.banner-ttl-seconds": BANNER_TTL_HOST_CACHE, + "cache.video-ttl-seconds" : VIDEO_TTL_HOST_CACHE]) + private static final PbsContainerConfig DEFAULT_CACHE_TTL_CONFIG = new PbsContainerConfig([ + "cache.default-ttl-seconds.banner": BANNER_TTL_DEFAULT_CACHE, + "cache.default-ttl-seconds.video" : VIDEO_TTL_DEFAULT_CACHE, + "cache.default-ttl-seconds.native": NATIVE_TTL_DEFAULT_CACHE, + "cache.default-ttl-seconds.audio" : AUDIO_TTL_DEFAULT_CACHE]) + private static final PbsContainerConfig EMPTY_CACHE_TTL_CONFIG = new PbsContainerConfig([ + "cache.default-ttl-seconds.banner": "", + "cache.default-ttl-seconds.video" : "", + "cache.default-ttl-seconds.native": "", + "cache.default-ttl-seconds.audio" : ""]) + private static final PbsContainerConfig EMPTY_CACHE_TTL_HOST_CONFIG = new PbsContainerConfig([ + "cache.banner-ttl-seconds": "", + "cache.video-ttl-seconds" : ""]) + + private static final PbsContainerConfig ONLY_HOST_CACHE_TTL_CONFIG = CACHE_TTL_HOST_CONFIG + EMPTY_CACHE_TTL_CONFIG + private static final PbsContainerConfig EMPTY_TTL_CONFIG = EMPTY_CACHE_TTL_HOST_CONFIG + EMPTY_CACHE_TTL_CONFIG + private static final PbsContainerConfig HOST_AND_DEFAULT_CACHE_TTL_CONFIG = CACHE_TTL_HOST_CONFIG + DEFAULT_CACHE_TTL_CONFIG + private static final PbsContainerConfig ONLY_DEFAULT_CACHE_TTL_CONFIG = EMPTY_CACHE_TTL_HOST_CONFIG + DEFAULT_CACHE_TTL_CONFIG + + private static PrebidServerService pbsOnlyHostCacheTtlService + private static PrebidServerService pbsEmptyTtlService + private static PrebidServerService pbsHostAndDefaultCacheTtlService + private static PrebidServerService pbsOnlyDefaultCacheTtlService + + def setupSpec() { + pbsOnlyHostCacheTtlService = pbsServiceFactory.getService(ONLY_HOST_CACHE_TTL_CONFIG) + pbsEmptyTtlService = pbsServiceFactory.getService(EMPTY_TTL_CONFIG) + pbsHostAndDefaultCacheTtlService = pbsServiceFactory.getService(HOST_AND_DEFAULT_CACHE_TTL_CONFIG) + pbsOnlyDefaultCacheTtlService = pbsServiceFactory.getService(ONLY_DEFAULT_CACHE_TTL_CONFIG) + } + def cleanupSpec() { + pbsServiceFactory.removeContainer(ONLY_HOST_CACHE_TTL_CONFIG) + pbsServiceFactory.removeContainer(EMPTY_TTL_CONFIG) + pbsServiceFactory.removeContainer(HOST_AND_DEFAULT_CACHE_TTL_CONFIG) + pbsServiceFactory.removeContainer(ONLY_DEFAULT_CACHE_TTL_CONFIG) + } def "PBS auction should resolve bid.exp from response that is set by the bidder’s adapter"() { given: "Default basicResponse with exp" @@ -614,11 +640,7 @@ class BidExpResponseSpec extends BaseSpec { } def "PBS auction should resolve bid.exp when cache.default-ttl-seconds.{banner,video,audio,native} is specified and no higher-priority fields are present"() { - given: "Prebid server with empty host config and default cache ttl config" - def config = EMPTY_CACHE_TTL_HOST_CONFIG + DEFAULT_CACHE_TTL_CONFIG - def prebidServerService = pbsServiceFactory.getService(config) - - and: "Default bid request" + given: "Default bid request" def bidRequest = BidRequest.getDefaultBidRequest().tap { imp[0] = Imp.getDefaultImpression(mediaType) } @@ -628,14 +650,11 @@ class BidExpResponseSpec extends BaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes auction request" - def response = prebidServerService.sendAuctionRequest(bidRequest) + def response = pbsOnlyDefaultCacheTtlService.sendAuctionRequest(bidRequest) then: "Bid response should contain exp data" assert response.seatbid.first.bid.first.exp == bidExpValue - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(config) - where: mediaType | bidExpValue BANNER | BANNER_TTL_DEFAULT_CACHE diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidValidationSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/BidValidationSpec.groovy index 9dd17c31e0a..1d417e662b9 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidValidationSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/BidValidationSpec.groovy @@ -12,6 +12,7 @@ import org.prebid.server.functional.model.response.auction.Bid import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import spock.lang.PendingFeature @@ -48,7 +49,8 @@ class BidValidationSpec extends BaseSpec { def "PBS should throw an exception when bid request includes more than one distribution channel and strict setting enabled for service"() { given: "PBS with string setting enabled" - def strictPrebidService = pbsServiceFactory.getService(['auction.strict-app-site-dooh': 'true']) + def config = new PbsContainerConfig(['auction.strict-app-site-dooh': 'true']) + def strictPrebidService = pbsServiceFactory.getService(config) and: "Flush metrics" flushMetrics(strictPrebidService) @@ -83,7 +85,8 @@ class BidValidationSpec extends BaseSpec { def randomReferer = PBSUtils.randomString and: "PBS with string setting disabled" - def softPrebidService = pbsServiceFactory.getService(['auction.strict-app-site-dooh': 'false']) + def config = new PbsContainerConfig(['auction.strict-app-site-dooh': 'false']) + def softPrebidService = pbsServiceFactory.getService(config) and: "Request distribution channels" def requestDistributionChannels = bidRequest.getRequestDistributionChannels() diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidderParamsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/BidderParamsSpec.groovy deleted file mode 100644 index 49bbd9c2e17..00000000000 --- a/src/test/groovy/org/prebid/server/functional/tests/BidderParamsSpec.groovy +++ /dev/null @@ -1,1719 +0,0 @@ -package org.prebid.server.functional.tests - -import org.prebid.server.functional.model.bidder.AppNexus -import org.prebid.server.functional.model.bidder.BidderName -import org.prebid.server.functional.model.bidder.Generic -import org.prebid.server.functional.model.config.Endpoint -import org.prebid.server.functional.model.db.Account -import org.prebid.server.functional.model.db.StoredImp -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.Adrino -import org.prebid.server.functional.model.request.auction.Amx -import org.prebid.server.functional.model.request.auction.Banner -import org.prebid.server.functional.model.request.auction.BidRequest -import org.prebid.server.functional.model.request.auction.Device -import org.prebid.server.functional.model.request.auction.AnyUnsupportedBidder -import org.prebid.server.functional.model.request.auction.Geo -import org.prebid.server.functional.model.request.auction.Imp -import org.prebid.server.functional.model.request.auction.ImpExt -import org.prebid.server.functional.model.request.auction.ImpExtContext -import org.prebid.server.functional.model.request.auction.ImpExtContextData -import org.prebid.server.functional.model.request.auction.Native -import org.prebid.server.functional.model.request.auction.PrebidOptions -import org.prebid.server.functional.model.request.auction.PrebidStoredRequest -import org.prebid.server.functional.model.request.auction.Site -import org.prebid.server.functional.model.request.auction.Source -import org.prebid.server.functional.model.request.auction.Targeting -import org.prebid.server.functional.model.request.vtrack.VtrackRequest -import org.prebid.server.functional.model.request.vtrack.xml.Vast -import org.prebid.server.functional.model.response.auction.Adm -import org.prebid.server.functional.model.response.auction.Bid -import org.prebid.server.functional.model.response.auction.BidExt -import org.prebid.server.functional.model.response.auction.BidResponse -import org.prebid.server.functional.util.PBSUtils -import org.prebid.server.functional.util.privacy.CcpaConsent - -import static org.prebid.server.functional.model.Currency.CHF -import static org.prebid.server.functional.model.Currency.EUR -import static org.prebid.server.functional.model.Currency.JPY -import static org.prebid.server.functional.model.Currency.USD -import static org.prebid.server.functional.model.bidder.BidderName.ALIAS_UPPER_CASE -import static org.prebid.server.functional.model.bidder.BidderName.AMX -import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS -import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE -import static org.prebid.server.functional.model.bidder.BidderName.OPENX -import static org.prebid.server.functional.model.bidder.CompressionType.GZIP -import static org.prebid.server.functional.model.bidder.CompressionType.NONE -import static org.prebid.server.functional.model.request.auction.Asset.titleAsset -import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP -import static org.prebid.server.functional.model.request.auction.DistributionChannel.DOOH -import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE -import static org.prebid.server.functional.model.request.auction.SecurityLevel.NON_SECURE -import static org.prebid.server.functional.model.request.auction.SecurityLevel.SECURE -import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY -import static org.prebid.server.functional.model.response.auction.ErrorType.ALIAS -import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC -import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID -import static org.prebid.server.functional.model.response.auction.MediaType.AUDIO -import static org.prebid.server.functional.model.response.auction.MediaType.BANNER -import static org.prebid.server.functional.model.response.auction.MediaType.NATIVE -import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO -import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer -import static org.prebid.server.functional.util.HttpUtil.CONTENT_ENCODING_HEADER -import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED - -class BidderParamsSpec extends BaseSpec { - - private static final Map DISABLE_INVALID_BIDDER_CONFIGS = [ - "adapters.audiencenetwork.enabled": "false", - "adapters.adxcg.enabled" : "false", - "adapters.avocet.enabled" : "false", - "adapters.pangle.enabled" : "false", - "adapters.teqblaze.enabled" : "false", - "adapters.ix.enabled" : "false" - ] - - def "PBS should send request to bidder when adapter-defaults.enabled = #adapterDefault and adapters.BIDDER.enabled = #generic"() { - given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService(adapterConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain httpcalls" - assert response.ext?.debug?.httpcalls[BidderName.GENERIC.value] - - and: "Response should not contain error" - assert !response.ext?.errors - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(adapterConfig) - - where: - adapterDefault | generic | adapterConfig - "true" | "true" | ["adapter-defaults.enabled": adapterDefault, - "adapters.generic.enabled": generic] + DISABLE_INVALID_BIDDER_CONFIGS - - "false" | "true" | ["adapter-defaults.enabled": adapterDefault, - "adapters.generic.enabled": generic] - } - - def "PBS should not send request to bidder and emit error when adapter-defaults.enabled = #adapterDefault and adapters.BIDDER.enabled = #generic"() { - given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService(adapterConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain error" - assert response.ext?.errors[GENERIC]*.code == [2] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(adapterConfig) - - where: - adapterDefault | generic | adapterConfig - "false" | "false" | ["adapter-defaults.enabled": adapterDefault, - "adapters.generic.enabled": generic] - "true" | "false" | ["adapter-defaults.enabled": adapterDefault, - "adapters.generic.enabled": generic] + DISABLE_INVALID_BIDDER_CONFIGS - } - - def "PBS should modify vast xml when adapter-defaults.modifying-vast-xml-allowed = #adapterDefault and BIDDER.modifying-vast-xml-allowed = #generic"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapter-defaults.modifying-vast-xml-allowed": adapterDefault, - "adapters.generic.modifying-vast-xml-allowed": generic] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default vtrack request" - String payload = PBSUtils.randomString - def request = VtrackRequest.getDefaultVtrackRequest(encodeXml(Vast.getDefaultVastModel(payload))) - def accountId = PBSUtils.randomNumber - - and: "Account in the DB" - def account = new Account(uuid: accountId, eventsEnabled: true) - accountDao.save(account) - - when: "PBS processes vtrack request" - pbsService.sendPostVtrackRequest(request, accountId.toString()) - - then: "vast xml is modified" - def prebidCacheRequest = prebidCache.getXmlRecordedRequestsBody(payload) - assert prebidCacheRequest.size() == 1 - assert prebidCacheRequest.first().contains("${Endpoint.EVENT}?t=imp&b=${request.puts[0].bidid}&a=$accountId&bidder=${request.puts[0].bidder}") - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - adapterDefault | generic - "true" | "true" - "false" | "true" - } - - def "PBS should not modify vast xml when adapter-defaults.modifying-vast-xml-allowed = #adapterDefault and BIDDER.modifying-vast-xml-allowed = #generic"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapter-defaults.modifying-vast-xml-allowed": adapterDefault, - "adapters.generic.modifying-vast-xml-allowed": generic] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default VtrackRequest" - String payload = PBSUtils.randomString - def request = VtrackRequest.getDefaultVtrackRequest(encodeXml(Vast.getDefaultVastModel(payload))) - def accountId = PBSUtils.randomNumber - - and: "Account in the DB" - def account = new Account(uuid: accountId, eventsEnabled: true) - accountDao.save(account) - - when: "PBS processes vtrack request" - pbsService.sendPostVtrackRequest(request, accountId.toString()) - - then: "vast xml is not modified" - def prebidCacheRequest = prebidCache.getXmlRecordedRequestsBody(payload) - assert prebidCacheRequest.size() == 1 - assert !prebidCacheRequest.first().contains("${Endpoint.EVENT}?t=imp&b=${request.puts[0].bidid}&a=$accountId&bidder=${request.puts[0].bidder}") - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - adapterDefault | generic - "true" | "false" - "false" | "false" - } - - def "PBS should mask values when adapter-defaults.pbs-enforces-ccpa = #adapterDefault settings when BIDDER.pbs-enforces-ccpa = #generic"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapter-defaults.pbs-enforces-ccpa": adapterDefault, - "adapters.generic.pbs-enforces-ccpa": generic] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - def validCcpa = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) - bidRequest.regs.usPrivacy = validCcpa - def lat = PBSUtils.getRandomDecimal(0, 90) - def lon = PBSUtils.getRandomDecimal(0, 90) - bidRequest.device = new Device(geo: new Geo(lat: lat, lon: lon)) - - when: "PBS processes auction request" - pbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain masked values" - def bidderRequests = bidder.getBidderRequest(bidRequest.id) - assert bidderRequests.device?.geo?.lat as BigDecimal == PBSUtils.roundDecimal(lat, 2) - assert bidderRequests.device?.geo?.lon as BigDecimal == PBSUtils.roundDecimal(lon, 2) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - adapterDefault | generic - "true" | "true" - "false" | "true" - } - - def "PBS should not mask values when adapter-defaults.pbs-enforces-ccpa = #adapterDefault settings when BIDDER.pbs-enforces-ccpa = #generic"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapter-defaults.pbs-enforces-ccpa": adapterDefault, - "adapters.generic.pbs-enforces-ccpa": generic] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - def validCcpa = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) - bidRequest.regs.usPrivacy = validCcpa - def lat = PBSUtils.getRandomDecimal(0, 90) as float - def lon = PBSUtils.getRandomDecimal(0, 90) as float - bidRequest.device = new Device(geo: new Geo(lat: lat, lon: lon)) - - when: "PBS processes auction request" - pbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain not masked values" - def bidderRequests = bidder.getBidderRequest(bidRequest.id) - assert bidderRequests.device?.geo?.lat == lat - assert bidderRequests.device?.geo?.lon == lon - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - adapterDefault | generic - "true" | "false" - "false" | "false" - } - - def "PBS should prefer bidder params from imp[*].ext.prebid.bidder.BIDDER when ext.prebid.bidderparams.BIDDER is specified"() { - given: "Default basic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - def firstParam = PBSUtils.randomNumber - bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) - - and: "Set bidderParam to bidRequest" - bidRequest.ext.prebid.bidderParams = [(BidderName.GENERIC): [firstParam: PBSUtils.randomNumber]] - - when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain zoneId value from imp[*].ext.prebid.bidder.BIDDER" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam - - and: "Bidder request should contain requested bidder param for related itself bidder" - assert bidderRequest.ext.prebid.bidderParams[GENERIC] == bidRequest.ext.prebid.bidderParams[GENERIC] - } - - def "PBS should send bidder params from imp[*].ext.prebid.bidder.BIDDER when ext.prebid.bidderparams.BIDDER isn't specified"() { - given: "Default basic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - def firstParam = PBSUtils.randomNumber - bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) - - and: "Set bidderParam = null to bidRequest" - bidRequest.ext.prebid.bidderParams = null - - when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain zoneId value from imp[*].ext.prebid.bidder.BIDDER" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam - } - - def "PBS should merge bidder params from imp[*].ext.prebid.bidder.BIDDER and ext.prebid.bidderparams.BIDDER"() { - given: "Default basic BidRequest with zoneId = null" - def bidRequest = BidRequest.defaultBidRequest - def firstParam = PBSUtils.randomNumber - bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) - - and: "Set bidderParam to bidRequest" - def secondParam = PBSUtils.randomNumber - bidRequest.ext.prebid.bidderParams = [(BidderName.GENERIC): [secondParam: secondParam]] - - when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should merge bidder params" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam - assert bidderRequest.imp[0]?.ext?.bidder?.secondParam == secondParam - } - - def "PBS should only send bidder params from ext.prebid.bidderparams.BIDDER to specified bidder"() { - given: "Default basic BidRequest" - def bidRequest = BidRequest.defaultBidRequest - def firstParam = PBSUtils.randomNumber - bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) - bidRequest.imp.first().ext.prebid.bidder.appNexus = null - - and: "Set bidderParam to bidRequest" - bidRequest.ext.prebid.bidderParams = [(APPNEXUS): [placement_id: PBSUtils.randomNumber]] - - when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain bidder param from another bidder" - bidder.getBidderRequest(bidRequest.id) - } - - def "PBS should reject bidder when bidder params from request doesn't satisfy json-schema for auction request"() { - given: "BidRequest with bad bidder datatype" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp << Imp.defaultImpression - imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "PBS should not fail the entire auction" - assert response.seatbid[0].bid.size() == 1 - - and: "PBS should call bidder" - assert bidder.getRequestCount(bidRequest.id) == 1 - - and: "Bidder with invalid params should be dropped" - assert response.ext?.warnings[PREBID]*.code == [999, 999] - assert response.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + - "\$.exampleProperty: integer found, string expected", - "WARNING: request.imp[0].ext must contain at least one valid bidder"] - } - - def "PBS should reject bidder when bidder params from stored request doesn't satisfy json-schema for auction request"() { - given: "BidRequest with stored request, without imp" - def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomNumber) - imp = null - } - - and: "Default stored request with bad bidder datatype" - def storedRequestModel = BidRequest.defaultStoredRequest.tap { - imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber - } - - and: "Save storedRequest into DB" - def storedRequest = StoredRequest.getStoredRequest(bidRequest, storedRequestModel) - storedRequestDao.save(storedRequest) - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder should be dropped" - assert response.ext?.warnings[PREBID]*.code == [999, 999] - assert response.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + - "\$.exampleProperty: integer found, string expected", - "WARNING: request.imp[0].ext must contain at least one valid bidder"] - - and: "PBS should not call bidder" - assert bidder.getRequestCount(bidRequest.id) == 0 - - and: "seatbid should be empty" - assert response.seatbid.isEmpty() - } - - def "PBS should reject bidder when bidder params from stored request doesn't satisfy json-schema for amp request"() { - given: "AmpRequest with bad bidder datatype" - def ampRequest = AmpRequest.defaultAmpRequest - def ampStoredRequest = BidRequest.defaultBidRequest.tap { - site.publisher.id = ampRequest.account - imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber - } - - and: "Save storedRequest into DB" - def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest) - storedRequestDao.save(storedRequest) - - when: "PBS processes amp request" - def response = defaultPbsService.sendAmpRequest(ampRequest) - - then: "Bidder should be dropped" - assert response.ext?.warnings[PREBID]*.code == [999, 999] - assert response.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + - "\$.exampleProperty: integer found, string expected", - "WARNING: request.imp[0].ext must contain at least one valid bidder"] - - and: "PBS should not call bidder" - assert bidder.getRequestCount(ampStoredRequest.id) == 0 - - and: "targeting should be empty" - assert response.targeting.isEmpty() - } - - def "PBS should emit error when filter-imp-media-type = true and #configMediaType is empty in bidder config"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - ("adapters.generic.meta-info.${configMediaType}".toString()): ""] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain empty seatbid" - assert response.seatbid.isEmpty() - - and: "Response should contain error" - assert response.ext?.warnings[GENERIC]*.code == [2] - assert response.ext?.warnings[GENERIC]*.message == ["Bidder does not support any media types."] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - configMediaType | bidRequest - "app-media-types" | BidRequest.getDefaultBidRequest(APP) - "site-media-types" | BidRequest.getDefaultBidRequest(SITE) - } - - def "PBS should not validate request when filter-imp-media-type = false and #configMediaType is empty in bidder config"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "false", - ("adapters.generic.meta-info.${configMediaType}".toString()): ""] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain seatbid" - assert response.seatbid - - and: "Response should not contain error" - assert !response.ext?.errors - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - configMediaType | bidRequest - "app-media-types" | BidRequest.getDefaultBidRequest(APP) - "site-media-types" | BidRequest.getDefaultBidRequest(SITE) - } - - def "PBS should emit error when filter-imp-media-type = true and request contains media type that is not configured in bidder config"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.site-media-types": "native"] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with banner, native" - def bidRequest = BidRequest.defaultBidRequest.tap { - site = Site.defaultSite - imp[0].banner = Banner.defaultBanner - imp[0].nativeObj = Native.defaultNative - } - - and: "Default basic bid with adm" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) - - and: "Set bidder response" - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "PBS should remove not configured media type from bidder request" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert !bidderRequest.imp[0]?.banner - assert bidderRequest.imp[0]?.nativeObj - - and: "Response should not contain warnings" - assert !response.ext?.warnings - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should not validate request when filter-imp-media-type = false and request contains only media type that is not configured in bidder config"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "false", - "adapters.generic.meta-info.site-media-types": "native"] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with banner, native" - def bidRequest = BidRequest.defaultBidRequest.tap { - site = Site.defaultSite - imp[0].banner = Banner.defaultBanner - imp[0].nativeObj = Native.defaultNative - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "PBS should not remove not configured media type from bidder request" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0]?.banner - assert bidderRequest.imp[0]?.nativeObj - - and: "Response should not contain error" - assert !response.ext?.errors - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should emit error for request with multiple impressions when filter-imp-media-type = true, one of imp doesn't contain supported media type"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.site-media-types": "native,video"] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with banner, native" - def nativeImp = Imp.getDefaultImpression(NATIVE) - def bidRequest = BidRequest.defaultBidRequest.tap { - site = Site.defaultSite - imp = [Imp.defaultImpression, nativeImp] - } - - and: "Default basic bid with adm" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { - seatbid.first().bid = [Bid.getDefaultBid(nativeImp)] - } - - and: "Set bidder response" - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "PBS should remove banner imp from bidder request" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp.size() == 1 - assert !bidderRequest.imp[0].banner - assert bidderRequest.imp[0].nativeObj - - and: "Response should contain error" - assert response.ext?.warnings[GENERIC]*.code == [2] - assert response.ext?.warnings[GENERIC]*.message == - ["Imp ${bidRequest.imp[0].id} does not have a supported media type and has been removed from the " + - "request for this bidder." as String] - - and: "seatbid should not be empty" - assert !response.seatbid.isEmpty() - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS auction should reject the bidder with media-type that is not supported by DOOH configuration with proper warning"() { - given: "PBS service with configuration for dooh media-types" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.dooh-media-types": mediaType] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - when: "Requesting PBS auction" - def bidResponse = pbsService.sendAuctionRequest(bidRequest) - - then: "Bid response should contain proper warning" - assert bidResponse.ext?.warnings[GENERIC]?.message.contains("Bid request contains 0 impressions after filtering.") - - and: "Bid response shouldn't contain any seatbid" - assert !bidResponse.seatbid - - and: "Should't send any bidder request" - assert !bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - mediaType | bidRequest - VIDEO.value | BidRequest.getDefaultBidRequest(DOOH) - NATIVE.value | BidRequest.getDefaultBidRequest(DOOH) - AUDIO.value | BidRequest.getDefaultBidRequest(DOOH) - BANNER.value | BidRequest.getDefaultVideoRequest(DOOH) - "${BANNER}, ${VIDEO}" as String | BidRequest.getDefaultBidRequest(DOOH).tap { imp[0] = Imp.getDefaultImpression(NATIVE) } - } - - def "PBS auction should reject only imps with media-type that is not supported by DOOH configuration with proper warning"() { - given: "PBS service with configuration for dooh media-types" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.dooh-media-types": mediaType.value] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid response with adm and nurl" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { - seatbid[0].bid[0].adm = new Adm(assets: [titleAsset]) - seatbid[0].bid[0].nurl = PBSUtils.randomString - } - bidder.setResponse(bidRequest.id, bidResponse) - - when: "Requesting PBS auction" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Bid response should contain proper warning" - assert response.ext?.warnings[GENERIC]?.message == - ["Imp ${bidRequest.imp[1].id} does not have a supported media type and has been removed from the request for this bidder."] - - and: "Bid response should contain seatbid" - assert response.seatbid - - and: "Should send bidder request with only proper imp" - assert bidder.getBidderRequest(bidRequest.id).imp.id == [bidRequest.imp.first().id] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - - where: - mediaType | bidRequest - BANNER | BidRequest.getDefaultBidRequest(DOOH).tap { imp << Imp.getDefaultImpression(VIDEO) } - VIDEO | BidRequest.getDefaultVideoRequest(DOOH).tap { imp << Imp.getDefaultImpression(NATIVE) } - AUDIO | BidRequest.getDefaultAudioRequest(DOOH).tap { imp << Imp.getDefaultImpression(NATIVE) } - } - - def "PBS should return empty seatBit when filter-imp-media-type = true, request.imp doesn't contain supported media type"() { - given: "Pbs config" - def pbsConfig = ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.site-media-types": "native,video"] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with banner" - def bidRequest = BidRequest.defaultBidRequest.tap { - site = Site.defaultSite - imp.first().banner = Banner.defaultBanner - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "PBS should not call bidder" - assert bidder.getRequestCount(bidRequest.id) == 0 - - and: "Response should contain errors" - assert response.ext?.warnings[GENERIC]*.code == [2, 2] - assert response.ext?.warnings[GENERIC]*.message == - ["Imp ${bidRequest.imp[0].id} does not have a supported media type and has been removed from " + - "the request for this bidder.", - "Bid request contains 0 impressions after filtering."] - - and: "seatbid should be empty" - assert response.seatbid.isEmpty() - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send server specific info to bidder when such is set in PBS config"() { - given: "PBS with server info configuration" - def serverDataCenter = PBSUtils.randomString - def serverExternalUrl = "https://${PBSUtils.randomString}.com/" - def serverHostVendorId = PBSUtils.randomNumber - def pbsConfig = ["datacenter-region" : serverDataCenter, - "external-url" : serverExternalUrl as String, - "gdpr.host-vendor-id": serverHostVendorId as String] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Bid request" - def bidRequest = BidRequest.defaultBidRequest - - when: "PBS auction is requested" - pbsService.sendAuctionRequest(bidRequest) - - then: "PBS has sent server info to bidder during auction" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - - assert bidderRequest?.ext?.prebid?.server?.externalUrl == serverExternalUrl - assert bidderRequest.ext.prebid.server.datacenter == serverDataCenter - assert bidderRequest.ext.prebid.server.gvlId == serverHostVendorId - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should request to bidder with header Content-Encoding = gzip when adapters.BIDDER.endpoint-compression = gzip"() { - given: "PBS with adapter configuration" - def compressionType = GZIP.value - def pbsConfig = ["adapters.generic.enabled" : "true", - "adapters.generic.endpoint-compression": compressionType] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain header Content-Encoding = gzip" - assert response.ext?.debug?.httpcalls?.get(BidderName.GENERIC.value)?.requestHeaders?.first() - ?.get(CONTENT_ENCODING_HEADER)?.first() == compressionType - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send request to bidder without header Content-Encoding when adapters.BIDDER.endpoint-compression = none"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapters.generic.enabled" : "true", - "adapters.generic.endpoint-compression": NONE.value] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should not contain header Content-Encoding" - assert !response.ext?.debug?.httpcalls?.get(BidderName.GENERIC.value)?.requestHeaders?.first() - ?.get(CONTENT_ENCODING_HEADER) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should not treat reserved imp[].ext.tid object as a bidder"() { - given: "Default basic BidRequest with imp[].ext.tid object" - def bidRequest = BidRequest.defaultBidRequest - def tid = PBSUtils.getRandomString() - bidRequest.imp.first().ext.tid = tid - - when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "imp[].ext.tid object should be passed to a bidder" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp?.first()?.ext?.tid == tid - } - - def "PBS auction should populate imp[0].secure depend which value in imp stored request"() { - given: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) - } - - and: "Save storedImp into DB" - def storedImp = StoredImp.getStoredImp(bidRequest).tap { - impData = Imp.defaultImpression.tap { - it.secure = secureStoredRequest - } - } - storedImpDao.save(storedImp) - - when: "Requesting PBS auction" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain imp[0].secure same value as in request" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0].secure == secureBidderRequest - - where: - secureStoredRequest | secureBidderRequest - null | SECURE - SECURE | SECURE - NON_SECURE | NON_SECURE - } - - def "PBS auction should populate imp[0].secure depend which value in imp request"() { - given: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].secure = secureRequest - } - - when: "Requesting PBS auction" - defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain imp[0].secure same value as in request" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0].secure == secureBidderRequest - - where: - secureRequest | secureBidderRequest - null | SECURE - SECURE | SECURE - NON_SECURE | NON_SECURE - } - - def "PBS shouldn't emit warning and proceed auction when imp.ext.anyUnsupportedBidder and imp.ext.prebid.bidder.generic in the request"() { - given: "Default bid request" - def unsupportedBidder = new AnyUnsupportedBidder(anyUnsupportedField: PBSUtils.randomString) - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.anyUnsupportedBidder = unsupportedBidder - imp[0].ext.prebid.bidder.generic = new Generic() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain imp.ext.anyUnsupportedBidder" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0].ext.anyUnsupportedBidder == unsupportedBidder - - and: "Response shouldn't contain warning" - assert !response?.ext?.warnings - } - - def "PBS should emit warning and proceed auction when imp.ext.anyUnsupportedBidder and imp.ext.generic in the request"() { - given: "Default bid request" - def unsupportedBidder = new AnyUnsupportedBidder(anyUnsupportedField: PBSUtils.randomString) - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.generic = new Generic() - imp[0].ext.anyUnsupportedBidder = unsupportedBidder - imp[0].ext.prebid.bidder = null - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder request should contain imp.ext.anyUnsupportedBidder" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.imp[0].ext.anyUnsupportedBidder == unsupportedBidder - - and: "PBS should emit an warning" - assert response?.ext?.warnings[PREBID]*.code == [999] - assert response?.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.anyUnsupportedBidder was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder contains unknown bidder: anyUnsupportedBidder"] - } - - def "PBS should emit warning and proceed auction when ext.prebid fields include adunitcode"() { - given: "Default bid request with populated ext.prebid.bidderParams" - def genericBidderParams = PBSUtils.randomString - def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.bidderParams = [adUnitCode : PBSUtils.randomString, - (GENERIC.value): genericBidderParams] - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "PBS should emit an warning" - assert response?.ext?.warnings[PREBID]*.code == [999] - assert response?.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.adUnitCode was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder contains unknown bidder: adUnitCode"] - } - - def "PBS shouldn't emit warning and proceed auction when all imp.ext fields known for PBS"() { - given: "Default bid request with populated imp.ext" - def impExt = ImpExt.getDefaultImpExt().tap { - prebid.bidder.generic = null - prebid.adUnitCode = PBSUtils.randomString - generic = new Generic() - all = PBSUtils.randomNumber - context = new ImpExtContext(data: new ImpExtContextData()) - data = new ImpExtContextData(pbAdSlot: PBSUtils.randomString) - general = PBSUtils.randomString - gpid = PBSUtils.randomString - skadn = PBSUtils.randomString - tid = PBSUtils.randomString - } - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext = impExt - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "Bidder request should contain same field as requested" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - verifyAll(bidderRequest.imp[0].ext) { - it.bidder == impExt.generic - it.all == impExt.all - it.context == impExt.context - it.data == impExt.data - it.general == impExt.general - it.gpid == impExt.gpid - it.skadn == impExt.skadn - it.tid == impExt.tid - it.prebid.adUnitCode == impExt.prebid.adUnitCode - } - } - - def "PBS shouldn't emit warning and proceed auction when all imp.ext.prebid fields known for PBS"() { - given: "PBS with old ortb version" - def pbsConfig = ['adapters.generic.ortb-version': '2.5'] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with populated imp.ext.prebid" - def impExt = ImpExt.getDefaultImpExt().tap { - prebid.adUnitCode = PBSUtils.randomString - prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) - prebid.isRewardedInventory = PBSUtils.getRandomNumber(0, 1) - prebid.options = new PrebidOptions(echoVideoAttrs: PBSUtils.randomBoolean) - } - def bidRequest = BidRequest.defaultVideoRequest.tap { - imp[0].rwdd = null - imp[0].ext = impExt - } - - and: "Save storedImp into DB" - def storedImp = StoredImp.getStoredImp(bidRequest) - storedImpDao.save(storedImp) - - and: "Default bid response" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "Bidder request should contain same field as requested" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - verifyAll(bidderRequest.imp[0].ext.prebid) { - it.adUnitCode == impExt.prebid.adUnitCode - it.storedRequest == impExt.prebid.storedRequest - it.isRewardedInventory == impExt.prebid.isRewardedInventory - it.options.echoVideoAttrs == impExt.prebid.options.echoVideoAttrs - } - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should proceed auction without warning when all ext.prebid.bidderParams fields are known"() { - given: "Default bid request with populated ext.prebid.bidderParams" - def genericBidderParams = PBSUtils.randomString - def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.bidderParams = [all : PBSUtils.randomString, - context : PBSUtils.randomString, - data : PBSUtils.randomString, - general : PBSUtils.randomString, - gpid : PBSUtils.randomString, - skadn : PBSUtils.randomString, - tid : PBSUtils.randomString, - (GENERIC.value): genericBidderParams - ] - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "Bidder request should bidderParams only for bidder" - def bidderRequest = bidder.getBidderRequest(bidRequest.id) - assert bidderRequest.ext.prebid.bidderParams == [(GENERIC.value): genericBidderParams] - } - - def "PBS should send request to bidder when adapters.bidder.meta-info.currency-accepted not specified"() { - given: "PBS with adapter configuration" - def pbsConfig = ['adapters.generic.meta-info.currency-accepted': ''] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with generic bidder" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain http calls" - assert response.ext?.debug?.httpcalls[BidderName.GENERIC.value] - - and: "Response should contain seatBid" - assert response.seatbid.bid.flatten().size() == 1 - - and: "Bidder request should be valid" - assert bidder.getBidderRequest(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "PBS response shouldn't contain seatNonBid" - assert !response.ext.seatnonbid - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send request to bidder when adapters.bidder.aliases.bidder.meta-info.currency-accepted not specified"() { - given: "PBS with adapter configuration" - def pbsConfig = [ - "adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id" : "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.generic.aliases.alias.meta-info.currency-accepted": ""] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with alias bidder" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - imp[0].ext.prebid.bidder.alias = new Generic() - imp[0].ext.prebid.bidder.generic = null - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain http calls" - assert response.ext?.debug?.httpcalls[BidderName.ALIAS.value] - - and: "Response should contain seatBid" - assert response.seatbid.bid.flatten().size() == 1 - - and: "Bidder request should be valid" - assert bidder.getBidderRequest(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "PBS response shouldn't contain seatNonBid" - assert !response.ext.seatnonbid - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send request to bidder when adapters.bidder.meta-info.currency-accepted intersect with requested currency"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapters.generic.meta-info.currency-accepted": "${USD},${EUR}".toString()] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain http calls" - assert response.ext?.debug?.httpcalls[BidderName.GENERIC.value] - - and: "Response should contain seatBid" - assert response.seatbid.bid.flatten().size() == 1 - - and: "Bidder request should be valid" - assert bidder.getBidderRequest(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "PBS response shouldn't contain seatNonBid and contain errors" - assert !response.ext.seatnonbid - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS shouldn't send request to bidder and emit warning when adapters.bidder.meta-info.currency-accepted not intersect with requested currency"() { - given: "PBS with adapter configuration" - def pbsConfig = ["adapters.generic.meta-info.currency-accepted": "${JPY},${CHF}".toString()] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - } - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain http calls" - assert !response.ext?.debug?.httpcalls - - and: "Response shouldn't contain seatBid" - assert !response.seatbid - - and: "Pbs shouldn't make bidder request" - assert !bidder.getBidderRequests(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response should seatNon bid with code 205" - assert response.ext.seatnonbid.size() == 1 - - and: "PBS should emit an warnings" - assert response.ext?.warnings[GENERIC]*.code == [999] - assert response.ext?.warnings[GENERIC]*.message == - ["No match between the configured currencies and bidRequest.cur"] - - def seatNonBid = response.ext.seatnonbid[0] - assert seatNonBid.seat == BidderName.GENERIC - assert seatNonBid.nonBid[0].impId == bidRequest.imp[0].id - assert seatNonBid.nonBid[0].statusCode == REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send request to bidder when adapters.bidder.aliases.bidder.meta-info.currency-accepted intersect with requested currency"() { - given: "PBS with adapter configuration" - def pbsConfig = [ - "adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id" : "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.generic.aliases.alias.meta-info.currency-accepted": "${USD},${EUR}".toString()] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with alias bidder" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - imp[0].ext.prebid.bidder.alias = new Generic() - imp[0].ext.prebid.bidder.generic = null - } - - and: "Default bid response" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain http calls" - assert response.ext?.debug?.httpcalls[ALIAS.value] - - and: "Response should contain seatBid" - assert response.seatbid.bid.flatten().size() == 1 - - and: "Bidder request should be valid" - assert bidder.getBidderRequest(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "Response shouldn't contain warning" - assert !response.ext?.warnings - - and: "PBS response shouldn't contain seatNonBid and contain errors" - assert !response.ext.seatnonbid - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS shouldn't send request to bidder and emit warning when adapters.bidder.aliases.bidder.meta-info.currency-accepted not intersect with requested currency"() { - given: "PBS with adapter configuration" - def pbsConfig = [ - "adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id" : "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.generic.aliases.alias.meta-info.currency-accepted": "${JPY},${CHF}".toString()] - def pbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default basic BidRequest with alias bidder" - def bidRequest = BidRequest.defaultBidRequest.tap { - cur = [USD] - ext.prebid.returnAllBidStatus = true - imp[0].ext.prebid.bidder.alias = new Generic() - imp[0].ext.prebid.bidder.generic = null - } - - and: "Default bid response" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = pbsService.sendAuctionRequest(bidRequest) - - then: "Response shouldn't contain http calls" - assert !response.ext?.debug?.httpcalls - - and: "Response shouldn't contain seatBid" - assert !response.seatbid - - and: "Pbs shouldn't make bidder request" - assert !bidder.getBidderRequests(bidRequest.id) - - and: "Response shouldn't contain error" - assert !response.ext?.errors - - and: "PBS should emit an warnings" - assert response.ext?.warnings[ALIAS]*.code == [999] - assert response.ext?.warnings[ALIAS]*.message == - ["No match between the configured currencies and bidRequest.cur"] - - and: "Response should seatNon bid with code 205" - assert response.ext.seatnonbid.size() == 1 - - def seatNonBid = response.ext.seatnonbid[0] - assert seatNonBid.seat == BidderName.ALIAS - assert seatNonBid.nonBid[0].impId == bidRequest.imp[0].id - assert seatNonBid.nonBid[0].statusCode == REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should reject alias bidders when bidder params from request doesn't satisfy own json-schema"() { - given: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.tap { - it.generic.exampleProperty = PBSUtils.randomNumber - //Adrino hard coded bidder alias in generic.yaml - it.adrino = new Adrino(hash: PBSUtils.randomNumber) - } - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder should be dropped" - assert response.ext?.warnings[PREBID]*.code == [999, 999, 999] - assert response.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + - "\$.exampleProperty: integer found, string expected", - "WARNING: request.imp[0].ext.prebid.bidder.adrino was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.adrino failed validation.\n" + - "\$.hash: integer found, string expected", - "WARNING: request.imp[0].ext must contain at least one valid bidder"] - - and: "PBS should not call bidder" - assert bidder.getRequestCount(bidRequest.id) == 0 - - and: "targeting should be empty" - assert response.seatbid.isEmpty() - } - - def "PBS should reject alias bidders when bidder params from request doesn't satisfy aliased json-schema"() { - given: "Default basic generic BidRequest" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.tap { - it.generic.exampleProperty = PBSUtils.randomNumber - //Adrino hard coded bidder alias in generic.yaml - it.adrino = new Adrino(hash: PBSUtils.randomNumber) - } - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bidder should be dropped" - assert response.ext?.warnings[PREBID]*.code == [999, 999, 999] - assert response.ext?.warnings[PREBID]*.message == - ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + - "\$.exampleProperty: integer found, string expected", - "WARNING: request.imp[0].ext.prebid.bidder.adrino was dropped with a reason: " + - "request.imp[0].ext.prebid.bidder.adrino failed validation.\n" + - "\$.hash: integer found, string expected", - "WARNING: request.imp[0].ext must contain at least one valid bidder"] - - and: "PBS should not call bidder" - assert bidder.getRequestCount(bidRequest.id) == 0 - - and: "targeting should be empty" - assert response.seatbid.isEmpty() - } - - def "PBS should send bidder code from imp[].ext.prebid.bidder to seatbid.bid.ext.prebid.meta.adapterCode"() { - given: "Default basic bid request" - def bidRequest = BidRequest.defaultBidRequest - - and: "Default bid response" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { - seatbid[0].seat = OPENX - } - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] - - and: "Bidder request should be valid" - assert bidder.getBidderRequest(bidRequest.id) - } - - def "PBS should send bidder code from imp[].ext.prebid.bidder to seatbid.bid.ext.prebid.meta.adapterCode when requested soft alias"() { - given: "Default bid request with alias" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.tap { - generic = null - alias = new Generic() - } - ext.prebid.aliases = [(ALIAS.value): BidderName.GENERIC] - ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [BidderName.ALIAS] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${BidderName.ALIAS}"] - assert targeting["hb_size_${BidderName.ALIAS}"] - assert targeting["hb_bidder"] == BidderName.ALIAS.value - assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS.value) - - and: "Bidder request should be valid and not contain aliases" - def bidderRequests = bidder.getBidderRequests(bidRequest.id).first - assert !bidderRequests.ext.prebid.aliases - } - - def "PBS should populate same code for adapter code when make call for generic hard code alias"() { - given: "PBS config with bidder" - def pbsConfig = ["adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id": "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with alias" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.tap { - generic = null - alias = new Generic() - } - ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [BidderName.ALIAS] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${BidderName.ALIAS}"] - assert targeting["hb_size_${BidderName.ALIAS}"] - assert targeting["hb_bidder"] == BidderName.ALIAS.value - assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should make call for alias when hard alias and demandSource specified"() { - given: "PBS config with bidder" - def pbsConfig = ["adapters.amx.enabled" : "true", - "adapters.amx.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.amx.aliases.alias.enabled" : "true", - "adapters.amx.aliases.alias.meta-info.vendor-id": "0", - "adapters.amx.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid Request with generic and openx bidder within separate imps" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.tap { - generic = null - alias = new Generic() - } - ext.prebid.targeting = new Targeting() - } - - and: "Bid response with bidder code" - def demandSource = PBSUtils.randomString - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest, BidderName.ALIAS).tap { - it.seatbid[0].bid[0].ext = new BidExt(demandSource: demandSource) - } - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain demand source" - assert response.seatbid.bid.ext.prebid.meta.demandSource.flatten() == [demandSource] - - and: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [BidderName.ALIAS] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${BidderName.ALIAS}"] - assert targeting["hb_size_${BidderName.ALIAS}"] - assert targeting["hb_bidder"] == BidderName.ALIAS.value - assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should send bidder code from imp[].ext.prebid.bidder to seatbid.bid.ext.prebid.meta.adapterCode when requested soft alias with upper case"() { - given: "Default bid request with alias" - def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.aliases = [(ALIAS.value): BidderName.GENERIC] - ext.prebid.targeting = new Targeting() - imp[0].ext.prebid.bidder.tap { - generic = null - aliasUpperCase = new Generic() - } - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [ALIAS_UPPER_CASE] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${ALIAS_UPPER_CASE}"] - assert targeting["hb_size_${ALIAS_UPPER_CASE}"] - assert targeting["hb_bidder"] == ALIAS_UPPER_CASE.value - assert targeting["hb_bidder_${ALIAS_UPPER_CASE}"] == ALIAS_UPPER_CASE.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS_UPPER_CASE.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - } - - def "PBS should populate targeting with bidder in camel case when bidder with camel case was requested"() { - given: "Default bid request" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.generic = null - imp[0].ext.prebid.bidder.genericCamelCase = new Generic() - it.ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${GENERIC_CAMEL_CASE}"] - assert targeting["hb_size_${GENERIC_CAMEL_CASE}"] - assert targeting["hb_bidder"] == GENERIC_CAMEL_CASE.value - assert targeting["hb_bidder_${GENERIC_CAMEL_CASE}"] == GENERIC_CAMEL_CASE.value - - and: "Bid response should contain seat" - assert response.seatbid.seat == [GENERIC_CAMEL_CASE] - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(GENERIC_CAMEL_CASE.value) - - and: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] - } - - def "PBS should make call for alias in upper case when soft alias specified with same name in upper case strategy"() { - given: "Default bid request with soft alias and targeting" - def bidRequest = BidRequest.defaultBidRequest.tap { - ext.prebid.aliases = [(ALIAS.value): BidderName.GENERIC] - imp[0].ext.prebid.bidder.aliasUpperCase = new Generic() - imp[0].ext.prebid.bidder.generic = null - it.ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [ALIAS_UPPER_CASE] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${ALIAS_UPPER_CASE}"] - assert targeting["hb_size_${ALIAS_UPPER_CASE}"] - assert targeting["hb_bidder"] == ALIAS_UPPER_CASE.value - assert targeting["hb_bidder_${ALIAS_UPPER_CASE}"] == ALIAS_UPPER_CASE.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS_UPPER_CASE.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - } - - def "PBS should populate adapter code with requested bidder when conflict with soft and hard alias"() { - given: "PBS config with bidder" - def pbsConfig = ["adapters.amx.enabled" : "true", - "adapters.amx.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.amx.aliases.alias.enabled" : "true", - "adapters.amx.aliases.alias.meta-info.vendor-id": "0", - "adapters.amx.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Bid request with amx bidder and targeting" - def bidRequest = BidRequest.getDefaultBidRequest().tap { - imp[0].ext.prebid.bidder.alias = new Generic() - imp[0].ext.prebid.bidder.amx = null - imp[0].ext.prebid.bidder.generic = null - it.ext.prebid.aliases = [(ALIAS.value): BidderName.GENERIC] - it.ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [BidderName.ALIAS] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${BidderName.ALIAS}"] - assert targeting["hb_size_${BidderName.ALIAS}"] - assert targeting["hb_bidder"] == BidderName.ALIAS.value - assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should populate adapter code with requested bidder when conflict with soft and generic hard alias"() { - given: "PBS config with bidders" - def pbsConfig = ["adapters.amx.enabled" : "true", - "adapters.amx.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id": "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Bid request with amx bidder and targeting" - def bidRequest = BidRequest.getDefaultBidRequest().tap { - imp[0].ext.prebid.bidder.alias = new Generic() - imp[0].ext.prebid.bidder.amx = null - imp[0].ext.prebid.bidder.generic = null - it.ext.prebid.aliases = [(ALIAS.value): AMX] - it.ext.prebid.targeting = new Targeting() - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.ALIAS] - - and: "Response should contain seat bid" - assert response.seatbid.seat == [BidderName.ALIAS] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${BidderName.ALIAS}"] - assert targeting["hb_size_${BidderName.ALIAS}"] - assert targeting["hb_bidder"] == BidderName.ALIAS.value - assert targeting["hb_bidder_${BidderName.ALIAS}"] == BidderName.ALIAS.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(ALIAS.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should properly populate bidder code when soft alias ignore standalone adapter"() { - given: "PBS config with amx bidder" - def pbsConfig = ["adapters.amx.enabled" : "true", - "adapters.amx.endpoint": "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default bid request with soft alias and targeting" - def bidRequest = BidRequest.defaultBidRequest.tap { - imp[0].ext.prebid.bidder.amx = new Amx() - imp[0].ext.prebid.bidder.generic = null - ext.prebid.targeting = new Targeting() - ext.prebid.aliases = [(AMX.value): BidderName.GENERIC] - } - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Response should contain adapter code" - assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [AMX] - - and: "Response should contain seat" - assert response.seatbid.seat == [AMX] - - and: "Response should contain bidder targeting" - def targeting = response.seatbid[0].bid[0].ext.prebid.targeting - assert targeting["hb_pb_${AMX}"] - assert targeting["hb_size_${AMX}"] - assert targeting["hb_bidder"] == AMX.value - assert targeting["hb_bidder_${AMX}"] == AMX.value - - and: "Response should contain repose millis with corresponding bidder" - assert response.ext.responsetimemillis.containsKey(AMX.value) - - and: "Bidder request should be valid" - assert bidder.getBidderRequests(bidRequest.id) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } - - def "PBS should merge stored imp with appnexus bidder requested when reserve field specified"() { - given: "Pbs default config with appnexus" - def pbsConfig = ["adapters.${APPNEXUS.value}.enabled" : "true", - "adapters.${APPNEXUS.value}.endpoint": "$networkServiceContainer.rootUri/auction".toString()] - def defaultPbsService = pbsServiceFactory.getService(pbsConfig) - - and: "Default stored request with specified stored imps and request" - def storedRequestId = PBSUtils.randomString - def bidRequest = BidRequest.getDefaultBidRequest().tap { - imp[0].ext.prebid.bidder.generic = null - imp[0].ext.prebid.bidder.appNexus = AppNexus.getDefault().tap { - reserve = PBSUtils.getRandomDecimal() as Double - } - imp[0].ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) - ext.prebid.storedRequest = new PrebidStoredRequest(id: storedRequestId) - } - - and: "Save storedImp into DB" - def storedImp = StoredImp.getStoredImp(bidRequest).tap { - impData = Imp.defaultImpression - } - storedImpDao.save(storedImp) - - and: "Save stored request with source.tid and cur" - def storedBidRequest = new BidRequest(cur: [USD], source: new Source(tid: PBSUtils.randomString)) - def storedRequest = StoredRequest.getStoredRequest(storedRequestId, storedBidRequest) - storedRequestDao.save(storedRequest) - - and: "Default basic bid with bid.ext" - def bidResponse = BidResponse.getDefaultBidResponse(bidRequest, APPNEXUS).tap { - seatbid[0].bid[0].ext = new BidExt() - } - bidder.setResponse(bidRequest.id, bidResponse) - - when: "PBS processes auction request" - def response = defaultPbsService.sendAuctionRequest(bidRequest) - - then: "Bid response should contain appnexus and generic bidder" - assert response.seatbid.size() == 2 - assert response.seatbid.seat.sort() == [APPNEXUS, BidderName.GENERIC].sort() - - and: "Bidder requests should perform two bidder call" - def bidderRequests = bidder.getBidderRequests(bidRequest.id) - assert bidderRequests.size() == 2 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - } -} diff --git a/src/test/groovy/org/prebid/server/functional/tests/CacheSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/CacheSpec.groovy index 372d5045817..99a67c6cf17 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/CacheSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/CacheSpec.groovy @@ -10,11 +10,12 @@ import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.Targeting import org.prebid.server.functional.model.response.auction.Adm import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils -import static org.prebid.server.functional.model.response.auction.ErrorType.CACHE import static org.prebid.server.functional.model.AccountStatus.ACTIVE import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.response.auction.ErrorType.CACHE import static org.prebid.server.functional.model.response.auction.MediaType.BANNER import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer @@ -135,8 +136,8 @@ class CacheSpec extends BaseSpec { def "PBS should cache bids without api-key header when targeting is specified and api-key-secured disabled"() { given: "Pbs config with disabled api-key-secured and pbc.api.key" def apiKey = PBSUtils.randomString - def pbsConfig = ['pbc.api.key': apiKey, 'cache.api-key-secured': 'false'] - def pbsService = pbsServiceFactory.getService(['pbc.api.key': apiKey, 'cache.api-key-secured': 'false']) + def config = new PbsContainerConfig(['pbc.api.key': apiKey, 'cache.api-key-secured': 'false']) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -152,16 +153,13 @@ class CacheSpec extends BaseSpec { and: "PBS call shouldn't include api-key" assert !prebidCache.getRequestHeaders(bidRequest.imp[0].id)[PBS_API_HEADER] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache bids with api-key header when targeting is specified and api-key-secured enabled"() { given: "Pbs config with api-key-secured and pbc.api.key" def apiKey = PBSUtils.randomString - def pbsConfig = ['pbc.api.key': apiKey, 'cache.api-key-secured': 'true'] - def pbsService = pbsServiceFactory.getService(pbsConfig) + def config = new PbsContainerConfig(['pbc.api.key': apiKey, 'cache.api-key-secured': 'true']) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -177,20 +175,17 @@ class CacheSpec extends BaseSpec { and: "PBS call should include api-key" assert prebidCache.getRequestHeaders(bidRequest.imp[0].id)[PBS_API_HEADER] == [apiKey] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache banner bids with cache key that include account and datacenter short name when append-trace-info-to-cache-id enabled"() { given: "Pbs config with append-trace-info-to-cache-id" def serverDataCenter = PBSUtils.randomString def bannerHostTtl = PBSUtils.getRandomNumber(300, 1500) - def pbsConfig = ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), - 'datacenter-region' : serverDataCenter, - 'cache.append-trace-info-to-cache-id': 'true' - ] - def pbsService = pbsServiceFactory.getService(pbsConfig) + def config = new PbsContainerConfig( + ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), + 'datacenter-region' : serverDataCenter, + 'cache.append-trace-info-to-cache-id': 'true']) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -215,19 +210,16 @@ class CacheSpec extends BaseSpec { def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[ACCOUNT_JSON_CREATIVE_TTL_METRIC.formatted(bidRequest.accountId)] == bannerHostTtl assert metrics[ACCOUNT_REQUEST_OK_METRIC.formatted(bidRequest.accountId)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache video bids with cache key that include account and datacenter short name when append-trace-info-to-cache-id enabled"() { given: "Pbs config with append-trace-info-to-cache-id" def serverDataCenter = PBSUtils.randomString def videoHostTtl = PBSUtils.getRandomNumber(300, 1500) - def pbsConfig = ['cache.default-ttl-seconds.video' : videoHostTtl.toString(), - 'datacenter-region' : serverDataCenter, - 'cache.append-trace-info-to-cache-id': 'true' - ] + def pbsConfig = new PbsContainerConfig( + ['cache.default-ttl-seconds.video' : videoHostTtl.toString(), + 'datacenter-region' : serverDataCenter, + 'cache.append-trace-info-to-cache-id': 'true']) def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default BidRequest with cache, targeting" @@ -262,18 +254,15 @@ class CacheSpec extends BaseSpec { and: "PBS should include metrics prebid_cache_creative.{xml,json}.creative.ttl for general" assert metrics[JSON_CREATIVE_TTL_METRIC] == videoHostTtl assert metrics[XML_CREATIVE_TTL_METRIC] == videoHostTtl - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache bids with cache key that include account when append-trace-info-to-cache-id enabled and datacenter is null"() { given: "Pbs config with append-trace-info-to-cache-id" def bannerHostTtl = PBSUtils.getRandomNumber(300, 1500) - def pbsConfig = ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), - 'datacenter-region' : null, - 'cache.append-trace-info-to-cache-id': 'true' - ] + def pbsConfig = new PbsContainerConfig( + ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), + 'datacenter-region' : null, + 'cache.append-trace-info-to-cache-id': 'true']) def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default BidRequest with cache, targeting" @@ -299,19 +288,16 @@ class CacheSpec extends BaseSpec { def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[ACCOUNT_JSON_CREATIVE_TTL_METRIC.formatted(bidRequest.accountId)] == bannerHostTtl assert metrics[ACCOUNT_REQUEST_OK_METRIC.formatted(bidRequest.accountId)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache bids without cache key when account ID is too large"() { given: "Pbs config with append-trace-info-to-cache-id" def serverDataCenter = PBSUtils.randomString def bannerHostTtl = PBSUtils.getRandomNumber(300, 1500) - def pbsConfig = ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), - 'datacenter-region' : serverDataCenter, - 'cache.append-trace-info-to-cache-id': 'true' - ] + def pbsConfig = new PbsContainerConfig( + ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), + 'datacenter-region' : serverDataCenter, + 'cache.append-trace-info-to-cache-id': 'true']) def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default BidRequest with cache, targeting and large account ID" @@ -335,20 +321,17 @@ class CacheSpec extends BaseSpec { def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[ACCOUNT_JSON_CREATIVE_TTL_METRIC.formatted(bidRequest.accountId)] == bannerHostTtl assert metrics[ACCOUNT_REQUEST_OK_METRIC.formatted(bidRequest.accountId)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should cache bids without cache key when append-trace-info-to-cache-id disabled"() { given: "Pbs config with append-trace-info-to-cache-id" def bannerHostTtl = PBSUtils.getRandomNumber(300, 1500) def serverDataCenter = PBSUtils.randomString - def pbsConfig = ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), - 'datacenter-region' : serverDataCenter, - 'cache.append-trace-info-to-cache-id': 'false' - ] - def pbsService = pbsServiceFactory.getService(pbsConfig) + def config = new PbsContainerConfig( + ['cache.default-ttl-seconds.banner' : bannerHostTtl.toString(), + 'datacenter-region' : serverDataCenter, + 'cache.append-trace-info-to-cache-id': 'false']) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -369,9 +352,6 @@ class CacheSpec extends BaseSpec { def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[ACCOUNT_JSON_CREATIVE_TTL_METRIC.formatted(bidRequest.accountId)] == bannerHostTtl assert metrics[ACCOUNT_REQUEST_OK_METRIC.formatted(bidRequest.accountId)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should not cache bids when targeting isn't specified"() { @@ -485,10 +465,11 @@ class CacheSpec extends BaseSpec { def "PBS shouldn't cache bids when targeting is specified and config cache is invalid"() { given: "Pbs config with cache" - def INVALID_PREBID_CACHE_CONFIG = ["cache.path" : CACHE_PATH, - "cache.scheme": HTTP_SCHEME, - "cache.host" : CACHE_HOST] - def pbsService = pbsServiceFactory.getService(INVALID_PREBID_CACHE_CONFIG) + def config = new PbsContainerConfig( + ["cache.path" : CACHE_PATH, + "cache.scheme": HTTP_SCHEME, + "cache.host" : CACHE_HOST]) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -506,18 +487,16 @@ class CacheSpec extends BaseSpec { assert bidResponse.seatbid[0].bid[0].ext.prebid.targeting.findAll { it.key.startsWith("hb_cache") }.isEmpty() and: "PBS shouldn't call PBC" - assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 0 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(INVALID_PREBID_CACHE_CONFIG) + assert !prebidCache.getRequestCount(bidRequest.imp[0].id) } def "PBS should cache bids and emit error when targeting is specified and config cache is valid and internal is invalid"() { given: "Pbs config with cache" - def INVALID_PREBID_CACHE_CONFIG = ["cache.internal.path" : CACHE_PATH, - "cache.internal.scheme": HTTP_SCHEME, - "cache.internal.host" : CACHE_HOST] - def pbsService = pbsServiceFactory.getService(INVALID_PREBID_CACHE_CONFIG) + def config = new PbsContainerConfig( + ["cache.internal.path" : CACHE_PATH, + "cache.internal.scheme": HTTP_SCHEME, + "cache.internal.host" : CACHE_HOST]) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -527,8 +506,8 @@ class CacheSpec extends BaseSpec { when: "PBS processes auction request" def bidResponse = pbsService.sendAuctionRequest(bidRequest) - then: "PBS should call PBC" - assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 0 + then: "PBS shouldn't call PBC" + assert !prebidCache.getRequestCount(bidRequest.imp[0].id) and: "Seat bid shouldn't be discarded" assert !bidResponse.seatbid.isEmpty() @@ -544,20 +523,18 @@ class CacheSpec extends BaseSpec { then: "Response should contain error" assert bidResponse.ext?.errors[CACHE]*.code == [999] assert bidResponse.ext?.errors[CACHE]*.message[0] == ("Failed to resolve '${CACHE_HOST.tokenize(":")[0]}' [A(1)]") - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(INVALID_PREBID_CACHE_CONFIG) } def "PBS should cache bids when targeting is specified and config cache is invalid and internal cache config valid"() { given: "Pbs config with cache" - def INVALID_PREBID_CACHE_CONFIG = ["cache.path" : CACHE_PATH, - "cache.scheme": HTTPS_SCHEME, - "cache.host" : CACHE_HOST,] - def VALID_INTERNAL_CACHE_CONFIG = ["cache.internal.scheme": HTTP_SCHEME, - "cache.internal.host" : "$networkServiceContainer.hostAndPort".toString(), - "cache.internal.path" : INTERNAL_CACHE_PATH,] - def pbsService = pbsServiceFactory.getService(INVALID_PREBID_CACHE_CONFIG + VALID_INTERNAL_CACHE_CONFIG) + def config = new PbsContainerConfig( + ['cache.path' : CACHE_PATH, + 'cache.scheme' : HTTPS_SCHEME, + 'cache.host' : CACHE_HOST, + 'cache.internal.scheme': HTTP_SCHEME, + 'cache.internal.host' : networkServiceContainer.hostAndPort.toString(), + 'cache.internal.path' : INTERNAL_CACHE_PATH]) + def pbsService = pbsServiceFactory.getService(config) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -567,7 +544,7 @@ class CacheSpec extends BaseSpec { when: "PBS processes auction request" def bidResponse = pbsService.sendAuctionRequest(bidRequest) - then: "PBS shouldn't call PBC" + then: "PBS should call PBC" assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 1 and: "Bid response targeting should contain value" @@ -583,17 +560,15 @@ class CacheSpec extends BaseSpec { and: "Debug should contain http call" assert bidResponse.ext.debug.httpcalls['cache'][0].uri == "${HTTPS_SCHEME}://${CACHE_HOST + CACHE_PATH}" - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(INVALID_PREBID_CACHE_CONFIG + VALID_INTERNAL_CACHE_CONFIG) } def "PBS should cache bids when targeting is specified and config cache and internal cache config valid"() { given: "Pbs config with cache" - def VALID_INTERNAL_CACHE_CONFIG = ["cache.internal.scheme": HTTP_SCHEME, - "cache.internal.host" : "$networkServiceContainer.hostAndPort".toString(), - "cache.internal.path" : INTERNAL_CACHE_PATH] - def pbsService = pbsServiceFactory.getService(VALID_INTERNAL_CACHE_CONFIG) + def pbsConfig = new PbsContainerConfig( + ["cache.internal.scheme": HTTP_SCHEME, + "cache.internal.host" : "$networkServiceContainer.hostAndPort".toString(), + "cache.internal.path" : INTERNAL_CACHE_PATH]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default BidRequest with cache, targeting" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -619,9 +594,6 @@ class CacheSpec extends BaseSpec { and: "Debug should contain http call" assert bidResponse.ext.debug.httpcalls['cache'][0].uri == "${HTTP_SCHEME}://${networkServiceContainer.hostAndPort + INTERNAL_CACHE_PATH}" - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(VALID_INTERNAL_CACHE_CONFIG) } def "PBS should cache bids and add targeting values when account cache config #accountAuctionConfig"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/CacheVtrackSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/CacheVtrackSpec.groovy index bfab691b3f3..65928a35970 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/CacheVtrackSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/CacheVtrackSpec.groovy @@ -12,6 +12,7 @@ import org.prebid.server.functional.model.request.vtrack.xml.Vast import org.prebid.server.functional.model.response.vtrack.TransferValue import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST @@ -37,12 +38,12 @@ class CacheVtrackSpec extends BaseSpec { private static final String CACHE_HOST = "${PBSUtils.randomString}:${PBSUtils.getRandomNumber(0, 65535)}".toString() private static final String HTTP_SCHEME = 'http' - private static final Map INVALID_PREBID_CACHE_CONFIG = ["cache.path" : CACHE_PATH, + private static final PbsContainerConfig INVALID_PREBID_CACHE_CONFIG = new PbsContainerConfig(["cache.path" : CACHE_PATH, "cache.scheme": HTTP_SCHEME, - "cache.host" : CACHE_HOST] - private static final Map VALID_INTERNAL_CACHE = ["cache.internal.scheme": HTTP_SCHEME, + "cache.host" : CACHE_HOST]) + private static final PbsContainerConfig VALID_INTERNAL_CACHE = new PbsContainerConfig(["cache.internal.scheme": HTTP_SCHEME, "cache.internal.host" : "$networkServiceContainer.hostAndPort".toString(), - "cache.internal.path" : CACHE_ENDPOINT] + "cache.internal.path" : CACHE_ENDPOINT]) private static PrebidServerService pbsServiceWithInternalCache def setupSpec() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/CookieSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/CookieSyncSpec.groovy deleted file mode 100644 index 43453891d1a..00000000000 --- a/src/test/groovy/org/prebid/server/functional/tests/CookieSyncSpec.groovy +++ /dev/null @@ -1,2397 +0,0 @@ -//file:noinspection GroovyGStringKey -package org.prebid.server.functional.tests - -import org.prebid.server.functional.model.UidsCookie -import org.prebid.server.functional.model.bidder.BidderName -import org.prebid.server.functional.model.config.AccountAuctionConfig -import org.prebid.server.functional.model.config.AccountCcpaConfig -import org.prebid.server.functional.model.config.AccountConfig -import org.prebid.server.functional.model.config.AccountCookieSyncConfig -import org.prebid.server.functional.model.config.AccountCoopSyncConfig -import org.prebid.server.functional.model.config.AccountPrivacyConfig -import org.prebid.server.functional.model.config.PrivacySandbox -import org.prebid.server.functional.model.db.Account -import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest -import org.prebid.server.functional.model.request.cookiesync.FilterSettings -import org.prebid.server.functional.model.request.cookiesync.MethodFilter -import org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse -import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo -import org.prebid.server.functional.service.PrebidServerException -import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.util.HttpUtil -import org.prebid.server.functional.util.PBSUtils -import org.prebid.server.functional.util.privacy.CcpaConsent -import org.prebid.server.functional.util.privacy.TcfConsent - -import java.time.Instant -import java.util.concurrent.TimeUnit - -import static org.prebid.server.functional.model.AccountStatus.ACTIVE -import static org.prebid.server.functional.model.bidder.BidderName.AAX -import static org.prebid.server.functional.model.bidder.BidderName.ACEEX -import static org.prebid.server.functional.model.bidder.BidderName.ACUITYADS -import static org.prebid.server.functional.model.bidder.BidderName.ADKERNEL -import static org.prebid.server.functional.model.bidder.BidderName.ALIAS -import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS -import static org.prebid.server.functional.model.bidder.BidderName.BOGUS -import static org.prebid.server.functional.model.bidder.BidderName.GENERIC -import static org.prebid.server.functional.model.bidder.BidderName.OPENX -import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE -import static org.prebid.server.functional.model.request.cookiesync.FilterType.EXCLUDE -import static org.prebid.server.functional.model.request.cookiesync.FilterType.INCLUDE -import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.NO_COOKIE -import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.OK -import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Format.BLANK -import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Format.PIXEL -import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.IFRAME -import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT -import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer -import static org.prebid.server.functional.util.HttpUtil.SET_COOKIE_HEADER -import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED -import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID -import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS -import static org.prebid.server.functional.util.privacy.TcfConsent.MAGNITE_VENDOR_ID - -class CookieSyncSpec extends BaseSpec { - - private static final UserSyncInfo.Type USER_SYNC_TYPE = REDIRECT - private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync" - private static final String ALL_BIDDERS = "*" - private static final Integer DEFAULT_PBS_BIDDERS_SIZE = 8 - - private static final Map GENERIC_CONFIG = [ - "adapters.${GENERIC.value}.usersync.redirect.url" : USER_SYNC_URL, - "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String] - private static final Map ACEEX_CONFIG = [ - "adapters.${ACEEX.value}.enabled" : "true", - "adapters.${ACEEX.value}.usersync.cookie-family-name" : ACEEX.value, - "adapters.${ACEEX.value}.usersync.redirect.url" : "https://test.redirect.endpoint.com={redirect_url}"] - private static final Map MAGNITE_CONFIG = [ - "adapters.${MAGNITE.value}.enabled" : "true", - "adapters.${MAGNITE.value}.meta-info.vendor-id" : MAGNITE_VENDOR_ID as String, - "adapters.${MAGNITE.value}.usersync.cookie-family-name" : MAGNITE.value, - "adapters.${MAGNITE.value}.usersync.redirect.url" : "https://test.redirect.endpoint.com", - "adapters.${MAGNITE.value}.usersync.iframe.url" : "https://test.iframe.endpoint.com&redir={redirect_url}"] - private static final Map OPENX_CONFIG = [ - "adapters.${OPENX.value}.enabled" : "true", - "adapters.${OPENX.value}.usersync.cookie-family-name" : OPENX.value, - "adapters.${OPENX.value}.usersync.redirect.url" : USER_SYNC_URL, - "adapters.${OPENX.value}.usersync.iframe.url" : USER_SYNC_URL] - private static final Map APPNEXUS_CONFIG = [ - "adapters.${APPNEXUS.value}.enabled" : "true", - "adapters.${APPNEXUS.value}.aliases.mediafuse.enabled" : "false", - "adapters.${APPNEXUS.value}.usersync.cookie-family-name" : APPNEXUS.value, - "adapters.${APPNEXUS.value}.usersync.redirect.url" : "https://test.appnexus.redirect.com/getuid?{redirect_url}"] - private static final Map AAX_CONFIG = ["adapters.${AAX.value}.enabled": "true"] - private static final Map ACUITYADS_CONFIG = ["adapters.${ACUITYADS.value}.enabled": "true"] - private static final Map ADKERNEL_CONFIG = [ - "adapters.${ADKERNEL.value}.enabled" : "true", - "adapters.${ADKERNEL.value}.aliases.rxnetwork.enabled": "false", - "adapters.${ADKERNEL.value}.aliases.152media.enabled" : "false" - - ] - - private static final Map PBS_CONFIG = APPNEXUS_CONFIG + MAGNITE_CONFIG + OPENX_CONFIG + - GENERIC_CONFIG + ACEEX_CONFIG + AAX_CONFIG + ACUITYADS_CONFIG + ADKERNEL_CONFIG + - ["cookie-sync.pri": "grid, ix, adkernel"] - - private final PrebidServerService prebidServerService = pbsServiceFactory.getService(PBS_CONFIG) - - def "PBS cookie sync request shouldn't replace synced as family bidder and fill up response with enabled bidders to the limit in request"() { - given: "PBS config with alias bidder without cookie family name" - def bidderAlias = ALIAS - def prebidServerService = pbsServiceFactory.getService(GENERIC_CONFIG + APPNEXUS_CONFIG - + ["adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": null]) - - and: "Default cookie sync request" - def requestLimit = 2 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [bidderAlias] - limit = requestLimit - coopSync = true - debug = false - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain synced bidder" - assert response.bidderStatus.size() == requestLimit - - and: "Response shouldn't contain family bidder" - assert !response.getBidderUserSync(GENERIC) - - and: "Response should contain coop-synced bidder" - assert response.getBidderUserSync(bidderAlias) - assert response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync should use requested bidder name in sync url instead of cookie family name"() { - given: "PBS config with alias bidder using source bidder cookie family name" - def bidderAlias = ALIAS - def prebidServerService = pbsServiceFactory.getService(GENERIC_CONFIG + - ["adapters.${GENERIC.value}.usersync.redirect.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": GENERIC.value]) - - and: "Cookie sync request for alias bidder" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [bidderAlias] - limit = 1 - coopSync = true - debug = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain source bidder" - assert !response.getBidderUserSync(GENERIC) - - and: "Response should contain alias bidder sync" - def bidderStatus = response.getBidderUserSync(bidderAlias) - - and: "Sync url should contain requested bidder name" - assert bidderStatus.userSync.url.contains("setuid%3Fbidder%3D${bidderAlias}") - - and: "Sync url shouldn't contain cookie family name" - assert !bidderStatus.userSync.url.contains("setuid%3Fbidder%3D${GENERIC}") - } - - def "PBS cookie sync request should replace bidder without config and fill up response with enabled bidders to the limit in request"() { - given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(MAGNITE_CONFIG + GENERIC_CONFIG - + ["adapters.${BOGUS.value}.enabled": "true"]) - - and: "Default Cookie sync request" - def requestLimit = 2 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [BOGUS] - limit = requestLimit - coopSync = true - debug = false - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain synced bidder" - assert response.bidderStatus.size() == requestLimit - - and: "Response shouldn't contain bogus" - assert !response.getBidderUserSync(BOGUS) - - and: "Response should contain coop-synced bidder" - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request should replace unknown bidder and fill up response with enabled bidders to the limit in request"() { - given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(MAGNITE_CONFIG + APPNEXUS_CONFIG) - - and: "Cookie sync request" - def requestLimit = 2 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [BOGUS] - limit = requestLimit - coopSync = true - debug = false - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain synced bidder" - assert response.bidderStatus.size() == requestLimit - - and: "Response shouldn't contain bogus" - assert !response.getBidderUserSync(BOGUS) - - and: "Response should contain coop-synced bidder" - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request should replace disabled bidder and fill up response with enabled bidders to the limit in request"() { - given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(MAGNITE_CONFIG + APPNEXUS_CONFIG - + ["adapters.${GENERIC.value}.enabled": "false",]) - - and: "Default Cookie sync request" - def requestLimit = 2 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC] - limit = requestLimit - coopSync = true - debug = false - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain synced bidder" - assert response.bidderStatus.size() == requestLimit - - and: "Response shouldn't contain generic" - assert !response.getBidderUserSync(GENERIC) - - and: "Response should contain coop-synced bidder" - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request should replace filtered bidder and fill up response with enabled bidders to the limit in request"() { - given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(MAGNITE_CONFIG + APPNEXUS_CONFIG) - - and: "Cookie sync request" - def requestLimit = 2 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC] - limit = requestLimit - coopSync = true - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) - debug = false - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain synced bidder" - assert response.bidderStatus.size() == requestLimit - - and: "Response shouldn't contain generic" - assert !response.getBidderUserSync(GENERIC) - - and: "Response should contain coop-synced bidder" - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder disabled"() { - given: "PBS bidder config " - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.enabled": "false"]) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = true - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't return error" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder without sync config"() { - given: "PBS bidder config without cookie family name" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.${GENERIC.value}.usersync.cookie-family-name": null]) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = true - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't return error" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder family already in uids cookie"() { - given: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = true - } - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response shouldn't return error" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder synced"() { - given: "PBS config with alias bidder without cookie family name" - def bidderAlias = ALIAS - def prebidServerService = pbsServiceFactory.getService(GENERIC_CONFIG - + ["adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": null]) - - and: "Cookie sync request with 2 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [bidderAlias] - coopSync = true - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain bidder error" - def bidderStatus = response.getBidderUserSync(bidderAlias) - assert !bidderStatus?.error - - and: "Response should indicate bidder has no cookie" - assert bidderStatus?.noCookie == true - - and: "Response should contain bidder user sync information" - verifyAll(bidderStatus?.userSync) { - it.url == USER_SYNC_URL - it.type == REDIRECT - } - } - - def "PBS cookie sync request should reflect error when coop-sync enabled and coop sync bidder with gdpr"() { - given: "Valid consent string" - def validConsentString = new TcfConsent.Builder() - .setPurposesLITransparency(BASIC_ADS) - .setVendorLegitimateInterest([GENERIC_VENDOR_ID]) - .setDisclosedVendors([GENERIC_VENDOR_ID]) - .build() - - and: "Cookie sync request with gdpr and gdprConsent" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [] - coopSync = true - gdpr = 1 - gdprConsent = validConsentString - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Rejected by TCF" - - and: "Metric should contain cookie_sync.BIDDER.tcf.blocked" - def metric = this.prebidServerService.sendCollectedMetricsRequest() - assert metric["cookie_sync.generic.tcf.blocked"] == 1 - } - - def "PBS cookie sync request should reflect error when coop-sync enabled and coop sync bidder with ccpa"() { - given: "PBS bidder config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["adapters.${bidderName.value}.ccpa-enforced": "true"] + GENERIC_CONFIG) - - and: "Cookie sync request with account and privacy" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [] - account = PBSUtils.randomString - usPrivacy = new CcpaConsent(optOutSale: ENFORCED) - coopSync = true - } - - and: "Save account config into DB" - def ccpaConfig = new AccountCcpaConfig(enabled: true) - def accountConfig = new AccountConfig(privacy: new AccountPrivacyConfig(ccpa: ccpaConfig)) - def account = new Account(uuid: cookieSyncRequest.account, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(bidderName) - assert bidderStatus.error == "Rejected by CCPA" - } - - def "PBS cookie sync request should reflect error when coop-sync enabled and coop sync bidder filtered"() { - given: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [] - coopSync = true - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Rejected by request filter" - - and: "Metric should contain cookie_sync.generic.filtered" - def metric = prebidServerService.sendCollectedMetricsRequest() - assert metric["cookie_sync.generic.filtered"] == 1 - } - - def "PBS cookie sync request should reflect error even when response is full by account cookie sync config limit"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - } - - and: "Save account with cookie config" - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain 1 valid bidder and 1 bidder with error" - assert response.bidderStatus.size() == 2 - - and: "Response should contain valid generic" - assert response.getBidderUserSync(GENERIC) - - and: "Response should contain invalid bogus bidder" - def bogusBidderStatus = response.getBidderUserSync(BOGUS) - assert bogusBidderStatus?.error == "Unsupported bidder" - assert bogusBidderStatus?.noCookie == null - assert bogusBidderStatus?.userSync == null - - where: - accountConfig << [new AccountConfig(status: ACTIVE, cookieSync: new AccountCookieSyncConfig(defaultLimit: 1)), - new AccountConfig(status: ACTIVE, cookieSyncSnakeCase: new AccountCookieSyncConfig(defaultLimit: 1))] - } - - def "PBS cookie sync request should reflect error even when response is full by PBS config limit"() { - given: "PBS config with expanded limit" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": "1"] + PBS_CONFIG) - - and: "Default cookie sync request with coop-sync and without bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain 1 valid bidder and 1 bidder with error" - assert response.bidderStatus.size() == 2 - - and: "Response should contain generic" - assert response.getBidderUserSync(GENERIC) - - and: "Response should contain error for bogus bidder" - def bogusBidderStatus = response.getBidderUserSync(BOGUS) - assert bogusBidderStatus?.error == "Unsupported bidder" - assert bogusBidderStatus?.noCookie == null - assert bogusBidderStatus?.userSync == null - } - - def "PBS cookie sync request should reflect error even when response is full by request limit"() { - given: "Cookie sync request" - def cookieSyncRequest = CookieSyncRequest.getDefaultCookieSyncRequest().tap { - bidders = [GENERIC, BOGUS] - limit = 1 - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain 1 valid bidder and 1 bidder with error" - assert response.bidderStatus.size() == 2 - - and: "Response should contain generic" - assert response.getBidderUserSync(GENERIC) - - and: "Response should contain error for bogus bidder" - def bogusBidderStatus = response.getBidderUserSync(BOGUS) - assert bogusBidderStatus?.error == "Unsupported bidder" - assert bogusBidderStatus?.noCookie == null - assert bogusBidderStatus?.userSync == null - } - - def "PBS cookie sync request with valid uids cookie should return status OK without user sync information"() { - given: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response should contain information about bidder status" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Already in sync" - assert bidderStatus?.userSync == null - assert bidderStatus?.noCookie == null - } - - def "PBS cookie sync request without uids cookie should return bidder user sync information"() { - given: "Default Cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain sync information for configured bidder" - assert response.bidderStatus.size() == 1 - - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) - assert bidderStatus?.userSync?.type == USER_SYNC_TYPE - assert bidderStatus?.noCookie == true - } - - def "PBS cookie sync request should not emit error for already synced bidder without debug flag"() { - given: "Default cookie sync request without debug flag" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - debug = false - } - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response should not contain information about bidder status" - assert response.bidderStatus.size() == 0 - } - - def "PBS cookie sync should preserve requested bidder when cookie family name is configured"() { - given: "PBS bidder config with configured cookie family name" - def bidder = BOGUS - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.usersync.cookie-family-name": bidder.value]) - - and: "Cookie sync request for generic bidder" - def cookieSyncRequest = CookieSyncRequest.getDefaultCookieSyncRequest([GENERIC]) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain requested bidder" - assert response.bidderStatus.size() == 1 - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) - assert bidderStatus?.userSync?.type == USER_SYNC_TYPE - assert bidderStatus?.noCookie == true - } - - def "PBS cookie sync should be able to read custom cookie family name from uids cookie"() { - given: "PBS bidder config with defined cookie family name" - def bidder = BOGUS - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + - ["adapters.${GENERIC.value}.usersync.cookie-family-name": bidder.value]) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - def uidsCookie = UidsCookie.getDefaultUidsCookie(bidder) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response should contain information about bidder status" - assert response.bidderStatus.size() == 1 - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Already in sync" - assert bidderStatus?.userSync == null - assert bidderStatus?.noCookie == null - } - - def "PBS cookie sync request with unknown bidder respond with an error for that bidder"() { - given: "Default cookie sync request with bogus bidder" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain information for all requested bidders" - assert response.status == NO_COOKIE - assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() - - and: "Response should contain error for unknown bidder" - def unknownBidderStatus = response.getBidderUserSync(BOGUS) - assert unknownBidderStatus?.error == "Unsupported bidder" - assert unknownBidderStatus?.noCookie == null - assert unknownBidderStatus?.userSync == null - - and: "Response should contain sync information for configured bidder" - def configuredBidderStatus = response.getBidderUserSync(GENERIC) - assert configuredBidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) - assert configuredBidderStatus?.userSync?.type == USER_SYNC_TYPE - assert configuredBidderStatus?.noCookie == true - } - - def "PBS cookie sync request with bidder without cookie family name should emit an error"() { - given: "PBS bidder config without cookie family name" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.${GENERIC.value}.usersync.cookie-family-name": null]) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.error == "No sync config" - assert bidderStatus?.noCookie == null - assert bidderStatus?.userSync == null - } - - def "PBS cookie sync request with disabled bidder should emit an error"() { - given: "PBS config with disabled bidder" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.${GENERIC.value}.enabled": "false"]) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.error == "Disabled bidder" - assert bidderStatus?.noCookie == null - assert bidderStatus?.userSync == null - } - - def "PBS cookie sync with enabled coop-sync should sync all enabled bidders"() { - given: "PBS config with expanded limit" - def countOfEnabledBidders = 3 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": countOfEnabledBidders.toString()] + PBS_CONFIG) - - and: "Default cookie sync request with coop-sync and without bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = true - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain all 3 enabled bidders" - assert response.bidderStatus.size() == countOfEnabledBidders - } - - def "PBS cookie sync request should resolve alias and source bidder into a single sync when alias doesn't override cookie-family-name"() { - given: "PBS config with alias bidder without cookie family name" - def bidderAlias = ALIAS - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": null]) - - and: "Cookie sync request with 2 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, bidderAlias] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain sync information for single resolved bidder" - def validBidderUserSyncs = getValidBidderUserSyncs(response).values().toList() - verifyAll(validBidderUserSyncs) { - it.url == [USER_SYNC_URL] - it.type == [USER_SYNC_TYPE] - } - - and: "Response should contain duplicate bidder error" - def rejectedBidderStatus = getRejectedBidderUserSyncs(response).values().toList() - assert rejectedBidderStatus == ["Duplicate bidder synced as ${GENERIC.value}"] - } - - def "PBS cookie sync request with alias bidder should sync independently when alias provide cookie-family-name"() { - given: "PBS config with alias bidder with cookie family name" - def bidderAlias = ALIAS - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG - + ["adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", - "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": bidderAlias.value]) - - and: "Cookie sync request with 2 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, bidderAlias] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "PBS should return sync for both bidders" - assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() - response.bidderStatus.each { - assert it.userSync?.url?.startsWith(USER_SYNC_URL) - assert it.userSync?.type == USER_SYNC_TYPE - assert it.noCookie == true - } - } - - def "PBS cookie sync request with host cookie should return bidder sync with host cookie uid when there is no uids cookie"() { - given: "PBS bidders config" - def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService( - ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name": cookieName] + PBS_CONFIG) - - and: "Default cookie sync request" - def uidsCookie = UidsCookie.defaultUidsCookie - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC] - } - - and: "Host cookie" - def uid = UUID.randomUUID().toString() - def cookies = [(cookieName): uid] - - when: "PBS processes cookie sync request with cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) - - then: "Response should contain uid from cookies" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert HttpUtil.decodeUrl(bidderStatus.userSync?.url).contains("uid=${uid}") - } - - def "PBS cookie sync request with host cookie should return bidder sync with host cookie uid when uids are different"() { - given: "PBS bidders config" - def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService( - ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name": cookieName] + PBS_CONFIG) - - and: "Default cookie sync request" - def uidsCookie = UidsCookie.defaultUidsCookie.tap { - tempUIDs[GENERIC].uid = UUID.randomUUID().toString() - } - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC] - } - - and: "Host cookie" - def hostCookieUid = UUID.randomUUID().toString() - def cookies = [(cookieName): hostCookieUid] - - when: "PBS processes cookie sync request with cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) - - then: "Response should contain uid from cookies" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert HttpUtil.decodeUrl(bidderStatus.userSync?.url).contains("uid=${hostCookieUid}") - } - - def "PBS cookie sync request with host cookie should return an error when host cookie uid matches uids cookie uid for bidder"() { - given: "PBS bidders config" - def cookieName = PBSUtils.randomString - def prebidServerService = pbsServiceFactory.getService( - ["host-cookie.family" : GENERIC.value, - "host-cookie.cookie-name": cookieName] + PBS_CONFIG) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - - and: "Default uids cookie" - def uid = UUID.randomUUID().toString() - def uidsCookie = UidsCookie.defaultUidsCookie.tap { - tempUIDs[GENERIC].uid = uid - } - - and: "Host cookie" - def cookies = [(cookieName): uid] - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) - - then: "Response should contain already in sync bidder" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.error == "Already in sync" - assert bidderStatus?.noCookie == null - assert bidderStatus?.userSync == null - } - - def "PBS cookie sync request with host cookie shouldn't return bidder sync when host cookie doesn't match requested bidder"() { - given: "PBS bidders config" - def prebidServerService = pbsServiceFactory.getService( - ["host-cookie.family" : PBSUtils.randomString, - "host-cookie.cookie-name": PBSUtils.randomString] + PBS_CONFIG) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should contain already in sync bidder" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.error == "Already in sync" - assert bidderStatus?.noCookie == null - assert bidderStatus?.userSync == null - - where: - hostCookieFamily || hostCookieName - PBSUtils.randomString || PBSUtils.randomString - null || PBSUtils.randomString - PBSUtils.randomString || null - } - - def "PBS cookie sync request with host cookie shouldn't return bidder sync when host cookie doesn't have configured name"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["host-cookie.family" : bidderName.value, - "host-cookie.cookie-name": null] + PBS_CONFIG) - - and: "Default cookie sync request" - def uidsCookie = UidsCookie.defaultUidsCookie - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [bidderName] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should contain already in sync bidder" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus?.error == "Already in sync" - assert bidderStatus?.noCookie == null - assert bidderStatus?.userSync == null - } - - def "PBS cookie sync without cookie-sync.default-limit config and with cookie sync account config limit should use limit from request"() { - given: "Default cookie sync request with 3 bidders" - def requestLimit = 1 - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - limit = requestLimit - bidders = [MAGNITE, APPNEXUS, GENERIC] - account = accountId - debug = false - } - - and: "Save account with cookie sync config" - def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: 2) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain one synced bidder" - assert response.bidderStatus.size() == requestLimit - } - - def "PBS cookie sync with cookie-sync.default-limit config should use limit from cookie sync account config"() { - given: "PBS bidders config" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": "2"] + PBS_CONFIG) - - and: "Default cookie sync request with 3 bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [MAGNITE, APPNEXUS, GENERIC] - account = accountId - debug = false - } - - and: "Save account with cookie config" - def accountDefaultLimit = 1 - def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: accountDefaultLimit) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain one synced bidder" - assert response.bidderStatus.size() == accountDefaultLimit - } - - def "PBS cookie sync with cookie-sync.default-limit config should use limit from request"() { - given: "PBS config" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": "2"] + PBS_CONFIG) - - and: "Default cookie sync request with 3 bidders" - def requestLimit = 1 - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - limit = requestLimit - bidders = [MAGNITE, APPNEXUS, GENERIC] - debug = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only two synced bidder" - assert response.bidderStatus.size() == requestLimit - } - - def "PBS cookie sync with cookie-sync.default-limit config should use limit from PBS config"() { - given: "PBS config" - def defaultLimit = 1 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": defaultLimit.toString()] + PBS_CONFIG) - - and: "Default cookie sync request with 2 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, MAGNITE] - debug = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only one synced bidder" - assert response.bidderStatus.size() == defaultLimit - } - - def "PBS cookie sync with cookie-sync.max-limit should use max-limit from PBS config"() { - given: "PBS bidders config" - def maxLimit = 2 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.max-limit" : maxLimit.toString(), - "cookie-sync.default-limit": "1"] + PBS_CONFIG) - - and: "Default cookie sync request with 3 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, APPNEXUS, MAGNITE] - limit = 5 - debug = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only one synced bidder" - assert response.bidderStatus.size() == maxLimit - } - - def "PBS cookie sync with cookie-sync.max-limit should use max-limit from cookie sync account config"() { - given: "PBS bidders config" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": "1", - "cookie-sync.max-limit" : "1"] + PBS_CONFIG) - - and: "Default cookie sync request with 3 bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, APPNEXUS, MAGNITE] - limit = 5 - account = accountId - debug = false - } - - and: "Save account with cookie sync config" - def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: accountMaxLimit, maxLimitSnakeCase: accountMaxLimitSnakeCase) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only two synced bidder" - assert response.bidderStatus.size() == 2 - - where: - accountMaxLimit | accountMaxLimitSnakeCase - 2 | null - null | 2 - } - - def "PBS cookie sync with cookie-sync.pri and enabled coop-sync in config should sync bidder which present in cookie-sync.pri config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.coop-sync.default": "true", - "cookie-sync.pri" : bidderName.value] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain generic bidder from cookie-sync.pri config" - def genericBidder = response.getBidderUserSync(bidderName) - assert genericBidder?.userSync?.url - assert genericBidder?.userSync?.type - } - - def "PBS cookie sync with cookie-sync.pri and disabled coop-sync in config shouldn't sync bidder which present in cookie-sync.pir config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.coop-sync.default": "false", - "cookie-sync.pri" : bidderName.value] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain generic bidder from cookie-sync.pri config" - assert !response.getBidderUserSync(bidderName) - } - - def "PBS cookie sync with cookie-sync.pri and in all places disabled coop sync in account shouldn't sync bidder which present in cookie-sync.pir config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : bidderName.value, - "cookie-sync.coop-sync.default": "false"] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: false)) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain generic bidder which present in cookie-sync.pri config" - assert !response.getBidderUserSync(bidderName) - } - - def "PBS cookie sync should sync bidder by limit value"() { - given: "PBS config with bidders usersync config" - def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG) - - and: "Default cookie sync request with 2 bidders and limit of 1" - def limit = 1 - def bidders = [GENERIC, MAGNITE] - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - it.limit = limit - it.bidders = bidders - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only one valid user sync" - def validBidderUserSyncs = getValidBidderUserSyncs(response) - assert validBidderUserSyncs.size() == limit - validBidderUserSyncs.every { - it.value.url - it.value.type - } - - and: "Discarded bidder user sync should contain an error" - def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) - assert rejectedBidderUserSyncs.size() == bidders.size() - limit - assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } - } - - def "PBS cookie sync with enabled coop-sync in request and when bidder invalid should log error: bidder is provided for prioritized coop-syncing but #reason"() { - given: "Start time" - def startTime = Instant.now() - - and: "PBS config" - def prebidServerService = pbsServiceFactory.getService(config) - - and: "Cookie sync request with coop-sync" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - coopSync = true - } - - when: "PBS processes cookie sync request" - prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "PBS log should contain message" - def logs = prebidServerService.getLogsByTime(startTime) - assert getLogsByText(logs, reason).size() == 1 - - where: - reason | config - "is invalid bidder name, ignoring" | ["cookie-sync.pri": PBSUtils.randomString] - "disabled in current pbs instance, ignoring" | ["adapters.generic.enabled": "false", - "cookie-sync.pri" : GENERIC.value] - "has no user-sync configuration, ignoring" | ["adapters.generic.usersync.cookie-family-name": "null", - "cookie-sync.pri" : GENERIC.value] - } - - def "PBS cookie sync with enabled coop-sync in PBS config and when bidder invalid should log error: bidder is provided for prioritized coop-syncing but #reason"() { - given: "Start time" - def startTime = Instant.now() - - and: "PBS config" - def prebidServerService = pbsServiceFactory.getService(config + - ["cookie-sync.coop-sync.default": "true"]) - - and: "Cookie sync request with coop-sync" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - coopSync = null - } - - when: "PBS processes cookie sync request" - prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "PBS log should contain message" - def logs = prebidServerService.getLogsByTime(startTime) - assert getLogsByText(logs, reason).size() == 1 - - where: - reason | config - "is invalid bidder name, ignoring" | ["cookie-sync.pri": PBSUtils.randomString] - "disabled in current pbs instance, ignoring" | ["adapters.generic.enabled": "false", - "cookie-sync.pri" : GENERIC.value] - "has no user-sync configuration, ignoring" | ["adapters.generic.usersync.cookie-family-name": "null", - "cookie-sync.pri" : GENERIC.value] - } - - def "PBS cookie sync with enabled coop-sync in account cookie sync and when bidder invalid should log error: bidder is provided for prioritized coop-syncing but #reason"() { - given: "Start time" - def startTime = Instant.now() - - and: "PBS config" - def prebidServerService = pbsServiceFactory.getService(config + - ["cookie-sync.coop-sync.default": "false"]) - - and: "Cookie sync request with disabled coop-sync" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - coopSync = null - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: false)) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "PBS log should contain message" - def logs = prebidServerService.getLogsByTime(startTime) - assert getLogsByText(logs, reason).size() == 1 - - where: - reason | config - "is invalid bidder name, ignoring" | ["cookie-sync.pri": PBSUtils.randomString] - "disabled in current pbs instance, ignoring" | ["adapters.generic.enabled": "false", - "cookie-sync.pri" : GENERIC.value] - "has no user-sync configuration, ignoring" | ["adapters.generic.usersync.cookie-family-name": "null", - "cookie-sync.pri" : GENERIC.value] - } - - def "PBS cookie sync with cookie-sync.pri and enabled coop sync should sync bidder which present in cookie-sync.pri"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : bidderName.value, - "cookie-sync.coop-sync.default": "false"] + GENERIC_CONFIG) - - and: "Default cookie sync request with coop-sync" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = true - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain generic bidder" - def genericBidder = response.getBidderUserSync(bidderName) - assert genericBidder?.userSync?.url - assert genericBidder?.userSync?.type - } - - def "PBS cookie sync with pri and enabled coop sync in cookie sync account should sync bidder which present in pir account config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : "null", - "cookie-sync.coop-sync.default": "false"] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(pri: [bidderName.value], coopSync: new AccountCoopSyncConfig(enabled: true)) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain generic bidder from pri account config" - def genericBidder = response.getBidderUserSync(bidderName) - assert genericBidder?.userSync?.url - assert genericBidder?.userSync?.type - } - - def "PBS cookie sync with coop-sync.default config and pri in cookie sync account should sync bidder which present in pir account config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : "null", - "cookie-sync.coop-sync.default": "true"] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(pri: [bidderName.value]) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain generic bidder from pri account config" - def genericBidder = response.getBidderUserSync(bidderName) - assert genericBidder?.userSync?.url - assert genericBidder?.userSync?.type - } - - def "PBS cookie sync with cookie-sync.pri and enabled coop sync in account should sync bidder which present in cookie-sync.pir config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : bidderName.value, - "cookie-sync.coop-sync.default": "false"] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = null - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: true)) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain generic bidder from cookie-sync.pri config" - def genericBidder = response.getBidderUserSync(bidderName) - assert genericBidder?.userSync?.url - assert genericBidder?.userSync?.type - } - - def "PBS cookie sync with cookie-sync.pri and disabled coop-sync in request shouldn't sync bidder which present in cookie-sync.pri config"() { - given: "PBS bidders config" - def bidderName = GENERIC - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.pri" : bidderName.value, - "cookie-sync.coop-sync.default": "false"] + GENERIC_CONFIG) - - and: "Default cookie sync request without coop-sync and bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = null - coopSync = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain generic bidder" - assert !response.getBidderUserSync(bidderName) - } - - def "PBS cookie sync with filter setting should reject bidder sync"() { - given: "Cookie sync request with filter settings" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Rejected by request filter" - - and: "Metric should contain cookie_sync.FAMILY.filtered" - def metric = prebidServerService.sendCollectedMetricsRequest() - assert metric["cookie_sync.generic.filtered"] == 1 - } - - def "PBS cookie sync with gdpr should reject bidder sync"() { - given: "Valid consent string" - def validConsentString = new TcfConsent.Builder() - .setPurposesLITransparency(BASIC_ADS) - .setVendorLegitimateInterest([GENERIC_VENDOR_ID]) - .setDisclosedVendors([GENERIC_VENDOR_ID]) - .build() - - and: "Cookie sync request with gdpr and gdprConsent" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - gdpr = 1 - gdprConsent = validConsentString - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Rejected by TCF" - - and: "Metric should contain cookie_sync.BIDDER.tcf.blocked" - def metric = prebidServerService.sendCollectedMetricsRequest() - assert metric["cookie_sync.generic.tcf.blocked"] == 1 - } - - def "PBS cookie sync with ccpa should reject bidder sync"() { - given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.${GENERIC.value}.ccpa-enforced": "true"] + GENERIC_CONFIG) - - and: "Flush metrics" - flushMetrics(prebidServerService) - - and: "Cookie sync request with account and privacy" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = PBSUtils.randomString - usPrivacy = new CcpaConsent(optOutSale: ENFORCED) - } - - and: "Save account config into DB" - def ccpaConfig = new AccountCcpaConfig(enabled: true) - def accountConfig = new AccountConfig(privacy: new AccountPrivacyConfig(ccpa: ccpaConfig)) - def account = new Account(uuid: cookieSyncRequest.account, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(GENERIC) - assert bidderStatus.error == "Rejected by CCPA" - } - - def "PBS cookie sync should emit error when requested bidder rejected by limit"() { - given: "PBS config with bidders usersync config" - def limit = 1 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.max-limit" : limit as String, - "cookie-sync.default-limit": limit as String] + PBS_CONFIG) - - and: "Default cookie sync request with 2 bidders" - def bidders = [GENERIC, MAGNITE] - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - it.bidders = bidders - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain only one valid user sync" - def validBidderUserSyncs = getValidBidderUserSyncs(response) - assert validBidderUserSyncs.size() == limit - - and: "Discarded bidder user sync should contain an error" - def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) - assert rejectedBidderUserSyncs.size() == bidders.size() - limit - assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } - } - - def "PBS cookie sync shouldn't emit error limit reached when bidder coop-synced"() { - given: "PBS config with bidders usersync config" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.max-limit" : "1", - "cookie-sync.default-limit": "1"] + PBS_CONFIG) - - and: "Default cookie sync request with 2 bidders" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - coopSync = true - bidders = [MAGNITE] - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response shouldn't contain generic bidder" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request should successful pass when request body empty"() { - given: "Empty cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest() - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain '#formatParam' format parameter" - def genericBidderStatus = response.getBidderUserSync(ACEEX) - assert genericBidderStatus?.userSync?.type == REDIRECT - assert HttpUtil.findUrlParameterValue(genericBidderStatus.userSync?.url, "f") == PIXEL.name - - and: "Response should contain '#formatParam' format parameter" - def magniteBidderStatus = response.getBidderUserSync(MAGNITE) - assert magniteBidderStatus?.userSync?.type == IFRAME - assert HttpUtil.findUrlParameterValue(magniteBidderStatus.userSync?.url, "f") == BLANK.name - - and: "Response should contain coop-synced bidder" - assert response.bidderStatus.bidder.containsAll(ADKERNEL, ACUITYADS, ACEEX, APPNEXUS, AAX, MAGNITE, OPENX, GENERIC) - } - - def "PBS cookie sync request shouldn't return bidder due to filter setting request"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - image = new MethodFilter().tap { - filter = EXCLUDE - bidders = [APPNEXUS] - } - } - def cookieSyncRequest = new CookieSyncRequest().tap { - it.filterSettings = filterSettings - it.limit = 0 - it.coopSync = false - it.debug = true - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Bidder should be excluded by filter" - assert !response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request should include all bidder due to filterSettings"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: [MAGNITE], filter: INCLUDE) - image = new MethodFilter(bidders: [APPNEXUS], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Bidder should be include by filter" - assert response.getBidderUserSync(APPNEXUS) - assert response.getBidderUserSync(MAGNITE) - } - - def "PBS cookie sync request should exclude all iframe bidders when asterisk present in bidders filterSettings"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: ALL_BIDDERS, filter: EXCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain only bidders with IMAGE" - assert response?.bidderStatus?.every { it.getUserSync().type == REDIRECT } - } - - def "PBS cookie sync request should exclude all image bidders when asterisk present in bidders filterSettings"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - image = new MethodFilter(bidders: ALL_BIDDERS, filter: EXCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contains all bidders with IFRAME" - assert response?.bidderStatus?.every { it.getUserSync().type == IFRAME } - } - - def "PBS cookie sync request shouldn't include bidder with invalid user sync type"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: [GENERIC], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain bidders with Redirect type" - def userSync = response.getBidderUserSync(GENERIC) - assert userSync?.userSync?.type == REDIRECT - } - - def "PBS cookie sync request shouldn't exclude bidder with invalid user sync type"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: [GENERIC], filter: EXCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain bidders with Redirect type" - def userSync = response.getBidderUserSync(GENERIC) - assert userSync?.userSync?.type == REDIRECT - } - - def "PBS cookie sync request should ignore iframe invalid bidder in method filter bidders"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: [bidders], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response shouldn't contain invalid bidders" - assert !response.getBidderUserSync(bidders) - - where: - bidders << [BOGUS, null] - } - - def "PBS cookie sync request should ignore image invalid bidder in method filter bidders"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - image = new MethodFilter(bidders: [bidders], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response shouldn't contain invalid bidders" - assert !response.getBidderUserSync(bidders) - - where: - bidders << [BOGUS, null] - } - - def "PBS cookie sync request should successfully passed when account is absent"() { - given: "Cookie sync request with empty account" - def cookieSyncRequest = new CookieSyncRequest(account: null) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain configured bidders" - assert response?.getBidderStatus()?.bidder?.sort() == - [GENERIC, MAGNITE, APPNEXUS, OPENX, ACEEX, ACUITYADS, AAX, ADKERNEL].sort() - } - - def "PBS cookie sync request should return url for all bidders when no uids cookie is present"() { - given: "Cookie sync request with empty account" - def cookieSyncRequest = new CookieSyncRequest() - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain info for all configured bidder" - def bidderStatus = response?.bidderStatus?.userSync - assert bidderStatus?.url - assert bidderStatus?.type - } - - def "PBS cookie sync request shouldn't return sync url when active uids cookie is present for bidder"() { - given: "Empty cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest() - - and: "Set up uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request with uids cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response shouldn't contain bidder" - assert !response?.getBidderUserSync(GENERIC) - - and: "Response should contain configured bidders" - assert response?.getBidderStatus()?.bidder?.sort() == - [MAGNITE, APPNEXUS, OPENX, ACEEX, ACUITYADS, AAX, ADKERNEL].sort() - } - - def "PBS cookie sync request shouldn't return iframe sync url included by sync type bidders for bidder in cookie"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - iframe = new MethodFilter(bidders: [GENERIC], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - and: "Set up uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request with uids cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response shouldn't contain generic bidder" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request shouldn't return image sync url included by sync type bidders for bidder in cookie"() { - given: "Cookie sync request with filter setting" - def filterSettings = new FilterSettings().tap { - image = new MethodFilter(bidders: [APPNEXUS], filter: INCLUDE) - } - def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) - - and: "Set up uids cookie with appnexus" - def uidsCookie = UidsCookie.getDefaultUidsCookie(APPNEXUS) - - when: "PBS processes cookie sync request with generic uid cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response shouldn't contain generic bidder" - assert !response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request shouldn't return requested bidder when bidders present in uids cookie"() { - given: "Cookie sync request with generic bidders" - def cookieSyncRequest = new CookieSyncRequest(bidders: [GENERIC]) - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - when: "PBS processes cookie sync request with generic uid cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) - - then: "Response should have status 'OK'" - assert response.status == OK - - and: "Response shouldn't contain generic bidder" - assert !response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request should return all possible bidder"() { - given: "Cookie sync request with non specified bidders and specified coop sync" - def cookieSyncRequest = new CookieSyncRequest(bidders: null, coopSync: true) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain coop sync bidders" - assert response.bidderStatus.size() == DEFAULT_PBS_BIDDERS_SIZE - assert response.getBidderUserSync(AAX) - assert response.getBidderUserSync(ACUITYADS) - assert response.getBidderUserSync(ADKERNEL) - assert response.getBidderUserSync(OPENX) - assert response.getBidderUserSync(GENERIC) - assert response.getBidderUserSync(APPNEXUS) - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(ACEEX) - } - - def "PBS cookie sync request should contain request bidders and rest from coop sync"() { - given: "PBS config with expanded limit" - def defaultSyncLimit = 3 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": defaultSyncLimit as String] + PBS_CONFIG) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [APPNEXUS, GENERIC] - coopSync = true - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - then: "Response should contain requested bidder and coop-synced" - assert response.getBidderStatus().size() > cookieSyncRequest.bidders.size() - assert response.getBidderUserSync(APPNEXUS) - assert response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request should contain only request bidders when coop sync off"() { - given: "PBS config with expanded limit" - def defaultSyncLimit = 3 - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": defaultSyncLimit as String] + PBS_CONFIG) - - and: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [APPNEXUS, GENERIC] - coopSync = false - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - then: "Response should contain requested bidder and coop-synced" - assert response.getBidderStatus().size() == cookieSyncRequest.bidders.size() - assert response.getBidderUserSync(APPNEXUS) - assert response.getBidderUserSync(GENERIC) - } - - def "PBS cookie sync request should contain only request bidders with limit when coop sync off and limit specified"() { - given: "Default cookie sync request" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [APPNEXUS, GENERIC, MAGNITE] - coopSync = false - limit = 2 - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain requested bidder limit" - def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) - assert rejectedBidderUserSyncs.size() == cookieSyncRequest.bidders.size() - cookieSyncRequest.limit - assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } - } - - def "PBS cookie sync request should return only requested bidder and reduce image list by filter settings"() { - given: "Default cookie sync request" - def cookieSyncRequest = new CookieSyncRequest().tap { - bidders = [MAGNITE, APPNEXUS, ACEEX] - coopSync = false - filterSettings = new FilterSettings().tap { - image = new MethodFilter(bidders: [ACEEX], filter: EXCLUDE) - iframe = new MethodFilter(bidders: [MAGNITE], filter: INCLUDE) - } - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain two requested bidders" - assert response.getBidderStatus().size() == cookieSyncRequest.bidders.size() - 1 - assert response.getBidderUserSync(MAGNITE) - assert response.getBidderUserSync(APPNEXUS) - - and: "Response shouldn't contain requested bidders due to filter" - assert !response.getBidderUserSync(ACEEX) - } - - def "PBS cookie sync request shouldn't return any bidder when coop sync off and bidder is invalid"() { - given: "Cookie sync request body with bidders and disabled coop-sync" - def cookieSyncRequest = new CookieSyncRequest(coopSync: false, bidders: givenBidder) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response shouldn't contain amount of invalid bidder" - assert response.getBidderStatus().size() == 0 - - where: - givenBidder << [[BOGUS], []] - } - - def "PBS cookie sync request shouldn't return all bidders when coop sync #coopSync and limit param specified"() { - given: "Cookie sync request with bidders and limit" - def cookieSyncRequest = new CookieSyncRequest(coopSync: coopSync, bidders: [APPNEXUS, MAGNITE], limit: 1) - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain amount of bidder that define in request" - assert response.getBidderStatus().size() == cookieSyncRequest.limit - - where: - coopSync << [true, false] - } - - def "PBS cookie sync request shouldn't increase amount of bidder then define in request"() { - given: "Empty cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - limit = 1 - bidders = [MAGNITE, GENERIC] - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [MAGNITE, GENERIC], filter: INCLUDE)) - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain amount of bidder that define in request" - assert response.getBidderStatus().size() == cookieSyncRequest.limit - } - - def "PBS cookie sync request should return eight users sync bidders when limit isn't define"() { - given: "Empty cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - limit = null - bidders = null - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status 'NO_COOKIE'" - assert response.status == NO_COOKIE - - and: "Response should contain eight bidder by default" - assert response?.getBidderStatus()?.size() == DEFAULT_PBS_BIDDERS_SIZE - } - - def "PBS cookie sync request should limit the number of returned bidders"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - it.limit = PBSUtils.getRandomNumber(1, 3) - it.coopSync = true - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should have status" - assert response.getBidderStatus().size() == cookieSyncRequest.limit - } - - def "PBS cookie sync request should return bidders matched in bidders and filter settings"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - it.coopSync = false - it.bidders = [GENERIC, MAGNITE] - it.filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC, MAGNITE, APPNEXUS], filter: INCLUDE)) - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contains the same size" - assert response.bidderStatus.bidder.size() == cookieSyncRequest.bidders.size() - - and: "Should contain requested bidders" - assert response.bidderStatus.bidder.containsAll(GENERIC, MAGNITE) - } - - def "PBS cookie sync request should fill response with all available coop sync bidder when limit is not specified"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - it.coopSync = true - it.limit = null - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contains all available coop sync bidders" - assert response.bidderStatus.bidder.size() == DEFAULT_PBS_BIDDERS_SIZE - } - - def "PBS cookie sync request should override general configuration limit"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - it.coopSync = true - it.limit = PBSUtils.getRandomNumber(1, DEFAULT_PBS_BIDDERS_SIZE) - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contains same count of bidder as specified limit" - assert response.bidderStatus.size() == cookieSyncRequest.limit - } - - def "PBS cookie sync request should return bidders without excluded by filter settings"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - coopSync = false - bidders = [ACEEX, MAGNITE] - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [ACEEX], filter: EXCLUDE)) - debug = true - } - - when: "PBS processes cookie sync request without cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def bidderStatus = response.getBidderUserSync(ACEEX) - assert bidderStatus.error == "Rejected by request filter" - - and: "Response should contain one valid bidder" - assert response.getBidderUserSync(MAGNITE) - } - - def "PBS cookie sync request shouldn't include bidder when bidder specified in uids cookie"() { - given: "Cookie sync request body" - def cookieSyncRequest = new CookieSyncRequest().tap { - coopSync = false - bidders = [APPNEXUS, MAGNITE] - filterSettings = new FilterSettings(image: new MethodFilter(bidders: [APPNEXUS, MAGNITE], filter: INCLUDE)) - debug = false - } - - and: "Given uid cookie" - def cookie = UidsCookie.getDefaultUidsCookie(APPNEXUS) - - when: "PBS processes cookie sync request with cookies" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, cookie) - - then: "Response should contain valid bidder" - assert response.getBidderUserSync(MAGNITE) - - and: "Response shouldn't contain bidder that present in uids cookie" - assert !response.getBidderUserSync(APPNEXUS) - } - - def "PBS cookie sync request shouldn't limit bidders with zero value in config"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: 0) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain valid bidder status" - assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() - } - - def "PBS cookie sync request should max limit override default limit"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - debug = false - } - - and: "Save account with cookie config" - def maxLimit = 1 - def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: maxLimit, defaultLimit: 2) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to config" - assert response.bidderStatus.size() == maxLimit - } - - def "PBS cookie sync request should max limit in account take precedence over request limit"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, APPNEXUS, ADKERNEL] - account = accountId - limit = null - debug = false - } - - and: "Save account with cookie config" - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to config" - assert response.bidderStatus.size() == 2 - - where: - accountConfig << [new AccountConfig(status: ACTIVE, cookieSyncSnakeCase: new AccountCookieSyncConfig(maxLimit: 2)), - new AccountConfig(status: ACTIVE, cookieSync: new AccountCookieSyncConfig(maxLimit: 2))] - } - - def "PBS cookie sync request should capped to max limit"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - limit = limitRequest - debug = false - } - - and: "Save account with cookie config" - def maxLimit = 1 - def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: maxLimit) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to config" - assert response.bidderStatus.size() == maxLimit - - where: - limitRequest << [0, 2, null] - } - - def "PBS cookie sync request should account limit override general configuration limit when not limit in request"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - limit = null - debug = false - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: accountDefaultLimit, defaultLimitSnakeCase: accountDefaultLimitSnakeCase) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to config" - assert response.bidderStatus.size() == 1 - - where: - accountDefaultLimit | accountDefaultLimitSnakeCase - 1 | null - null | 1 - } - - def "PBS cookie sync request should take precedence request limit over account and global config"() { - given: "PBS config with expanded limit" - def prebidServerService = pbsServiceFactory.getService( - ["cookie-sync.default-limit": "3"] + PBS_CONFIG) - - and: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - limit = 1 - debug = false - } - - and: "Save account with cookie config" - def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: 2) - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to request limit" - assert response.bidderStatus.size() == cookieSyncRequest.limit - } - - def "PBS cookie sync request should take presence coop sync over coop sync in config"() { - given: "Default cookie sync request" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - bidders = [GENERIC, BOGUS] - account = accountId - coopSync = true - } - - and: "Save account with cookie config" - def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain corresponding bidders size due to global config" - assert response.bidderStatus.size() == 9 - - where: - cookieSyncConfig << [new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: true)), - new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: false)), - new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: null)), - new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: true)), - new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: false)), - new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: null))] - } - - def "PBS cookie sync request should respond with an error when gdpr param is 1 and consent isn't specified"() { - given: "Cookie sync request body with gdpr = 1 and gdprConsent = null" - def cookieSyncRequest = new CookieSyncRequest().tap { - gdpr = 1 - gdprConsent = null - } - - when: "PBS processes cookie sync request" - prebidServerService.sendCookieSyncRequest(cookieSyncRequest) - - then: "Response should contain error" - def serverException = thrown(PrebidServerException) - assert serverException.responseBody == "Invalid request format: gdpr_consent is required if gdpr is 1" - } - - def "PBS shouldn't set cookie deprecation header from the account when privacySandbox is #privacySandbox"() { - given: "Default cookie sync request with account" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = accountId - } - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Save account with cookie and privacySandbox configs" - def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) - def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) - - then: "Response shouldn't contain cookie header" - assert !response.headers[SET_COOKIE_HEADER] - - where: - privacySandbox << [null, - PrivacySandbox.getDefaultPrivacySandbox(null), - PrivacySandbox.getDefaultPrivacySandbox(false)] - } - - def "PBS shouldn't set cookie deprecation header from the account when cookies is included in original request"() { - given: "Default cookie sync request with account" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = accountId - } - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Save account with cookie and privacySandbox configs" - def privacySandbox = PrivacySandbox.defaultPrivacySandbox - def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) - def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def setCookieDefaultHeader = ['receive-cookie-deprecation': '1'] - def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie, setCookieDefaultHeader) - - then: "Response shouldn't contain cookie header" - assert !response.headers[SET_COOKIE_HEADER] - } - - def "PBS should set cookie deprecation header from the account when cookies is not included in original request"() { - given: "Default cookie sync request with account" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = accountId - } - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Save account with cookie and privacySandbox configs" - def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) - def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) - - then: "Response should contain cookie header" - assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == - ["receive-cookie-deprecation=1; Max-Age=${privacySandbox.cookieDeprecation.ttlSeconds}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] - - where: - privacySandbox << [PrivacySandbox.defaultPrivacySandbox, PrivacySandbox.getDefaultPrivacySandbox(true, -PBSUtils.randomNumber)] - } - - def "PBS should set cookie deprecation header on default value of week when ttlSec is not specified in privacy sandbox settings"() { - given: "Default cookie sync request with account" - def accountId = PBSUtils.randomNumber - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = accountId - } - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Save account with cookie and privacySandbox configs" - def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: PrivacySandbox.getDefaultPrivacySandbox(true, null)) - def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) - def account = new Account(uuid: accountId, config: accountConfig) - accountDao.save(account) - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) - - then: "Response should contain cookie header" - assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == - ["receive-cookie-deprecation=1; Max-Age=${TimeUnit.DAYS.toSeconds(7)}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] - } - - def "PBS should set cookie deprecation header from the default account when default account contain privacy sandbox and request account is empty"() { - given: "Pbs with PF configuration with privacySandbox" - def privacySandbox = PrivacySandbox.defaultPrivacySandbox - def defaultAccountConfigSettings = AccountConfig.defaultAccountConfig.tap { - auction = new AccountAuctionConfig(privacySandbox: privacySandbox) - } - def pbsService = pbsServiceFactory.getService(PBS_CONFIG + - ["settings.default-account-config": encode(defaultAccountConfigSettings)]) - - and: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Cookie sync request body" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = null - } - - when: "PBS processes cookie sync request" - def response = pbsService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) - - then: "Response should contain cookie header" - assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == - ["receive-cookie-deprecation=1; Max-Age=${privacySandbox.cookieDeprecation.ttlSeconds}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] - } - - def "PBS shouldn't set cookie deprecation header when cookie sync request doesn't contain account"() { - given: "Set up generic uids cookie" - def uidsCookie = UidsCookie.defaultUidsCookie - - and: "Cookie sync request body" - def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { - account = null - } - - when: "PBS processes cookie sync request" - def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) - - then: "Response shouldn't contain cookie header" - assert !response.headers[SET_COOKIE_HEADER] - } - - private static Map getValidBidderUserSyncs(CookieSyncResponse cookieSyncResponse) { - cookieSyncResponse.bidderStatus - .findAll { it.userSync } - .collectEntries { [it.bidder, it.userSync] } - } - - private static Map getRejectedBidderUserSyncs(CookieSyncResponse cookieSyncResponse) { - cookieSyncResponse.bidderStatus - .findAll { it.error } - .collectEntries { [it.bidder, it.error] } - } - - private static List removeExpiresValue(List cookies) { - cookies.collect { it.replaceFirst(/Expires=[^;]+;/, "Expires=*;") } - } -} diff --git a/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy index 662f9423848..47044a04719 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy @@ -4,6 +4,7 @@ import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.CurrencyConversion import org.prebid.server.functional.util.CurrencyUtil @@ -18,12 +19,17 @@ import static org.prebid.server.functional.util.CurrencyUtil.DEFAULT_CURRENCY class CurrencySpec extends BaseSpec { + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig(PbsConfig.currencyConverterConfig) private static final CurrencyConversion currencyConversion = new CurrencyConversion(networkServiceContainer) private static PrebidServerService pbsService def setupSpec() { currencyConversion.setCurrencyConversionRatesResponse() - pbsService = pbsServiceFactory.getService(PbsConfig.currencyConverterConfig) + pbsService = pbsServiceFactory.getService(PBS_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(PBS_CONFIG) } def "PBS should return currency rates"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/DebugSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/DebugSpec.groovy index cb21fc92675..33faba61611 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/DebugSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/DebugSpec.groovy @@ -14,6 +14,7 @@ import org.prebid.server.functional.model.request.auction.StoredBidResponse import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import spock.lang.PendingFeature @@ -33,6 +34,12 @@ class DebugSpec extends BaseSpec { private static final String ACCOUNT_DEBUG_REQUESTS_METRIC = "account.%s.debug_requests" private static final String REQUEST_OK_WEB_METRICS = "requests.ok.openrtb2-web" + private static final PbsContainerConfig BIDDER_DEBUG_DISABLED_CONFIG = new PbsContainerConfig(["adapters.generic.debug.allow": "false"]) + private static final PbsContainerConfig BIDDER_DEBUG_ENABLED_CONFIG = new PbsContainerConfig(["adapters.generic.debug.allow": "true"]) + private static final PbsContainerConfig DEBUG_OVERRIDE_DISABLED_CONFIG = BIDDER_DEBUG_DISABLED_CONFIG + ["debug.override-token": overrideToken] + private static final PbsContainerConfig DEBUG_OVERRIDE_ENABLED_CONFIG = BIDDER_DEBUG_ENABLED_CONFIG + ["debug.override-token": overrideToken] + private static final PbsContainerConfig DEBUG_OVERRIDE_TOKEN_CONFIG = new PbsContainerConfig(["debug.override-token": overrideToken]) + def "PBS should return debug information and emit metrics when debug flag is #debug and test flag is #test"() { given: "Default BidRequest with test flag" def bidRequest = BidRequest.defaultBidRequest @@ -65,7 +72,7 @@ class DebugSpec extends BaseSpec { def "PBS shouldn't return debug information when debug flag is #debug and test flag is #test"() { given: "Default BidRequest with test flag" def bidRequest = BidRequest.defaultBidRequest - bidRequest.ext.prebid.debug = test + bidRequest.ext.prebid.debug = debug bidRequest.test = test and: "Flash metrics" @@ -93,7 +100,7 @@ class DebugSpec extends BaseSpec { def "PBS should not return debug information when bidder-level setting debug.allowed = false"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["adapters.generic.debug.allow": "false"]) + def pbsService = pbsServiceFactory.getService(BIDDER_DEBUG_DISABLED_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -113,7 +120,7 @@ class DebugSpec extends BaseSpec { def "PBS should return debug information when bidder-level setting debug.allowed = true"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["adapters.generic.debug.allow": "true"]) + def pbsService = pbsServiceFactory.getService(BIDDER_DEBUG_ENABLED_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -131,7 +138,7 @@ class DebugSpec extends BaseSpec { def "PBS should not return debug information when bidder-level setting debug.allowed = false is overridden by account-level setting debug-allowed = false"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["adapters.generic.debug.allow": "false"]) + def pbsService = pbsServiceFactory.getService(BIDDER_DEBUG_DISABLED_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -161,7 +168,7 @@ class DebugSpec extends BaseSpec { def "PBS should not return debug information when bidder-level setting debug.allowed = false is overridden by account-level setting debug-allowed = true"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["adapters.generic.debug.allow": "false"]) + def pbsService = pbsServiceFactory.getService(BIDDER_DEBUG_DISABLED_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -190,7 +197,7 @@ class DebugSpec extends BaseSpec { def "PBS should not return debug information when bidder-level setting debug.allowed = true is overridden by account-level setting debug-allowed = false"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["adapters.generic.debug.allow": "true"]) + def pbsService = pbsServiceFactory.getService(BIDDER_DEBUG_ENABLED_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -228,9 +235,9 @@ class DebugSpec extends BaseSpec { assert !response.ext?.warnings } - def "PBS should return debug information when bidder-level setting debug.allowed = #debugAllowedConfig and account-level setting debug-allowed = #debugAllowedAccount is overridden by x-pbs-debug-override header"() { + def "PBS should return debug information when bidder and account debug restrictions are overridden by x-pbs-debug-override header"() { given: "PBS with debug configuration" - def pbsService = pbsServiceFactory.getService(pbdConfig) + def pbsService = pbsServiceFactory.getService(config) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest @@ -251,18 +258,15 @@ class DebugSpec extends BaseSpec { assert !response.ext?.warnings where: - debugAllowedConfig | debugAllowedAccount | pbdConfig - false | true | ["debug.override-token" : overrideToken, - "adapters.generic.debug.allow": "false"] - true | false | ["debug.override-token" : overrideToken, - "adapters.generic.debug.allow": "true"] - false | false | ["debug.override-token" : overrideToken, - "adapters.generic.debug.allow": "false"] + config | debugAllowedAccount + DEBUG_OVERRIDE_DISABLED_CONFIG | true + DEBUG_OVERRIDE_ENABLED_CONFIG | false + DEBUG_OVERRIDE_DISABLED_CONFIG | false } def "PBS should not return debug information when x-pbs-debug-override header is incorrect"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService(["debug.override-token": overrideToken]) + def pbsService = pbsServiceFactory.getService(DEBUG_OVERRIDE_TOKEN_CONFIG) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest diff --git a/src/test/groovy/org/prebid/server/functional/tests/EidsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/EidsSpec.groovy index 53ff2b7813d..f20c1ea567e 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/EidsSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/EidsSpec.groovy @@ -11,14 +11,15 @@ import org.prebid.server.functional.model.request.auction.UidExt import org.prebid.server.functional.model.request.auction.User import org.prebid.server.functional.model.request.auction.UserExt import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE -import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN import static org.prebid.server.functional.model.bidder.BidderName.WILDCARD import static org.prebid.server.functional.model.request.auction.DebugCondition.DISABLED @@ -162,9 +163,9 @@ class EidsSpec extends BaseSpec { def "PBs eid permissions should affect only specified on source"() { given: "PBs with openx bidder" - def pbsService = pbsServiceFactory.getService( - ["adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def config = new PbsContainerConfig(["adapters.openx.enabled" : "true", + "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def pbsService = pbsServiceFactory.getService(config) and: "Default bid request with eidpremissions and openx bidder" def eidSource = PBSUtils.randomString @@ -193,9 +194,9 @@ class EidsSpec extends BaseSpec { def "PBs eid permissions for non existing source should not stop auction"() { given: "PBs with openx bidder" - def pbsService = pbsServiceFactory.getService( - ["adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def config = new PbsContainerConfig(["adapters.openx.enabled" : "true", + "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def pbsService = pbsServiceFactory.getService(config) and: "Default bid request with eidpremissions and openx bidder" def firstEid = new Eid(source: PBSUtils.randomString, uids: [new Uid(id: PBSUtils.randomString)]) diff --git a/src/test/groovy/org/prebid/server/functional/tests/FilterMultiFormatSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/FilterMultiFormatSpec.groovy index 1ab45de4bec..b8bd2fcfa69 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/FilterMultiFormatSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/FilterMultiFormatSpec.groovy @@ -11,6 +11,7 @@ import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.BidderControls import org.prebid.server.functional.model.request.auction.GenericPreferredBidder import org.prebid.server.functional.model.request.auction.Native +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC @@ -20,10 +21,15 @@ import static org.prebid.server.functional.model.response.auction.MediaType.NULL class FilterMultiFormatSpec extends BaseSpec { + private static final PbsContainerConfig DEFAULT_MULTIFORMAT_ENABLED_CONFIG = new PbsContainerConfig(['adapter-defaults.ortb.multiformat-supported': 'true']) + private static final PbsContainerConfig DEFAULT_MULTIFORMAT_DISABLED_CONFIG = new PbsContainerConfig(['adapter-defaults.ortb.multiformat-supported': 'false']) + private static final PbsContainerConfig GENERIC_MULTIFORMAT_ENABLED_CONFIG = new PbsContainerConfig(['adapters.generic.ortb.multiformat-supported': 'true']) + private static final PbsContainerConfig GENERIC_MULTIFORMAT_DISABLED_CONFIG = new PbsContainerConfig(['adapters.generic.ortb.multiformat-supported': 'false']) + private static final PbsContainerConfig DEFAULT_AND_GENERIC_MULTIFORMAT_DISABLED_CONFIG = DEFAULT_MULTIFORMAT_DISABLED_CONFIG + GENERIC_MULTIFORMAT_DISABLED_CONFIG + def "PBS should respond with all requested media types when default adapters multi format is true in config and preferred media type specified at account level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "true") + def pbsService = pbsServiceFactory.getService(DEFAULT_MULTIFORMAT_ENABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -47,8 +53,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with all requested media types when default adapters multi format is true in config and preferred media type specified at request level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "true") + def pbsService = pbsServiceFactory.getService(DEFAULT_MULTIFORMAT_ENABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -77,8 +82,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with one requested preferred media type when default adapters multi format is false in config and preferred media type specified at account level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(DEFAULT_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -102,8 +106,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with one requested preferred media type when default adapters multi format is false in config and preferred media type specified at request level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(DEFAULT_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -132,8 +135,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with all requested media type when multi format is true in config and preferred media type specified at request level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "true") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_ENABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -162,8 +164,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with all requested media type when multi format is true in config and preferred media type specified at account level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "true") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_ENABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -187,8 +188,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with one requested preferred media type when multi format is false in config and preferred media type specified at account level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -212,8 +212,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with one requested preferred media type when multi format is false in config and preferred media type preferred at request level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -242,8 +241,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with warning and don't make a bidder call when multi format at request and preferred media type specified at account level with non requested media type"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with audio and nativeObj type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -271,8 +269,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with warning and don't make a bidder call when multi format at request and preferred media type specified at request level with non requested media type"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with audio and nativeObj type and preferredMediaType BANNER" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -302,8 +299,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS shouldn't respond with warning and make a bidder call when request doesn't contain multi format and preferred media type specified at account level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with audio and nativeObj type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -329,8 +325,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS shouldn't respond with warning and make a bidder call when request doesn't contain multi format and preferred media type specified at request level"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with audio and nativeObj type and preferredMediaType BANNER" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -358,8 +353,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS shouldn't respond with warning and make a bidder call when request doesn't contain multi format and multi format is false and preferred media type specified at request level with null"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -386,8 +380,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS shouldn't respond with warning and make a bidder call when request doesn't contain multi format and multi format is false and preferred media type specified at account level with null"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -412,9 +405,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should respond with preferred media type that specified in request when preferred media type specified in both places"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "false", - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(DEFAULT_AND_GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with banner and audio type" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -445,9 +436,7 @@ class FilterMultiFormatSpec extends BaseSpec { def "PBS should not preferred media type specified at request level when it's alias bidder"() { given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - "adapter-defaults.ortb.multiformat-supported": "false", - "adapters.generic.ortb.multiformat-supported": "false") + def pbsService = pbsServiceFactory.getService(DEFAULT_AND_GENERIC_MULTIFORMAT_DISABLED_CONFIG) and: "Default bid request with alias" def bidRequest = BidRequest.defaultBidRequest.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy index 3d19d9d878d..ebf1ba3fb63 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy @@ -7,6 +7,7 @@ import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Device import org.prebid.server.functional.model.request.auction.Geo +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import java.time.Instant @@ -26,22 +27,24 @@ class GeoSpec extends BaseSpec { private static final String GEO_LOCATION_REQUESTS = "geolocation_requests" private static final String GEO_LOCATION_FAIL = "geolocation_fail" private static final String GEO_LOCATION_SUCCESSFUL = "geolocation_successful" - private static final Map GEO_LOCATION = ["geolocation.type" : "configuration", - "geolocation.configurations.[0].address-pattern" : USA_IP.v4, - "geolocation.configurations.[0].geo-info.country": USA.ISOAlpha2, - "geolocation.configurations.[0].geo-info.region" : ALABAMA.abbreviation, - "geolocation.configurations.[1].address-pattern" : CAN_IP.v4, - "geolocation.configurations.[1].geo-info.country": CAN.ISOAlpha2, - "geolocation.configurations.[1].geo-info.region" : QUEBEC.abbreviation] + private static final PbsContainerConfig GEO_LOCATION_CONFIG = new PbsContainerConfig([ + 'geolocation.enabled' : 'true', + 'geolocation.type' : 'configuration', + 'geolocation.configurations.[0].address-pattern' : USA_IP.v4, + 'geolocation.configurations.[0].geo-info.country': USA.ISOAlpha2, + 'geolocation.configurations.[0].geo-info.region' : ALABAMA.abbreviation, + 'geolocation.configurations.[1].address-pattern' : CAN_IP.v4, + 'geolocation.configurations.[1].geo-info.country': CAN.ISOAlpha2, + 'geolocation.configurations.[1].geo-info.region' : QUEBEC.abbreviation + ]) def "PBS should populate geo with country and region and take precedence from device.id when geo location enabled in host and account config and ip specified in both places"() { given: "PBS service with geolocation and default account configs" def config = AccountConfig.defaultAccountConfig.tap { settings = settingDefaultAccountGeoLookup } - def defaultPbsService = pbsServiceFactory.getService( - ["settings.default-account-config": encode(config), - "geolocation.enabled" : "true"] + GEO_LOCATION) + def pbsConfig = GEO_LOCATION_CONFIG + ['settings.default-account-config': encode(config)] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -64,10 +67,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": CAN_IP.v4]) + pbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": CAN_IP.v4]) then: "Bidder request should contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -75,7 +78,7 @@ class GeoSpec extends BaseSpec { assert bidderRequests.device.geo.region == ALABAMA.abbreviation and: "Metrics processed across activities should be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[GEO_LOCATION_REQUESTS] == 1 assert metrics[GEO_LOCATION_SUCCESSFUL] == 1 assert !metrics[GEO_LOCATION_FAIL] @@ -94,9 +97,8 @@ class GeoSpec extends BaseSpec { def config = AccountConfig.defaultAccountConfig.tap { settings = new AccountSetting(geoLookup: defaultAccountGeoLookup) } - def defaultPbsService = pbsServiceFactory.getService( - ["settings.default-account-config": encode(config), - "geolocation.enabled" : "true"] + GEO_LOCATION) + def pbsConfig = GEO_LOCATION_CONFIG + ['settings.default-account-config': encode(config)] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -119,10 +121,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request should contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -130,7 +132,7 @@ class GeoSpec extends BaseSpec { assert bidderRequests.device.geo.region == ALABAMA.abbreviation and: "Metrics processed across activities should be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[GEO_LOCATION_REQUESTS] == 1 assert metrics[GEO_LOCATION_SUCCESSFUL] == 1 assert !metrics[GEO_LOCATION_FAIL] @@ -147,9 +149,8 @@ class GeoSpec extends BaseSpec { def config = AccountConfig.defaultAccountConfig.tap { settings = new AccountSetting(geoLookup: defaultAccountGeoLookup) } - def defaultPbsService = pbsServiceFactory.getService( - ["settings.default-account-config": encode(config), - "geolocation.enabled" : "true"] + GEO_LOCATION) + def pbsConfig = GEO_LOCATION_CONFIG + ['settings.default-account-config': encode(config)] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -172,10 +173,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) + pbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) then: "Bidder request should contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -183,7 +184,7 @@ class GeoSpec extends BaseSpec { assert bidderRequests.device.geo.region == ALABAMA.abbreviation and: "Metrics processed across activities should be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[GEO_LOCATION_REQUESTS] == 1 assert metrics[GEO_LOCATION_SUCCESSFUL] == 1 assert !metrics[GEO_LOCATION_FAIL] @@ -200,9 +201,10 @@ class GeoSpec extends BaseSpec { def config = AccountConfig.defaultAccountConfig.tap { settings = new AccountSetting(geoLookup: defaultAccountGeoLookupConfig) } - def defaultPbsService = pbsServiceFactory.getService(GEO_LOCATION + - ["settings.default-account-config": encode(config), - "geolocation.enabled" : hostGeolocation]) + def pbsConfig = GEO_LOCATION_CONFIG + + ['settings.default-account-config': encode(config), + 'geolocation.enabled' : hostGeolocation] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -225,10 +227,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request shouldn't contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -236,7 +238,7 @@ class GeoSpec extends BaseSpec { assert !bidderRequests.device.geo.region and: "Metrics processed across geo location shouldn't be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert !metrics[GEO_LOCATION_REQUESTS] assert !metrics[GEO_LOCATION_SUCCESSFUL] assert !metrics[GEO_LOCATION_FAIL] @@ -254,9 +256,10 @@ class GeoSpec extends BaseSpec { def config = AccountConfig.defaultAccountConfig.tap { settings = new AccountSetting(geoLookup: defaultAccountGeoLookupConfig) } - def defaultPbsService = pbsServiceFactory.getService(GEO_LOCATION + - ["settings.default-account-config": encode(config), - "geolocation.enabled" : hostGeolocation]) + def pbsConfig = GEO_LOCATION_CONFIG + + ['settings.default-account-config': encode(config), + 'geolocation.enabled' : hostGeolocation] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -279,10 +282,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) + pbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) then: "Bidder request shouldn't contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -290,7 +293,7 @@ class GeoSpec extends BaseSpec { assert !bidderRequests.device.geo.region and: "Metrics processed across geo location shouldn't be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert !metrics[GEO_LOCATION_REQUESTS] assert !metrics[GEO_LOCATION_SUCCESSFUL] assert !metrics[GEO_LOCATION_FAIL] @@ -308,9 +311,9 @@ class GeoSpec extends BaseSpec { def startTime = Instant.now() and: "PBS service with geolocation" - def defaultPbsService = pbsServiceFactory.getService(GEO_LOCATION + - ["geolocation.configurations.[0].address-pattern": PBSUtils.randomNumber as String, - "geolocation.enabled" : "true"]) + def pbsConfig = GEO_LOCATION_CONFIG + + ['geolocation.configurations.[0].address-pattern': PBSUtils.randomNumber as String] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -333,10 +336,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request shouldn't contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -344,17 +347,20 @@ class GeoSpec extends BaseSpec { assert !bidderRequests.device.geo.region and: "Metrics processed across geo location should be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[GEO_LOCATION_REQUESTS] == 1 assert metrics[GEO_LOCATION_FAIL] == 1 assert !metrics[GEO_LOCATION_SUCCESSFUL] and: "PBs should emit geo failed logs" - def logs = defaultPbsService.getLogsByTime(startTime) + def logs = pbsService.getLogsByTime(startTime) def getLocation = getLogsByText(logs, "GeoLocationServiceWrapper") assert getLocation.size() == 1 assert getLocation[0].contains("Geolocation lookup failed: " + "ConfigurationGeoLocationService: Geo location lookup failed.") + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't populate geo with country, region and emit error in log and metric when geo look up failed and ip present in header"() { @@ -362,9 +368,9 @@ class GeoSpec extends BaseSpec { def startTime = Instant.now() and: "PBS service with geolocation" - def defaultPbsService = pbsServiceFactory.getService(GEO_LOCATION + - ["geolocation.configurations.[0].address-pattern": PBSUtils.randomNumber as String, - "geolocation.enabled" : "true"]) + def pbsConfig = GEO_LOCATION_CONFIG + + ['geolocation.configurations.[0].address-pattern': PBSUtils.randomNumber as String] + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -387,10 +393,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) + pbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) then: "Bidder request shouldn't contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -398,23 +404,25 @@ class GeoSpec extends BaseSpec { assert !bidderRequests.device.geo.region and: "Metrics processed across geo location should be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert metrics[GEO_LOCATION_REQUESTS] == 1 assert metrics[GEO_LOCATION_FAIL] == 1 assert !metrics[GEO_LOCATION_SUCCESSFUL] and: "PBs should emit geo failed logs" - def logs = defaultPbsService.getLogsByTime(startTime) + def logs = pbsService.getLogsByTime(startTime) def getLocation = getLogsByText(logs, "GeoLocationServiceWrapper") assert getLocation.size() == 1 assert getLocation[0].contains("Geolocation lookup failed: " + "ConfigurationGeoLocationService: Geo location lookup failed.") + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't populate country and region via geo when geo enabled in account and country and region specified in request and ip present in device.id"() { given: "PBS service with geolocation" - def defaultPbsService = pbsServiceFactory.getService( - ["geolocation.enabled": "true"] + GEO_LOCATION) + def pbsService = pbsServiceFactory.getService(GEO_LOCATION_CONFIG) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -437,10 +445,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + pbsService.sendAuctionRequest(bidRequest) then: "Bidder request should contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -448,7 +456,7 @@ class GeoSpec extends BaseSpec { assert bidderRequests.device.geo.region == ONTARIO.abbreviation and: "Metrics processed across activities shouldn't be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert !metrics[GEO_LOCATION_REQUESTS] assert !metrics[GEO_LOCATION_SUCCESSFUL] assert !metrics[GEO_LOCATION_FAIL] @@ -456,8 +464,7 @@ class GeoSpec extends BaseSpec { def "PBS shouldn't populate country and region via geo when geo enabled in account and country and region specified in request and ip present in header"() { given: "PBS service with geolocation" - def defaultPbsService = pbsServiceFactory.getService( - ["geolocation.enabled": "true"] + GEO_LOCATION) + def pbsService = pbsServiceFactory.getService(GEO_LOCATION_CONFIG) and: "Default bid request with device and geo data" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -480,10 +487,10 @@ class GeoSpec extends BaseSpec { accountDao.save(account) and: "Flush metric" - flushMetrics(defaultPbsService) + flushMetrics(pbsService) when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) + pbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4]) then: "Bidder request should contain country and region" def bidderRequests = bidder.getBidderRequest(bidRequest.id) @@ -491,7 +498,7 @@ class GeoSpec extends BaseSpec { assert bidderRequests.device.geo.region == ONTARIO.abbreviation and: "Metrics processed across activities shouldn't be updated" - def metrics = defaultPbsService.sendCollectedMetricsRequest() + def metrics = pbsService.sendCollectedMetricsRequest() assert !metrics[GEO_LOCATION_REQUESTS] assert !metrics[GEO_LOCATION_SUCCESSFUL] assert !metrics[GEO_LOCATION_FAIL] diff --git a/src/test/groovy/org/prebid/server/functional/tests/HttpSettingsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/HttpSettingsSpec.groovy index bdf1d453fe8..f5b5100f589 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/HttpSettingsSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/HttpSettingsSpec.groovy @@ -1,6 +1,5 @@ package org.prebid.server.functional.tests -import org.apache.http.HttpStatus import org.prebid.server.functional.model.UidsCookie import org.prebid.server.functional.model.config.Endpoint import org.prebid.server.functional.model.db.StoredRequest @@ -14,6 +13,7 @@ import org.prebid.server.functional.model.request.vtrack.xml.Vast import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.HttpSettings import org.prebid.server.functional.util.PBSUtils import org.prebid.server.util.ResourceUtil @@ -25,19 +25,26 @@ import static org.prebid.server.functional.testcontainers.Dependencies.networkSe class HttpSettingsSpec extends BaseSpec { // Check that PBS actually applied account config only possible by relying on side effects. - static PrebidServerService prebidServerService - static PrebidServerService prebidServerServiceWithRfc + private static PrebidServerService prebidServerService + private static PrebidServerService prebidServerServiceWithRfc private static final String rfcEndpoint = "/stored-requests-rfc" private static final HttpSettings httpSettings = new HttpSettings(networkServiceContainer) private static final HttpSettings httpSettingsWithRfc = new HttpSettings(networkServiceContainer, rfcEndpoint) - private static final Map PBS_CONFIG_WITH_RFC = new HashMap<>(PbsConfig.httpSettingsConfig) + + + private static final PbsContainerConfig HTTP_SETTINGS_CONFIG = new PbsContainerConfig(PbsConfig.httpSettingsConfig) + private static final PbsContainerConfig HTTP_SETTINGS_RFC_CONFIG = HTTP_SETTINGS_CONFIG + ['settings.http.endpoint' : "${networkServiceContainer.rootUri}${rfcEndpoint}".toString(), 'settings.http.rfc3986-compatible': 'true'] def setupSpec() { - prebidServerService = pbsServiceFactory.getService(PbsConfig.httpSettingsConfig) - prebidServerServiceWithRfc = pbsServiceFactory.getService(PBS_CONFIG_WITH_RFC) + prebidServerService = pbsServiceFactory.getService(HTTP_SETTINGS_CONFIG) + prebidServerServiceWithRfc = pbsServiceFactory.getService(HTTP_SETTINGS_RFC_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(HTTP_SETTINGS_CONFIG) + pbsServiceFactory.removeContainer(HTTP_SETTINGS_RFC_CONFIG) } def "PBS should take account information from http data source on auction request"() { @@ -190,10 +197,10 @@ class HttpSettingsSpec extends BaseSpec { def "PBS should take account information from http data source on setuid request"() { given: "Pbs config with adapters.generic.usersync.redirect.*" - def pbsConfig = PbsConfig.httpSettingsConfig + - ["adapters.generic.usersync.redirect.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), - "adapters.generic.usersync.redirect.format-override": "blank"] - def prebidServerService = pbsServiceFactory.getService(pbsConfig) + def config = HTTP_SETTINGS_CONFIG + + ['adapters.generic.usersync.redirect.url' : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), + 'adapters.generic.usersync.redirect.format-override': 'blank'] + def pbsService = pbsServiceFactory.getService(config) and: "Get default SetuidRequest and set account, gdpr=1 " def request = SetuidRequest.defaultSetuidRequest @@ -206,7 +213,7 @@ class HttpSettingsSpec extends BaseSpec { httpSettings.setResponse(request.account, httpSettingsResponse) when: "PBS processes setuid request" - def response = prebidServerService.sendSetUidRequest(request, uidsCookie) + def response = pbsService.sendSetUidRequest(request, uidsCookie) then: "Response should contain tempUIDs cookie" assert !response.uidsCookie.uids @@ -217,18 +224,16 @@ class HttpSettingsSpec extends BaseSpec { and: "There should be only one account request" assert httpSettings.getRequestCount(request.account) == 1 - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) + cleanup: + pbsServiceFactory.removeContainer(config) } def "PBS should take account information from http data source on setuid request when rfc3986 enabled"() { given: "Pbs config with adapters.generic.usersync.redirect.*" - def pbsConfig = new HashMap<>(PbsConfig.httpSettingsConfig) + - ['settings.http.endpoint' : "${networkServiceContainer.rootUri}${rfcEndpoint}".toString(), - 'settings.http.rfc3986-compatible' : 'true', - 'adapters.generic.usersync.redirect.url' : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), + def config = HTTP_SETTINGS_RFC_CONFIG + + ['adapters.generic.usersync.redirect.url' : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), 'adapters.generic.usersync.redirect.format-override': 'blank'] - def prebidServerService = pbsServiceFactory.getService(pbsConfig) + def pbsService = pbsServiceFactory.getService(config) and: "Get default SetuidRequest and set account, gdpr=1 " def request = SetuidRequest.defaultSetuidRequest @@ -241,7 +246,7 @@ class HttpSettingsSpec extends BaseSpec { httpSettingsWithRfc.setRfcResponse(request.account, httpSettingsResponse) when: "PBS processes setuid request" - def response = prebidServerService.sendSetUidRequest(request, uidsCookie) + def response = pbsService.sendSetUidRequest(request, uidsCookie) then: "Response should contain tempUIDs cookie" assert !response.uidsCookie.uids @@ -252,8 +257,8 @@ class HttpSettingsSpec extends BaseSpec { and: "There should be only one account request" assert httpSettingsWithRfc.getRfcRequestCount(request.account) == 1 - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) + cleanup: + pbsServiceFactory.removeContainer(config) } def "PBS should take account information from http data source on vtrack request"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/ImpRequestSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/ImpRequestSpec.groovy index 2b0e4146a6c..327c7e42bfe 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/ImpRequestSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/ImpRequestSpec.groovy @@ -8,6 +8,7 @@ import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.Pmp import org.prebid.server.functional.model.request.auction.PrebidStoredRequest import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static org.prebid.server.functional.model.bidder.BidderName.ALIAS @@ -15,17 +16,17 @@ import static org.prebid.server.functional.model.bidder.BidderName.ALIAS_CAMEL_C import static org.prebid.server.functional.model.bidder.BidderName.EMPTY import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE -import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.bidder.BidderName.GENER_X import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN import static org.prebid.server.functional.model.bidder.BidderName.WILDCARD -import static org.prebid.server.functional.model.bidder.BidderName.GENER_X import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer class ImpRequestSpec extends BaseSpec { - private final PrebidServerService defaultPbsServiceWithAlias = pbsServiceFactory.getService(GENERIC_ALIAS_CONFIG) + private final PrebidServerService defaultPbsServiceWithAlias = pbsServiceFactory.getService(new PbsContainerConfig(GENERIC_ALIAS_CONFIG)) private static final String EMPTY_ID = "" def "PBS should update imp fields when imp.ext.prebid.imp contain bidder information"() { @@ -229,9 +230,9 @@ class ImpRequestSpec extends BaseSpec { def "PBS should always update specified bidder imp when imp.ext.prebid.imp contain such bidder"() { given: "PBs with openx bidder" - def pbsService = pbsServiceFactory.getService( - ["adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def config = new PbsContainerConfig(["adapters.openx.enabled" : "true", + "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def pbsService = pbsServiceFactory.getService(config) and: "Default basic BidRequest" def impPmp = Pmp.defaultPmp diff --git a/src/test/groovy/org/prebid/server/functional/tests/InfluxDBSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/InfluxDBSpec.groovy index 4e0253c1f95..8be9db2a837 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/InfluxDBSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/InfluxDBSpec.groovy @@ -6,6 +6,7 @@ import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED import static org.prebid.server.functional.testcontainers.Dependencies.influxdbContainer @@ -14,7 +15,7 @@ class InfluxDBSpec extends BaseSpec { private static final String ACCOUNT_REJECTED_METRIC = "influx.metric.account.%s.requests.rejected.invalid-account" - private static final Map PBS_CONFIG_WITH_INFLUX_AND_ENFORCE_VALIDATION_ACCOUNTANT = [ + private static final PbsContainerConfig PBS_CONFIG_WITH_INFLUX_AND_ENFORCE_VALIDATION_ACCOUNTANT = new PbsContainerConfig([ "metrics.influxdb.enabled" : "true", "metrics.influxdb.prefix" : "influx.metric.", "metrics.influxdb.host" : influxdbContainer.getNetworkAliases().get(0), @@ -25,7 +26,7 @@ class InfluxDBSpec extends BaseSpec { "metrics.influxdb.interval" : "1", "metrics.influxdb.connectTimeout": "5000", "metrics.influxdb.readTimeout" : "100", - "settings.enforce-valid-account": true as String] + "settings.enforce-valid-account": true as String]) private static final PrebidServerService pbsServiceWithEnforceValidAccount = pbsServiceFactory.getService(PBS_CONFIG_WITH_INFLUX_AND_ENFORCE_VALIDATION_ACCOUNTANT) diff --git a/src/test/groovy/org/prebid/server/functional/tests/MetricsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/MetricsSpec.groovy index 8a38ab04e60..df2453060a0 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/MetricsSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/MetricsSpec.groovy @@ -8,6 +8,7 @@ import org.prebid.server.functional.model.request.auction.Dooh import org.prebid.server.functional.model.request.auction.Site import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR import static org.prebid.server.functional.model.config.AccountMetricsVerbosityLevel.BASIC @@ -18,7 +19,11 @@ import static org.prebid.server.functional.model.request.auction.DistributionCha class MetricsSpec extends BaseSpec { - private final PrebidServerService softPrebidService = pbsServiceFactory.getService(['auction.strict-app-site-dooh': 'false']) + private static PrebidServerService softPrebidService + + def setupSpec() { + softPrebidService = pbsServiceFactory.getService(new PbsContainerConfig(['auction.strict-app-site-dooh': 'false'])) + } def setup() { flushMetrics(defaultPbsService) diff --git a/src/test/groovy/org/prebid/server/functional/tests/OrtbConverterSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/OrtbConverterSpec.groovy index 61e9463ed41..c90010b9eaa 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/OrtbConverterSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/OrtbConverterSpec.groovy @@ -30,8 +30,8 @@ import org.prebid.server.functional.model.request.auction.Video import org.prebid.server.functional.model.request.auction.VideoPlcmtSubtype import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils -import spock.lang.Shared import static org.prebid.server.functional.model.request.auction.Content.Channel import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP @@ -41,10 +41,13 @@ class OrtbConverterSpec extends BaseSpec { private final static String ORTB_PROPERTY_VERSION = "adapters.generic.ortb-version" - @Shared - PrebidServerService prebidServerServiceWithNewOrtb = pbsServiceFactory.getService([(ORTB_PROPERTY_VERSION): "2.6"]) - @Shared - PrebidServerService prebidServerServiceWithElderOrtb = pbsServiceFactory.getService([(ORTB_PROPERTY_VERSION): "2.5"]) + private static PrebidServerService prebidServerServiceWithNewOrtb + private static PrebidServerService prebidServerServiceWithElderOrtb + + def setupSpec() { + prebidServerServiceWithNewOrtb = pbsServiceFactory.getService(new PbsContainerConfig([(ORTB_PROPERTY_VERSION): "2.6"])) + prebidServerServiceWithElderOrtb = pbsServiceFactory.getService(new PbsContainerConfig([(ORTB_PROPERTY_VERSION): "2.5"])) + } def "PBS shouldn't move regs.{gdpr,usPrivacy} to regs.ext.{gdpr,usPrivacy} when adapter support ortb 2.6"() { given: "Default bid request with regs object" diff --git a/src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy index dd3b49efcc1..a9d3a64aa15 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy @@ -17,14 +17,14 @@ import org.prebid.server.functional.model.request.auction.Format import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.ImpExt import org.prebid.server.functional.model.request.auction.ImpExtPrebid +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.StoredBidResponse -import org.prebid.server.functional.model.request.profile.Profile import org.prebid.server.functional.model.request.profile.ImpProfile +import org.prebid.server.functional.model.request.profile.Profile import org.prebid.server.functional.model.request.profile.ProfileMergePrecedence -import org.prebid.server.functional.model.request.profile.RequestProfile import org.prebid.server.functional.model.request.profile.ProfileType -import org.prebid.server.functional.model.request.auction.Site +import org.prebid.server.functional.model.request.profile.RequestProfile import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.model.response.auction.SeatBid @@ -32,9 +32,9 @@ import org.prebid.server.functional.repository.dao.ProfileImpDao import org.prebid.server.functional.repository.dao.ProfileRequestDao import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.testcontainers.container.PrebidServerContainer +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.util.ContainerFileUtil import org.prebid.server.functional.util.PBSUtils -import org.testcontainers.images.builder.Transferable import spock.lang.PendingFeature import static org.prebid.server.functional.model.AccountStatus.ACTIVE @@ -54,20 +54,20 @@ class ProfileSpec extends BaseSpec { private static final Integer LIMIT_HOST_PROFILE = 2 private static final Integer ACCOUNT_ID_FILE_STORAGE = PBSUtils.randomNumber - private static final Map FILESYSTEM_CONFIG = [ + private static final PbsContainerConfig FILESYSTEM_CONFIG = new PbsContainerConfig([ 'settings.filesystem.settings-filename' : SETTINGS_FILENAME, 'settings.filesystem.profiles-dir' : PROFILES_PATH, 'settings.filesystem.stored-requests-dir' : REQUESTS_PATH, 'settings.filesystem.stored-imps-dir' : IMPS_PATH, 'settings.filesystem.stored-responses-dir': RESPONSES_PATH, 'settings.filesystem.categories-dir' : CATEGORIES_PATH - ] + ]) - private static final Map PROFILES_CONFIG = [ + private static final PbsContainerConfig PROFILES_CONFIG = new PbsContainerConfig([ 'auction.profiles.fail-on-unknown': "false", 'auction.profiles.limit' : LIMIT_HOST_PROFILE.toString(), 'settings.database.profiles-query': "SELECT accountId, profileId, profile, mergePrecedence, type FROM profiles " + - "WHERE profileId in (%REQUEST_ID_LIST%, %IMP_ID_LIST%)".toString()] + "WHERE profileId in (%REQUEST_ID_LIST%, %IMP_ID_LIST%)".toString()]) private static final String LIMIT_ERROR_MESSAGE = 'Profiles exceeded the limit.' private static final String CONFIG_ERROR_MESSAGE = 'Profiles storage not configured.' @@ -82,7 +82,6 @@ class ProfileSpec extends BaseSpec { private static final ProfileImpDao profileImpDao = repository.profileImpDao private static final ProfileRequestDao profileRequestDao = repository.profileRequestDao - private static PrebidServerContainer pbsContainer private static PrebidServerService pbsWithStoredProfiles private static RequestProfile fileRequestProfile private static RequestProfile fileRequestProfileWithEmptyMerge @@ -90,11 +89,8 @@ class ProfileSpec extends BaseSpec { private static ImpProfile fileImpProfileWithEmptyMerge def setupSpec() { - pbsContainer = new PrebidServerContainer(FILESYSTEM_CONFIG + PROFILES_CONFIG) fileRequestProfile = RequestProfile.getProfile(ACCOUNT_ID_FILE_STORAGE.toString()) fileImpProfile = ImpProfile.getProfile(ACCOUNT_ID_FILE_STORAGE.toString()) - pbsContainer.withCopyToContainer(Transferable.of(encode(fileRequestProfile)), "$PROFILES_PATH/${fileRequestProfile.fileName}") - pbsContainer.withCopyToContainer(Transferable.of(encode(fileImpProfile)), "$PROFILES_PATH/${fileImpProfile.fileName}") fileRequestProfileWithEmptyMerge = RequestProfile.getProfile(ACCOUNT_ID_FILE_STORAGE.toString()).tap { mergePrecedence = null } @@ -105,21 +101,13 @@ class ProfileSpec extends BaseSpec { } mergePrecedence = null } - pbsContainer.withCopyToContainer(Transferable.of(encode(fileRequestProfileWithEmptyMerge)), "$PROFILES_PATH/${fileRequestProfileWithEmptyMerge.fileName}") - pbsContainer.withCopyToContainer(Transferable.of(encode(fileImpProfileWithEmptyMerge)), "$PROFILES_PATH/${fileImpProfileWithEmptyMerge.fileName}") - pbsContainer.withFolder(REQUESTS_PATH) - pbsContainer.withFolder(IMPS_PATH) - pbsContainer.withFolder(RESPONSES_PATH) - pbsContainer.withFolder(CATEGORIES_PATH) + def profiles = [fileRequestProfile, fileImpProfile, fileRequestProfileWithEmptyMerge, fileImpProfileWithEmptyMerge] + .collectEntries { profile -> ContainerFileUtil.jsonFile("$PROFILES_PATH/${profile.fileName}", profile)} def accountsConfig = new FileSystemAccountsConfig(accounts: [new AccountConfig(id: ACCOUNT_ID_FILE_STORAGE, status: ACTIVE)]) - pbsContainer.withCopyToContainer(Transferable.of(encodeYaml(accountsConfig)), - SETTINGS_FILENAME) - pbsContainer.start() - pbsWithStoredProfiles = new PrebidServerService(pbsContainer) - } + def accountsFile = ContainerFileUtil.yamlFile(SETTINGS_FILENAME, accountsConfig) + def folders = ContainerFileUtil.emptyFolders(REQUESTS_PATH, IMPS_PATH, RESPONSES_PATH, CATEGORIES_PATH) - def cleanupSpec() { - pbsContainer.stop() + pbsWithStoredProfiles = pbsServiceFactory.getService((FILESYSTEM_CONFIG + PROFILES_CONFIG).withFiles(folders + profiles + accountsFile)) } def "PBS should use profile for request when it exist in database"() { @@ -934,9 +922,6 @@ class ProfileSpec extends BaseSpec { def exception = thrown(PrebidServerException) assert exception.statusCode == 400 assert exception.responseBody == INVALID_REQUEST_PREFIX + NO_IMP_PROFILE_MESSAGE.formatted(invalidProfileId) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(PROFILES_CONFIG + ['auction.profiles.fail-on-unknown': 'true']) } def "PBS should fail auction when fail-on-unknown-profile default and profile is missing"() { @@ -960,9 +945,6 @@ class ProfileSpec extends BaseSpec { def exception = thrown(PrebidServerException) assert exception.statusCode == 400 assert exception.responseBody == INVALID_REQUEST_PREFIX + NO_IMP_PROFILE_MESSAGE.formatted(invalidProfileId) - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(PROFILES_CONFIG + ['auction.profiles.fail-on-unknown': null]) } def "PBS should prioritise fail-on-unknown-profile from account over host config"() { @@ -1522,35 +1504,19 @@ class ProfileSpec extends BaseSpec { ] } - def "PBS should throw exception when profiles are not configured for filesystem and request contain profileId"() { - given: "PBS with profiles.fail-on-unknown config" - def config = FILESYSTEM_CONFIG + PROFILES_CONFIG + ['settings.filesystem.profiles-dir': null] - pbsContainer = new PrebidServerContainer(config) - pbsContainer.withFolder(REQUESTS_PATH) - pbsContainer.withFolder(IMPS_PATH) - pbsContainer.withFolder(RESPONSES_PATH) - pbsContainer.withFolder(CATEGORIES_PATH) - def accountsConfig = new FileSystemAccountsConfig(accounts: [new AccountConfig(id: ACCOUNT_ID_FILE_STORAGE, status: ACTIVE)]) - pbsContainer.withCopyToContainer(Transferable.of(encodeYaml(accountsConfig)), - SETTINGS_FILENAME) - pbsContainer.start() - pbsWithStoredProfiles = new PrebidServerService(pbsContainer) - - and: "BidRequest with profile" + def "PBS should throw exception when profiles are not configured for filesystem and request contains profileId"() { + given: "BidRequest with profile" def requestWithProfile = BidRequest.getDefaultBidRequest().tap { - it.ext.prebid.profileNames = [PBSUtils.randomString] + ext.prebid.profileNames = [PBSUtils.randomString] } when: "PBS processes auction request" defaultPbsService.sendAuctionRequest(requestWithProfile) - then: "PBs should throw error due to invalid profile config" + then: "PBS should throw error due to invalid profile config" def exception = thrown(PrebidServerException) assert exception.statusCode == 400 assert exception.responseBody == INVALID_REQUEST_PREFIX + CONFIG_ERROR_MESSAGE - - cleanup: "Stop and remove pbs container" - pbsContainer.stop() } private static BidRequest getRequestWithProfiles(String accountId, List profiles) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/SchainSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/SchainSpec.groovy index 9b0dce39aec..cd8616e0aea 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/SchainSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/SchainSpec.groovy @@ -7,8 +7,8 @@ import org.prebid.server.functional.model.request.auction.SourceExt import org.prebid.server.functional.model.request.auction.SupplyChain import org.prebid.server.functional.model.request.auction.SupplyChainNode import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils -import spock.lang.Shared import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN @@ -16,15 +16,28 @@ import static org.prebid.server.functional.model.request.auction.Fd.EXCHANGE class SchainSpec extends BaseSpec { - private static final GLOBAL_SUPPLY_SCHAIN_NODE = new SupplyChainNode().tap { + private static final SupplyChainNode GLOBAL_SUPPLY_SCHAIN_NODE = new SupplyChainNode().tap { asi = PBSUtils.randomString sid = PBSUtils.randomString hp = PBSUtils.randomNumber rid = PBSUtils.randomString } - @Shared - PrebidServerService prebidServerService = pbsServiceFactory.getService(["auction.host-schain-node": encode(GLOBAL_SUPPLY_SCHAIN_NODE)]) + private static final PbsContainerConfig GLOBAL_SCHAIN_CONFIG = new PbsContainerConfig(['auction.host-schain-node': encode(GLOBAL_SUPPLY_SCHAIN_NODE)]) + private static final PbsContainerConfig ORTB_25_CONFIG = new PbsContainerConfig(['adapters.generic.ortb-version': '2.5']) + + private static PrebidServerService prebidServerService + private static PrebidServerService ortb25PbsService + + def setupSpec() { + prebidServerService = pbsServiceFactory.getService(GLOBAL_SCHAIN_CONFIG) + ortb25PbsService = pbsServiceFactory.getService(ORTB_25_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(GLOBAL_SCHAIN_CONFIG) + pbsServiceFactory.removeContainer(ORTB_25_CONFIG) + } def "Global schain node should be appended when only ext.prebid.schains exists"() { given: "Basic bid request" @@ -161,10 +174,7 @@ class SchainSpec extends BaseSpec { } def "PBS should use source.ext.schain when ext.prebid.schains.bidder isn't requested"() { - given: "Pbs config" - def defaultPbsService = pbsServiceFactory.getService([("adapters.generic.ortb-version"): "2.5"]) - - and: "Default basic BidRequest with schain obj" + given: "Default basic BidRequest with schain obj" def supplyChain = SupplyChain.defaultSupplyChain def bidRequest = BidRequest.defaultBidRequest.tap { source = new Source(ext: new SourceExt(schain: supplyChain)) @@ -172,7 +182,7 @@ class SchainSpec extends BaseSpec { } when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + ortb25PbsService.sendAuctionRequest(bidRequest) then: "Bidder request should contain requested source.ext.schain" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -181,10 +191,7 @@ class SchainSpec extends BaseSpec { } def "PBS should use ext.prebid.schains.schain instead of source.ext.chain when ext.prebid.schains.bidder is requested"() { - given: "Pbs config" - def defaultPbsService = pbsServiceFactory.getService([("adapters.generic.ortb-version"): "2.5"]) - - and: "Default basic BidRequest with schain obj" + given: "Default basic BidRequest with schain obj" def supplyChain = SupplyChain.defaultSupplyChain def bidRequest = BidRequest.defaultBidRequest.tap { source = new Source(ext: new SourceExt(schain: SupplyChain.defaultSupplyChain)) @@ -192,7 +199,7 @@ class SchainSpec extends BaseSpec { } when: "PBS processes auction request" - defaultPbsService.sendAuctionRequest(bidRequest) + ortb25PbsService.sendAuctionRequest(bidRequest) then: "Bidder request should contain requested ext.prebid.schains[*].schain" def bidderRequest = bidder.getBidderRequest(bidRequest.id) diff --git a/src/test/groovy/org/prebid/server/functional/tests/SeatNonBidSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/SeatNonBidSpec.groovy index d4886f35e98..edc7cb9d4ed 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/SeatNonBidSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/SeatNonBidSpec.groovy @@ -13,16 +13,17 @@ import org.prebid.server.functional.model.request.auction.StoredAuctionResponse import org.prebid.server.functional.model.response.auction.Adm import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.SeatBid +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils +import static org.apache.http.HttpStatus.SC_BAD_REQUEST import static org.apache.http.HttpStatus.SC_CONTINUE import static org.apache.http.HttpStatus.SC_INSUFFICIENT_STORAGE -import static org.apache.http.HttpStatus.SC_OK -import static org.apache.http.HttpStatus.SC_BAD_REQUEST +import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR import static org.apache.http.HttpStatus.SC_NO_CONTENT +import static org.apache.http.HttpStatus.SC_OK import static org.apache.http.HttpStatus.SC_PROCESSING import static org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE -import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR import static org.prebid.server.functional.model.AccountStatus.ACTIVE import static org.prebid.server.functional.model.config.BidValidationEnforcement.ENFORCE import static org.prebid.server.functional.model.request.auction.DebugCondition.DISABLED @@ -32,10 +33,10 @@ import static org.prebid.server.functional.model.request.auction.SecurityLevel.S import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_BIDDER_UNREACHABLE import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_INVALID_BID_RESPONSE import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_NO_BID +import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_TIMED_OUT import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BLOCKED_UNSUPPORTED_MEDIA_TYPE import static org.prebid.server.functional.model.response.auction.BidRejectionReason.RESPONSE_REJECTED_INVALID_CREATIVE_NOT_SECURE import static org.prebid.server.functional.model.response.auction.BidRejectionReason.RESPONSE_REJECTED_INVALID_CREATIVE_SIZE -import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_TIMED_OUT class SeatNonBidSpec extends BaseSpec { @@ -146,7 +147,7 @@ class SeatNonBidSpec extends BaseSpec { def "PBS should populate seatNonBid when returnAllBidStatus=true and requested bidder responded with not secure status code"() { given: "PBS with secure-markup enforcement" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": ENFORCE.value]) + def pbsService = pbsServiceFactory.getService(new PbsContainerConfig(["auction.validations.secure-markup": ENFORCE.value])) and: "A bid request with secure and returnAllBidStatus flags set" def bidRequest = requestWithAllBidStatus.tap { @@ -257,7 +258,7 @@ class SeatNonBidSpec extends BaseSpec { def "PBS should populate seatNonBid when bidder is rejected due to timeout"() { given: "PBS config with min and max time-out" def timeout = 50 - def pbsService = pbsServiceFactory.getService(["auction.biddertmax.min": timeout as String]) + def pbsService = pbsServiceFactory.getService(new PbsContainerConfig(["auction.biddertmax.min": timeout as String])) and: "Default bid request with max timeout" def bidRequest = requestWithAllBidStatus.tap { @@ -285,9 +286,9 @@ class SeatNonBidSpec extends BaseSpec { def "PBS should populate seatNonBid when filter-imp-media-type=true and imp doesn't contain supported media type"() { given: "Pbs config" - def pbsService = pbsServiceFactory.getService( + def pbsService = pbsServiceFactory.getService(new PbsContainerConfig( ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.site-media-types": "banner"]) + "adapters.generic.meta-info.site-media-types": "banner"])) and: "Default basic BidRequest with banner" def bidRequest = BidRequest.defaultVideoRequest.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/SecondaryBidderSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/SecondaryBidderSpec.groovy index 706e5a9d648..64f5edee1fa 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/SecondaryBidderSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/SecondaryBidderSpec.groovy @@ -9,13 +9,13 @@ import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.Bidder import org.prebid.server.functional.util.PBSUtils -import spock.lang.Shared import static org.prebid.server.functional.model.bidder.BidderName.ALIAS -import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_TIMED_OUT import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer @@ -31,17 +31,18 @@ class SecondaryBidderSpec extends BaseSpec { "adapters.${GENERIC.value}.aliases.${ALIAS}.enabled" : "true", "adapters.${GENERIC.value}.aliases.${ALIAS}.meta-info.vendor-id": "0", "adapters.${GENERIC.value}.aliases.${ALIAS}.endpoint" : "$networkServiceContainer.rootUri$GENERIC_ALIAS_AUCTION_ENDPOINT".toString()] + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig(OPENX_CONFIG + GENERIC_ALIAS_CONFIG) private static final Integer RESPONSE_DELAY_MILLISECONDS = 5_000 private static final Bidder openXBidder = new Bidder(networkServiceContainer, OPENX_AUCTION_ENDPOINT) private static final Bidder genericAliasBidder = new Bidder(networkServiceContainer, GENERIC_ALIAS_AUCTION_ENDPOINT) private static final String WARNING_TIME_OUT_MESSAGE = "secondary bidder timed out, auction proceeded" - private static final PrebidServerService pbsServiceWithOpenXBidder = pbsServiceFactory.getService(OPENX_CONFIG + GENERIC_ALIAS_CONFIG) + private static final PrebidServerService pbsServiceWithOpenXBidder = pbsServiceFactory.getService(PBS_CONFIG) @Override def cleanupSpec() { - pbsServiceFactory.removeContainer(OPENX_CONFIG + GENERIC_ALIAS_CONFIG) + pbsServiceFactory.removeContainer(PBS_CONFIG) } def setup() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/SetUidSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/SetUidSpec.groovy index d14d58c3f61..5e7f20aaa34 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/SetUidSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/SetUidSpec.groovy @@ -6,10 +6,10 @@ import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo import org.prebid.server.functional.model.response.setuid.SetuidResponse import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.TcfConsent import org.prebid.server.util.ResourceUtil -import spock.lang.Shared import java.time.Clock import java.time.ZonedDateTime @@ -21,9 +21,9 @@ import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE import static org.prebid.server.functional.model.bidder.BidderName.GRID +import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.OPENX_ALIAS -import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN import static org.prebid.server.functional.model.bidder.BidderName.WILDCARD import static org.prebid.server.functional.model.request.setuid.UidWithExpiry.defaultUidWithExpiry @@ -42,13 +42,14 @@ class SetUidSpec extends BaseSpec { private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync" private static final String GENERIC_COOKIE_FAMILY_NAME = GENERIC.value private static final String VENDOR_ID = PBSUtils.randomNumber as String - private static final Map UID_COOKIES_CONFIG = ['setuid.number-of-uid-cookies': MAX_NUMBER_OF_UID_COOKIES.toString()] - private static final Map GENERIC_ALIAS_CONFIG = ["adapters.generic.aliases.alias.enabled" : "true", - "adapters.generic.aliases.alias.meta-info.vendor-id": "0", - "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] + private static final PbsContainerConfig UID_COOKIES_CONFIG = new PbsContainerConfig( + ['setuid.number-of-uid-cookies': MAX_NUMBER_OF_UID_COOKIES.toString()]) + private static final PbsContainerConfig GENERIC_ALIAS_CONFIG = new PbsContainerConfig(["adapters.generic.aliases.alias.enabled" : "true", + "adapters.generic.aliases.alias.meta-info.vendor-id": "0", + "adapters.generic.aliases.alias.endpoint" : "$networkServiceContainer.rootUri/auction".toString()]) private static final String TCF_ERROR_MESSAGE = "The gdpr_consent param prevents cookies from being saved" private static final int UNAVAILABLE_FOR_LEGAL_REASONS_CODE = 451 - private static final Map PBS_CONFIG = + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig( ["host-cookie.max-cookie-size-bytes" : MAX_COOKIE_SIZE as String, "adapters.${MAGNITE.value}.enabled" : "true", @@ -83,12 +84,25 @@ class SetUidSpec extends BaseSpec { "adapters.${GENERIC}.aliases.${OPENX_ALIAS}.meta-info.vendor-id" : VENDOR_ID, "adapters.${GENERIC}.aliases.${OPENX_ALIAS}.usersync.cookie-family-name" : GENERIC_COOKIE_FAMILY_NAME, "adapters.${GENERIC}.aliases.${OPENX_ALIAS}.usersync.${USER_SYNC_TYPE.value}.url" : USER_SYNC_URL, - "adapters.${GENERIC}.aliases.${OPENX_ALIAS}.usersync.${USER_SYNC_TYPE.value}.uid-macro" : ""] + "adapters.${GENERIC}.aliases.${OPENX_ALIAS}.usersync.${USER_SYNC_TYPE.value}.uid-macro" : ""]) + + private static final PbsContainerConfig SINGLE_COOKIES_CONFIG = PBS_CONFIG + GENERIC_ALIAS_CONFIG + private static final PbsContainerConfig MULTIPLE_COOKIES_CONFIG = SINGLE_COOKIES_CONFIG + UID_COOKIES_CONFIG + private static final PbsContainerConfig PRIORITIZED_GENERIC_CONFIG = PBS_CONFIG + ['cookie-sync.pri': GENERIC.value] - @Shared - PrebidServerService singleCookiesPbsService = pbsServiceFactory.getService(PBS_CONFIG + GENERIC_ALIAS_CONFIG) - @Shared - PrebidServerService multipleCookiesPbsService = pbsServiceFactory.getService(PBS_CONFIG + UID_COOKIES_CONFIG + GENERIC_ALIAS_CONFIG) + private static PrebidServerService singleCookiesPbsService + private static PrebidServerService multipleCookiesPbsService + + def setupSpec() { + singleCookiesPbsService = pbsServiceFactory.getService(SINGLE_COOKIES_CONFIG) + multipleCookiesPbsService = pbsServiceFactory.getService(MULTIPLE_COOKIES_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(SINGLE_COOKIES_CONFIG) + pbsServiceFactory.removeContainer(MULTIPLE_COOKIES_CONFIG) + pbsServiceFactory.removeContainer(PRIORITIZED_GENERIC_CONFIG) + } def "PBS should set uids cookie"() { given: "Default SetuidRequest" @@ -195,7 +209,7 @@ class SetUidSpec extends BaseSpec { def "PBS setuid should remove most distant expiration bidder when size is full"() { given: "PBS config" - def pbsConfig = PBS_CONFIG + ["cookie-sync.pri": GENERIC.value] + def pbsConfig = PRIORITIZED_GENERIC_CONFIG def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Setuid request" @@ -219,9 +233,6 @@ class SetUidSpec extends BaseSpec { then: "Response should contain uids cookies" assert response.uidsCookie.tempUIDs[MAGNITE] assert response.uidsCookie.tempUIDs[GENERIC] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS setuid should ignore requested bidder and log metric when cookie's filled and requested bidder not in prioritize list"() { @@ -291,7 +302,7 @@ class SetUidSpec extends BaseSpec { def "PBS setuid should remove most distant expiration uid and log metric when cookie's filled and this uid's not on the pri"() { given: "PBS config" - def pbsConfig = PBS_CONFIG + ["cookie-sync.pri": GENERIC.value] + def pbsConfig = PRIORITIZED_GENERIC_CONFIG def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Flush metrics" @@ -317,9 +328,6 @@ class SetUidSpec extends BaseSpec { then: "Response should contain uids cookies" assert response.uidsCookie.tempUIDs[APPNEXUS] assert response.uidsCookie.tempUIDs[GENERIC] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS set uid should emit sizeblocked metric and remove most distant expiration bidder from uids cookie for non-prioritized bidder"() { @@ -452,6 +460,9 @@ class SetUidSpec extends BaseSpec { def exception = thrown(PrebidServerException) assert exception.statusCode == 401 assert exception.responseBody == 'Unauthorized: Sync is not allowed for this uids' + + cleanup: "Stop and remove pbs container" + pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should merge cookies when incoming request have multiple uids cookies"() { @@ -479,13 +490,10 @@ class SetUidSpec extends BaseSpec { def "PBS should send multiple uids cookies by priority and expiration timestamp"() { given: "PBS config" - def pbsConfig = PBS_CONFIG + - UID_COOKIES_CONFIG + - ["cookie-sync.pri": "$OPENX.value, $GENERIC.value" as String] + - ["host-cookie.max-cookie-size-bytes": MAX_COOKIE_SIZE as String] + def pbsConfig = PBS_CONFIG + UID_COOKIES_CONFIG + + ['cookie-sync.pri': "${OPENX.value}, ${GENERIC.value}"] def prebidServerService = pbsServiceFactory.getService(pbsConfig) - and: "Setuid request" def request = SetuidRequest.defaultSetuidRequest diff --git a/src/test/groovy/org/prebid/server/functional/tests/StoredResponseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/StoredResponseSpec.groovy index 0b6f62923c7..731c73cbd1b 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/StoredResponseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/StoredResponseSpec.groovy @@ -11,6 +11,7 @@ import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.model.response.auction.SeatBid import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import spock.lang.PendingFeature @@ -18,7 +19,11 @@ import static org.prebid.server.functional.model.bidder.BidderName.GENERIC class StoredResponseSpec extends BaseSpec { - private final PrebidServerService pbsService = pbsServiceFactory.getService(["cache.default-ttl-seconds.banner": ""]) + private static PrebidServerService pbsService + + def setupSpec() { + pbsService = pbsServiceFactory.getService(new PbsContainerConfig(["cache.default-ttl-seconds.banner": ""])) + } @PendingFeature def "PBS should not fail auction with storedAuctionResponse when request bidder params doesn't satisfy json-schema"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/TargetingSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/TargetingSpec.groovy index 008f4c6a721..845fba19590 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/TargetingSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/TargetingSpec.groovy @@ -35,6 +35,7 @@ import org.prebid.server.functional.model.response.auction.SeatBid import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.Bidder import org.prebid.server.functional.util.PBSUtils @@ -65,17 +66,23 @@ class TargetingSpec extends BaseSpec { private static final String EMPTY_CPM = "0.0" private static final Integer DEFAULT_TRUNCATE_CHARS = 20 private static final Integer EXTENDED_TRUNCATE_CHARS = PbsConfig.targetingConfig.get('settings.targeting.truncate-attr-chars').toInteger() - private static final Map EMPTY_TARGETING_CONFIG = ['settings.targeting.truncate-attr-chars': null] as Map - private static final Map ONLY_WINNING_BIDS_CONFIG = ["auction.cache.only-winning-bids": "true"] - private static final Map DISABLED_ONLY_WINNING_BIDS_CONFIG = ["auction.cache.only-winning-bids": "false"] private static final String DROP_PREFIX_WARNING = "Key prefix value is dropped to default. " + "Decrease custom prefix length or increase truncateattrchars by %s" private static final String TRUNCATED_WARNING = "The following keys have been truncated:" - private static final PrebidServerService pbsWithDefaultTargetingLength = pbsServiceFactory.getService(EMPTY_TARGETING_CONFIG) - private static final PrebidServerService pbsWithOnlyWinningBids = pbsServiceFactory.getService(EMPTY_TARGETING_CONFIG + ONLY_WINNING_BIDS_CONFIG) - private static final PrebidServerService pbsWithDisabledOnlyWinningBids = pbsServiceFactory.getService(EMPTY_TARGETING_CONFIG + DISABLED_ONLY_WINNING_BIDS_CONFIG) + private static final PbsContainerConfig EMPTY_TARGETING_CONFIG = new PbsContainerConfig(['settings.targeting.truncate-attr-chars': null]) + private static final PbsContainerConfig ONLY_WINNING_BIDS_CONFIG = EMPTY_TARGETING_CONFIG + ['auction.cache.only-winning-bids': 'true'] + private static final PbsContainerConfig DISABLED_ONLY_WINNING_BIDS_CONFIG = EMPTY_TARGETING_CONFIG + ['auction.cache.only-winning-bids': 'false'] + private static PrebidServerService pbsWithDefaultTargetingLength + private static PrebidServerService pbsWithOnlyWinningBids + private static PrebidServerService pbsWithDisabledOnlyWinningBids + + def setupSpec() { + pbsWithDefaultTargetingLength = pbsServiceFactory.getService(EMPTY_TARGETING_CONFIG) + pbsWithOnlyWinningBids = pbsServiceFactory.getService(ONLY_WINNING_BIDS_CONFIG) + pbsWithDisabledOnlyWinningBids = pbsServiceFactory.getService(DISABLED_ONLY_WINNING_BIDS_CONFIG) + } def cleanupSpec() { pbsServiceFactory.removeContainer(EMPTY_TARGETING_CONFIG + ONLY_WINNING_BIDS_CONFIG) pbsServiceFactory.removeContainer(EMPTY_TARGETING_CONFIG + DISABLED_ONLY_WINNING_BIDS_CONFIG) @@ -429,10 +436,10 @@ class TargetingSpec extends BaseSpec { def "PBS should auction populate ext.prebid.targeting with proper size when truncateTargetAttr is define"() { given: "PBs config with additional openx bidder" - def pbsConfig = [ + def pbsConfig = new PbsContainerConfig([ "adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()] - def pbsWithDefaultTargetingLength = pbsServiceFactory.getService(pbsConfig) + "adapters.openx.endpoint": "$networkServiceContainer.rootUri/auction".toString()]) + def pbsWithOpenx = pbsServiceFactory.getService(pbsConfig) and: "Default bid request" def accountId = PBSUtils.randomNumber as String @@ -449,7 +456,7 @@ class TargetingSpec extends BaseSpec { accountDao.save(account) when: "PBS processes auction request" - def response = pbsWithDefaultTargetingLength.sendAuctionRequest(bidRequest) + def response = pbsWithOpenx.sendAuctionRequest(bidRequest) then: "Response should contain targeting with corresponding length" assert response.seatbid.bid.ext.prebid.targeting @@ -1281,7 +1288,7 @@ class TargetingSpec extends BaseSpec { def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) and: "PBS with default account" - def pbsConfig = ["settings.default-account-config": encode(accountConfig)] + def pbsConfig = new PbsContainerConfig(["settings.default-account-config": encode(accountConfig)]) def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default basic BidRequest" @@ -1632,8 +1639,8 @@ class TargetingSpec extends BaseSpec { def "PBS should assign bid ranks across all seatbids combined when the request contains imps with multiple bidders"() { given: "PBS config with openX bidder" def endpoint = '/openx-auction' - def pbsConfig = ["adapters.openx.enabled" : "true", - "adapters.openx.endpoint": "$networkServiceContainer.rootUri$endpoint".toString()] + def pbsConfig = new PbsContainerConfig(["adapters.openx.enabled" : "true", + "adapters.openx.endpoint": "$networkServiceContainer.rootUri$endpoint".toString()]) def prebidServerService = pbsServiceFactory.getService(pbsConfig) def openxBidder = new Bidder(networkServiceContainer, endpoint) diff --git a/src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy index cff45989db1..f09db6be7c7 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy @@ -5,12 +5,12 @@ 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.PrebidStoredRequest import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.testcontainers.container.PrebidServerContainer +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils -import org.testcontainers.utility.MountableFile import spock.lang.Shared import static org.prebid.server.functional.testcontainers.container.PrebidServerContainer.APP_WORKDIR +import static org.prebid.server.functional.util.ContainerFileUtil.jsonFile class TimeoutSpec extends BaseSpec { @@ -18,8 +18,8 @@ class TimeoutSpec extends BaseSpec { private static final int MIN_TIMEOUT = PBSUtils.getRandomNumber(50, 150) private static final Long MAX_AUCTION_BIDDER_TIMEOUT = 3000 private static final Long MIN_AUCTION_BIDDER_TIMEOUT = 1000 - private static final Map PBS_CONFIG = ["auction.biddertmax.max": MAX_AUCTION_BIDDER_TIMEOUT as String, - "auction.biddertmax.min": MIN_AUCTION_BIDDER_TIMEOUT as String] + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig(["auction.biddertmax.max": MAX_AUCTION_BIDDER_TIMEOUT as String, + "auction.biddertmax.min": MIN_AUCTION_BIDDER_TIMEOUT as String]) @Shared PrebidServerService prebidServerService = pbsServiceFactory.getService(PBS_CONFIG) @@ -132,18 +132,13 @@ class TimeoutSpec extends BaseSpec { } def "PBS should take data by priority when request, stored request, default request are defined"() { - given: "Default request with timeout" - def defaultRequestModel = new BidRequest(tmax: defaultRequestTmax) - def defaultRequest = PBSUtils.createJsonFile(defaultRequestModel) - - and: "Pbs config with default request" - def pbsContainer = new PrebidServerContainer( - ["default-request.file.path": APP_WORKDIR + defaultRequest.fileName, - "auction.biddertmax.max" : MAX_TIMEOUT as String]).tap { - withCopyFileToContainer(MountableFile.forHostPath(defaultRequest), APP_WORKDIR) - } - pbsContainer.start() - def pbsService = new PrebidServerService(pbsContainer) + given: "PBS service with default request" + def defaultRequestPath = APP_WORKDIR + 'default-request.json' + def defaultRequest = new BidRequest(tmax: defaultRequestTmax) + def pbsConfig = new PbsContainerConfig(['default-request.file.path': defaultRequestPath, + 'auction.biddertmax.max' : MAX_TIMEOUT.toString()], + jsonFile(defaultRequestPath, defaultRequest)) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default basic BidRequest with timeout" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -156,24 +151,21 @@ class TimeoutSpec extends BaseSpec { tmax = storedRequestTmax as Long } - and: "Save storedRequest into DB" + and: "Save stored request into DB" def storedRequest = StoredRequest.getStoredRequest(bidRequest.ext.prebid.storedRequest.id, storedRequestModel) storedRequestDao.save(storedRequest) when: "PBS processes auction request with warmup" def response = pbsService.withWarmup().sendAuctionRequest(bidRequest) - then: "Response should not contain error" + then: "Response should not contain errors or warnings" assert !response.ext?.errors assert !response.ext?.warnings - then: "Bidder request should contain correct tmax" + and: "Bidder request should contain correct tmax" def bidderRequest = bidder.getBidderRequest(bidRequest.id) assert isInternalProcessingTime(bidderRequest.tmax, DEFAULT_TIMEOUT) - cleanup: "Stop container with default request" - pbsContainer.stop() - where: requestTmax | storedRequestTmax | defaultRequestTmax DEFAULT_TIMEOUT | getRandomTimeout() | getRandomTimeout() @@ -287,9 +279,9 @@ class TimeoutSpec extends BaseSpec { def "PBS should choose min timeout form config for bidder request when in request value lowest that in auction.biddertmax.min"() { given: "PBS config with percent" def minBidderTmax = PBSUtils.getRandomNumber(MIN_TIMEOUT, MAX_TIMEOUT) - def prebidServerService = pbsServiceFactory.getService( - ["auction.biddertmax.min": minBidderTmax as String, - "auction.biddertmax.max": MAX_TIMEOUT as String]) + def config = new PbsContainerConfig(["auction.biddertmax.min": minBidderTmax as String, + "auction.biddertmax.max": MAX_TIMEOUT as String]) + def prebidServerService = pbsServiceFactory.getService(config) and: "Default basic BidRequest" def timeout = PBSUtils.getRandomNumber(0, minBidderTmax) @@ -311,9 +303,9 @@ class TimeoutSpec extends BaseSpec { def "PBS should change timeout for bidder due to percent in auction.biddertmax.percent"() { given: "PBS config with percent" def percent = PBSUtils.getRandomNumber(2, 98) - def pbsConfig = ["auction.biddertmax.percent": percent as String, - "auction.biddertmax.max" : MAX_TIMEOUT as String, - "auction.biddertmax.min" : MIN_TIMEOUT as String] + def pbsConfig = new PbsContainerConfig(["auction.biddertmax.percent": percent as String, + "auction.biddertmax.max" : MAX_TIMEOUT as String, + "auction.biddertmax.min" : MIN_TIMEOUT as String]) def prebidServerService = pbsServiceFactory.getService( pbsConfig) @@ -332,14 +324,11 @@ class TimeoutSpec extends BaseSpec { and: "PBS response should contain tmax from request" assert bidResponse?.ext?.tmaxrequest == timeout as Long - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should apply auction.biddertmax.max timeout when adapters.generic.tmax-deduction-ms exceeds valid top range"() { given: "PBS config with adapters.generic.tmax-deduction-ms" - def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": PBSUtils.getRandomNumber(MAX_AUCTION_BIDDER_TIMEOUT as int) as String] + def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": PBSUtils.getRandomNumber(MAX_AUCTION_BIDDER_TIMEOUT as int)] def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default basic BidRequest with generic bidder" @@ -356,14 +345,11 @@ class TimeoutSpec extends BaseSpec { and: "PBS response should contain tmax" assert bidResponse?.ext?.tmaxrequest == MAX_AUCTION_BIDDER_TIMEOUT - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should resolve timeout as usual when adapters.generic.tmax-deduction-ms specifies zero"() { given: "PBS config with adapters.generic.tmax-deduction-ms" - def pbsConfig = ["adapters.generic.tmax-deduction-ms": "0"] + PBS_CONFIG + def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": "0"] def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default basic BidRequest with generic bidder" @@ -383,9 +369,6 @@ class TimeoutSpec extends BaseSpec { and: "PBS response should contain tmax" assert bidResponse?.ext?.tmaxrequest == timeout as Long - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should properly resolve tmax deduction ms when adapters.generic.tmax-deduction-ms specified"() { @@ -409,9 +392,6 @@ class TimeoutSpec extends BaseSpec { and: "PBS response should contain tmax" assert bidResponse?.ext?.tmaxrequest == randomTimeout as Long - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } private static long getPercentOfValue(int percent, int value) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/TopicsHeaderSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/TopicsHeaderSpec.groovy index ea2bbebb67e..38f6060db4f 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/TopicsHeaderSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/TopicsHeaderSpec.groovy @@ -7,6 +7,7 @@ import org.prebid.server.functional.model.request.auction.ExtData import org.prebid.server.functional.model.request.auction.Segment import org.prebid.server.functional.model.request.auction.User import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.HttpUtil import org.prebid.server.functional.util.PBSUtils @@ -15,8 +16,11 @@ class TopicsHeaderSpec extends BaseSpec { private static final DEFAULT_SEGTAX_VALUE = 599 private static final PRIVACY_SENDBOX_DOMAIN = "privacy-sandbox-domain" - private final PrebidServerService prebidServerServiceWithTopicsDomain - = pbsServiceFactory.getService(["auction.privacysandbox.topicsdomain": PRIVACY_SENDBOX_DOMAIN]) + private static PrebidServerService prebidServerServiceWithTopicsDomain + + def setupSpec() { + prebidServerServiceWithTopicsDomain = pbsServiceFactory.getService(new PbsContainerConfig(["auction.privacysandbox.topicsdomain": PRIVACY_SENDBOX_DOMAIN])) + } def "PBS should populate user.data when Sec-Browsing-Topics header present in request"() { given: "Default basic BidRequest with generic bidder" @@ -260,8 +264,8 @@ class TopicsHeaderSpec extends BaseSpec { def "PBS should populate user.data with empty name when privacy sand box present with empty name"() { given: "PBS with empty auction privacy sand box" - def prebidServerServiceWithTopicsDomain - = pbsServiceFactory.getService(["auction.privacysandbox.topicsdomain": topicsdomain]) + def config = new PbsContainerConfig(["auction.privacysandbox.topicsdomain": topicsdomain]) + def prebidServerServiceWithTopicsDomain = pbsServiceFactory.getService(config) and: "Default basic BidRequest with generic bidder" def bidRequest = BidRequest.defaultBidRequest.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/UUIDSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/UUIDSpec.groovy index eb988ac130b..6e57676dd46 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/UUIDSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/UUIDSpec.groovy @@ -7,6 +7,8 @@ import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.PrebidStoredRequest import org.prebid.server.functional.model.request.auction.Source +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP @@ -14,11 +16,19 @@ import static org.prebid.server.functional.model.request.auction.DistributionCha class UUIDSpec extends BaseSpec { - def "PBS auction should generate UUID for APP BidRequest id and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) + private static final PbsContainerConfig GENERATION_ENABLED_CONFIG = new PbsContainerConfig(['settings.generate-storedrequest-bidrequest-id': 'true']) + private static final PbsContainerConfig GENERATION_DISABLED_CONFIG = new PbsContainerConfig(['settings.generate-storedrequest-bidrequest-id': 'false']) - and: "Flush metrics" + private static PrebidServerService pbsWithGenerationEnabled + private static PrebidServerService pbsWithGenerationDisabled + + def setupSpec() { + pbsWithGenerationEnabled = pbsServiceFactory.getService(GENERATION_ENABLED_CONFIG) + pbsWithGenerationDisabled = pbsServiceFactory.getService(GENERATION_DISABLED_CONFIG) + } + + def "PBS auction should generate UUID for APP BidRequest id and merge StoredRequest"() { + given: "Flush metrics" flushMetrics(pbsService) and: "Default bid request with stored request and id" @@ -49,10 +59,10 @@ class UUIDSpec extends BaseSpec { assert bidderRequest.id != bidRequestId where: - bidRequestId | generateBidRequestId - null | "false" - PBSUtils.randomString | "true" - "{{UUID}}" | "false" + bidRequestId | pbsService + null | pbsWithGenerationDisabled + PBSUtils.randomString | pbsWithGenerationEnabled + "{{UUID}}" | pbsWithGenerationDisabled } def "PBS auction shouldn't generate UUID for BidRequest id when BidRequest doesn't have APP"() { @@ -81,11 +91,8 @@ class UUIDSpec extends BaseSpec { assert bidderRequest.id == bidRequestId } - def "PBS amp should generate UUID for BidRequest id and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) - - and: "Default AMP request with custom Id" + def "PBS amp should generate UUID for BidRequest id and merge StoredRequest"() { + given: "Default AMP request with custom Id" def ampRequest = AmpRequest.defaultAmpRequest.tap { tagId = bidRequestId } @@ -106,16 +113,13 @@ class UUIDSpec extends BaseSpec { assert bidderRequest.id != bidRequestId where: - bidRequestId | generateBidRequestId - PBSUtils.randomString | "true" - "{{UUID}}" | "false" + bidRequestId | pbsService + PBSUtils.randomString | pbsWithGenerationEnabled + "{{UUID}}" | pbsWithGenerationDisabled } - def "PBS auction should generate UUID for source.tid and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) - - and: "Flush metrics" + def "PBS auction should generate UUID for source.tid and merge StoredRequest"() { + given: "Flush metrics" flushMetrics(pbsService) and: "Default bid request with stored request and id" @@ -146,17 +150,14 @@ class UUIDSpec extends BaseSpec { assert bidderRequest.source.tid != sourceTid where: - sourceTid | generateBidRequestId - null | "false" - "{{UUID}}" | "false" - PBSUtils.randomString | "true" + sourceTid | pbsService + null | pbsWithGenerationDisabled + "{{UUID}}" | pbsWithGenerationDisabled + PBSUtils.randomString | pbsWithGenerationEnabled } - def "PBS amp should generate UUID for source.tid id and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) - - and: "Default AMP request with custom Id" + def "PBS amp should generate UUID for source.tid id and merge StoredRequest"() { + given: "Default AMP request with custom Id" def ampRequest = AmpRequest.defaultAmpRequest and: "Default StoredBidRequest" @@ -171,23 +172,20 @@ class UUIDSpec extends BaseSpec { when: "PBS processes amp request" def ampResponse = pbsService.sendAmpRequest(ampRequest) - then: "Actual bid request ID should be different from incoming bid request id" + then: "Actual source.tid should be different from incoming source.tid" def requestId = ampResponse.ext?.debug?.resolvedRequest?.id def bidderRequest = bidder.getBidderRequest(requestId) assert bidderRequest.source.tid != sourceTid where: - sourceTid | generateBidRequestId - null | "false" - PBSUtils.randomString | "true" - "{{UUID}}" | "false" + sourceTid | pbsService + null | pbsWithGenerationDisabled + PBSUtils.randomString | pbsWithGenerationEnabled + "{{UUID}}" | pbsWithGenerationDisabled } - def "PBS auction should generate UUID for imp[].ext.tid and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) - - and: "Flush metrics" + def "PBS auction should generate UUID for imp[].ext.tid and merge StoredRequest"() { + given: "Flush metrics" flushMetrics(pbsService) and: "Default bid request with stored request and id" @@ -197,7 +195,7 @@ class UUIDSpec extends BaseSpec { ext.prebid.storedRequest = new PrebidStoredRequest(id: storedRequestId) } - and: "Save storedRequest into DB with cur and source.tid" + and: "Save storedRequest into DB with cur" def currencies = [Currency.BOGUS] def storedBidRequest = new BidRequest(cur: currencies) def storedRequest = StoredRequest.getStoredRequest(storedRequestId, storedBidRequest) @@ -214,21 +212,18 @@ class UUIDSpec extends BaseSpec { def bidderRequest = bidder.getBidderRequest(bidResponse.id) assert bidderRequest.cur.first() == currencies[0] - and: "Actual source.tid should be different from incoming source.tid" + and: "Actual imp[].ext.tid should be different from incoming imp[].ext.tid" assert bidderRequest.imp[0].ext.tid != impExtTid where: - impExtTid | generateBidRequestId - null | "false" - PBSUtils.randomString | "true" - "{{UUID}}" | "false" + impExtTid | pbsService + null | pbsWithGenerationDisabled + PBSUtils.randomString | pbsWithGenerationEnabled + "{{UUID}}" | pbsWithGenerationDisabled } - def "PBS amp should generate UUID for imp[].ext.tid id and merge StoredRequest when generate-storedrequest-bidrequest-id = #generateBidRequestId"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": (generateBidRequestId)]) - - and: "Default AMP request with custom Id" + def "PBS amp should generate UUID for imp[].ext.tid id and merge StoredRequest"() { + given: "Default AMP request with custom Id" def ampRequest = AmpRequest.defaultAmpRequest and: "Default StoredBidRequest" @@ -243,23 +238,20 @@ class UUIDSpec extends BaseSpec { when: "PBS processes amp request" def ampResponse = pbsService.sendAmpRequest(ampRequest) - then: "Actual bid request ID should be different from incoming bid request id" + then: "Actual imp[].ext.tid should be different from incoming imp[].ext.tid" def requestId = ampResponse.ext?.debug?.resolvedRequest?.id def bidderRequest = bidder.getBidderRequest(requestId) assert bidderRequest.imp[0].ext.tid != impExtTid where: - impExtTid | generateBidRequestId - null | "false" - PBSUtils.randomString | "true" - "{{UUID}}" | "false" + impExtTid | pbsService + null | pbsWithGenerationDisabled + PBSUtils.randomString | pbsWithGenerationEnabled + "{{UUID}}" | pbsWithGenerationDisabled } def "PBS should generate UUID for empty imp[].id when generate-storedrequest-bidrequest-id = true"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": "true"]) - - and: "Default bid request with stored request and id" + given: "Default bid request with stored request and id" def bidRequest = BidRequest.getDefaultBidRequest(APP).tap { imp[1] = Imp.defaultImpression.tap { it.id = null @@ -267,7 +259,7 @@ class UUIDSpec extends BaseSpec { } when: "Requesting PBS auction" - def bidResponse = pbsService.sendAuctionRequest(bidRequest) + def bidResponse = pbsWithGenerationEnabled.sendAuctionRequest(bidRequest) then: "BidResponse should generate UUID for imp[].id" def bidderRequest = bidder.getBidderRequest(bidResponse.id) @@ -275,34 +267,29 @@ class UUIDSpec extends BaseSpec { } def "PBS auction should re-assign UUID for all imp[].id and merge StoredRequest when imp[].id not different and generate-storedrequest-bidrequest-id = true"() { - given: "PBS config with settings.generate-storedrequest-bidrequest-id" - def pbsService = pbsServiceFactory.getService(["settings.generate-storedrequest-bidrequest-id": "true"]) - - and: "Flush metrics" - flushMetrics(pbsService) + given: "Flush metrics" + flushMetrics(pbsWithGenerationEnabled) and: "Default bid request with stored request and id" def storedRequestId = PBSUtils.randomString def bidRequest = BidRequest.getDefaultBidRequest(APP).tap { - def imp = Imp.defaultImpression.tap { - id = PBSUtils.randomString - } - addImp(imp) - addImp(imp) + def duplicateImpId = PBSUtils.randomString + addImp(Imp.defaultImpression.tap { id = duplicateImpId }) + addImp(Imp.defaultImpression.tap { id = duplicateImpId }) ext.prebid.storedRequest = new PrebidStoredRequest(id: storedRequestId) } - and: "Save storedRequest into DB with cur and source.tid" + and: "Save storedRequest into DB with cur" def currencies = [Currency.BOGUS] def storedBidRequest = new BidRequest(cur: currencies) def storedRequest = StoredRequest.getStoredRequest(storedRequestId, storedBidRequest) storedRequestDao.save(storedRequest) when: "Requesting PBS auction" - def bidResponse = pbsService.sendAuctionRequest(bidRequest) + def bidResponse = pbsWithGenerationEnabled.sendAuctionRequest(bidRequest) then: "Metric stored_requests_found should be updated" - def metrics = pbsService.sendCollectedMetricsRequest() + def metrics = pbsWithGenerationEnabled.sendCollectedMetricsRequest() assert metrics["stored_requests_found"] == 1 and: "BidResponse should be merged with stored request" diff --git a/src/test/groovy/org/prebid/server/functional/tests/UserSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/UserSyncSpec.groovy index fea96bea8f0..a5198ea5c72 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/UserSyncSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/UserSyncSpec.groovy @@ -1,6 +1,7 @@ package org.prebid.server.functional.tests import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.HttpUtil import static org.prebid.server.functional.model.bidder.BidderName.GENERIC @@ -12,12 +13,26 @@ import static org.prebid.server.functional.testcontainers.Dependencies.networkSe class UserSyncSpec extends BaseSpec { - private static final Map GENERIC_USERSYNC_CONFIG = ["adapters.${GENERIC.value}.usersync.${IFRAME.value}.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()] + private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}" + + private static final PbsContainerConfig GENERIC_USERSYNC_CONFIG = new PbsContainerConfig(["adapters.${GENERIC.value}.usersync.${IFRAME.value}.url": USER_SYNC_URL]) + + private static final PbsContainerConfig ENABLED_USERSYNC_CONFIG = GENERIC_USERSYNC_CONFIG + ["adapters.${GENERIC.value}.usersync.enabled": "true"] + + private static final PbsContainerConfig DISABLED_USERSYNC_CONFIG = GENERIC_USERSYNC_CONFIG + ["adapters.${GENERIC.value}.usersync.enabled": "false"] + + def cleanupSpec() { + pbsServiceFactory.removeContainer(GENERIC_USERSYNC_CONFIG) + pbsServiceFactory.removeContainer(ENABLED_USERSYNC_CONFIG) + pbsServiceFactory.removeContainer(DISABLED_USERSYNC_CONFIG) + } def "PBS should return usersync url with '#formatParam' format parameter for #userSyncFormat when format-override absent"() { - given: "Pbs config with usersync.#userSyncFormat" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.generic.usersync.${userSyncFormat.value}.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()]) + given: "PBS config with usersync.#userSyncFormat" + def pbsConfig = new PbsContainerConfig([ + "adapters.${GENERIC.value}.usersync.${userSyncFormat.value}.url": USER_SYNC_URL + ]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest @@ -30,6 +45,9 @@ class UserSyncSpec extends BaseSpec { assert bidderStatus?.userSync?.type == userSyncFormat assert HttpUtil.findUrlParameterValue(bidderStatus.userSync?.url, "f") == formatParam + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + where: userSyncFormat || formatParam REDIRECT || PIXEL.name @@ -37,10 +55,12 @@ class UserSyncSpec extends BaseSpec { } def "PBS should return overridden usersync url format for #userSyncFormat usersync when format-override is #formatOverride"() { - given: "Pbs config with usersync.#userSyncFormat and iframe.format-override: #formatOverride" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.generic.usersync.${userSyncFormat.value}.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), - "adapters.generic.usersync.${userSyncFormat.value}.format-override": formatOverride.value]) + given: "PBS config with usersync.#userSyncFormat and iframe.format-override: #formatOverride" + def pbsConfig = new PbsContainerConfig([ + "adapters.${GENERIC.value}.usersync.${userSyncFormat.value}.url" : USER_SYNC_URL, + "adapters.${GENERIC.value}.usersync.${userSyncFormat.value}.format-override": formatOverride.value + ]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest @@ -53,6 +73,9 @@ class UserSyncSpec extends BaseSpec { assert bidderStatus?.userSync?.type == userSyncFormat assert HttpUtil.findUrlParameterValue(bidderStatus.userSync?.url, "f") == formatOverride.name + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + where: userSyncFormat || formatOverride REDIRECT || BLANK @@ -62,10 +85,11 @@ class UserSyncSpec extends BaseSpec { } def "PBS should return empty uid in usersync url when uid macro is not present in config"() { - given: "Pbs config with usersync.#userSyncFormat.url" - def prebidServerService = pbsServiceFactory.getService( - ["adapters.generic.usersync.${userSyncFormat.value}.url" : "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), - "adapters.generic.usersync.${userSyncFormat.value}.uid-macro" : null]) + given: "PBS config with usersync.#userSyncFormat.url" + def pbsConfig = new PbsContainerConfig( + ["adapters.${GENERIC.value}.usersync.${userSyncFormat.value}.url" : USER_SYNC_URL, + "adapters.${GENERIC.value}.usersync.${userSyncFormat.value}.uid-macro": null]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest @@ -77,6 +101,9 @@ class UserSyncSpec extends BaseSpec { def bidderStatus = response.getBidderUserSync(GENERIC) assert HttpUtil.findUrlParameterValue(bidderStatus.userSync?.url, "uid").isEmpty() + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + where: userSyncFormat << [REDIRECT, IFRAME] } @@ -98,8 +125,7 @@ class UserSyncSpec extends BaseSpec { def "PBS cookie sync should sync bidder when bidder.usersync.enabled=true"() { given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG - + ["adapters.${GENERIC.value}.usersync.enabled": "true"]) + def prebidServerService = pbsServiceFactory.getService(ENABLED_USERSYNC_CONFIG) and: "Default Cookie sync request" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest @@ -114,8 +140,7 @@ class UserSyncSpec extends BaseSpec { def "PBS cookie sync shouldn't sync bidder and emit error when bidder.usersync.enabled=false"() { given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG - + ["adapters.${GENERIC.value}.usersync.enabled": "false"]) + def prebidServerService = pbsServiceFactory.getService(DISABLED_USERSYNC_CONFIG) and: "Default Cookie sync request" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest @@ -132,8 +157,7 @@ class UserSyncSpec extends BaseSpec { def "PBS cookie sync shouldn't coop-sync bidder when coop-sync=true and bidder.usersync.enabled=false "() { given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG - + ["adapters.${GENERIC.value}.usersync.enabled": "false"]) + def prebidServerService = pbsServiceFactory.getService(DISABLED_USERSYNC_CONFIG) and: "Cookie sync request without bidders and coop-sync=true" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { @@ -153,8 +177,7 @@ class UserSyncSpec extends BaseSpec { def "PBS cookie sync should coop-sync bidder when coop-sync=true and bidder.usersync.enabled=true "() { given: "PBS bidder config" - def prebidServerService = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG - + ["adapters.${GENERIC.value}.usersync.enabled": "true"]) + def prebidServerService = pbsServiceFactory.getService(ENABLED_USERSYNC_CONFIG) and: "Cookie sync request without bidders and coop-sync=true" def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderConfigurationSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderConfigurationSpec.groovy new file mode 100644 index 00000000000..d6fb80d4bd3 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderConfigurationSpec.groovy @@ -0,0 +1,266 @@ +package org.prebid.server.functional.tests.bidder + +import org.prebid.server.functional.model.bidder.Generic +import org.prebid.server.functional.model.config.Endpoint +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.request.auction.Device +import org.prebid.server.functional.model.request.auction.Geo +import org.prebid.server.functional.model.request.vtrack.VtrackRequest +import org.prebid.server.functional.model.request.vtrack.xml.Vast +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec +import org.prebid.server.functional.util.PBSUtils +import org.prebid.server.functional.util.privacy.CcpaConsent + +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.GENER_X +import static org.prebid.server.functional.model.bidder.CompressionType.GZIP +import static org.prebid.server.functional.model.bidder.CompressionType.NONE +import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC +import static org.prebid.server.functional.util.HttpUtil.CONTENT_ENCODING_HEADER +import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED + +class BidderConfigurationSpec extends BaseSpec { + + private static final Map DISABLE_INVALID_BIDDER_CONFIGS = [ + "adapters.audiencenetwork.enabled": "false", + "adapters.adxcg.enabled" : "false", + "adapters.avocet.enabled" : "false", + "adapters.pangle.enabled" : "false", + "adapters.teqblaze.enabled" : "false", + "adapters.ix.enabled" : "false" + ] + + private static final PbsContainerConfig BIDDER_CONFIG = new PbsContainerConfig([ + "adapters.${GENERIC.value}.enabled" : true, + "adapters.${GENERIC.value}.meta-info.vendor-id" : 0, + + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.enabled" : true, + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.vendor-id" : 0, + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.modifying-vast-xml-allowed" : true, + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.pbs-enforces-ccpa" : true, + + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.enabled" : "true", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.meta-info.vendor-id" : "0", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.modifying-vast-xml-allowed": "false", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.pbs-enforces-ccpa" : "false" + ]) + + private static final PbsContainerConfig ENABLED_DEFAULTS_CONFIG = BIDDER_CONFIG + [ + "adapter-defaults.enabled" : "true", + "adapter-defaults.modifying-vast-xml-allowed": "true", + "adapter-defaults.pbs-enforces-ccpa" : "true", + "adapters.generic.endpoint-compression" : GZIP.value + ] + DISABLE_INVALID_BIDDER_CONFIGS + + private static final PbsContainerConfig DISABLED_DEFAULTS_CONFIG = BIDDER_CONFIG + [ + "adapter-defaults.enabled" : "false", + "adapter-defaults.modifying-vast-xml-allowed": "false", + "adapter-defaults.pbs-enforces-ccpa" : "false", + "adapters.generic.endpoint-compression" : NONE.value + ] + + private static final PbsContainerConfig BIDDER_DISABLED_DEFAULTS_ENABLED_CONFIG = new PbsContainerConfig([ + "adapter-defaults.enabled": "true", + "adapters.generic.enabled": "false" + ] + DISABLE_INVALID_BIDDER_CONFIGS) + + private static final PbsContainerConfig BIDDER_DISABLED_DEFAULTS_DISABLED_CONFIG = new PbsContainerConfig([ + "adapter-defaults.enabled": "false", + "adapters.generic.enabled": "false" + ]) + + private static PrebidServerService enabledDefaultService + private static PrebidServerService disabledDefaultService + + def setupSpec() { + enabledDefaultService = pbsServiceFactory.getService(ENABLED_DEFAULTS_CONFIG) + disabledDefaultService = pbsServiceFactory.getService(DISABLED_DEFAULTS_CONFIG) + } + + def cleanupSpec() { + pbsServiceFactory.removeContainer(ENABLED_DEFAULTS_CONFIG) + pbsServiceFactory.removeContainer(DISABLED_DEFAULTS_CONFIG) + } + + def "PBS should reject disabled generic bidder regardless of adapter defaults"() { + given: "PBS with disabled generic bidder" + def pbsService = pbsServiceFactory.getService(pbsConfig) + def bidRequest = BidRequest.defaultBidRequest + + when: "PBS processes auction request" + def response = pbsService.sendAuctionRequest(bidRequest) + + then: "Response contains bidder error" + assert response.ext?.errors[GENERIC]*.code == [2] + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + + where: + pbsConfig << [BIDDER_DISABLED_DEFAULTS_ENABLED_CONFIG, BIDDER_DISABLED_DEFAULTS_DISABLED_CONFIG] + } + + def "PBS should call enabled generic bidder regardless of adapter defaults"() { + given: "Default bidRequest" + def bidRequest = BidRequest.defaultBidRequest + + when: "PBS processes auction request" + def response = pbsService.sendAuctionRequest(bidRequest) + + then: "Bidder is called" + assert response.ext?.debug?.httpcalls[GENERIC.value] + + and: "Response has no errors" + assert !response.ext?.errors + + where: + pbsService << [enabledDefaultService, disabledDefaultService] + } + + def "PBS should modify VAST XML when bidder allows modification regardless of adapter defaults"() { + given: "Vtrack request for alias" + def payload = PBSUtils.randomString + def request = VtrackRequest.getDefaultVtrackRequest(encodeXml(Vast.getDefaultVastModel(payload))).tap { + puts[0].bidder = ALIAS.value + } + def accountId = PBSUtils.randomNumber + + and: "Account in DB" + accountDao.save(new Account(uuid: accountId, eventsEnabled: true)) + + when: "PBS processes vtrack request" + pbsService.sendPostVtrackRequest(request, accountId.toString()) + + then: "Cached VAST contains impression tracking" + def cachedVast = prebidCache.getXmlRecordedRequestsBody(payload) + assert cachedVast.size() == 1 + assert cachedVast.first().contains("${Endpoint.EVENT}?t=imp&b=${request.puts[0].bidid}&a=$accountId&bidder=${request.puts[0].bidder}") + + where: + pbsService << [enabledDefaultService, disabledDefaultService] + } + + def "PBS should preserve VAST XML when bidder disallows modification regardless of adapter defaults"() { + given: "Vtrack request for alias" + def payload = PBSUtils.randomString + def request = VtrackRequest.getDefaultVtrackRequest(encodeXml(Vast.getDefaultVastModel(payload))).tap { + puts[0].bidder = GENER_X.value + } + def accountId = PBSUtils.randomNumber + + and: "Account in DB" + accountDao.save(new Account(uuid: accountId, eventsEnabled: true)) + + when: "PBS processes vtrack request" + pbsService.sendPostVtrackRequest(request, accountId.toString()) + + then: "Cached VAST does not contain impression tracking" + def cachedVast = prebidCache.getXmlRecordedRequestsBody(payload) + assert cachedVast.size() == 1 + assert !cachedVast.first().contains("${Endpoint.EVENT}?t=imp&b=${request.puts[0].bidid}&a=$accountId&bidder=${request.puts[0].bidder}") + + where: + pbsService << [enabledDefaultService, disabledDefaultService] + } + + def "PBS should mask CCPA-sensitive geo for bidder with CCPA enforcement enabled"() { + given: "Bid request with CCPA consent and geo" + def lat = PBSUtils.getRandomDecimal(0, 90) + def lon = PBSUtils.getRandomDecimal(0, 90) + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.generic = null + imp[0].ext.prebid.bidder.alias = new Generic() + regs.usPrivacy = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) + device = new Device(geo: new Geo(lat: lat, lon: lon)) + } + + when: "PBS processes auction request" + pbsService.sendAuctionRequest(bidRequest) + + then: "Bidder receives masked coordinates" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.device?.geo?.lat as BigDecimal == PBSUtils.roundDecimal(lat, 2) + assert bidderRequest.device?.geo?.lon as BigDecimal == PBSUtils.roundDecimal(lon, 2) + + where: + pbsService << [enabledDefaultService, disabledDefaultService] + } + + def "PBS should preserve CCPA-sensitive geo for bidder with CCPA enforcement disabled"() { + given: "Bid request with CCPA consent and geo" + def lat = PBSUtils.getRandomDecimal(0, 90) as float + def lon = PBSUtils.getRandomDecimal(0, 90) as float + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.generic = null + imp[0].ext.prebid.bidder.generX = new Generic() + regs.usPrivacy = new CcpaConsent(explicitNotice: ENFORCED, optOutSale: ENFORCED) + device = new Device(geo: new Geo(lat: lat, lon: lon)) + } + + when: "PBS processes auction request" + pbsService.sendAuctionRequest(bidRequest) + + then: "Bidder receives original coordinates" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.device?.geo?.lat == lat + assert bidderRequest.device?.geo?.lon == lon + + where: + pbsService << [enabledDefaultService, disabledDefaultService] + } + + def "PBS should gzip bidder request when endpoint compression is gzip"() { + given: "Default bidRequest" + def bidRequest = BidRequest.defaultBidRequest + + when: "PBS processes auction request" + def response = enabledDefaultService.sendAuctionRequest(bidRequest) + + then: "Bidder request contains gzip content encoding" + assert response.ext?.debug?.httpcalls?.get(GENERIC.value)?.requestHeaders?.first() + ?.get(CONTENT_ENCODING_HEADER)?.first() == GZIP.value + } + + def "PBS should omit content encoding when endpoint compression is none"() { + given: "Default bidRequest" + def bidRequest = BidRequest.defaultBidRequest + + when: "PBS processes auction request" + def response = disabledDefaultService.sendAuctionRequest(bidRequest) + + then: "Bidder request has no content encoding" + assert !response.ext?.debug?.httpcalls?.get(GENERIC.value)?.requestHeaders?.first() + ?.get(CONTENT_ENCODING_HEADER) + } + + def "PBS should forward configured server information to bidder"() { + given: "PBS with server info configuration" + def serverDataCenter = PBSUtils.randomString + def serverExternalUrl = "https://${PBSUtils.randomString}.com/".toString() + def serverHostVendorId = PBSUtils.randomNumber + def pbsConfig = new PbsContainerConfig([ + "datacenter-region" : serverDataCenter, + "external-url" : serverExternalUrl, + "gdpr.host-vendor-id": serverHostVendorId.toString() + ]) + def pbsService = pbsServiceFactory.getService(pbsConfig) + + and: "Bid request" + def bidRequest = BidRequest.defaultBidRequest + + when: "PBS processes auction request" + pbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request contains configured server information" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest?.ext?.prebid?.server?.externalUrl == serverExternalUrl + assert bidderRequest.ext.prebid.server.datacenter == serverDataCenter + assert bidderRequest.ext.prebid.server.gvlId == serverHostVendorId + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderCurrencySpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderCurrencySpec.groovy new file mode 100644 index 00000000000..82d4d936ce6 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderCurrencySpec.groovy @@ -0,0 +1,241 @@ +package org.prebid.server.functional.tests.bidder + +import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.bidder.Generic +import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.Dependencies +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec + +import static org.prebid.server.functional.model.Currency.EUR +import static org.prebid.server.functional.model.Currency.GBP +import static org.prebid.server.functional.model.Currency.JPY +import static org.prebid.server.functional.model.Currency.USD +import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY +import static org.prebid.server.functional.model.response.auction.ErrorType.ALIAS +import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC + +class BidderCurrencySpec extends BaseSpec { + + private static final PrebidServerService noCurrencyAcceptedService = pbsServiceFactory.getService(new PbsContainerConfig( + "adapters.${BidderName.GENERIC}.meta-info.currency-accepted": "", + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.enabled": "true", + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.meta-info.vendor-id": "0", + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.endpoint": "$Dependencies.networkServiceContainer.rootUri/auction".toString(), + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.meta-info.currency-accepted": "" + )) + + private static PrebidServerService withCurrencyAcceptedService = pbsServiceFactory.getService(new PbsContainerConfig( + "adapters.generic.meta-info.currency-accepted": "${USD},${GBP}".toString(), + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.enabled": "true", + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.meta-info.vendor-id": "0", + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.endpoint": "$Dependencies.networkServiceContainer.rootUri/auction".toString(), + "adapters.${BidderName.GENERIC}.aliases.${BidderName.ALIAS}.meta-info.currency-accepted": "${EUR},${JPY}".toString() + )) + + def "PBS should send request to bidder when adapters.bidder.meta-info.currency-accepted not specified"() { + given: "Default bid request with generic bidder" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [USD] + ext.prebid.returnAllBidStatus = true + } + + when: "PBS processes auction request" + def response = noCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response should contain http calls" + assert response.ext?.debug?.httpcalls[BidderName.GENERIC.value] + + and: "Response should contain seatBid" + assert response.seatbid.bid.flatten().size() == 1 + + and: "Bidder request should be valid" + assert bidder.getBidderRequest(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "PBS response shouldn't contain seatNonBid" + assert !response.ext.seatnonbid + } + + def "PBS should send request to bidder when adapters.bidder.aliases.bidder.meta-info.currency-accepted not specified"() { + given: "Default bid request with alias bidder" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [USD] + ext.prebid.returnAllBidStatus = true + imp[0].ext.prebid.bidder.alias = new Generic() + imp[0].ext.prebid.bidder.generic = null + } + + when: "PBS processes auction request" + def response = noCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response should contain http calls" + assert response.ext?.debug?.httpcalls[BidderName.ALIAS.value] + + and: "Response should contain seatBid" + assert response.seatbid.bid.flatten().size() == 1 + + and: "Bidder request should be valid" + assert bidder.getBidderRequest(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "PBS response shouldn't contain seatNonBid" + assert !response.ext.seatnonbid + } + + def "PBS should send request to bidder when adapters.bidder.meta-info.currency-accepted intersect with requested currency"() { + given: "Default basic generic BidRequest" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [USD] + ext.prebid.returnAllBidStatus = true + } + + when: "PBS processes auction request" + def response = withCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response should contain http calls" + assert response.ext?.debug?.httpcalls[BidderName.GENERIC.value] + + and: "Response should contain seatBid" + assert response.seatbid.bid.flatten().size() == 1 + + and: "Bidder request should be valid" + assert bidder.getBidderRequest(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "PBS response shouldn't contain seatNonBid and contain errors" + assert !response.ext.seatnonbid + } + + def "PBS shouldn't send request to bidder and emit warning when adapters.bidder.meta-info.currency-accepted not intersect with requested currency"() { + given: "Default basic generic BidRequest" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [EUR] + ext.prebid.returnAllBidStatus = true + } + + when: "PBS processes auction request" + def response = withCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain http calls" + assert !response.ext?.debug?.httpcalls + + and: "Response shouldn't contain seatBid" + assert !response.seatbid + + and: "Pbs shouldn't make bidder request" + assert !bidder.getBidderRequests(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response should seatNon bid with code 205" + assert response.ext.seatnonbid.size() == 1 + + and: "PBS should emit an warnings" + assert response.ext?.warnings[GENERIC]*.code == [999] + assert response.ext?.warnings[GENERIC]*.message == + ["No match between the configured currencies and bidRequest.cur"] + + def seatNonBid = response.ext.seatnonbid[0] + assert seatNonBid.seat == BidderName.GENERIC + assert seatNonBid.nonBid[0].impId == bidRequest.imp[0].id + assert seatNonBid.nonBid[0].statusCode == REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY + } + + def "PBS should send request to bidder when adapters.bidder.aliases.bidder.meta-info.currency-accepted intersect with requested currency"() { + given: "Default basic BidRequest with alias bidder" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [JPY] + ext.prebid.returnAllBidStatus = true + imp[0].ext.prebid.bidder.alias = new Generic() + imp[0].ext.prebid.bidder.generic = null + } + + and: "Default bid response" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { + cur = JPY + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = withCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response should contain http calls" + assert response.ext?.debug?.httpcalls[ALIAS.value] + + and: "Response should contain seatBid" + assert response.seatbid.bid.flatten().size() == 1 + + and: "Bidder request should be valid" + assert bidder.getBidderRequest(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "PBS response shouldn't contain seatNonBid and contain errors" + assert !response.ext.seatnonbid + } + + def "PBS shouldn't send request to bidder and emit warning when adapters.bidder.aliases.bidder.meta-info.currency-accepted not intersect with requested currency"() { + given: "Default basic BidRequest with alias bidder" + def bidRequest = BidRequest.defaultBidRequest.tap { + cur = [GBP] + ext.prebid.returnAllBidStatus = true + imp[0].ext.prebid.bidder.alias = new Generic() + imp[0].ext.prebid.bidder.generic = null + } + + and: "Default bid response" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = withCurrencyAcceptedService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain http calls" + assert !response.ext?.debug?.httpcalls + + and: "Response shouldn't contain seatBid" + assert !response.seatbid + + and: "Pbs shouldn't make bidder request" + assert !bidder.getBidderRequests(bidRequest.id) + + and: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "PBS should emit an warnings" + assert response.ext?.warnings[ALIAS]*.code == [999] + assert response.ext?.warnings[ALIAS]*.message == + ["No match between the configured currencies and bidRequest.cur"] + + and: "Response should seatNon bid with code 205" + assert response.ext.seatnonbid.size() == 1 + + def seatNonBid = response.ext.seatnonbid[0] + assert seatNonBid.seat == BidderName.ALIAS + assert seatNonBid.nonBid[0].impId == bidRequest.imp[0].id + assert seatNonBid.nonBid[0].statusCode == REQUEST_BLOCKED_UNACCEPTABLE_CURRENCY + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidderFieldDisplayBehaviorSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFieldDisplayBehaviorSpec.groovy similarity index 99% rename from src/test/groovy/org/prebid/server/functional/tests/BidderFieldDisplayBehaviorSpec.groovy rename to src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFieldDisplayBehaviorSpec.groovy index 57df9ae7c53..fe6f5ee5874 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidderFieldDisplayBehaviorSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFieldDisplayBehaviorSpec.groovy @@ -1,4 +1,4 @@ -package org.prebid.server.functional.tests +package org.prebid.server.functional.tests.bidder import org.prebid.server.functional.model.ChannelType import org.prebid.server.functional.model.bidder.Generic @@ -42,13 +42,14 @@ import org.prebid.server.functional.model.request.auction.UserExt import org.prebid.server.functional.model.request.auction.UserExtPrebid import org.prebid.server.functional.model.request.auction.UserTime import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils import static org.prebid.server.functional.model.Currency.USD import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC -import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.mock.services.currencyconversion.CurrencyConversionRatesResponse.defaultConversionRates import static org.prebid.server.functional.model.request.auction.AdjustmentType.MULTIPLIER import static org.prebid.server.functional.model.request.auction.BidAdjustmentMediaType.BANNER diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidderFormatSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFormatSpec.groovy similarity index 82% rename from src/test/groovy/org/prebid/server/functional/tests/BidderFormatSpec.groovy rename to src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFormatSpec.groovy index b47a2e47ddf..70d24295897 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidderFormatSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderFormatSpec.groovy @@ -1,4 +1,4 @@ -package org.prebid.server.functional.tests +package org.prebid.server.functional.tests.bidder import org.prebid.server.functional.model.bidder.BidderName import org.prebid.server.functional.model.config.AccountAuctionConfig @@ -18,9 +18,10 @@ import org.prebid.server.functional.model.request.auction.Video import org.prebid.server.functional.model.response.auction.Adm import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils import spock.lang.PendingFeature -import spock.lang.Shared import static org.prebid.server.functional.model.AccountStatus.ACTIVE import static org.prebid.server.functional.model.config.BidValidationEnforcement.ENFORCE @@ -32,9 +33,16 @@ import static org.prebid.server.functional.model.response.auction.ErrorType.GENE class BidderFormatSpec extends BaseSpec { - @Shared private static final RANDOM_NUMBER = PBSUtils.randomNumber + private static final PbsContainerConfig BANNER_DEFAULT_CONFIG = new PbsContainerConfig(['auction.validations.banner-creative-max-size': null]) + private static final PbsContainerConfig BANNER_WARN_CONFIG = BANNER_DEFAULT_CONFIG + ['auction.validations.banner-creative-max-size': WARN.value] + private static final PbsContainerConfig BANNER_SKIP_CONFIG = BANNER_DEFAULT_CONFIG + ['auction.validations.banner-creative-max-size': SKIP.value] + private static final PbsContainerConfig BANNER_ENFORCE_CONFIG = BANNER_DEFAULT_CONFIG + ['auction.validations.banner-creative-max-size': ENFORCE.value] + private static final PbsContainerConfig SECURE_WARN_CONFIG = new PbsContainerConfig(['auction.validations.secure-markup': WARN.value]) + private static final PbsContainerConfig SECURE_SKIP_CONFIG = new PbsContainerConfig(['auction.validations.secure-markup': SKIP.value]) + private static final PbsContainerConfig SECURE_ENFORCE_CONFIG = new PbsContainerConfig(['auction.validations.secure-markup': ENFORCE.value]) + def "PBS should successfully pass when banner.format width and height is valid"() { given: "Default bid request with banner format" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -156,7 +164,7 @@ class BidderFormatSpec extends BaseSpec { def "PBS should emit error and metrics when banner-creative-max-size: warn and bid response W or H is larger that request W or H"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with banner format" def storedResponseId = PBSUtils.randomNumber @@ -212,18 +220,18 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSize | configCreativeMaxSize | responseWidth | responseHeight - null | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | WARN.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - WARN | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - WARN | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - WARN | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 + accountCretiveMaxSize | pbsConfig | responseWidth | responseHeight + null | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | BANNER_WARN_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 } def "PBS shouldn't emit error and metrics when banner-creative-max-size: skip and bid response W or H is larger that request W or H"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with banner format" def storedResponseId = PBSUtils.randomNumber @@ -250,6 +258,9 @@ class BidderFormatSpec extends BaseSpec { def account = new Account(status: ACTIVE, uuid: bidRequest.accountId, config: accountConfig) accountDao.save(account) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -270,24 +281,21 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSizeSnakeCase | accountCretiveMaxSize | configCreativeMaxSize | responseWidth | responseHeight - null | null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | null | SKIP.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - null | SKIP | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | SKIP | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | SKIP | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 - null | null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | null | SKIP.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - SKIP | null | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - SKIP | null | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - SKIP | null | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 + accountCretiveMaxSizeSnakeCase | accountCretiveMaxSize | pbsConfig | responseWidth | responseHeight + null | null | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | null | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | null | BANNER_SKIP_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + null | SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + SKIP | null | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + SKIP | null | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + SKIP | null | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 } def "PBS should emit error and metrics and remove bid response from consideration when banner-creative-max-size: enforce and bid response W or H is larger that request W or H"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with banner format" def storedResponseId = PBSUtils.randomNumber @@ -314,7 +322,7 @@ class BidderFormatSpec extends BaseSpec { def account = getAccountWithSpecifiedBannerMax(bidRequest.accountId, accountCretiveMaxSize) accountDao.save(account) - and: + and: "Flush metrics" flushMetrics(pbsService) when: "Requesting PBS auction" @@ -341,18 +349,18 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSize | configCreativeMaxSize | responseWidth | responseHeight - null | ENFORCE.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | ENFORCE.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | ENFORCE.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - ENFORCE | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 + accountCretiveMaxSize | pbsConfig | responseWidth | responseHeight + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 } - def "PBS shouldn't emit error and metrics when banner-creative-max-size #configCreativeMaxSize and bid response W or H is same that request W or H"() { + def "PBS shouldn't emit error and metrics when bid response dimensions match banner format with configured max-size enforcement"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with banner format" def storedResponseId = PBSUtils.randomNumber @@ -377,6 +385,9 @@ class BidderFormatSpec extends BaseSpec { def account = getAccountWithSpecifiedBannerMax(bidRequest.accountId, accountCretiveMaxSize) accountDao.save(account) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -397,18 +408,18 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSize | configCreativeMaxSize - null | SKIP.value - SKIP | null - ENFORCE | null - null | ENFORCE.value - WARN | null - null | WARN.value + accountCretiveMaxSize | pbsConfig + null | BANNER_SKIP_CONFIG + SKIP | BANNER_DEFAULT_CONFIG + ENFORCE | BANNER_DEFAULT_CONFIG + null | BANNER_ENFORCE_CONFIG + WARN | BANNER_DEFAULT_CONFIG + null | BANNER_WARN_CONFIG } - def "PBS shouldn't emit error and metrics when media type isn't banner and banner-creative-max-size #configCreativeMaxSize and bid response W or H is larger that request W or H"() { + def "PBS shouldn't emit error and metrics when media type is not banner regardless of configured banner max-size enforcement"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with video W and H" def storedResponseId = PBSUtils.randomNumber @@ -433,6 +444,9 @@ class BidderFormatSpec extends BaseSpec { def account = getAccountWithSpecifiedBannerMax(bidRequest.accountId, accountCretiveMaxSize) accountDao.save(account) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -451,30 +465,30 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSize | configCreativeMaxSize | responseWidth | responseHeight - null | ENFORCE.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | ENFORCE.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | ENFORCE.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - ENFORCE | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 - null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | SKIP.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - SKIP | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - SKIP | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - SKIP | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 - null | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - null | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - null | WARN.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - WARN | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - WARN | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - WARN | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 + accountCretiveMaxSize | pbsConfig | responseWidth | responseHeight + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | BANNER_ENFORCE_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + null | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | BANNER_SKIP_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + SKIP | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + null | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + null | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + null | BANNER_WARN_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + WARN | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 } def "PBS should emit error and metrics and remove bid response from consideration and account value should take precedence over host when banner-creative-max-size enforce and bid response W or H is larger that request W or H"() { given: "PBS with banner creative max size" - def pbsService = pbsServiceFactory.getService(["auction.validations.banner-creative-max-size": configCreativeMaxSize]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with banner format" def storedResponseId = PBSUtils.randomNumber @@ -501,7 +515,7 @@ class BidderFormatSpec extends BaseSpec { def account = getAccountWithSpecifiedBannerMax(bidRequest.accountId, accountCretiveMaxSize) accountDao.save(account) - and: + and: "Flush metrics" flushMetrics(pbsService) when: "Requesting PBS auction" @@ -528,22 +542,22 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - accountCretiveMaxSize | configCreativeMaxSize | responseWidth | responseHeight - ENFORCE | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - ENFORCE | WARN.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - ENFORCE | WARN.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - ENFORCE | null | RANDOM_NUMBER + 1 | RANDOM_NUMBER - ENFORCE | null | RANDOM_NUMBER | RANDOM_NUMBER + 1 - ENFORCE | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 - ENFORCE | SKIP.value | RANDOM_NUMBER + 1 | RANDOM_NUMBER - ENFORCE | SKIP.value | RANDOM_NUMBER | RANDOM_NUMBER + 1 + accountCretiveMaxSize | pbsConfig | responseWidth | responseHeight + ENFORCE | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + ENFORCE | BANNER_WARN_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + ENFORCE | BANNER_WARN_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + ENFORCE | BANNER_DEFAULT_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 + ENFORCE | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + 1 + ENFORCE | BANNER_SKIP_CONFIG | RANDOM_NUMBER + 1 | RANDOM_NUMBER + ENFORCE | BANNER_SKIP_CONFIG | RANDOM_NUMBER | RANDOM_NUMBER + 1 } @PendingFeature(reason = "Waiting for confirmation") - def "PBS shouldn't make a validation for audio media type when secure is #secure and secure markUp is #secureMarkup"() { - given: "PBS with secure-markUp: #secureMarkup" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": secureMarkup]) + def "PBS shouldn't make a validation for audio media type when secure is #secure and configured secure-markup"() { + given: "PBS with secure-markup configuration" + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Audio bid request" def storedResponseId = PBSUtils.randomNumber @@ -562,6 +576,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -582,18 +599,18 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - secure | secureMarkup - SECURE | SKIP.value - SECURE | ENFORCE.value - SECURE | WARN.value - NON_SECURE | SKIP.value - NON_SECURE | ENFORCE.value - NON_SECURE | WARN.value + secure | pbsConfig + SECURE | SECURE_SKIP_CONFIG + SECURE | SECURE_ENFORCE_CONFIG + SECURE | SECURE_WARN_CONFIG + NON_SECURE | SECURE_SKIP_CONFIG + NON_SECURE | SECURE_ENFORCE_CONFIG + NON_SECURE | SECURE_WARN_CONFIG } def "PBS should emit metrics and error when imp[0].secure = 1 and config WARN and bid response adm contain #url"() { given: "PBS with secure-markUp: warn" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": WARN.value]) + def pbsService = pbsServiceFactory.getService(SECURE_WARN_CONFIG) and: "Default bid request with secure and banner or video or nativeObj" def storedResponseId = PBSUtils.randomNumber @@ -617,6 +634,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -651,7 +671,7 @@ class BidderFormatSpec extends BaseSpec { def "PBS should emit metrics and error when imp[0].secure = 1, banner and config SKIP and bid response adm contain #url"() { given: "PBS with secure-markUp: skip" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": SKIP.value]) + def pbsService = pbsServiceFactory.getService(SECURE_SKIP_CONFIG) and: "Default bid request with secure and banner or video or nativeObj" def storedResponseId = PBSUtils.randomNumber @@ -670,6 +690,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -701,7 +724,7 @@ class BidderFormatSpec extends BaseSpec { def "PBS should emit metrics and error and remove bid response when imp[0].secure = 1, banner and config ENFORCE and bid response adm contain #url"() { given: "PBS with secure-markUp: enforce" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": ENFORCE.value]) + def pbsService = pbsServiceFactory.getService(SECURE_ENFORCE_CONFIG) and: "Default bid request with secure and banner or video or nativeObj" def storedResponseId = PBSUtils.randomNumber @@ -725,6 +748,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -759,8 +785,7 @@ class BidderFormatSpec extends BaseSpec { def "PBS shouldn't emit errors and metrics when imp[0].secure = #secure and bid response adm contain #url"() { given: "PBS with secure-markUp" - def pbsService = pbsServiceFactory - .getService(["auction.validations.secure-markup": secureMarkup]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with secure" def storedResponseId = PBSUtils.randomNumber @@ -778,6 +803,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -798,21 +826,21 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - url | secure | secureMarkup - "http%3A" | NON_SECURE | SKIP.value - "http" | NON_SECURE | SKIP.value - "https" | SECURE | SKIP.value - "http%3A" | NON_SECURE | WARN.value - "http" | NON_SECURE | WARN.value - "https" | SECURE | WARN.value - "http%3A" | NON_SECURE | ENFORCE.value - "http" | NON_SECURE | ENFORCE.value - "https" | SECURE | ENFORCE.value + url | secure | pbsConfig + "http%3A" | NON_SECURE | SECURE_SKIP_CONFIG + "http" | NON_SECURE | SECURE_SKIP_CONFIG + "https" | SECURE | SECURE_SKIP_CONFIG + "http%3A" | NON_SECURE | SECURE_WARN_CONFIG + "http" | NON_SECURE | SECURE_WARN_CONFIG + "https" | SECURE | SECURE_WARN_CONFIG + "http%3A" | NON_SECURE | SECURE_ENFORCE_CONFIG + "http" | NON_SECURE | SECURE_ENFORCE_CONFIG + "https" | SECURE | SECURE_ENFORCE_CONFIG } - def "PBS should ignore specified secureMarkup #secureMarkup validation when secure is 0"() { + def "PBS should ignore specified secure-markup validation when secure is 0"() { given: "PBS with secure-markUp" - def pbsService = pbsServiceFactory.getService(["auction.validations.secure-markup": secureMarkup]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with stored bid response and secure" def storedResponseId = PBSUtils.randomNumber @@ -831,6 +859,9 @@ class BidderFormatSpec extends BaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) + and: "Flush metrics" + flushMetrics(pbsService) + when: "Requesting PBS auction" def bidResponse = pbsService.sendAuctionRequest(bidRequest) @@ -849,16 +880,16 @@ class BidderFormatSpec extends BaseSpec { assert !bidder.getBidderRequests(bidRequest.id) where: - secureMarkup | url - WARN.value | "http" - WARN.value | "http%3A" - WARN.value | "https" - ENFORCE.value | "http" - ENFORCE.value | "http%3A" - ENFORCE.value | "https" - SKIP.value | "https" - SKIP.value | "http%3A" - SKIP.value | "https" + pbsConfig | url + SECURE_WARN_CONFIG | "http" + SECURE_WARN_CONFIG | "http%3A" + SECURE_WARN_CONFIG | "https" + SECURE_ENFORCE_CONFIG | "http" + SECURE_ENFORCE_CONFIG | "http%3A" + SECURE_ENFORCE_CONFIG | "https" + SECURE_SKIP_CONFIG | "https" + SECURE_SKIP_CONFIG | "http%3A" + SECURE_SKIP_CONFIG | "http" } private static Account getAccountWithSpecifiedBannerMax(String accountId, BidValidationEnforcement bannerMaxSizeEnforcement) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/BidderInsensitiveCaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderInsensitiveCaseSpec.groovy similarity index 95% rename from src/test/groovy/org/prebid/server/functional/tests/BidderInsensitiveCaseSpec.groovy rename to src/test/groovy/org/prebid/server/functional/tests/bidder/BidderInsensitiveCaseSpec.groovy index ef74c3a9a06..3855286bb89 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/BidderInsensitiveCaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderInsensitiveCaseSpec.groovy @@ -1,4 +1,4 @@ -package org.prebid.server.functional.tests +package org.prebid.server.functional.tests.bidder import org.prebid.server.functional.model.bidder.Generic import org.prebid.server.functional.model.db.StoredResponse @@ -16,12 +16,12 @@ import org.prebid.server.functional.model.request.auction.StoredBidResponse import org.prebid.server.functional.model.request.auction.Targeting import org.prebid.server.functional.model.request.auction.Uid import org.prebid.server.functional.model.request.auction.User -import org.prebid.server.functional.model.request.auction.UserExt -import org.prebid.server.functional.model.request.auction.UserExtPrebid import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest import org.prebid.server.functional.model.response.auction.Bid import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils import static org.prebid.server.functional.model.bidder.BidderName.ALIAS @@ -262,10 +262,10 @@ class BidderInsensitiveCaseSpec extends BaseSpec { } def "PBS should respond errors with same bidder name which bidder name came in request with another case strategy"() { - given: "PBS with adapter configuration" - def pbsService = pbsServiceFactory.getService( - ["adapter-defaults.enabled": "false", - "adapters.generic.enabled": "false"]) + given: "PBS service with adapter configuration" + def pbsConfig = new PbsContainerConfig(["adapter-defaults.enabled": "false", + "adapters.generic.enabled": "false"]) + def pbsService = pbsServiceFactory.getService(pbsConfig) and: "Default basic generic BidRequest" def bidRequest = BidRequest.defaultBidRequest.tap { @@ -283,10 +283,10 @@ class BidderInsensitiveCaseSpec extends BaseSpec { } def "PBS should respond warnings with same bidder name which bidder name came in request with another case strategy"() { - given: "Pbs config" - def pbsService = pbsServiceFactory.getService( - ["auction.filter-imp-media-type.enabled" : "true", - "adapters.generic.meta-info.app-media-types": ""]) + given: "Pbs service with media type config" + def pbsConfig = new PbsContainerConfig(["auction.filter-imp-media-type.enabled" : "true", + "adapters.generic.meta-info.app-media-types": ""]) + def pbsService = pbsServiceFactory.getService(pbsConfig) def bidRequest = BidRequest.getDefaultBidRequest(APP).tap { imp[0].ext.prebid.bidder.tap { diff --git a/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderMediaFilteringSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderMediaFilteringSpec.groovy new file mode 100644 index 00000000000..81796afc2ba --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderMediaFilteringSpec.groovy @@ -0,0 +1,265 @@ +package org.prebid.server.functional.tests.bidder + +import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.bidder.Generic +import org.prebid.server.functional.model.request.auction.Banner +import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.request.auction.DistributionChannel +import org.prebid.server.functional.model.request.auction.Imp +import org.prebid.server.functional.model.request.auction.Native +import org.prebid.server.functional.model.request.auction.Site +import org.prebid.server.functional.model.response.auction.Adm +import org.prebid.server.functional.model.response.auction.Bid +import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.model.response.auction.ErrorType +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec +import org.prebid.server.functional.util.PBSUtils + +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.GENER_X +import static org.prebid.server.functional.model.request.auction.Asset.getTitleAsset +import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP +import static org.prebid.server.functional.model.request.auction.DistributionChannel.DOOH +import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE +import static org.prebid.server.functional.model.response.auction.MediaType.AUDIO +import static org.prebid.server.functional.model.response.auction.MediaType.BANNER +import static org.prebid.server.functional.model.response.auction.MediaType.NATIVE +import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO + +class BidderMediaFilteringSpec extends BaseSpec { + + private static final PbsContainerConfig BIDDER_CONFIG = new PbsContainerConfig( + ["adapters.${GENERIC.value}.enabled" : "true", + "adapters.${GENERIC.value}.meta-info.vendor-id" : "0", + "adapters.${GENERIC.value}.meta-info.site-media-types" : "banner,video,native", + "adapters.${GENERIC.value}.meta-info.app-media-types" : "banner,video,native", + "adapters.${GENERIC.value}.meta-info.dooh-media-types" : "banner,video,native,audio", + + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.enabled" : "true", + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.vendor-id" : "0", + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.site-media-types" : "native,video", + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.app-media-types" : "video,native", + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.dooh-media-types" : "banner,video,audio", + + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.enabled" : "true", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.meta-info.vendor-id" : '0', + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.meta-info.site-media-types": "", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.meta-info.app-media-types" : "", + "adapters.${GENERIC.value}.aliases.${GENER_X.value}.meta-info.dooh-media-types": ""]) + + private static final filterMediaService = pbsServiceFactory.getService(BIDDER_CONFIG + ['auction.filter-imp-media-type.enabled': 'true']) + private static final freeMediaService = pbsServiceFactory.getService(BIDDER_CONFIG + ['auction.filter-imp-media-type.enabled': 'false']) + + def "PBS should reject #channel request when bidder supports no media types"() { + given: "Bid request for bidder without supported media types" + def bidRequest = getBidderRequest(channel, GENER_X) + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Response should contain no bids" + assert response.seatbid.isEmpty() + + and: "Response should warn about unsupported media types" + assert response.ext?.warnings[ErrorType.GENER_X]*.code == [2] + assert response.ext?.warnings[ErrorType.GENER_X]*.message == ["Bidder does not support any media types."] + + where: + channel << [SITE, APP, DOOH] + } + + def "PBS should accept #channel request when bidder supports no media types and filtering is disabled"() { + given: "Bid request for bidder without supported media types" + def bidRequest = getBidderRequest(channel, GENER_X) + + when: "PBS processes auction request" + def response = freeMediaService.sendAuctionRequest(bidRequest) + + then: "Response should contain bids" + assert response.seatbid + + and: "Response should contain no errors" + assert !response.ext?.errors + + where: + channel << [SITE, APP, DOOH] + } + + def "PBS should remove unsupported banner and retain native media type in SITE impression"() { + given: "SITE request with banner and native media types" + def bidRequest = getBidderRequest(SITE, ALIAS).tap { + site = Site.defaultSite + imp[0].banner = Banner.defaultBanner + imp[0].nativeObj = Native.defaultNative + } + + and: "Bidder response for the impression" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should receive native media type without banner" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert !bidderRequest.imp[0]?.banner + assert bidderRequest.imp[0]?.nativeObj + + and: "Response should contain no warnings" + assert !response.ext?.warnings + } + + def "PBS should retain unsupported banner in SITE impression when filtering is disabled"() { + given: "SITE request with banner and native media types" + def bidRequest = getBidderRequest(SITE, ALIAS).tap { + site = Site.defaultSite + imp[0].banner = Banner.defaultBanner + imp[0].nativeObj = Native.defaultNative + } + + when: "PBS processes auction request" + def response = freeMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should receive both media types" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0]?.banner + assert bidderRequest.imp[0]?.nativeObj + + and: "Response should contain no errors" + assert !response.ext?.errors + } + + def "PBS should remove unsupported banner impression and retain native impression in SITE request"() { + given: "SITE request with banner and native impressions" + def nativeImp = Imp.getDefaultImpression(NATIVE).tap { + ext.prebid.bidder.generic = null + ext.prebid.bidder.alias = new Generic() + } + def bidRequest = getBidderRequest(SITE, ALIAS).tap { + site = Site.defaultSite + imp << nativeImp + } + + and: "Bidder response for supported native impression" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { + seatbid.first().bid = [Bid.getDefaultBid(nativeImp)] + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should receive only the native impression" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp.id == [nativeImp.id] + assert bidderRequest.imp.first().nativeObj + + and: "Response should warn about the removed banner impression" + assert response.ext?.warnings[ErrorType.ALIAS]*.code == [2] + assert response.ext?.warnings[ErrorType.ALIAS]*.message == + ["Imp ${bidRequest.imp[0].id} does not have a supported media type and has been removed from the " + + "request for this bidder." as String] + + and: "Response should contain bids" + assert response.seatbid + } + + def "PBS should reject SITE request when all impressions have unsupported media types"() { + given: "SITE request with unsupported banner impression" + def bidRequest = getBidderRequest(SITE, ALIAS).tap { + site = Site.defaultSite + imp.first().banner = Banner.defaultBanner + } + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should not receive a request" + assert bidder.getRequestCount(bidRequest.id) == 0 + + and: "Response should warn about the removed impression and empty request" + assert response.ext?.warnings[ErrorType.ALIAS]*.code == [2, 2] + assert response.ext?.warnings[ErrorType.ALIAS]*.message == + ["Imp ${bidRequest.imp[0].id} does not have a supported media type and has been removed from the request for this bidder." as String, + "Bid request contains 0 impressions after filtering."] + + and: "Response should contain no bids" + assert response.seatbid.isEmpty() + } + + def "PBS should reject DOOH request when all impressions have unsupported media types"() { + given: "DOOH request with unsupported native impression" + def bidRequest = getBidderRequest(DOOH, ALIAS).tap { + imp.first().banner = null + imp.first().nativeObj = Native.defaultNative + } + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should not receive a request" + assert !bidder.getBidderRequests(bidRequest.id) + + and: "Response should warn about the removed impression and empty request" + assert response.ext?.warnings[ErrorType.ALIAS]*.code == [2, 2] + assert response.ext?.warnings[ErrorType.ALIAS]*.message == + ["Imp ${bidRequest.imp[0].id} does not have a supported media type and has been removed from the request for this bidder." as String, + "Bid request contains 0 impressions after filtering."] + + and: "Response should contain no bids" + assert !response.seatbid + } + + def "PBS should retain #mediaType impression and remove unsupported native impression in DOOH request"() { + given: "DOOH request with supported and unsupported impressions" + def bidRequest = getBidderRequest(DOOH, ALIAS).tap { + imp = [Imp.getDefaultImpression(mediaType), Imp.getDefaultImpression(NATIVE)] + imp[0].ext.prebid.bidder.generic = null + imp[0].ext.prebid.bidder.alias = new Generic() + imp[1].ext.prebid.bidder.generic = null + imp[1].ext.prebid.bidder.alias = new Generic() + } + + and: "Bidder response for supported impression" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { + seatbid[0].bid[0].adm = new Adm(assets: [titleAsset]) + seatbid[0].bid[0].nurl = PBSUtils.randomString + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = filterMediaService.sendAuctionRequest(bidRequest) + + then: "Bidder should receive only the supported impression" + assert bidder.getBidderRequest(bidRequest.id).imp.id == [bidRequest.imp.first().id] + + and: "Response should warn about the removed native impression" + assert response.ext?.warnings[ErrorType.ALIAS]*.code == [2] + assert response.ext?.warnings[ErrorType.ALIAS]*.message == + ["Imp ${bidRequest.imp[1].id} does not have a supported media type and has been removed from the request for this bidder." as String] + + and: "Response should contain bids" + assert response.seatbid + + where: + mediaType << [BANNER, VIDEO, AUDIO] + } + + private static BidRequest getBidderRequest(DistributionChannel channel, BidderName bidder) { + return BidRequest.getDefaultBidRequest(channel).tap { + if (bidder != GENERIC) { + imp.first().ext.prebid.bidder.with { + generic = null + + if (bidder == GENER_X) { + generX = new Generic() + } else if (bidder == ALIAS) { + alias = new Generic() + } + } + } + } + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderParamsSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderParamsSpec.groovy new file mode 100644 index 00000000000..adddb88d38f --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/bidder/BidderParamsSpec.groovy @@ -0,0 +1,569 @@ +package org.prebid.server.functional.tests.bidder + +import org.prebid.server.functional.model.bidder.AppNexus +import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.bidder.Generic +import org.prebid.server.functional.model.db.StoredImp +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.Adrino +import org.prebid.server.functional.model.request.auction.AnyUnsupportedBidder +import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.request.auction.Imp +import org.prebid.server.functional.model.request.auction.ImpExt +import org.prebid.server.functional.model.request.auction.ImpExtContext +import org.prebid.server.functional.model.request.auction.ImpExtContextData +import org.prebid.server.functional.model.request.auction.PrebidOptions +import org.prebid.server.functional.model.request.auction.PrebidStoredRequest +import org.prebid.server.functional.model.request.auction.Source +import org.prebid.server.functional.model.request.auction.Targeting +import org.prebid.server.functional.model.response.auction.BidExt +import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.testcontainers.Dependencies +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec +import org.prebid.server.functional.util.PBSUtils + +import static org.prebid.server.functional.model.Currency.USD +import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.request.auction.SecurityLevel.NON_SECURE +import static org.prebid.server.functional.model.request.auction.SecurityLevel.SECURE +import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC +import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID + +class BidderParamsSpec extends BaseSpec { + + def "PBS should prefer bidder params from imp[*].ext.prebid.bidder.BIDDER when ext.prebid.bidderparams.BIDDER is specified"() { + given: "Default basic BidRequest" + def bidRequest = BidRequest.defaultBidRequest + def firstParam = PBSUtils.randomNumber + bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) + + and: "Set bidderParam to bidRequest" + bidRequest.ext.prebid.bidderParams = [(BidderName.GENERIC): [firstParam: PBSUtils.randomNumber]] + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain firstParam value from imp[*].ext.prebid.bidder.BIDDER" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam + + and: "Bidder request should contain requested bidder param for related itself bidder" + assert bidderRequest.ext.prebid.bidderParams[GENERIC] == bidRequest.ext.prebid.bidderParams[GENERIC] + } + + def "PBS should send bidder params from imp[*].ext.prebid.bidder.BIDDER when ext.prebid.bidderparams.BIDDER isn't specified"() { + given: "Default basic BidRequest" + def bidRequest = BidRequest.defaultBidRequest + def firstParam = PBSUtils.randomNumber + bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) + + and: "Set bidderParam = null to bidRequest" + bidRequest.ext.prebid.bidderParams = null + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain firstParam value from imp[*].ext.prebid.bidder.BIDDER" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam + } + + def "PBS should merge bidder params from imp[*].ext.prebid.bidder.BIDDER and ext.prebid.bidderparams.BIDDER"() { + given: "Default basic BidRequest" + def bidRequest = BidRequest.defaultBidRequest + def firstParam = PBSUtils.randomNumber + bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) + + and: "Set bidderParam to bidRequest" + def secondParam = PBSUtils.randomNumber + bidRequest.ext.prebid.bidderParams = [(BidderName.GENERIC): [secondParam: secondParam]] + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should merge bidder params" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0]?.ext?.bidder?.firstParam == firstParam + assert bidderRequest.imp[0]?.ext?.bidder?.secondParam == secondParam + } + + def "PBS should only send bidder params from ext.prebid.bidderparams.BIDDER to specified bidder"() { + given: "Default basic BidRequest" + def bidRequest = BidRequest.defaultBidRequest + def firstParam = PBSUtils.randomNumber + bidRequest.imp.first().ext.prebid.bidder.generic = new Generic(firstParam: firstParam) + bidRequest.imp.first().ext.prebid.bidder.appNexus = null + + and: "Set bidderParam to bidRequest" + bidRequest.ext.prebid.bidderParams = [(APPNEXUS): [placement_id: PBSUtils.randomNumber]] + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should not contain params from another bidder" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0].ext.bidder.firstParam == firstParam + assert !bidderRequest.imp[0].ext.bidder.placementId + } + + def "PBS should reject bidder when bidder params from request doesn't satisfy json-schema for auction request"() { + given: "BidRequest with bad bidder datatype" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp << Imp.defaultImpression + imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "PBS should not fail the entire auction" + assert response.seatbid[0].bid.size() == 1 + + and: "Bidder request should contain only valid impression" + assert bidder.getBidderRequest(bidRequest.id).imp*.id == [bidRequest.imp[1].id] + + and: "Bidder with invalid params should be dropped" + assert response.ext?.warnings[PREBID]*.code == [999, 999] + assert response.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + + "\$.exampleProperty: integer found, string expected", + "WARNING: request.imp[0].ext must contain at least one valid bidder"] + } + + def "PBS should reject bidder when bidder params from stored request doesn't satisfy json-schema for auction request"() { + given: "BidRequest with stored request, without imp" + def bidRequest = BidRequest.defaultBidRequest.tap { + ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomNumber) + imp = null + } + + and: "Default stored request with bad bidder datatype" + def storedRequestModel = BidRequest.defaultStoredRequest.tap { + imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getStoredRequest(bidRequest, storedRequestModel) + storedRequestDao.save(storedRequest) + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder should be dropped" + assert response.ext?.warnings[PREBID]*.code == [999, 999] + assert response.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + + "\$.exampleProperty: integer found, string expected", + "WARNING: request.imp[0].ext must contain at least one valid bidder"] + + and: "PBS should not call bidder" + assert bidder.getRequestCount(bidRequest.id) == 0 + + and: "seatbid should be empty" + assert response.seatbid.isEmpty() + } + + def "PBS should reject bidder when bidder params from stored request doesn't satisfy json-schema for amp request"() { + given: "AmpRequest with bad bidder datatype" + def ampRequest = AmpRequest.defaultAmpRequest + def ampStoredRequest = BidRequest.defaultBidRequest.tap { + site.publisher.id = ampRequest.account + imp[0].ext.prebid.bidder.generic.exampleProperty = PBSUtils.randomNumber + } + + and: "Save storedRequest into DB" + def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest) + storedRequestDao.save(storedRequest) + + when: "PBS processes amp request" + def response = defaultPbsService.sendAmpRequest(ampRequest) + + then: "Bidder should be dropped" + assert response.ext?.warnings[PREBID]*.code == [999, 999] + assert response.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + + "\$.exampleProperty: integer found, string expected", + "WARNING: request.imp[0].ext must contain at least one valid bidder"] + + and: "PBS should not call bidder" + assert bidder.getRequestCount(ampStoredRequest.id) == 0 + + and: "targeting should be empty" + assert response.targeting.isEmpty() + } + + def "PBS should not treat reserved imp[].ext.tid as bidder"() { + given: "Default basic BidRequest with imp[].ext.tid object" + def bidRequest = BidRequest.defaultBidRequest + def tid = PBSUtils.getRandomString() + bidRequest.imp.first().ext.tid = tid + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "imp[].ext.tid object should be passed to a bidder" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp?.first()?.ext?.tid == tid + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + } + + def "PBS auction should populate imp[0].secure depend which value in imp stored request"() { + given: "Default bid request" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) + } + + and: "Save storedImp into DB" + def storedImp = StoredImp.getStoredImp(bidRequest).tap { + impData = Imp.defaultImpression.tap { + it.secure = secureStoredRequest + } + } + storedImpDao.save(storedImp) + + when: "Requesting PBS auction" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain imp[0].secure same value as in request" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0].secure == secureBidderRequest + + where: + secureStoredRequest | secureBidderRequest + null | SECURE + SECURE | SECURE + NON_SECURE | NON_SECURE + } + + def "PBS auction should populate imp[0].secure depend which value in imp request"() { + given: "Default bid request" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].secure = secureRequest + } + + when: "Requesting PBS auction" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain imp[0].secure same value as in request" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0].secure == secureBidderRequest + + where: + secureRequest | secureBidderRequest + null | SECURE + SECURE | SECURE + NON_SECURE | NON_SECURE + } + + def "PBS shouldn't emit warning and proceed auction when imp.ext.anyUnsupportedBidder and imp.ext.prebid.bidder.generic in the request"() { + given: "Default bid request" + def unsupportedBidder = new AnyUnsupportedBidder(anyUnsupportedField: PBSUtils.randomString) + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.anyUnsupportedBidder = unsupportedBidder + imp[0].ext.prebid.bidder.generic = new Generic() + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain imp.ext.anyUnsupportedBidder" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0].ext.anyUnsupportedBidder == unsupportedBidder + + and: "Response shouldn't contain warning" + assert !response?.ext?.warnings + } + + def "PBS should emit warning and proceed auction when imp.ext.anyUnsupportedBidder and imp.ext.generic in the request"() { + given: "Default bid request" + def unsupportedBidder = new AnyUnsupportedBidder(anyUnsupportedField: PBSUtils.randomString) + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.generic = new Generic() + imp[0].ext.anyUnsupportedBidder = unsupportedBidder + imp[0].ext.prebid.bidder = null + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain imp.ext.anyUnsupportedBidder" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.imp[0].ext.anyUnsupportedBidder == unsupportedBidder + + and: "PBS should emit an warning" + assert response?.ext?.warnings[PREBID]*.code == [999] + assert response?.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.anyUnsupportedBidder was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder contains unknown bidder: anyUnsupportedBidder"] + } + + def "PBS should emit warning and proceed auction when ext.prebid fields include adunitcode"() { + given: "Default bid request with populated ext.prebid.bidderParams" + def genericBidderParams = PBSUtils.randomString + def bidRequest = BidRequest.defaultBidRequest.tap { + ext.prebid.bidderParams = [adUnitCode : PBSUtils.randomString, + (GENERIC.value): genericBidderParams] + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "PBS should emit an warning" + assert response?.ext?.warnings[PREBID]*.code == [999] + assert response?.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.adUnitCode was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder contains unknown bidder: adUnitCode"] + } + + def "PBS shouldn't emit warning and proceed auction when all imp.ext fields known for PBS"() { + given: "Default bid request with populated imp.ext" + def impExt = ImpExt.getDefaultImpExt().tap { + prebid.bidder.generic = null + prebid.adUnitCode = PBSUtils.randomString + generic = new Generic() + all = PBSUtils.randomNumber + context = new ImpExtContext(data: new ImpExtContextData()) + data = new ImpExtContextData(pbAdSlot: PBSUtils.randomString) + general = PBSUtils.randomString + gpid = PBSUtils.randomString + skadn = PBSUtils.randomString + tid = PBSUtils.randomString + } + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext = impExt + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "Bidder request should contain same field as requested" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + verifyAll(bidderRequest.imp[0].ext) { + it.bidder == impExt.generic + it.all == impExt.all + it.context == impExt.context + it.data == impExt.data + it.general == impExt.general + it.gpid == impExt.gpid + it.skadn == impExt.skadn + it.tid == impExt.tid + it.prebid.adUnitCode == impExt.prebid.adUnitCode + } + } + + def "PBS shouldn't emit warning and proceed auction when all imp.ext.prebid fields known for PBS"() { + given: "PBS with old ortb version" + def config = new PbsContainerConfig(['adapters.generic.ortb-version': '2.5']) + def pbsService = pbsServiceFactory.getService(config) + + and: "Default bid request with populated imp.ext.prebid" + def impExt = ImpExt.getDefaultImpExt().tap { + prebid.adUnitCode = PBSUtils.randomString + prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) + prebid.isRewardedInventory = PBSUtils.getRandomNumber(0, 1) + prebid.options = new PrebidOptions(echoVideoAttrs: PBSUtils.randomBoolean) + } + def bidRequest = BidRequest.defaultVideoRequest.tap { + imp[0].rwdd = null + imp[0].ext = impExt + } + + and: "Save storedImp into DB" + def storedImp = StoredImp.getStoredImp(bidRequest) + storedImpDao.save(storedImp) + + and: "Default bid response" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest) + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = pbsService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "Bidder request should contain same field as requested" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + verifyAll(bidderRequest.imp[0].ext.prebid) { + it.adUnitCode == impExt.prebid.adUnitCode + it.storedRequest == impExt.prebid.storedRequest + it.isRewardedInventory == impExt.prebid.isRewardedInventory + it.options.echoVideoAttrs == impExt.prebid.options.echoVideoAttrs + } + } + + def "PBS should proceed auction without warning when all ext.prebid.bidderParams fields are known"() { + given: "Default bid request with populated ext.prebid.bidderParams" + def genericBidderParams = PBSUtils.randomString + def bidRequest = BidRequest.defaultBidRequest.tap { + ext.prebid.bidderParams = [all : PBSUtils.randomString, + context : PBSUtils.randomString, + data : PBSUtils.randomString, + general : PBSUtils.randomString, + gpid : PBSUtils.randomString, + skadn : PBSUtils.randomString, + tid : PBSUtils.randomString, + (GENERIC.value): genericBidderParams + ] + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response shouldn't contain error" + assert !response.ext?.errors + + and: "Response shouldn't contain warning" + assert !response.ext?.warnings + + and: "Bidder request should bidderParams only for bidder" + def bidderRequest = bidder.getBidderRequest(bidRequest.id) + assert bidderRequest.ext.prebid.bidderParams == [(GENERIC.value): genericBidderParams] + } + + def "PBS should reject alias bidders when bidder params from request doesn't satisfy own json-schema"() { + given: "Default bid request" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.tap { + it.generic.exampleProperty = PBSUtils.randomNumber + //Adrino hard coded bidder alias in generic.yaml + it.adrino = new Adrino(hash: PBSUtils.randomNumber) + } + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder should be dropped" + assert response.ext?.warnings[PREBID]*.code == [999, 999, 999] + assert response.ext?.warnings[PREBID]*.message == + ["WARNING: request.imp[0].ext.prebid.bidder.generic was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.generic failed validation.\n" + + "\$.exampleProperty: integer found, string expected", + "WARNING: request.imp[0].ext.prebid.bidder.adrino was dropped with a reason: " + + "request.imp[0].ext.prebid.bidder.adrino failed validation.\n" + + "\$.hash: integer found, string expected", + "WARNING: request.imp[0].ext must contain at least one valid bidder"] + + and: "PBS should not call bidder" + assert bidder.getRequestCount(bidRequest.id) == 0 + + and: "targeting should be empty" + assert response.seatbid.isEmpty() + } + + def "PBS should send bidder code from imp[].ext.prebid.bidder to seatbid.bid.ext.prebid.meta.adapterCode"() { + given: "Default basic bid request" + def bidRequest = BidRequest.defaultBidRequest + + and: "Default bid response" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { + seatbid[0].seat = OPENX + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] + + and: "Bidder request should be valid" + assert bidder.getBidderRequest(bidRequest.id) + } + + def "PBS should populate targeting with bidder in camel case when bidder with camel case was requested"() { + given: "Default bid request" + def bidRequest = BidRequest.defaultBidRequest.tap { + imp[0].ext.prebid.bidder.generic = null + imp[0].ext.prebid.bidder.genericCamelCase = new Generic() + it.ext.prebid.targeting = new Targeting() + } + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Response should contain bidder targeting" + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting + assert targeting["hb_pb_${GENERIC_CAMEL_CASE}"] + assert targeting["hb_size_${GENERIC_CAMEL_CASE}"] + assert targeting["hb_bidder"] == GENERIC_CAMEL_CASE.value + assert targeting["hb_bidder_${GENERIC_CAMEL_CASE}"] == GENERIC_CAMEL_CASE.value + + and: "Bid response should contain seat" + assert response.seatbid.seat == [GENERIC_CAMEL_CASE] + + and: "Response should contain repose millis with corresponding bidder" + assert response.ext.responsetimemillis.containsKey(GENERIC_CAMEL_CASE.value) + + and: "Response should contain adapter code" + assert response.seatbid.bid.ext.prebid.meta.adapterCode.flatten() == [BidderName.GENERIC] + } + + def "PBS should merge stored imp with appnexus bidder requested when reserve field specified"() { + given: "Pbs default config with appnexus" + def config = new PbsContainerConfig(["adapters.${APPNEXUS.value}.enabled" : "true", + "adapters.${APPNEXUS.value}.endpoint": "$Dependencies.networkServiceContainer.rootUri/auction".toString()]) + def defaultPbsService = pbsServiceFactory.getService(config) + + and: "Default stored request with specified stored imps and request" + def storedRequestId = PBSUtils.randomString + def bidRequest = BidRequest.getDefaultBidRequest().tap { + imp[0].ext.prebid.bidder.generic = null + imp[0].ext.prebid.bidder.appNexus = AppNexus.getDefault().tap { + reserve = PBSUtils.getRandomDecimal() as Double + } + imp[0].ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomString) + ext.prebid.storedRequest = new PrebidStoredRequest(id: storedRequestId) + } + + and: "Save storedImp into DB" + def storedImp = StoredImp.getStoredImp(bidRequest).tap { + impData = Imp.defaultImpression + } + storedImpDao.save(storedImp) + + and: "Save stored request with source.tid and cur" + def storedBidRequest = new BidRequest(cur: [USD], source: new Source(tid: PBSUtils.randomString)) + def storedRequest = StoredRequest.getStoredRequest(storedRequestId, storedBidRequest) + storedRequestDao.save(storedRequest) + + and: "Default basic bid with bid.ext" + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest, APPNEXUS).tap { + seatbid[0].bid[0].ext = new BidExt() + } + bidder.setResponse(bidRequest.id, bidResponse) + + when: "PBS processes auction request" + def response = defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bid response should contain appnexus and generic bidder" + assert response.seatbid.size() == 2 + assert response.seatbid.seat.sort() == [APPNEXUS, BidderName.GENERIC].sort() + + and: "Bidder requests should perform two bidder call" + def bidderRequests = bidder.getBidderRequests(bidRequest.id) + assert bidderRequests.size() == 2 + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncAliasSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncAliasSpec.groovy new file mode 100644 index 00000000000..84a14b2c0ae --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncAliasSpec.groovy @@ -0,0 +1,111 @@ +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.service.PrebidServerService + +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.NO_COOKIE +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT + +class CookieSyncAliasSpec extends CookieSyncBaseSpec { + + private static PrebidServerService pbsWithAliasService + + def setupSpec() { + pbsWithAliasService = pbsServiceFactory.getService(PBS_WITH_ALIAS_CONFIG) + } + + def "PBS cookie sync request shouldn't replace synced as family bidder and fill up response with enabled bidders to the limit in request"() { + given: "Default cookie sync request" + def requestLimit = 2 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [ALIAS] + limit = requestLimit + coopSync = true + debug = false + } + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithAliasService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain source bidder" + assert !response.getBidderUserSync(GENERIC) + + and: "Response should contain coop-synced bidder" + assert response.bidderStatus.size() == requestLimit + assert response.getBidderUserSync(ALIAS) + } + + def "PBS cookie sync should use requested bidder name in sync url instead of cookie family name"() { + given: "Cookie sync request for alias bidder" + def bidderAlias = ALIAS + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [bidderAlias] + limit = 1 + coopSync = true + debug = false + } + + when: "PBS processes cookie sync request" + def response = pbsWithAliasService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain source bidder" + assert !response.getBidderUserSync(GENERIC) + + and: "Response should contain alias bidder sync" + def bidderStatus = response.getBidderUserSync(bidderAlias) + + and: "Sync url should contain requested bidder name" + assert bidderStatus.userSync.url.contains("setuid%3Fbidder%3D${bidderAlias}") + + and: "Sync url shouldn't contain cookie family name" + assert !bidderStatus.userSync.url.contains("setuid%3Fbidder%3D${GENERIC}") + } + + def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder synced"() { + given: "Cookie sync request with 2 bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [ALIAS] + coopSync = true + } + + when: "PBS processes cookie sync request" + def response = pbsWithAliasService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain bidder error" + def bidderStatus = response.getBidderUserSync(ALIAS) + assert !bidderStatus?.error + + and: "Response should indicate bidder has no cookie" + assert bidderStatus?.noCookie == true + + and: "Response should contain bidder user sync information" + verifyAll(bidderStatus?.userSync) { + bidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) + it.type == REDIRECT + } + } + + def "PBS cookie sync request with alias bidder should sync as the source bidder when alias doesn't override cookie-family-name"() { + given: "Cookie sync request with 2 bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, ALIAS] + } + + when: "PBS processes cookie sync request" + def response = pbsWithAliasService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain sync information for single resolved bidder" + def validBidderUserSyncs = getValidBidderUserSyncs(response).values().toList() + assert validBidderUserSyncs.url.every { it.startsWith(USER_SYNC_URL) } + assert validBidderUserSyncs.type == [USER_SYNC_TYPE] + + and: "Response should contain duplicate bidder error" + def rejectedBidderStatus = getRejectedBidderUserSyncs(response).values().toList() + assert rejectedBidderStatus == ["Duplicate bidder synced as ${GENERIC.value}"] + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncBaseSpec.groovy new file mode 100644 index 00000000000..cd1246b54ee --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncBaseSpec.groovy @@ -0,0 +1,98 @@ +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse +import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo +import org.prebid.server.functional.testcontainers.Dependencies +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.tests.BaseSpec +import org.prebid.server.functional.util.PBSUtils + +import static org.prebid.server.functional.model.bidder.BidderName.AAX +import static org.prebid.server.functional.model.bidder.BidderName.ACEEX +import static org.prebid.server.functional.model.bidder.BidderName.ACUITYADS +import static org.prebid.server.functional.model.bidder.BidderName.ADKERNEL +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS +import static org.prebid.server.functional.model.bidder.BidderName.BOGUS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT +import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID +import static org.prebid.server.functional.util.privacy.TcfConsent.MAGNITE_VENDOR_ID + +abstract class CookieSyncBaseSpec extends BaseSpec { + + protected static final UserSyncInfo.Type USER_SYNC_TYPE = REDIRECT + protected static final Integer COOKIE_SYNC_DEFAULT_LIMIT = 2 + protected static final Integer COOKIE_SYNC_MAX_LIMIT = 3 + protected static final String RANDOM_COOKIE_NAME = PBSUtils.randomString + + protected static final String USER_SYNC_URL = "$Dependencies.networkServiceContainer.rootUri/generic-usersync" + protected static final String ALL_BIDDERS = "*" + protected static final List DEFAULT_PBS_BIDDERS = [GENERIC, ACEEX, MAGNITE, OPENX, APPNEXUS, AAX, ADKERNEL] + + protected static final Map GENERIC_CONFIG = [ + "adapters.${GENERIC.value}.usersync.redirect.url": USER_SYNC_URL + '&redir={redirect_url}', + "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String] + protected static final Map MAGNITE_CONFIG = [ + "adapters.${MAGNITE.value}.enabled" : "true", + "adapters.${MAGNITE.value}.meta-info.vendor-id" : MAGNITE_VENDOR_ID as String, + "adapters.${MAGNITE.value}.usersync.cookie-family-name": MAGNITE.value, + "adapters.${MAGNITE.value}.usersync.redirect.url" : "https://test.redirect.endpoint.com", + "adapters.${MAGNITE.value}.usersync.iframe.url" : "https://test.iframe.endpoint.com&redir={redirect_url}"] + protected static final Map APPNEXUS_CONFIG = [ + "adapters.${APPNEXUS.value}.enabled" : "true", + "adapters.${APPNEXUS.value}.aliases.mediafuse.enabled" : "false", + "adapters.${APPNEXUS.value}.usersync.cookie-family-name": APPNEXUS.value, + "adapters.${APPNEXUS.value}.usersync.redirect.url" : "https://test.appnexus.redirect.com/getuid?{redirect_url}"] + private static final Map ALIAS_NO_FAMILY_CONFIG = [ + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.enabled" : "true", + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, + "adapters.${GENERIC.value}.aliases.${ALIAS.value}.usersync.cookie-family-name": null] + private static final Map COOKIE_SYNC_CONFIG = [ + "cookie-sync.max-limit" : COOKIE_SYNC_MAX_LIMIT.toString(), + "cookie-sync.default-limit": COOKIE_SYNC_DEFAULT_LIMIT.toString()] + private static final Map ACEEX_CONFIG = [ + "adapters.${ACEEX.value}.enabled" : "true", + "adapters.${ACEEX.value}.usersync.cookie-family-name": ACEEX.value, + "adapters.${ACEEX.value}.usersync.redirect.url" : "https://test.redirect.endpoint.com={redirect_url}"] + private static final Map OPENX_CONFIG = [ + "adapters.${OPENX.value}.enabled" : "true", + "adapters.${OPENX.value}.usersync.cookie-family-name": OPENX.value, + "adapters.${OPENX.value}.usersync.redirect.url" : USER_SYNC_URL, + "adapters.${OPENX.value}.usersync.iframe.url" : USER_SYNC_URL] + private static final Map BOGUS_CONFIG = ["adapters.${BOGUS.value}.enabled": "true"] + private static final Map AAX_CONFIG = ["adapters.${AAX.value}.enabled": "true"] + private static final Map ACUITYADS_CONFIG = ["adapters.${ACUITYADS.value}.enabled": "false"] + private static final Map ADKERNEL_CONFIG = [ + "adapters.${ADKERNEL.value}.enabled" : "true", + "adapters.${ADKERNEL.value}.aliases.rxnetwork.enabled": "false", + "adapters.${ADKERNEL.value}.aliases.152media.enabled" : "false" + ] + + protected static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig(APPNEXUS_CONFIG + MAGNITE_CONFIG + OPENX_CONFIG + + GENERIC_CONFIG + ACEEX_CONFIG + AAX_CONFIG + ACUITYADS_CONFIG + ADKERNEL_CONFIG + BOGUS_CONFIG + + ["cookie-sync.pri": "grid, ix, adkernel"]) + + protected static final PbsContainerConfig PBS_WITH_LIMIT_CONFIG = PBS_CONFIG + COOKIE_SYNC_CONFIG + + protected static final PbsContainerConfig PBS_WITH_ALIAS_CONFIG = PBS_CONFIG + ALIAS_NO_FAMILY_CONFIG + + protected static Map getValidBidderUserSyncs(CookieSyncResponse cookieSyncResponse) { + cookieSyncResponse.bidderStatus + .findAll { it.userSync } + .collectEntries { [it.bidder, it.userSync] } + } + + protected static Map getRejectedBidderUserSyncs(CookieSyncResponse cookieSyncResponse) { + cookieSyncResponse.bidderStatus + .findAll { it.error } + .collectEntries { [it.bidder, it.error] } + } + + protected static List removeExpiresValue(List cookies) { + cookies.collect { it.replaceFirst(/Expires=[^;]+;/, "Expires=*;") } + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncConfigurationSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncConfigurationSpec.groovy new file mode 100644 index 00000000000..18c4d39b7f1 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncConfigurationSpec.groovy @@ -0,0 +1,340 @@ +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.UidsCookie +import org.prebid.server.functional.model.config.AccountAuctionConfig +import org.prebid.server.functional.model.config.AccountCcpaConfig +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.config.AccountPrivacyConfig +import org.prebid.server.functional.model.config.PrivacySandbox +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.util.HttpUtil +import org.prebid.server.functional.util.PBSUtils +import org.prebid.server.functional.util.privacy.CcpaConsent + +import static org.prebid.server.functional.model.bidder.BidderName.ALIAS +import static org.prebid.server.functional.model.bidder.BidderName.BOGUS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.NO_COOKIE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.OK +import static org.prebid.server.functional.util.HttpUtil.SET_COOKIE_HEADER +import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED + +class CookieSyncConfigurationSpec extends CookieSyncBaseSpec { + + private static final PbsContainerConfig NO_COOKIE_FAMILY_CONFIG = new PbsContainerConfig(["adapters.${GENERIC.value}.usersync.cookie-family-name": null]) + + private static final PbsContainerConfig CUSTOM_COOKIE_FAMILY_CONFIG = PBS_CONFIG + ["adapters.${GENERIC.value}.usersync.cookie-family-name": BOGUS.value] + + private static final PbsContainerConfig HOST_COOKIE_CONFIG = PBS_CONFIG + + ['host-cookie.family' : GENERIC.value, + 'host-cookie.cookie-name': RANDOM_COOKIE_NAME] + + def "PBS cookie sync request should replace disabled bidder and fill up response with enabled bidders to the limit in request"() { + given: "PBS bidder config" + def pbsConfig = new PbsContainerConfig(MAGNITE_CONFIG + APPNEXUS_CONFIG + ["adapters.${GENERIC.value}.enabled": "false"]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) + + and: "Default Cookie sync request" + def requestLimit = 2 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC] + limit = requestLimit + coopSync = true + debug = false + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain synced bidder" + assert response.bidderStatus.size() == requestLimit + + and: "Response shouldn't contain generic" + assert !response.getBidderUserSync(GENERIC) + + and: "Response should contain coop-synced bidder" + assert DEFAULT_PBS_BIDDERS.containsAll(response.bidderStatus.bidder) + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + } + + def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder without sync config"() { + given: "PBS bidder config without cookie family name" + def prebidServerService = pbsServiceFactory.getService(NO_COOKIE_FAMILY_CONFIG) + + and: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = true + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't return error" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync should preserve requested bidder when cookie family name is configured"() { + given: "PBS bidder config with configured cookie family name" + def prebidServerService = pbsServiceFactory.getService(CUSTOM_COOKIE_FAMILY_CONFIG) + + and: "Cookie sync request for generic bidder" + def cookieSyncRequest = CookieSyncRequest.getDefaultCookieSyncRequest([GENERIC]) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain requested bidder" + assert response.bidderStatus.size() == 1 + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) + assert bidderStatus?.userSync?.type == USER_SYNC_TYPE + assert bidderStatus?.noCookie == true + } + + def "PBS cookie sync should be able to read custom cookie family name from uids cookie"() { + given: "PBS bidder config with defined cookie family name" + def bidder = BOGUS + def prebidServerService = pbsServiceFactory.getService(CUSTOM_COOKIE_FAMILY_CONFIG) + + and: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest + def uidsCookie = UidsCookie.getDefaultUidsCookie(bidder) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response should contain information about bidder status" + assert response.bidderStatus.size() == 1 + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Already in sync" + assert bidderStatus?.userSync == null + assert bidderStatus?.noCookie == null + } + + def "PBS cookie sync request with bidder without cookie family name should emit an error"() { + given: "PBS bidder config without cookie family name" + def prebidServerService = pbsServiceFactory.getService(NO_COOKIE_FAMILY_CONFIG) + + and: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus?.error == "No sync config" + assert bidderStatus?.noCookie == null + assert bidderStatus?.userSync == null + } + + def "PBS cookie sync request with alias bidder should sync independently when alias provide cookie-family-name"() { + given: "PBS config with alias bidder with cookie family name" + def bidderAlias = ALIAS + def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + + ["adapters.${GENERIC.value}.aliases.${bidderAlias.value}.enabled" : "true", + "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.meta-info.vendor-id" : "0", + "adapters.${GENERIC.value}.aliases.${bidderAlias.value}.usersync.cookie-family-name": bidderAlias.value]) + + and: "Cookie sync request with 2 bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, bidderAlias] + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "PBS should return sync for both bidders" + assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() + response.bidderStatus.each { + assert it.userSync?.url?.startsWith(USER_SYNC_URL) + assert it.userSync?.type == USER_SYNC_TYPE + assert it.noCookie == true + } + } + + def "PBS cookie sync request with host cookie should return bidder sync with host cookie uid when there is no uids cookie"() { + given: "PBS bidders config" + def prebidServerService = pbsServiceFactory.getService(HOST_COOKIE_CONFIG) + + and: "Default cookie sync request" + def uidsCookie = UidsCookie.defaultUidsCookie + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC] + } + + and: "Host cookie" + def uid = UUID.randomUUID().toString() + def cookies = [(RANDOM_COOKIE_NAME): uid] + + when: "PBS processes cookie sync request with cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) + + then: "Response should contain uid from cookies" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert HttpUtil.decodeUrl(bidderStatus.userSync?.url).contains("uid=${uid}") + } + + def "PBS cookie sync request with host cookie should return bidder sync with host cookie uid when uids are different"() { + given: "PBS bidders config" + def prebidServerService = pbsServiceFactory.getService(HOST_COOKIE_CONFIG) + + and: "Default cookie sync request" + def uidsCookie = UidsCookie.defaultUidsCookie.tap { + tempUIDs[GENERIC].uid = UUID.randomUUID().toString() + } + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC] + } + + and: "Host cookie" + def hostCookieUid = UUID.randomUUID().toString() + def cookies = [(RANDOM_COOKIE_NAME): hostCookieUid] + + when: "PBS processes cookie sync request with cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) + + then: "Response should contain uid from cookies" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert HttpUtil.decodeUrl(bidderStatus.userSync?.url).contains("uid=${hostCookieUid}") + } + + def "PBS cookie sync request with host cookie should return an error when host cookie uid matches uids cookie uid for bidder"() { + given: "PBS bidders config" + def prebidServerService = pbsServiceFactory.getService(HOST_COOKIE_CONFIG) + + and: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest + + and: "Default uids cookie" + def uid = UUID.randomUUID().toString() + def uidsCookie = UidsCookie.defaultUidsCookie.tap { + tempUIDs[GENERIC].uid = uid + } + + and: "Host cookie" + def cookies = [(RANDOM_COOKIE_NAME): uid] + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie, cookies) + + then: "Response should contain already in sync bidder" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus?.error == "Already in sync" + assert bidderStatus?.noCookie == null + assert bidderStatus?.userSync == null + } + + def "PBS cookie sync request with host cookie shouldn't return bidder sync when host cookie doesn't have configured name"() { + given: "PBS bidders config" + def bidderName = GENERIC + def prebidServerService = pbsServiceFactory.getService( + HOST_COOKIE_CONFIG + ['host-cookie.cookie-name': null]) + + and: "Default cookie sync request" + def uidsCookie = UidsCookie.defaultUidsCookie + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [bidderName] + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should contain already in sync bidder" + def bidderStatus = response.getBidderUserSync(bidderName) + assert bidderStatus?.error == "Already in sync" + assert bidderStatus?.noCookie == null + assert bidderStatus?.userSync == null + } + + def "PBS cookie sync should sync bidder by limit value"() { + given: "PBS config with bidders usersync config" + def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG) + + and: "Default cookie sync request with 2 bidders and limit of 1" + def limit = 1 + def bidders = [GENERIC, MAGNITE] + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.limit = limit + it.bidders = bidders + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain only one valid user sync" + def validBidderUserSyncs = getValidBidderUserSyncs(response) + assert validBidderUserSyncs.values().url.size() == limit + assert validBidderUserSyncs.values().type.size() == limit + + and: "Discarded bidder user sync should contain an error" + def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) + assert rejectedBidderUserSyncs.size() == bidders.size() - limit + assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } + } + + def "PBS cookie sync with ccpa should reject bidder sync"() { + given: "PBS bidder config" + def prebidServerService = pbsServiceFactory.getService( + new PbsContainerConfig(GENERIC_CONFIG + ["adapters.${GENERIC.value}.ccpa-enforced": 'true'])) + + and: "Flush metrics" + flushMetrics(prebidServerService) + + and: "Cookie sync request with account and privacy" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = PBSUtils.randomString + usPrivacy = new CcpaConsent(optOutSale: ENFORCED) + } + + and: "Save account config into DB" + def ccpaConfig = new AccountCcpaConfig(enabled: true) + def accountConfig = new AccountConfig(privacy: new AccountPrivacyConfig(ccpa: ccpaConfig)) + def account = new Account(uuid: cookieSyncRequest.account, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Rejected by CCPA" + } + + def "PBS should set cookie deprecation header from the default account when default account contain privacy sandbox and request account is empty"() { + given: "Pbs with PF configuration with privacySandbox" + def privacySandbox = PrivacySandbox.defaultPrivacySandbox + def defaultAccountConfigSettings = AccountConfig.defaultAccountConfig.tap { + auction = new AccountAuctionConfig(privacySandbox: privacySandbox) + } + def pbsService = pbsServiceFactory.getService(PBS_CONFIG + + ["settings.default-account-config": encode(defaultAccountConfigSettings)]) + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Cookie sync request body" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = null + } + + when: "PBS processes cookie sync request" + def response = pbsService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) + + then: "Response should contain cookie header" + assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == + ["receive-cookie-deprecation=1; Max-Age=${privacySandbox.cookieDeprecation.ttlSeconds}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncNoLimitSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncNoLimitSpec.groovy new file mode 100644 index 00000000000..87f4c7e3351 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncNoLimitSpec.groovy @@ -0,0 +1,269 @@ +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.UidsCookie +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.config.AccountCookieSyncConfig +import org.prebid.server.functional.model.config.AccountCoopSyncConfig +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.model.request.cookiesync.FilterSettings +import org.prebid.server.functional.model.request.cookiesync.MethodFilter +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.util.HttpUtil +import org.prebid.server.functional.util.PBSUtils + +import static org.prebid.server.functional.model.AccountStatus.ACTIVE +import static org.prebid.server.functional.model.bidder.BidderName.AAX +import static org.prebid.server.functional.model.bidder.BidderName.ACEEX +import static org.prebid.server.functional.model.bidder.BidderName.ADKERNEL +import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS +import static org.prebid.server.functional.model.bidder.BidderName.BOGUS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.request.cookiesync.FilterType.EXCLUDE +import static org.prebid.server.functional.model.request.cookiesync.FilterType.INCLUDE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.NO_COOKIE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.OK +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Format.BLANK +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Format.PIXEL +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.IFRAME +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT + +class CookieSyncNoLimitSpec extends CookieSyncBaseSpec { + + private static PrebidServerService pbsWithoutLimitService + + def setupSpec() { + pbsWithoutLimitService = pbsServiceFactory.getService(PBS_CONFIG) + } + + def "PBS cookie sync should emit error when requested bidder rejected by limit"() { + given: "Default cookie sync request with 2 bidders" + def limit = 1 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.bidders = DEFAULT_PBS_BIDDERS + it.limit = limit + } + + when: "PBS processes cookie sync request" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain only one valid user sync" + def validBidderUserSyncs = getValidBidderUserSyncs(response) + assert validBidderUserSyncs.size() == limit + + and: "Discarded bidder user sync should contain an error" + def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) + assert rejectedBidderUserSyncs.size() == DEFAULT_PBS_BIDDERS.size() - limit + assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } + } + + def "PBS cookie sync request should successful pass when request body empty"() { + given: "Empty cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest() + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain '#formatParam' format parameter" + def genericBidderStatus = response.getBidderUserSync(ACEEX) + assert genericBidderStatus?.userSync?.type == REDIRECT + assert HttpUtil.findUrlParameterValue(genericBidderStatus.userSync?.url, "f") == PIXEL.name + + and: "Response should contain '#formatParam' format parameter" + def magniteBidderStatus = response.getBidderUserSync(MAGNITE) + assert magniteBidderStatus?.userSync?.type == IFRAME + assert HttpUtil.findUrlParameterValue(magniteBidderStatus.userSync?.url, "f") == BLANK.name + + and: "Response should contain coop-synced bidder" + assert response.bidderStatus.bidder.containsAll(DEFAULT_PBS_BIDDERS) + } + + def "PBS cookie sync request shouldn't include bidder with invalid user sync type"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: [GENERIC], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain bidders with Redirect type" + def userSync = response.getBidderUserSync(GENERIC) + assert userSync?.userSync?.type == REDIRECT + } + + def "PBS cookie sync request shouldn't exclude bidder with invalid user sync type"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: [GENERIC], filter: EXCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain bidders with Redirect type" + def userSync = response.getBidderUserSync(GENERIC) + assert userSync?.userSync?.type == REDIRECT + } + + def "PBS cookie sync request should successfully passed when account is absent"() { + given: "Cookie sync request with empty account" + def cookieSyncRequest = new CookieSyncRequest(account: null) + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain configured bidders" + assert response?.getBidderStatus()?.bidder?.toSorted() == DEFAULT_PBS_BIDDERS.toSorted() + } + + def "PBS cookie sync request shouldn't return sync url when active uids cookie is present for bidder"() { + given: "Empty cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest() + + and: "Set up uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request with uids cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response shouldn't contain bidder" + assert !response?.getBidderUserSync(GENERIC) + + and: "Response should contain configured bidders" + assert response?.getBidderStatus()?.bidder?.sort() == (DEFAULT_PBS_BIDDERS - GENERIC).sort() + } + + def "PBS cookie sync request should return all possible bidder"() { + given: "Cookie sync request with non specified bidders and specified coop sync" + def cookieSyncRequest = new CookieSyncRequest(bidders: null, coopSync: true) + + when: "PBS processes cookie sync request" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain coop sync bidders" + assert response.bidderStatus.size() == DEFAULT_PBS_BIDDERS.size() + assert response.getBidderUserSync(AAX) + assert response.getBidderUserSync(ADKERNEL) + assert response.getBidderUserSync(OPENX) + assert response.getBidderUserSync(GENERIC) + assert response.getBidderUserSync(APPNEXUS) + assert response.getBidderUserSync(MAGNITE) + assert response.getBidderUserSync(ACEEX) + } + + def "PBS cookie sync request should contain request bidders and rest from coop sync"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [APPNEXUS, GENERIC] + coopSync = true + } + + when: "PBS processes cookie sync request" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + then: "Response should contain requested bidder and coop-synced" + assert response.getBidderStatus().size() > cookieSyncRequest.bidders.size() + assert response.getBidderUserSync(APPNEXUS) + assert response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request should return eight users sync bidders when limit isn't define"() { + given: "Empty cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + limit = null + bidders = null + } + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain eight bidder by default" + assert response?.getBidderStatus()?.size() == DEFAULT_PBS_BIDDERS.size() + } + + def "PBS cookie sync request should fill response with all available coop sync bidder when limit is not specified"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + it.coopSync = true + it.limit = null + } + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contains all available coop sync bidders" + assert response.bidderStatus.bidder.size() == DEFAULT_PBS_BIDDERS.size() + } + + def "PBS cookie sync request should override general configuration limit"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + it.coopSync = true + it.limit = PBSUtils.getRandomNumber(1, DEFAULT_PBS_BIDDERS.size()) + } + + when: "PBS processes cookie sync request without cookies" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contains same count of bidder as specified limit" + assert response.bidderStatus.size() == cookieSyncRequest.limit + } + + def "PBS cookie sync request should take presence coop sync over coop sync in config"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + coopSync = true + } + + and: "Save account with cookie config" + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsWithoutLimitService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain corresponding bidders size due to global config" + assert response.bidderStatus.size() == (DEFAULT_PBS_BIDDERS + BOGUS).size() + + where: + cookieSyncConfig << [new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: true)), + new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: false)), + new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: null)), + new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: true)), + new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: false)), + new AccountCookieSyncConfig(coopSyncSnakeCase: new AccountCoopSyncConfig(enabled: null))] + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncPriSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncPriSpec.groovy new file mode 100644 index 00000000000..8cc7faa7758 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncPriSpec.groovy @@ -0,0 +1,308 @@ +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.config.AccountCookieSyncConfig +import org.prebid.server.functional.model.config.AccountCoopSyncConfig +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig +import org.prebid.server.functional.util.PBSUtils + +import java.time.Instant + +import static org.prebid.server.functional.model.AccountStatus.ACTIVE +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC + +class CookieSyncPriSpec extends CookieSyncBaseSpec { + + private static final boolean CORS_SUPPORT = false + + private static final PbsContainerConfig GENERIC_USERSYNC_CONFIG = new PbsContainerConfig(GENERIC_CONFIG) + + private static final PbsContainerConfig COOP_SYNC_BASE_CONFIG = GENERIC_USERSYNC_CONFIG + + ["adapters.${GENERIC.value}.usersync.redirect.url" : USER_SYNC_URL, + "adapters.${GENERIC.value}.usersync.redirect.support-cors": CORS_SUPPORT.toString(), + 'cookie-sync.pri' : GENERIC.value] + + private static final PbsContainerConfig COOP_SYNC_ENABLED_CONFIG = COOP_SYNC_BASE_CONFIG + ['cookie-sync.coop-sync.default': 'true'] + private static final PbsContainerConfig COOP_SYNC_DISABLED_CONFIG = COOP_SYNC_BASE_CONFIG + ['cookie-sync.coop-sync.default': 'false'] + + private static PrebidServerService pbsWithCoopSyncDefault + private static PrebidServerService pbsWithoutCoopSyncDefault + + def setupSpec() { + pbsWithCoopSyncDefault = pbsServiceFactory.getService(COOP_SYNC_ENABLED_CONFIG) + pbsWithoutCoopSyncDefault = pbsServiceFactory.getService(COOP_SYNC_DISABLED_CONFIG) + } + + def "PBS cookie sync with cookie-sync.pri and enabled coop-sync in config should sync bidder which present in cookie-sync.pri config"() { + given: "Default cookie sync request without coop-sync and bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = null + } + + when: "PBS processes cookie sync request" + def response = pbsWithCoopSyncDefault.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder from cookie-sync.pri config" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + } + + def "PBS cookie sync with cookie-sync.pri and disabled coop-sync in config shouldn't sync bidder which present in cookie-sync.pri config"() { + given: "Default cookie sync request without coop-sync and bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = null + } + + when: "PBS processes cookie sync request" + def response = pbsWithoutCoopSyncDefault.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain generic bidder from cookie-sync.pri config" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS should prioritise disabled account cookie sync config over #configType host config and shouldn't sync bidder"() { + given: "Default cookie sync request without coop-sync and bidders" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = null + account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: false)) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain generic bidder which present in cookie-sync.pri config" + assert !response.getBidderUserSync(GENERIC) + + where: + configType | pbsService + 'enabled coop-sync' | pbsWithCoopSyncDefault + 'disabled coop-sync' | pbsWithoutCoopSyncDefault + } + + def "PBS should prioritise enabled account cookie sync config over #configType host config and should sync bidder"() { + given: "Default cookie sync request without coop-sync and bidders" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = null + account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: true)) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder from cookie-sync.pri config" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + + where: + configType | pbsService + 'enabled coop-sync' | pbsWithCoopSyncDefault + 'disabled coop-sync' | pbsWithoutCoopSyncDefault + } + + def "PBS cookie sync with enabled coop-sync should log error when prioritized bidder name is invalid"() { + given: "Start time" + def startTime = Instant.now() + + and: "PBS config with invalid prioritized bidder" + def pbsConfig = new PbsContainerConfig([ + "cookie-sync.pri": PBSUtils.randomString + ]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) + + and: "Cookie sync request with coop-sync enabled" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + coopSync = true + } + + when: "PBS processes cookie sync request" + prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "PBS log should contain invalid bidder message" + def logs = prebidServerService.getLogsByTime(startTime) + assert getLogsByText(logs, "is invalid bidder name, ignoring").size() == 1 + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + } + + def "PBS cookie sync with enabled coop-sync should log error when prioritized bidder is disabled"() { + given: "Start time" + def startTime = Instant.now() + + and: "PBS config with disabled prioritized bidder" + def pbsConfig = new PbsContainerConfig([ + "adapters.generic.enabled": "false", + "cookie-sync.pri" : GENERIC.value + ]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) + + and: "Cookie sync request with coop-sync enabled" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + coopSync = true + } + + when: "PBS processes cookie sync request" + prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "PBS log should contain disabled bidder message" + def logs = prebidServerService.getLogsByTime(startTime) + assert getLogsByText(logs, "disabled in current pbs instance, ignoring").size() == 1 + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + } + + def "PBS cookie sync with enabled coop-sync should log error when prioritized bidder has no user sync configuration"() { + given: "Start time" + def startTime = Instant.now() + + and: "PBS config with prioritized bidder without user sync configuration" + def pbsConfig = new PbsContainerConfig([ + "adapters.generic.usersync.cookie-family-name": null, + "cookie-sync.pri" : GENERIC.value + ]) + def prebidServerService = pbsServiceFactory.getService(pbsConfig) + + and: "Cookie sync request with coop-sync enabled" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + coopSync = true + } + + when: "PBS processes cookie sync request" + prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "PBS log should contain missing user sync configuration message" + def logs = prebidServerService.getLogsByTime(startTime) + assert getLogsByText(logs, "has no user-sync configuration, ignoring").size() == 1 + + cleanup: + pbsServiceFactory.removeContainer(pbsConfig) + } + + def "PBS cookie sync with cookie-sync.pri and enabled coop sync should sync bidder which present in cookie-sync.pri"() { + given: "Default cookie sync request with coop-sync" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = true + } + + when: "PBS processes cookie sync request" + def response = pbsWithoutCoopSyncDefault.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + } + + def "PBS cookie sync with cookie-sync.pri and disabled coop-sync in request shouldn't sync bidder which present in cookie-sync.pri config"() { + given: "Default cookie sync request without coop-sync and bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = false + } + + when: "PBS processes cookie sync request" + def response = pbsWithoutCoopSyncDefault.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain generic bidder" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync with cookie-sync.pri and enabled coop sync in account should sync bidder which present in cookie-sync.pri config"() { + given: "Default cookie sync request without coop-sync and bidders" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.bidders = null + it.coopSync = null + it.account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(coopSync: new AccountCoopSyncConfig(enabled: true)) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsWithoutCoopSyncDefault.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder from cookie-sync.pri config" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + } + + def "PBS cookie sync with coop-sync.default config and pri in cookie sync account should sync bidder which present in pri account config"() { + given: "Default cookie sync request without coop-sync and bidders" + def accountId = PBSUtils.randomNumber + def pbsWithGenericCors = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG) + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = null + account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(pri: [GENERIC.value]) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsWithGenericCors.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder from pri account config" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + } + + def "PBS cookie sync with pri and enabled coop sync in cookie sync account should sync bidder which present in pri account config"() { + given: "Default cookie sync request without coop-sync and bidders" + def pbsWithGenericCors = pbsServiceFactory.getService(GENERIC_USERSYNC_CONFIG) + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.bidders = null + it.coopSync = null + it.account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(pri: [GENERIC.value], coopSync: new AccountCoopSyncConfig(enabled: true)) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = pbsWithGenericCors.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain generic bidder from pri account config" + def genericBidder = response.getBidderUserSync(GENERIC) + assert genericBidder?.userSync?.url + assert genericBidder?.userSync?.type + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncSpec.groovy new file mode 100644 index 00000000000..044caafad2a --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/cookiesync/CookieSyncSpec.groovy @@ -0,0 +1,1169 @@ +//file:noinspection GroovyGStringKey +package org.prebid.server.functional.tests.cookiesync + +import org.prebid.server.functional.model.UidsCookie +import org.prebid.server.functional.model.config.AccountAuctionConfig +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.config.AccountCookieSyncConfig +import org.prebid.server.functional.model.config.PrivacySandbox +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest +import org.prebid.server.functional.model.request.cookiesync.FilterSettings +import org.prebid.server.functional.model.request.cookiesync.MethodFilter +import org.prebid.server.functional.service.PrebidServerException +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.util.PBSUtils +import org.prebid.server.functional.util.privacy.TcfConsent + +import java.util.concurrent.TimeUnit + +import static org.prebid.server.functional.model.AccountStatus.ACTIVE +import static org.prebid.server.functional.model.bidder.BidderName.ACEEX +import static org.prebid.server.functional.model.bidder.BidderName.ACUITYADS +import static org.prebid.server.functional.model.bidder.BidderName.ADKERNEL +import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS +import static org.prebid.server.functional.model.bidder.BidderName.BOGUS +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.MAGNITE +import static org.prebid.server.functional.model.request.cookiesync.FilterType.EXCLUDE +import static org.prebid.server.functional.model.request.cookiesync.FilterType.INCLUDE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.NO_COOKIE +import static org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse.Status.OK +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.IFRAME +import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT +import static org.prebid.server.functional.util.HttpUtil.SET_COOKIE_HEADER +import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID +import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS + +class CookieSyncSpec extends CookieSyncBaseSpec { + + private static PrebidServerService prebidServerService + + def setupSpec() { + prebidServerService = pbsServiceFactory.getService(PBS_WITH_LIMIT_CONFIG) + } + + def "PBS cookie sync request should replace bidder without config and fill up response with enabled bidders to the limit in request"() { + given: "Default Cookie sync request" + def requestLimit = 2 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [BOGUS] + limit = requestLimit + coopSync = true + debug = false + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain synced bidder" + assert response.bidderStatus.size() == requestLimit + + and: "Response shouldn't contain bogus" + assert !response.getBidderUserSync(BOGUS) + + and: "Response should contain coop-synced bidder" + assert DEFAULT_PBS_BIDDERS.containsAll(response.bidderStatus.bidder) + } + + def "PBS cookie sync request should replace unknown bidder and fill up response with enabled bidders to the limit in request"() { + given: "Cookie sync request" + def requestLimit = 2 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [BOGUS] + limit = requestLimit + coopSync = true + debug = false + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain synced bidder" + assert response.bidderStatus.size() == requestLimit + + and: "Response shouldn't contain bogus" + assert !response.getBidderUserSync(BOGUS) + + and: "Response should contain coop-synced bidder" + assert DEFAULT_PBS_BIDDERS.containsAll(response.bidderStatus.bidder) + } + + def "PBS cookie sync request should replace filtered bidder and fill up response with enabled bidders to the limit in request"() { + given: "Cookie sync request" + def requestLimit = 2 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC] + limit = requestLimit + coopSync = true + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) + debug = false + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain synced bidder" + assert response.bidderStatus.size() == requestLimit + + and: "Response shouldn't contain generic" + assert !response.getBidderUserSync(GENERIC) + + and: "Response should contain coop-synced bidder" + assert DEFAULT_PBS_BIDDERS.containsAll(response.bidderStatus.bidder) + } + + def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder disabled"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = true + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't return error" + assert response.bidderStatus.error.every { it == null } + } + + def "PBS cookie sync request shouldn't reflect error when coop-sync enabled and coop sync bidder family already in uids cookie"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = true + } + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response shouldn't return error" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request should reflect error when coop-sync enabled and coop sync bidder with gdpr"() { + given: "Valid consent string" + def validConsentString = new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .setVendorLegitimateInterest([GENERIC_VENDOR_ID]) + .setDisclosedVendors([GENERIC_VENDOR_ID]) + .build() + + and: "Cookie sync request with gdpr and gdprConsent" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [] + coopSync = true + gdpr = 1 + gdprConsent = validConsentString + } + + flushMetrics(prebidServerService) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Rejected by TCF" + + and: "Metric should contain cookie_sync.BIDDER.tcf.blocked" + def metric = prebidServerService.sendCollectedMetricsRequest() + assert metric["cookie_sync.generic.tcf.blocked"] == 1 + } + + def "PBS cookie sync request should reflect error when coop-sync enabled and coop sync bidder filtered"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [] + coopSync = true + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Rejected by request filter" + + and: "Metric should contain cookie_sync.generic.filtered" + def metric = prebidServerService.sendCollectedMetricsRequest() + assert metric["cookie_sync.generic.filtered"] == 1 + } + + def "PBS cookie sync request should reflect error even when response is full by account cookie sync config limit"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + } + + and: "Save account with cookie config" + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain 1 valid bidder and 1 bidder with error" + assert response.bidderStatus.size() == 2 + + and: "Response should contain valid generic" + assert response.getBidderUserSync(GENERIC) + + and: "Response should contain invalid bogus bidder" + def bogusBidderStatus = response.getBidderUserSync(BOGUS) + assert bogusBidderStatus?.error == "Unsupported bidder" + assert bogusBidderStatus?.noCookie == null + assert bogusBidderStatus?.userSync == null + + where: + accountConfig << [new AccountConfig(status: ACTIVE, cookieSync: new AccountCookieSyncConfig(defaultLimit: 1)), + new AccountConfig(status: ACTIVE, cookieSyncSnakeCase: new AccountCookieSyncConfig(defaultLimit: 1))] + } + + def "PBS cookie sync request should reflect error even when response is full by PBS config limit"() { + given: "Default cookie sync request with coop-sync and without bidders" + def cookieSyncBidders = [GENERIC, MAGNITE, APPNEXUS] + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = cookieSyncBidders + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain valid bidders and 1 bidder with error" + verifyAll(response.bidderStatus) { + it.bidder.sort() == cookieSyncBidders.sort() + it.error.sort() == [null, null, "Limit reached"].sort() + } + } + + def "PBS cookie sync request should reflect error even when response is full by request limit"() { + given: "Cookie sync request" + def cookieSyncRequest = CookieSyncRequest.getDefaultCookieSyncRequest().tap { + bidders = [GENERIC, BOGUS] + limit = 1 + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain 1 valid bidder and 1 bidder with error" + assert response.bidderStatus.size() == 2 + + and: "Response should contain generic" + assert response.getBidderUserSync(GENERIC) + + and: "Response should contain error for bogus bidder" + def bogusBidderStatus = response.getBidderUserSync(BOGUS) + assert bogusBidderStatus?.error == "Unsupported bidder" + assert bogusBidderStatus?.noCookie == null + assert bogusBidderStatus?.userSync == null + } + + def "PBS cookie sync request with valid uids cookie should return status OK without user sync information"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response should contain information about bidder status" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Already in sync" + assert bidderStatus?.userSync == null + assert bidderStatus?.noCookie == null + } + + def "PBS cookie sync request without uids cookie should return bidder user sync information"() { + given: "Default Cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain sync information for configured bidder" + assert response.bidderStatus.size() == 1 + + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) + assert bidderStatus?.userSync?.type == USER_SYNC_TYPE + assert bidderStatus?.noCookie == true + } + + def "PBS cookie sync request should not emit error for already synced bidder without debug flag"() { + given: "Default cookie sync request without debug flag" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + debug = false + } + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response should not contain information about bidder status" + assert response.bidderStatus.size() == 0 + } + + def "PBS cookie sync request with unknown bidder respond with an error for that bidder"() { + given: "Default cookie sync request with bogus bidder" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain information for all requested bidders" + assert response.status == NO_COOKIE + assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() + + and: "Response should contain error for unknown bidder" + def unknownBidderStatus = response.getBidderUserSync(BOGUS) + assert unknownBidderStatus?.error == "Unsupported bidder" + assert unknownBidderStatus?.noCookie == null + assert unknownBidderStatus?.userSync == null + + and: "Response should contain sync information for configured bidder" + def configuredBidderStatus = response.getBidderUserSync(GENERIC) + assert configuredBidderStatus?.userSync?.url?.startsWith(USER_SYNC_URL) + assert configuredBidderStatus?.userSync?.type == USER_SYNC_TYPE + assert configuredBidderStatus?.noCookie == true + } + + def "PBS cookie sync request with disabled bidder should emit an error"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.getDefaultCookieSyncRequest([ACUITYADS]) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(ACUITYADS) + assert bidderStatus?.error == "Disabled bidder" + assert bidderStatus?.noCookie == null + assert bidderStatus?.userSync == null + } + + def "PBS cookie sync with enabled coop-sync should sync all enabled bidders"() { + given: "Default cookie sync request with coop-sync and without bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = null + coopSync = true + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain all 2 enabled bidders" + assert response.bidderStatus.size() == COOKIE_SYNC_DEFAULT_LIMIT + } + + def "PBS cookie sync with cookie-sync.default-limit config should use limit from cookie sync config"() { + given: "Default cookie sync request with 3 bidders" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.bidders = [MAGNITE, APPNEXUS, GENERIC] + it.account = accountId + it.limit = requestLimit + it.debug = false + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: accountLimit) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain one synced bidder" + assert response.bidderStatus.size() == 1 + + where: + requestLimit | accountLimit + 1 | null + null | 1 + } + + def "PBS cookie sync request should take precedence request limit over account and global config"() { + given: "Default cookie sync request with 3 bidders" + def accountId = PBSUtils.randomNumber + def requestLimit = 1 + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.bidders = [MAGNITE, APPNEXUS, GENERIC] + it.account = accountId + it.limit = requestLimit + it.debug = false + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: requestLimit + 1) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain one synced bidder" + assert response.bidderStatus.size() == requestLimit + } + + def "PBS cookie sync with cookie-sync.max-limit should use max-limit from PBS config"() { + given: "Default cookie sync request with 3 bidders" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, APPNEXUS, MAGNITE] + limit = COOKIE_SYNC_MAX_LIMIT + 1 + debug = false + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain only one synced bidder" + assert response.bidderStatus.size() == COOKIE_SYNC_MAX_LIMIT + } + + def "PBS cookie sync with cookie-sync.max-limit should use max-limit from cookie sync account config"() { + given: "Default cookie sync request with 3 bidders" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = DEFAULT_PBS_BIDDERS + limit = COOKIE_SYNC_MAX_LIMIT + 2 + account = accountId + debug = false + } + + and: "Save account with cookie sync config" + def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: accountMaxLimit, maxLimitSnakeCase: accountMaxLimitSnakeCase) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain only two synced bidder" + assert response.bidderStatus.size() == COOKIE_SYNC_MAX_LIMIT + 1 + + where: + accountMaxLimit | accountMaxLimitSnakeCase + COOKIE_SYNC_MAX_LIMIT + 1 | null + null | COOKIE_SYNC_MAX_LIMIT + 1 + } + + def "PBS cookie sync with filter setting should reject bidder sync"() { + given: "Cookie sync request with filter settings" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC], filter: EXCLUDE)) + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Rejected by request filter" + + and: "Metric should contain cookie_sync.FAMILY.filtered" + def metric = prebidServerService.sendCollectedMetricsRequest() + assert metric["cookie_sync.generic.filtered"] == 1 + } + + def "PBS cookie sync with gdpr should reject bidder sync"() { + given: "Valid consent string" + def validConsentString = new TcfConsent.Builder() + .setPurposesLITransparency(BASIC_ADS) + .setVendorLegitimateInterest([GENERIC_VENDOR_ID]) + .setDisclosedVendors([GENERIC_VENDOR_ID]) + .build() + + and: "Cookie sync request with gdpr and gdprConsent" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + gdpr = 1 + gdprConsent = validConsentString + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(GENERIC) + assert bidderStatus.error == "Rejected by TCF" + + and: "Metric should contain cookie_sync.BIDDER.tcf.blocked" + def metric = prebidServerService.sendCollectedMetricsRequest() + assert metric["cookie_sync.generic.tcf.blocked"] == 1 + } + + def "PBS cookie sync shouldn't emit error limit reached when bidder coop-synced"() { + given: "Default cookie sync request with single bidder" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.coopSync = true + it.bidders = [MAGNITE] + it.limit = 1 + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response shouldn't contain generic bidder" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request shouldn't return bidder due to filter setting request"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + image = new MethodFilter().tap { + filter = EXCLUDE + bidders = [APPNEXUS] + } + } + def cookieSyncRequest = new CookieSyncRequest().tap { + it.filterSettings = filterSettings + it.limit = 0 + it.coopSync = false + it.debug = true + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Bidder should be excluded by filter" + assert !response.getBidderUserSync(APPNEXUS) + } + + def "PBS cookie sync request should include all bidder due to filterSettings"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: [MAGNITE], filter: INCLUDE) + image = new MethodFilter(bidders: [APPNEXUS], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Bidder should be include by filter" + assert response.getBidderUserSync(APPNEXUS) + assert response.getBidderUserSync(MAGNITE) + } + + def "PBS cookie sync request should exclude all iframe bidders when asterisk present in bidders filterSettings"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: ALL_BIDDERS, filter: EXCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain only bidders with IMAGE" + assert response?.bidderStatus?.every { it.getUserSync().type == REDIRECT } + } + + def "PBS cookie sync request should exclude all image bidders when asterisk present in bidders filterSettings"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + image = new MethodFilter(bidders: ALL_BIDDERS, filter: EXCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contains all bidders with IFRAME" + assert response?.bidderStatus?.every { it.getUserSync().type == IFRAME } + } + + def "PBS cookie sync request should ignore iframe invalid bidder in method filter bidders"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: [bidders], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response shouldn't contain invalid bidders" + assert !response.getBidderUserSync(bidders) + + where: + bidders << [BOGUS, null] + } + + def "PBS cookie sync request should ignore image invalid bidder in method filter bidders"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + image = new MethodFilter(bidders: [bidders], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response shouldn't contain invalid bidders" + assert !response.getBidderUserSync(bidders) + + where: + bidders << [BOGUS, null] + } + + def "PBS cookie sync request should return url for all bidders when no uids cookie is present"() { + given: "Cookie sync request with empty account" + def cookieSyncRequest = new CookieSyncRequest() + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain info for all configured bidder" + def bidderStatus = response?.bidderStatus?.userSync + assert bidderStatus?.url + assert bidderStatus?.type + } + + def "PBS cookie sync request shouldn't return iframe sync url included by sync type bidders for bidder in cookie"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + iframe = new MethodFilter(bidders: [GENERIC], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + and: "Set up uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request with uids cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response shouldn't contain generic bidder" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request shouldn't return image sync url included by sync type bidders for bidder in cookie"() { + given: "Cookie sync request with filter setting" + def filterSettings = new FilterSettings().tap { + image = new MethodFilter(bidders: [APPNEXUS], filter: INCLUDE) + } + def cookieSyncRequest = new CookieSyncRequest(filterSettings: filterSettings, limit: 0) + + and: "Set up uids cookie with appnexus" + def uidsCookie = UidsCookie.getDefaultUidsCookie(APPNEXUS) + + when: "PBS processes cookie sync request with generic uid cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response shouldn't contain generic bidder" + assert !response.getBidderUserSync(APPNEXUS) + } + + def "PBS cookie sync request shouldn't return requested bidder when bidders present in uids cookie"() { + given: "Cookie sync request with generic bidders" + def cookieSyncRequest = new CookieSyncRequest(bidders: [GENERIC]) + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + when: "PBS processes cookie sync request with generic uid cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie) + + then: "Response should have status 'OK'" + assert response.status == OK + + and: "Response shouldn't contain generic bidder" + assert !response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request should contain only request bidders when coop sync off"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [APPNEXUS, GENERIC] + coopSync = false + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + then: "Response should contain requested bidder and coop-synced" + assert response.getBidderStatus().size() == cookieSyncRequest.bidders.size() + assert response.getBidderUserSync(APPNEXUS) + assert response.getBidderUserSync(GENERIC) + } + + def "PBS cookie sync request should contain only request bidders with limit when coop sync off and limit specified"() { + given: "Default cookie sync request" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [APPNEXUS, GENERIC, MAGNITE] + coopSync = false + limit = 2 + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain requested bidder limit" + def rejectedBidderUserSyncs = getRejectedBidderUserSyncs(response) + assert rejectedBidderUserSyncs.size() == cookieSyncRequest.bidders.size() - cookieSyncRequest.limit + assert rejectedBidderUserSyncs.every { it.value == "Limit reached" } + } + + def "PBS cookie sync request should return only requested bidder and reduce image list by filter settings"() { + given: "Default cookie sync request" + def cookieSyncRequest = new CookieSyncRequest().tap { + bidders = [MAGNITE, APPNEXUS, ACEEX] + coopSync = false + filterSettings = new FilterSettings().tap { + image = new MethodFilter(bidders: [ACEEX], filter: EXCLUDE) + iframe = new MethodFilter(bidders: [MAGNITE], filter: INCLUDE) + } + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain two requested bidders" + assert response.getBidderStatus().size() == cookieSyncRequest.bidders.size() - 1 + assert response.getBidderUserSync(MAGNITE) + assert response.getBidderUserSync(APPNEXUS) + + and: "Response shouldn't contain requested bidders due to filter" + assert !response.getBidderUserSync(ACEEX) + } + + def "PBS cookie sync request shouldn't return any bidder when coop sync off and bidder is invalid"() { + given: "Cookie sync request body with bidders and disabled coop-sync" + def cookieSyncRequest = new CookieSyncRequest(coopSync: false, bidders: givenBidder) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response shouldn't contain amount of invalid bidder" + assert response.getBidderStatus().size() == 0 + + where: + givenBidder << [[BOGUS], []] + } + + def "PBS cookie sync request shouldn't return all bidders when coop sync #coopSync and limit param specified"() { + given: "Cookie sync request with bidders and limit" + def cookieSyncRequest = new CookieSyncRequest(coopSync: coopSync, bidders: [APPNEXUS, MAGNITE], limit: 1) + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain amount of bidder that define in request" + assert response.getBidderStatus().size() == cookieSyncRequest.limit + + where: + coopSync << [true, false] + } + + def "PBS cookie sync request shouldn't increase amount of bidder then define in request"() { + given: "Empty cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + limit = 1 + bidders = [MAGNITE, GENERIC] + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [MAGNITE, GENERIC], filter: INCLUDE)) + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status 'NO_COOKIE'" + assert response.status == NO_COOKIE + + and: "Response should contain amount of bidder that define in request" + assert response.getBidderStatus().size() == cookieSyncRequest.limit + } + + def "PBS cookie sync request should limit the number of returned bidders"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + it.limit = PBSUtils.getRandomNumber(1, 3) + it.coopSync = true + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should have status" + assert response.getBidderStatus().size() == cookieSyncRequest.limit + } + + def "PBS cookie sync request should return bidders matched in bidders and filter settings"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + it.coopSync = false + it.bidders = [GENERIC, MAGNITE] + it.filterSettings = new FilterSettings(image: new MethodFilter(bidders: [GENERIC, MAGNITE, APPNEXUS], filter: INCLUDE)) + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contains the same size" + assert response.bidderStatus.bidder.size() == cookieSyncRequest.bidders.size() + + and: "Should contain requested bidders" + assert response.bidderStatus.bidder.containsAll([GENERIC, MAGNITE]) + } + + def "PBS cookie sync request should return bidders without excluded by filter settings"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + coopSync = false + bidders = [ACEEX, MAGNITE] + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [ACEEX], filter: EXCLUDE)) + debug = true + } + + when: "PBS processes cookie sync request without cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def bidderStatus = response.getBidderUserSync(ACEEX) + assert bidderStatus.error == "Rejected by request filter" + + and: "Response should contain one valid bidder" + assert response.getBidderUserSync(MAGNITE) + } + + def "PBS cookie sync request shouldn't include bidder when bidder specified in uids cookie"() { + given: "Cookie sync request body" + def cookieSyncRequest = new CookieSyncRequest().tap { + coopSync = false + bidders = [APPNEXUS, MAGNITE] + filterSettings = new FilterSettings(image: new MethodFilter(bidders: [APPNEXUS, MAGNITE], filter: INCLUDE)) + debug = false + } + + and: "Given uid cookie" + def cookie = UidsCookie.getDefaultUidsCookie(APPNEXUS) + + when: "PBS processes cookie sync request with cookies" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest, cookie) + + then: "Response should contain valid bidder" + assert response.getBidderUserSync(MAGNITE) + + and: "Response shouldn't contain bidder that present in uids cookie" + assert !response.getBidderUserSync(APPNEXUS) + } + + def "PBS cookie sync request shouldn't limit bidders with zero value in config"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: 0) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain valid bidder status" + assert response.bidderStatus.size() == cookieSyncRequest.bidders.size() + } + + def "PBS cookie sync request should max limit override default limit"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + debug = false + } + + and: "Save account with cookie config" + def maxLimit = 1 + def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: maxLimit, defaultLimit: 2) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain corresponding bidders size due to config" + assert response.bidderStatus.size() == maxLimit + } + + def "PBS cookie sync request should max limit in account take precedence over request limit"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, APPNEXUS, ADKERNEL] + account = accountId + limit = null + debug = false + } + + and: "Save account with cookie config" + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain corresponding bidders size due to config" + assert response.bidderStatus.size() == 2 + + where: + accountConfig << [new AccountConfig(status: ACTIVE, cookieSyncSnakeCase: new AccountCookieSyncConfig(maxLimit: 2)), + new AccountConfig(status: ACTIVE, cookieSync: new AccountCookieSyncConfig(maxLimit: 2))] + } + + def "PBS cookie sync request should capped to max limit"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + limit = limitRequest + debug = false + } + + and: "Save account with cookie config" + def maxLimit = 1 + def cookieSyncConfig = new AccountCookieSyncConfig(maxLimit: maxLimit) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain corresponding bidders size due to config" + assert response.bidderStatus.size() == maxLimit + + where: + limitRequest << [0, 2, null] + } + + def "PBS cookie sync request should account limit override general configuration limit when not limit in request"() { + given: "Default cookie sync request" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + bidders = [GENERIC, BOGUS] + account = accountId + limit = null + debug = false + } + + and: "Save account with cookie config" + def cookieSyncConfig = new AccountCookieSyncConfig(defaultLimit: accountDefaultLimit, defaultLimitSnakeCase: accountDefaultLimitSnakeCase) + def accountConfig = new AccountConfig(status: ACTIVE, cookieSync: cookieSyncConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain corresponding bidders size due to config" + assert response.bidderStatus.size() == 1 + + where: + accountDefaultLimit | accountDefaultLimitSnakeCase + 1 | null + null | 1 + } + + def "PBS cookie sync request should respond with an error when gdpr param is 1 and consent isn't specified"() { + given: "Cookie sync request body with gdpr = 1 and gdprConsent = null" + def cookieSyncRequest = new CookieSyncRequest().tap { + gdpr = 1 + gdprConsent = null + } + + when: "PBS processes cookie sync request" + prebidServerService.sendCookieSyncRequest(cookieSyncRequest) + + then: "Response should contain error" + def serverException = thrown(PrebidServerException) + assert serverException.responseBody == "Invalid request format: gdpr_consent is required if gdpr is 1" + } + + def "PBS shouldn't set cookie deprecation header from the account when privacySandbox is #privacySandbox"() { + given: "Default cookie sync request with account" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = accountId + } + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Save account with cookie and privacySandbox configs" + def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) + def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) + + then: "Response shouldn't contain cookie header" + assert !response.headers[SET_COOKIE_HEADER] + + where: + privacySandbox << [null, + PrivacySandbox.getDefaultPrivacySandbox(null), + PrivacySandbox.getDefaultPrivacySandbox(false)] + } + + def "PBS shouldn't set cookie deprecation header from the account when cookies is included in original request"() { + given: "Default cookie sync request with account" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = accountId + } + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Save account with cookie and privacySandbox configs" + def privacySandbox = PrivacySandbox.defaultPrivacySandbox + def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) + def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def setCookieDefaultHeader = ['receive-cookie-deprecation': '1'] + def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie, setCookieDefaultHeader) + + then: "Response shouldn't contain cookie header" + assert !response.headers[SET_COOKIE_HEADER] + } + + def "PBS should set cookie deprecation header from the account when cookies is not included in original request"() { + given: "Default cookie sync request with account" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = accountId + } + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Save account with cookie and privacySandbox configs" + def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox) + def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) + + then: "Response should contain cookie header" + assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == + ["receive-cookie-deprecation=1; Max-Age=${privacySandbox.cookieDeprecation.ttlSeconds}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] + + where: + privacySandbox << [PrivacySandbox.defaultPrivacySandbox, PrivacySandbox.getDefaultPrivacySandbox(true, -PBSUtils.randomNumber)] + } + + def "PBS should set cookie deprecation header on default value of week when ttlSec is not specified in privacy sandbox settings"() { + given: "Default cookie sync request with account" + def accountId = PBSUtils.randomNumber + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = accountId + } + + and: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Save account with cookie and privacySandbox configs" + def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: PrivacySandbox.getDefaultPrivacySandbox(true, null)) + def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) + + then: "Response should contain cookie header" + assert removeExpiresValue(response.headers[SET_COOKIE_HEADER]) == + ["receive-cookie-deprecation=1; Max-Age=${TimeUnit.DAYS.toSeconds(7)}; Expires=*; Path=/; Secure; HTTPOnly; SameSite=None; Partitioned"] + } + + def "PBS shouldn't set cookie deprecation header when cookie sync request doesn't contain account"() { + given: "Set up generic uids cookie" + def uidsCookie = UidsCookie.defaultUidsCookie + + and: "Cookie sync request body" + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + account = null + } + + when: "PBS processes cookie sync request" + def response = prebidServerService.sendCookieSyncRequestRaw(cookieSyncRequest, uidsCookie) + + then: "Response shouldn't contain cookie header" + assert !response.headers[SET_COOKIE_HEADER] + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/AbTestingModuleSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/AbTestingModuleSpec.groovy index de9d940de43..9cee9ea92ed 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/AbTestingModuleSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/AbTestingModuleSpec.groovy @@ -7,15 +7,18 @@ import org.prebid.server.functional.model.config.ExecutionPlan import org.prebid.server.functional.model.config.ModuleName import org.prebid.server.functional.model.config.Stage import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus import org.prebid.server.functional.model.request.auction.BidRequest -import org.prebid.server.functional.model.request.auction.FetchStatus import org.prebid.server.functional.model.request.auction.TraceLevel import org.prebid.server.functional.model.response.auction.AnalyticResult import org.prebid.server.functional.model.response.auction.InvocationResult +import org.prebid.server.functional.model.response.auction.ModuleActivityName import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import static org.prebid.server.functional.model.config.HookHttpEndpoint.AUCTION +import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING import static org.prebid.server.functional.model.config.ModuleName.PB_RESPONSE_CORRECTION import static org.prebid.server.functional.model.config.Stage.ALL_PROCESSED_BID_RESPONSES import static org.prebid.server.functional.model.config.Stage.BIDDER_REQUEST @@ -24,7 +27,6 @@ import static org.prebid.server.functional.model.request.auction.BidRequest.getD import static org.prebid.server.functional.model.response.auction.InvocationStatus.INVOCATION_FAILURE import static org.prebid.server.functional.model.response.auction.InvocationStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.ModuleActivityName.AB_TESTING -import static org.prebid.server.functional.model.response.auction.ModuleActivityName.ORTB2_BLOCKING import static org.prebid.server.functional.model.response.auction.ResponseAction.NO_ACTION import static org.prebid.server.functional.model.response.auction.ResponseAction.NO_INVOCATION @@ -34,20 +36,20 @@ class AbTestingModuleSpec extends ModuleBaseSpec { private final static Integer MAX_PERCENT_AB = 100 private final static String INVALID_HOOK_MESSAGE = "Hook implementation does not exist or disabled" - private final static Map> ORTB_STAGES = [(BIDDER_REQUEST) : [ModuleName.PB_ORTB2_BLOCKING], - (RAW_BIDDER_RESPONSE): [ModuleName.PB_ORTB2_BLOCKING]] + private final static Map> ORTB_STAGES = [(BIDDER_REQUEST) : [PB_ORTB2_BLOCKING], + (RAW_BIDDER_RESPONSE): [PB_ORTB2_BLOCKING]] private final static Map> RESPONSE_STAGES = [(ALL_PROCESSED_BID_RESPONSES): [PB_RESPONSE_CORRECTION]] private final static Map> MODULES_STAGES = ORTB_STAGES + RESPONSE_STAGES + private final static PbsContainerConfig PB_ORTB2_CONFIG = getModuleBaseSettings(PB_ORTB2_BLOCKING) - private final static Map MULTI_MODULE_CONFIG = getResponseCorrectionConfig() + getOrtb2BlockingSettings() + + private final static PbsContainerConfig MULTI_MODULE_CONFIG = getModuleBaseSettings(PB_RESPONSE_CORRECTION) + + getModuleBaseSettings(PB_ORTB2_BLOCKING) + ['hooks.host-execution-plan': null] - private static final PrebidServerService ortbModulePbsService = pbsServiceFactory.getService(getOrtb2BlockingSettings()) - private static final PrebidServerService pbsServiceWithMultipleModules = pbsServiceFactory.getService(MULTI_MODULE_CONFIG) + private static final PrebidServerService ortbModulePbsService = pbsServiceFactory.getService(PB_ORTB2_CONFIG) def cleanupSpec() { - pbsServiceFactory.removeContainer(getOrtb2BlockingSettings()) - pbsServiceFactory.removeContainer(MULTI_MODULE_CONFIG) + pbsServiceFactory.removeContainer(PB_ORTB2_CONFIG) } def "PBS shouldn't apply a/b test config when config of ab test is disabled"() { @@ -58,7 +60,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { flushMetrics(ortbModulePbsService) and: "Save account with ab test config" - def abTest = AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + def abTest = AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { enabled = false } def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { @@ -83,18 +85,18 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be as default call" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] } def "PBS shouldn't apply valid a/b test config when module is disabled"() { given: "PBS service with disabled module config" - def pbsConfig = getOrtb2BlockingSettings(false) + def pbsConfig = getModuleBaseSettings(PB_ORTB2_BLOCKING, false) def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default bid request with verbose trace" @@ -105,7 +107,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code)] + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code)] } def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(executionPlan: executionPlan)) def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) @@ -125,18 +127,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be with error call" def metrics = prebidServerService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[EXECUTION_ERROR_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[EXECUTION_ERROR_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[EXECUTION_ERROR_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[EXECUTION_ERROR_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] } def "PBS shouldn't apply a/b test config when module name is not matched"() { @@ -169,16 +168,16 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be as default call" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] where: - moduleName << [ModuleName.PB_ORTB2_BLOCKING.code.toUpperCase(), PBSUtils.randomString] + moduleName << [PB_ORTB2_BLOCKING.code.toUpperCase(), PBSUtils.randomString] } def "PBS should apply a/b test config for each module when multiple config are presents and set to allow modules"() { @@ -189,7 +188,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { flushMetrics(pbsServiceWithMultipleModules) and: "Save account with ab test config" - def ortb2AbTestConfig = AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + def ortb2AbTestConfig = AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = MAX_PERCENT_AB } def richMediaAbTestConfig = AbTest.getDefault(PB_RESPONSE_CORRECTION.code).tap { @@ -207,14 +206,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for specified module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_ACTION, NO_ACTION] - it.analyticsTags.activities.name.flatten().sort() == [ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() - it.analyticsTags.activities.status.flatten().sort() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS, FetchStatus.SUCCESS].sort() - it.analyticsTags.activities.results.status.flatten().sort() == [FetchStatus.SUCCESS_ALLOW, FetchStatus.RUN, FetchStatus.RUN].sort() - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.name.flatten().sort() == [ModuleActivityName.PB_ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() + it.analyticsTags.activities.status.flatten().sort() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS].sort() + it.analyticsTags.activities.results.status.flatten().sort() == [AnalyticTagStatus.SUCCESS_ALLOW, AnalyticTagStatus.RUN, AnalyticTagStatus.RUN].sort() + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for other module" @@ -223,15 +222,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS] it.action == [NO_ACTION] it.analyticsTags.activities.name.flatten() == [AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.RUN] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.RUN] it.analyticsTags.activities.results.values.module.flatten() == [PB_RESPONSE_CORRECTION] } and: "Metric for allowed to run pb-ortb2blocking module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] @@ -250,7 +249,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { flushMetrics(pbsServiceWithMultipleModules) and: "Save account with ab test config" - def ortb2AbTestConfig = AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + def ortb2AbTestConfig = AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = MIN_PERCENT_AB } def richMediaAbTestConfig = AbTest.getDefault(PB_RESPONSE_CORRECTION.code).tap { @@ -268,14 +267,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for ortb2blocking module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should apply ab test config for pb-response-correction module" @@ -284,15 +283,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS] it.action == [NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED] it.analyticsTags.activities.results.values.module.flatten() == [PB_RESPONSE_CORRECTION] } and: "Metric for skipped pb-ortb2blocking module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert !metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -311,7 +310,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { flushMetrics(pbsServiceWithMultipleModules) and: "Save account with ab test config" - def ortb2AbTestConfig = AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + def ortb2AbTestConfig = AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = MIN_PERCENT_AB } def richMediaAbTestConfig = AbTest.getDefault(PB_RESPONSE_CORRECTION.code).tap { @@ -329,14 +328,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for ortb2blocking module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for pb-response-correction module" @@ -345,15 +344,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS] it.action == [NO_ACTION] it.analyticsTags.activities.name.flatten() == [AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.RUN] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.RUN] it.analyticsTags.activities.results.values.module.flatten() == [PB_RESPONSE_CORRECTION] } and: "Metric for skipped ortb2blocking module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 and: "Metric for allowed to run pb-response-correction module should be updated based on ab test config" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -371,7 +370,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber]).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber]).tap { percentActive = MIN_PERCENT_AB }] } @@ -388,15 +387,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be updated based on ab test config" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 } def "PBS should apply a/b test config and run module when config is on max percentage or default value"() { @@ -408,7 +407,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = percentActive it.percentActiveSnakeCase = percentActiveSnakeCase }] @@ -425,21 +424,21 @@ class AbTestingModuleSpec extends ModuleBaseSpec { verifyAll(invocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_ACTION, NO_ACTION] - it.analyticsTags.activities.name.flatten().sort() == [ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() - it.analyticsTags.activities.status.flatten().sort() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS, FetchStatus.SUCCESS].sort() - it.analyticsTags.activities.results.status.flatten().sort() == [FetchStatus.SUCCESS_ALLOW, FetchStatus.RUN, FetchStatus.RUN].sort() - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.name.flatten().sort() == [ModuleActivityName.PB_ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() + it.analyticsTags.activities.status.flatten().sort() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS].sort() + it.analyticsTags.activities.results.status.flatten().sort() == [AnalyticTagStatus.SUCCESS_ALLOW, AnalyticTagStatus.RUN, AnalyticTagStatus.RUN].sort() + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be as default call" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] where: percentActive | percentActiveSnakeCase @@ -457,7 +456,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = percentActive it.percentActiveSnakeCase = percentActiveSnakeCase }] @@ -475,15 +474,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be updated based on ab test config" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 where: percentActive | percentActiveSnakeCase @@ -500,7 +499,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = percentActive it.percentActiveSnakeCase = percentActiveSnakeCase }] @@ -522,15 +521,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be updated based on ab test config" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 where: percentActive | percentActiveSnakeCase @@ -547,7 +546,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { it.percentActive = percentActive it.percentActiveSnakeCase = percentActiveSnakeCase }] @@ -569,21 +568,21 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS, SUCCESS] it.action == [NO_ACTION, NO_ACTION] - it.analyticsTags.activities.name.flatten().sort() == [ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() - it.analyticsTags.activities.status.flatten().sort() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS, FetchStatus.SUCCESS].sort() - it.analyticsTags.activities.results.status.flatten().sort() == [FetchStatus.SUCCESS_ALLOW, FetchStatus.RUN, FetchStatus.RUN].sort() - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.name.flatten().sort() == [ModuleActivityName.PB_ORTB2_BLOCKING, AB_TESTING, AB_TESTING].value.sort() + it.analyticsTags.activities.status.flatten().sort() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS].sort() + it.analyticsTags.activities.results.status.flatten().sort() == [AnalyticTagStatus.SUCCESS_ALLOW, AnalyticTagStatus.RUN, AnalyticTagStatus.RUN].sort() + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be as default call" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] where: percentActive | percentActiveSnakeCase @@ -600,7 +599,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = MIN_PERCENT_AB it.logAnalyticsTag = logAnalyticsTag it.logAnalyticsTagSnakeCase = logAnalyticsTagSnakeCase @@ -619,15 +618,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "Metric for specified module should be updated based on ab test config" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 where: logAnalyticsTag | logAnalyticsTagSnakeCase @@ -645,7 +644,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = MIN_PERCENT_AB it.logAnalyticsTag = logAnalyticsTag it.logAnalyticsTagSnakeCase = logAnalyticsTagSnakeCase @@ -670,8 +669,8 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be updated based on ab test config" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 where: logAnalyticsTag | logAnalyticsTagSnakeCase @@ -688,7 +687,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = MAX_PERCENT_AB it.logAnalyticsTag = logAnalyticsTag it.logAnalyticsTagSnakeCase = logAnalyticsTagSnakeCase @@ -713,13 +712,13 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be as default call" def metrics = ortbModulePbsService.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] where: logAnalyticsTag | logAnalyticsTagSnakeCase @@ -736,7 +735,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, ORTB_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = PBSUtils.getRandomNumber(MIN_PERCENT_AB, MAX_PERCENT_AB) }] } @@ -766,7 +765,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { def "PBS should apply a/b test config from host config when accounts is not specified when account config and default account doesn't include a/b test config"() { given: "PBS service with specific ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code, accouns).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code, accouns).tap { percentActive = MIN_PERCENT_AB }] } @@ -784,14 +783,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for specified module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for other module" @@ -805,8 +804,8 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 and: "Metric for non specified module should be as default call" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -815,9 +814,6 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - where: accouns << [null, []] } @@ -826,7 +822,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { given: "PBS service with specific ab test config" def accountId = PBSUtils.randomNumber def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber, accountId]).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber, accountId]).tap { percentActive = MIN_PERCENT_AB }] } @@ -847,14 +843,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for specified module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for other module" @@ -868,8 +864,8 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 and: "Metric for non specified module should be as default call" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -877,15 +873,12 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should apply a/b test config from host config for specific account and general config when account config and default account doesn't include a/b test config"() { given: "PBS service with specific ab test config" def accountId = PBSUtils.randomNumber - def ortb2AbTestConfig = AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code, []).tap { + def ortb2AbTestConfig = AbTest.getDefault(PB_ORTB2_BLOCKING.code, []).tap { it.percentActive = MIN_PERCENT_AB } def richMediaAbTestConfig = AbTest.getDefault(PB_RESPONSE_CORRECTION.code, [accountId]).tap { @@ -911,14 +904,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for ortb2blocking module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should apply ab test config for pb-response-correction module" @@ -927,15 +920,15 @@ class AbTestingModuleSpec extends ModuleBaseSpec { it.status == [SUCCESS] it.action == [NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED] it.analyticsTags.activities.results.values.module.flatten() == [PB_RESPONSE_CORRECTION] } and: "Metric for skipped pb-ortb2blocking module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert !metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -944,15 +937,12 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 assert metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't apply a/b test config from host config for non specified accounts when account config and default account doesn't include a/b test config"() { given: "PBS service with specific ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber]).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code, [PBSUtils.randomNumber]).tap { percentActive = MIN_PERCENT_AB }] } @@ -970,14 +960,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for specified module" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_ACTION, NO_ACTION] - it.analyticsTags.activities.name.flatten() == [ORTB2_BLOCKING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SUCCESS_ALLOW] + it.analyticsTags.activities.name.flatten() == [ModuleActivityName.PB_ORTB2_BLOCKING].value + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SUCCESS_ALLOW] it.analyticsTags.activities.results.values.module.flatten().every { it == null } } @@ -992,13 +982,13 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be as default call" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[CALL_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] - assert !metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] + assert !metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] and: "Metric for non specified module should be as default call" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -1006,15 +996,12 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should prioritise a/b test config from default account and only specified module when host and default account contains a/b test configs"() { given: "PBS service with specific ab test config" def accountExecutionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = MIN_PERCENT_AB }] } @@ -1023,7 +1010,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { } def hostExecutionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code)] + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code)] } def pbsConfig = MULTI_MODULE_CONFIG + ['hooks.host-execution-plan': encode(hostExecutionPlan)] + ["settings.default-account-config": encode(defaultAccountConfigSettings)] @@ -1040,14 +1027,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { then: "PBS should apply ab test config for specified module and call it based on all execution plans" def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS, SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION, NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING, AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS, FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED, FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for other modules and call them based on all execution plans" @@ -1061,8 +1048,8 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 2 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 2 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 2 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 2 and: "Metric for non specified module should be as default call" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 2 @@ -1070,15 +1057,12 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should prioritise a/b test config from account over default account and only specified module when specific account and default account contains a/b test configs"() { given: "PBS service with specific ab test config" def accountExecutionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code)] + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code)] } def defaultAccountConfigSettings = AccountConfig.defaultAccountConfig.tap { hooks = new AccountHooksConfiguration(executionPlan: accountExecutionPlan) @@ -1096,7 +1080,7 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Save account with ab test config" def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES).tap { - abTests = [AbTest.getDefault(ModuleName.PB_ORTB2_BLOCKING.code).tap { + abTests = [AbTest.getDefault(PB_ORTB2_BLOCKING.code).tap { percentActive = MIN_PERCENT_AB }] } @@ -1111,14 +1095,14 @@ class AbTestingModuleSpec extends ModuleBaseSpec { def invocationResults = response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List and: "PBS should apply ab test config for specified module" - def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, ModuleName.PB_ORTB2_BLOCKING) + def ortbBlockingInvocationResults = filterInvocationResultsByModule(invocationResults, PB_ORTB2_BLOCKING) verifyAll(ortbBlockingInvocationResults) { it.status == [SUCCESS, SUCCESS] it.action == [NO_INVOCATION, NO_INVOCATION] it.analyticsTags.activities.name.flatten() == [AB_TESTING, AB_TESTING].value - it.analyticsTags.activities.status.flatten() == [FetchStatus.SUCCESS, FetchStatus.SUCCESS] - it.analyticsTags.activities.results.status.flatten() == [FetchStatus.SKIPPED, FetchStatus.SKIPPED] - it.analyticsTags.activities.results.values.module.flatten() == [ModuleName.PB_ORTB2_BLOCKING, ModuleName.PB_ORTB2_BLOCKING] + it.analyticsTags.activities.status.flatten() == [AnalyticTagStatus.SUCCESS, AnalyticTagStatus.SUCCESS] + it.analyticsTags.activities.results.status.flatten() == [AnalyticTagStatus.SKIPPED, AnalyticTagStatus.SKIPPED] + it.analyticsTags.activities.results.values.module.flatten() == [PB_ORTB2_BLOCKING, PB_ORTB2_BLOCKING] } and: "PBS should not apply ab test config for other module" @@ -1132,8 +1116,8 @@ class AbTestingModuleSpec extends ModuleBaseSpec { and: "Metric for specified module should be updated based on ab test config" def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 - assert metrics[NO_INVOCATION_METRIC(ModuleName.PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 + assert metrics[NO_INVOCATION_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 and: "Metric for non specified module should be as default call" assert metrics[CALL_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] == 1 @@ -1141,9 +1125,6 @@ class AbTestingModuleSpec extends ModuleBaseSpec { assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NO_INVOCATION_METRIC(PB_RESPONSE_CORRECTION, ALL_PROCESSED_BID_RESPONSES)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } private static List filterInvocationResultsByModule(List invocationResults, ModuleName moduleName) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/GeneralModuleSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/GeneralModuleSpec.groovy index d883da8f219..a1740858251 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/GeneralModuleSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/GeneralModuleSpec.groovy @@ -15,7 +15,7 @@ import org.prebid.server.functional.model.request.auction.TraceLevel import org.prebid.server.functional.model.response.auction.InvocationResult import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.util.PBSUtils +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import java.time.Instant @@ -32,6 +32,7 @@ import static org.prebid.server.functional.model.config.Stage.RAW_BIDDER_RESPONS import static org.prebid.server.functional.model.request.auction.BidRequest.getDefaultBidRequest import static org.prebid.server.functional.model.response.auction.InvocationStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.ResponseAction.NO_ACTION +import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.PERSISTENT class GeneralModuleSpec extends ModuleBaseSpec { @@ -43,13 +44,12 @@ class GeneralModuleSpec extends ModuleBaseSpec { private final static Map> RESPONSE_STAGES = [(ALL_PROCESSED_BID_RESPONSES): [PB_RICHMEDIA_FILTER]] private final static Map> MODULES_STAGES = ORTB_STAGES + RESPONSE_STAGES private final static ExecutionPlan GLOBAL_EXECUTION_PLAN = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, MODULES_STAGES) - private final static Map MULTI_MODULE_CONFIG = getRichMediaFilterSettings(PBSUtils.randomString) + - getOrtb2BlockingSettings() + - ['settings.enforce-valid-account': 'true', - 'hooks.host-execution-plan' : encode(GLOBAL_EXECUTION_PLAN)] + private final static PbsContainerConfig MULTI_MODULE_CONFIG = getModuleBaseSettings(PB_RICHMEDIA_FILTER) + + getModuleBaseSettings(PB_ORTB2_BLOCKING) + + ['settings.enforce-valid-account': 'true', 'hooks.host-execution-plan': encode(GLOBAL_EXECUTION_PLAN)] - private static final PrebidServerService pbsServiceWithMultipleModule = pbsServiceFactory.getService(MULTI_MODULE_CONFIG + DISABLED_INVOKE_CONFIG) - private static final PrebidServerService pbsServiceWithMultipleModuleWithRequireInvoke = pbsServiceFactory.getService(MULTI_MODULE_CONFIG + ENABLED_INVOKE_CONFIG) + private static final PrebidServerService pbsServiceWithMultipleModule = pbsServiceFactory.getService(MULTI_MODULE_CONFIG + DISABLED_INVOKE_CONFIG, PERSISTENT) + private static final PrebidServerService pbsServiceWithMultipleModuleWithRequireInvoke = pbsServiceFactory.getService(MULTI_MODULE_CONFIG + ENABLED_INVOKE_CONFIG, PERSISTENT) def cleanupSpec() { pbsServiceFactory.removeContainer(MULTI_MODULE_CONFIG + DISABLED_INVOKE_CONFIG) @@ -182,9 +182,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { and: "RB-Richmedia-Filter module call metrics should be updated" assert metrics[CALL_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] == 1 assert metrics[NOOP_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should call all modules and traces response when account includes modules config and require-config-to-invoke is enabled"() { @@ -338,9 +335,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 assert metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 assert metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't call module when disabled in host config and no account config provided"() { @@ -373,9 +367,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] assert !metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] assert !metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't call module and not override host config when default-account module-execution config enabled module"() { @@ -412,9 +403,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { assert !metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] assert !metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] assert !metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should call module without account module config when default-account module-execution config enabling module"() { @@ -454,9 +442,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { assert metrics[CALL_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 assert metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, BIDDER_REQUEST)] == 1 assert metrics[NOOP_METRIC(PB_ORTB2_BLOCKING, RAW_BIDDER_RESPONSE)] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS shouldn't call any modules without account config when default-account module-execution config not enabling module"() { @@ -497,9 +482,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { assert !metrics[CALL_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NOOP_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - where: moduleExecutionStatus << [false, null] } @@ -545,9 +527,6 @@ class GeneralModuleSpec extends ModuleBaseSpec { and: "RB-Richmedia-Filter module call metrics shouldn't be updated" assert !metrics[CALL_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] assert !metrics[NOOP_METRIC(PB_RICHMEDIA_FILTER, ALL_PROCESSED_BID_RESPONSES)] - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should merge account level config without any errors when config contains proper request methods"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/ModuleBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/ModuleBaseSpec.groovy index da5057d472b..9607dcd9247 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/ModuleBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/ModuleBaseSpec.groovy @@ -1,31 +1,80 @@ package org.prebid.server.functional.tests.module -import org.prebid.server.functional.model.config.ModuleName -import org.prebid.server.functional.model.config.Endpoint +import org.prebid.server.functional.model.bidder.BidderName +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.config.AccountHooksConfiguration import org.prebid.server.functional.model.config.ExecutionPlan import org.prebid.server.functional.model.config.HookHttpEndpoint +import org.prebid.server.functional.model.config.ModuleName +import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.config.Stage +import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.response.auction.AnalyticResult import org.prebid.server.functional.model.response.auction.BidResponse +import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils +import static org.prebid.server.functional.model.bidder.BidderName.AMX +import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.bidder.BidderName.IX +import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.bidder.BidderName.OPENX_ALIAS +import static org.prebid.server.functional.model.config.HookHttpEndpoint.AUCTION import static org.prebid.server.functional.model.config.ModuleName.OPTABLE_TARGETING import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING import static org.prebid.server.functional.model.config.ModuleName.PB_REQUEST_CORRECTION import static org.prebid.server.functional.model.config.ModuleName.PB_RESPONSE_CORRECTION import static org.prebid.server.functional.model.config.ModuleName.PB_RICHMEDIA_FILTER import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE -import static org.prebid.server.functional.model.config.HookHttpEndpoint.AUCTION -import static org.prebid.server.functional.model.config.Stage.ALL_PROCESSED_BID_RESPONSES -import static org.prebid.server.functional.model.config.Stage.PROCESSED_AUCTION_REQUEST import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer +import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID class ModuleBaseSpec extends BaseSpec { + protected static final String WILDCARD = '*' + protected static final String RANDOM_DATACENTER_REGION = PBSUtils.randomString + protected static final Integer OPENX_VENDOR_ID = PBSUtils.getRandomNumber(0, 65534) + protected static final Integer AMX_VENDOR_ID = PBSUtils.getRandomNumber(0, 65534) + + protected static final Map GENERIC_CONFIG = [ + ("adapters.${GENERIC.value}.usersync.redirect.url".toString()) : "$networkServiceContainer.rootUri/generic-usersync".toString(), + ("adapters.${GENERIC.value}.usersync.redirect.support-cors".toString()): 'false', + ("adapters.${GENERIC.value}.meta-info.vendor-id".toString()) : GENERIC_VENDOR_ID.toString()] + + protected static final Map IX_CONFIG = getAdapterConfig(IX) + protected static final Map OPENX_CONFIG = getAdapterConfig(OPENX, OPENX_VENDOR_ID) + protected static final Map OPENX_ALIAS_CONFIG = getAdapterConfig(OPENX, OPENX_ALIAS, OPENX_VENDOR_ID) + protected static final Map AMX_CONFIG = getAdapterConfig(AMX, AMX_VENDOR_ID) + + private static final Map ENABLED_DEBUG_LOG_MODE = ["logging.level.root": "debug"] + + private static final Map ORTB_ADAPTER_CONFIG = ['adapter-defaults.ortb.multiformat-supported': 'false'] + + private static final Map MODIFYING_VAST_CONFIG = ["adapter-defaults.modifying-vast-xml-allowed": "false", + "adapters.generic.modifying-vast-xml-allowed": "false"] + + private static final Map CACHE_STORAGE_CONFIG = ['storage.pbc.path' : 'stored-cache', + 'storage.pbc.call-timeout-ms': '1000', + 'storage.pbc.enabled' : 'true', + 'cache.module.enabled' : 'true', + 'pbc.api.key' : PBSUtils.randomString, + 'cache.api-key-secured' : 'false'] + + protected final static PbsContainerConfig EXTERNAL_MODULES_CONFIG = getModuleBaseSettings(PB_RICHMEDIA_FILTER) + + getModuleBaseSettings(PB_RESPONSE_CORRECTION) + + getModuleBaseSettings(PB_ORTB2_BLOCKING) + + getModuleBaseSettings(PB_REQUEST_CORRECTION) + + getOptableTargetingSettings() + + getRulesEngineSettings() + + protected static PrebidServerService pbsServiceWithMultipleModules + def setupSpec() { prebidCache.setResponse() bidder.setResponse() + pbsServiceWithMultipleModules = pbsServiceFactory.getService(getDefaultMultipleModulesConfig()) } def cleanupSpec() { @@ -50,59 +99,77 @@ class ModuleBaseSpec extends BaseSpec { "modules.module.${module.code}.stage.${stage.metricValue}.hook.${module.code}-${stage.value}-hook.execution-error" } - protected static Map getResponseCorrectionConfig(HookHttpEndpoint endpoint = AUCTION) { - ["hooks.${PB_RESPONSE_CORRECTION.code}.enabled": true, - "hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, [(ALL_PROCESSED_BID_RESPONSES): [PB_RESPONSE_CORRECTION]]))] - .collectEntries { key, value -> [(key.toString()): value.toString()] } + protected PbsContainerConfig getDefaultMultipleModulesConfig() { + EXTERNAL_MODULES_CONFIG + + EMPTY_CACHE_TTL_CONFIG + + ENABLED_DEBUG_LOG_MODE + + ORTB_ADAPTER_CONFIG + + MODIFYING_VAST_CONFIG + + CACHE_STORAGE_CONFIG + + GENERIC_CONFIG + + IX_CONFIG + + AMX_CONFIG + + OPENX_CONFIG + + OPENX_ALIAS_CONFIG + + ['datacenter-region': RANDOM_DATACENTER_REGION] } - protected static Map getRichMediaFilterSettings(String scriptPattern, - Boolean filterMraidEnabled = true, - HookHttpEndpoint endpoint = AUCTION) { + protected static PbsContainerConfig getModuleBaseSettings(ModuleName name, boolean enabled = true) { + new PbsContainerConfig([("hooks.${name.code}.enabled".toString()): enabled.toString()]) + } - ["hooks.${PB_RICHMEDIA_FILTER.code}.enabled" : true, - "hooks.modules.${PB_RICHMEDIA_FILTER.code}.mraid-script-pattern": scriptPattern, - "hooks.modules.${PB_RICHMEDIA_FILTER.code}.filter-mraid" : filterMraidEnabled, - "hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, [(ALL_PROCESSED_BID_RESPONSES): [PB_RICHMEDIA_FILTER]]))] - .findAll { it.value != null } - .collectEntries { key, value -> [(key.toString()): value.toString()] } + protected static PbsContainerConfig getRichMediaFilterSettings(String scriptPattern, + boolean filterMraidEnabled = true) { + new PbsContainerConfig([ + "hooks.${PB_RICHMEDIA_FILTER.code}.enabled" : true, + "hooks.modules.${PB_RICHMEDIA_FILTER.code}.mraid-script-pattern": scriptPattern, + "hooks.modules.${PB_RICHMEDIA_FILTER.code}.filter-mraid" : filterMraidEnabled, + ]) } - protected static Map getDisabledRichMediaFilterSettings(String scriptPattern, - boolean filterMraidEnabled = true) { - ["hooks.${PB_RICHMEDIA_FILTER.code}.enabled" : false, - "hooks.modules.${PB_RICHMEDIA_FILTER.code}.mraid-script-pattern": scriptPattern, - "hooks.modules.${PB_RICHMEDIA_FILTER.code}.filter-mraid" : filterMraidEnabled] - .collectEntries { key, value -> [(key.toString()): value.toString()] } + protected static PbsContainerConfig getOptableTargetingSettings(boolean isEnabled = true) { + new PbsContainerConfig([ + "hooks.${OPTABLE_TARGETING.code}.enabled" : isEnabled.toString(), + "hooks.modules.${OPTABLE_TARGETING.code}.api-endpoint": "${networkServiceContainer.rootUri}/stored-cache", + "hooks.modules.${OPTABLE_TARGETING.code}.tenant" : PBSUtils.randomString, + "hooks.modules.${OPTABLE_TARGETING.code}.origin" : PBSUtils.randomString + ]) } - protected static Map getOptableTargetingSettings(boolean isEnabled = true, HookHttpEndpoint endpoint = AUCTION) { - ["hooks.${OPTABLE_TARGETING.code}.enabled" : isEnabled as String, - "hooks.modules.${OPTABLE_TARGETING.code}.api-endpoint": "$networkServiceContainer.rootUri/stored-cache".toString(), - "hooks.modules.${OPTABLE_TARGETING.code}.tenant" : PBSUtils.randomString, - "hooks.modules.${OPTABLE_TARGETING.code}.origin" : PBSUtils.randomString, - "hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, [(PROCESSED_AUCTION_REQUEST): [OPTABLE_TARGETING]]))] - .collectEntries { key, value -> [(key.toString()): value.toString()] } + protected static PbsContainerConfig getRulesEngineSettings() { + new PbsContainerConfig([ + "hooks.${PB_RULE_ENGINE.code}.enabled" : "true", + "hooks.${PB_RULE_ENGINE.code}.rule-cache.expire-after-minutes" : "10000", + "hooks.${PB_RULE_ENGINE.code}.rule-cache.max-size" : "20000", + "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-initial-delay-millis": "10000", + "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-max-delay-millis" : "10000", + "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-exponential-factor" : "1.2", + "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-exponential-jitter" : "1.2" + ]) } - protected static Map getOrtb2BlockingSettings(boolean isEnabled = true) { - ["hooks.${PB_ORTB2_BLOCKING.code}.enabled": isEnabled as String] + private static Map getAdapterConfig(BidderName bidder, Integer vendorId = null) { + [ + "adapters.${bidder.value}.enabled" : 'true', + "adapters.${bidder.value}.endpoint": "${networkServiceContainer.rootUri}/auction" + ] + (vendorId != null ? ["adapters.${bidder.value}.meta-info.vendor-id": vendorId] : [:]) } - protected static Map getRequestCorrectionSettings(HookHttpEndpoint endpoint = AUCTION, Stage stage = PROCESSED_AUCTION_REQUEST) { - ["hooks.${PB_REQUEST_CORRECTION.code}.enabled": "true", - "hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, PB_REQUEST_CORRECTION, [stage]))] + private static Map getAdapterConfig(BidderName bidder, BidderName alias, Integer vendorId = null) { + [ + "adapters.${bidder.value}.aliases.${alias.value}.enabled" : 'true', + "adapters.${bidder.value}.aliases.${alias.value}.endpoint": "${networkServiceContainer.rootUri}/auction" + ] + (vendorId != null ? ["adapters.${bidder.value}.aliases.${alias.value}.meta-info.vendor-id": vendorId] : [:]) } - protected static Map getRulesEngineSettings(HookHttpEndpoint endpoint = AUCTION, Stage stage = PROCESSED_AUCTION_REQUEST) { - ["hooks.${PB_RULE_ENGINE.code}.enabled" : "true", - "hooks.${PB_RULE_ENGINE.code}.rule-cache.expire-after-minutes" : "10000", - "hooks.${PB_RULE_ENGINE.code}.rule-cache.max-size" : "20000", - "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-initial-delay-millis": "10000", - "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-max-delay-millis" : "10000", - "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-exponential-factor" : "1.2", - "hooks.${PB_RULE_ENGINE.code}.rule-parsing.retry-exponential-jitter" : "1.2", - "hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, PB_RULE_ENGINE, [stage]))] + protected static Account getAccountWithModuleConfig(String accountId, + Map> modulesStages, + HookHttpEndpoint endpoint = AUCTION) { + + def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, modulesStages) + def accountHooksConfig = new AccountHooksConfiguration(executionPlan: executionPlan, modules: new PbsModulesConfig()) + def accountConfig = new AccountConfig(hooks: accountHooksConfig) + new Account(uuid: accountId, config: accountConfig) } protected static List getAnalyticResults(BidResponse response) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/analyticstag/AnalyticsTagsModuleSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/analyticstag/AnalyticsTagsModuleSpec.groovy index dfd34bccb86..b53f6110910 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/analyticstag/AnalyticsTagsModuleSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/analyticstag/AnalyticsTagsModuleSpec.groovy @@ -4,25 +4,23 @@ import org.prebid.server.functional.model.config.AccountAnalyticsConfig import org.prebid.server.functional.model.config.AccountConfig import org.prebid.server.functional.model.config.AccountHooksConfiguration import org.prebid.server.functional.model.config.ExecutionPlan -import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.db.StoredResponse +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus import org.prebid.server.functional.model.request.auction.AnalyticsOptions import org.prebid.server.functional.model.request.auction.BidRequest -import org.prebid.server.functional.model.request.auction.FetchStatus import org.prebid.server.functional.model.request.auction.PrebidAnalytics import org.prebid.server.functional.model.request.auction.RichmediaFilter import org.prebid.server.functional.model.request.auction.StoredBidResponse import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ModuleActivityName -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils -import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING -import static org.prebid.server.functional.model.config.ModuleName.PB_RICHMEDIA_FILTER import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.config.HookHttpEndpoint.AUCTION +import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING +import static org.prebid.server.functional.model.config.ModuleName.PB_RICHMEDIA_FILTER import static org.prebid.server.functional.model.config.Stage.ALL_PROCESSED_BID_RESPONSES import static org.prebid.server.functional.model.config.Stage.RAW_BIDDER_RESPONSE import static org.prebid.server.functional.model.request.auction.TraceLevel.VERBOSE @@ -30,13 +28,7 @@ import static org.prebid.server.functional.model.response.auction.ErrorType.PREB class AnalyticsTagsModuleSpec extends ModuleBaseSpec { - private static final PrebidServerService pbsServiceWithEnabledOrtb2Blocking = pbsServiceFactory.getService(getOrtb2BlockingSettings()) - - def cleanupSpec() { - pbsServiceFactory.removeContainer(getOrtb2BlockingSettings()) - } - - def "PBS should include analytics tag for pb-ortb2-blocking module in response when request and account allow client details"() { + def "PBS should include analytics tag for ortb2-blocking module in response when request and account allow client details"() { given: "Default account with module config" def bidRequest = BidRequest.defaultBidRequest.tap { it.ext.prebid.analytics = new PrebidAnalytics(options: new AnalyticsOptions(enableClientDetails: true)) @@ -50,7 +42,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - def bidResponse = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain ext.prebid.analyticsTags with module record" def analyticsTagPrebid = bidResponse.ext.prebid.analytics.tags.first @@ -59,12 +51,12 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { and: "Analytics tag should contain results with name and success status" def analyticResult = analyticsTagPrebid.analyticsTags.activities.first - assert analyticResult.status == FetchStatus.SUCCESS - assert analyticResult.name == ModuleActivityName.ORTB2_BLOCKING + assert analyticResult.status == AnalyticTagStatus.SUCCESS + assert analyticResult.name == ModuleActivityName.PB_ORTB2_BLOCKING and: "Should include appliedTo information in analytics tags results" verifyAll(analyticResult.results.first) { - it.status == FetchStatus.SUCCESS_ALLOW + it.status == AnalyticTagStatus.SUCCESS_ALLOW it.appliedTo.bidders == [GENERIC.value] it.appliedTo.impIds == bidRequest.imp.id } @@ -91,12 +83,10 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { storedResponseDao.save(storedResponse) and: "Account in the DB with cofig" - def richmediaFilter = new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME) - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: richmediaFilter) - def accountHooksConfig = new AccountHooksConfiguration(modules: richMediaFilterConfig) - def accountAnalyticsConfig = new AccountAnalyticsConfig(allowClientDetails: true) - def accountConfig = new AccountConfig(hooks: accountHooksConfig, analytics: accountAnalyticsConfig) - def account = new Account(uuid: bidRequest.accountId, config: accountConfig) + def account = (getAccountWithModuleConfig(bidRequest.accountId, [(ALL_PROCESSED_BID_RESPONSES): [PB_RICHMEDIA_FILTER]])).tap { + it.config.hooks.modules.pbRichmediaFilter = new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME) + it.config.analytics = new AccountAnalyticsConfig(allowClientDetails: true) + } accountDao.save(account) when: "PBS processes auction request" @@ -109,15 +99,18 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { and: "Analytics tag should contain results with name and success status" def analyticResult = analyticsTagPrebid.analyticsTags.activities.first - assert analyticResult.status == FetchStatus.SUCCESS + assert analyticResult.status == AnalyticTagStatus.SUCCESS assert analyticResult.name == ModuleActivityName.REJECT_RICHMEDIA and: "Should include appliedTo information in analytics tags results" verifyAll(analyticResult.results.first) { - it.status == FetchStatus.SUCCESS_BLOCK + it.status == AnalyticTagStatus.SUCCESS_BLOCK it.appliedTo.bidders == [GENERIC.value] it.appliedTo.impIds == bidRequest.imp.id } + + cleanup: "Stop and remove pbs container" + pbsServiceFactory.removeContainer(getRichMediaFilterSettings(PATTERN_NAME)) } def "PBS should include analytics tag in response when request and default account allow client details"() { @@ -127,7 +120,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { def accountConfig = new AccountConfig(hooks: hooksConfiguration, analytics: new AccountAnalyticsConfig(allowClientDetails: true)) and: "Prebid server with proper default account" - def pbsConfig = ['settings.default-account-config': encode(accountConfig)] + ortb2BlockingSettings + def pbsConfig = getModuleBaseSettings(PB_ORTB2_BLOCKING) + ['settings.default-account-config': encode(accountConfig)] def pbsServiceWithDefaultAccount = pbsServiceFactory.getService(pbsConfig) and: "Bid request with enabled client details" @@ -145,18 +138,15 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { and: "Analytics tag should contain results with name and success status" def analyticResult = analyticsTagPrebid.analyticsTags.activities.first - assert analyticResult.status == FetchStatus.SUCCESS - assert analyticResult.name == ModuleActivityName.ORTB2_BLOCKING + assert analyticResult.status == AnalyticTagStatus.SUCCESS + assert analyticResult.name == ModuleActivityName.PB_ORTB2_BLOCKING and: "Should include appliedTo information in analytics tags results" verifyAll(analyticResult.results.first) { - it.status == FetchStatus.SUCCESS_ALLOW + it.status == AnalyticTagStatus.SUCCESS_ALLOW it.appliedTo.bidders == [GENERIC.value] it.appliedTo.impIds == bidRequest.imp.id } - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should include analytics tag in response when request and account allow client details but default doesn't"() { @@ -166,7 +156,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { def defaultAccountConfig = new AccountConfig(hooks: defaultHooksConfiguration, analytics: new AccountAnalyticsConfig(allowClientDetails: false)) and: "Prebid server with proper default account" - def pbsConfig = ['settings.default-account-config': encode(defaultAccountConfig)] + ortb2BlockingSettings + def pbsConfig = getModuleBaseSettings(PB_ORTB2_BLOCKING) + ['settings.default-account-config': encode(defaultAccountConfig)] def pbsServiceWithDefaultAccount = pbsServiceFactory.getService(pbsConfig) and: "Bid request with enabled client details" @@ -191,18 +181,15 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { and: "Analytics tag should contain results with name and success status" def analyticResult = analyticsTagPrebid.analyticsTags.activities.first - assert analyticResult.status == FetchStatus.SUCCESS - assert analyticResult.name == ModuleActivityName.ORTB2_BLOCKING + assert analyticResult.status == AnalyticTagStatus.SUCCESS + assert analyticResult.name == ModuleActivityName.PB_ORTB2_BLOCKING and: "Should include appliedTo information in analytics tags results" verifyAll(analyticResult.results.first) { - it.status == FetchStatus.SUCCESS_ALLOW + it.status == AnalyticTagStatus.SUCCESS_ALLOW it.appliedTo.bidders == [GENERIC.value] it.appliedTo.impIds == bidRequest.imp.id } - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) } def "PBS should not include analytics tag in response without any warnings when timeout module disabled"() { @@ -242,7 +229,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - def bidResponse = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should not contain any analytics tag" assert !bidResponse?.ext?.prebid?.analytics?.tags @@ -265,7 +252,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - def bidResponse = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should not contain any analytics tag" assert !bidResponse?.ext?.prebid?.analytics?.tags @@ -289,7 +276,7 @@ class AnalyticsTagsModuleSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - def bidResponse = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should not contain any analytics tag" assert !bidResponse?.ext?.prebid?.analytics?.tags diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/optabletargeting/CacheStorageSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/optabletargeting/CacheStorageSpec.groovy index f3452ddd92d..e5a28c22083 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/optabletargeting/CacheStorageSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/optabletargeting/CacheStorageSpec.groovy @@ -1,11 +1,8 @@ package org.prebid.server.functional.tests.module.optabletargeting -import org.prebid.server.functional.model.config.AccountConfig -import org.prebid.server.functional.model.config.AccountHooksConfiguration import org.prebid.server.functional.model.config.IdentifierType import org.prebid.server.functional.model.config.OperatingSystem import org.prebid.server.functional.model.config.OptableTargetingConfig -import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Data @@ -14,14 +11,13 @@ import org.prebid.server.functional.model.request.auction.Eid import org.prebid.server.functional.model.request.auction.Geo import org.prebid.server.functional.model.request.auction.PublicCountryIp import org.prebid.server.functional.model.request.auction.User -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.scaffolding.StoredCache import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils -import static org.apache.commons.codec.binary.Base64.encodeBase64 import static org.apache.http.HttpStatus.SC_NOT_FOUND import static org.prebid.server.functional.model.config.ModuleName.OPTABLE_TARGETING +import static org.prebid.server.functional.model.config.Stage.PROCESSED_AUCTION_REQUEST import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer class CacheStorageSpec extends ModuleBaseSpec { @@ -36,23 +32,6 @@ class CacheStorageSpec extends ModuleBaseSpec { private static final StoredCache storedCache = new StoredCache(networkServiceContainer) - private static final Map CACHE_STORAGE_CONFIG = ['storage.pbc.path' : 'stored-cache', - 'storage.pbc.call-timeout-ms': '1000', - 'storage.pbc.enabled' : 'true', - 'cache.module.enabled' : 'true', - 'pbc.api.key' : PBSUtils.randomString, - 'cache.api-key-secured' : 'false'] - private static final Map MODULE_STORAGE_CACHE_CONFIG = getOptableTargetingSettings() + CACHE_STORAGE_CONFIG - private static final PrebidServerService prebidServerStoredCacheService = pbsServiceFactory.getService(MODULE_STORAGE_CACHE_CONFIG) - - def setup() { - storedCache.reset() - } - - def cleanupSpec() { - pbsServiceFactory.removeContainer(MODULE_STORAGE_CACHE_CONFIG) - } - def "PBS should update error metrics when no cached requests present"() { given: "Default BidRequest with cache and device info" def randomIfa = PBSUtils.randomString @@ -65,13 +44,13 @@ class CacheStorageSpec extends ModuleBaseSpec { accountDao.save(account) and: "Flash metrics" - flushMetrics(prebidServerStoredCacheService) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - prebidServerStoredCacheService.sendAuctionRequest(bidRequest) + def s = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should update metrics for new saved text storage cache" - def metrics = prebidServerStoredCacheService.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[METRIC_CREATIVE_READ_ERR] == 1 and: "No updates for success metrics" @@ -96,13 +75,13 @@ class CacheStorageSpec extends ModuleBaseSpec { storedCache.setCachingResponse(SC_NOT_FOUND) and: "Flash metrics" - flushMetrics(prebidServerStoredCacheService) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - prebidServerStoredCacheService.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should update error metrics" - def metrics = prebidServerStoredCacheService.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[METRIC_CREATIVE_WRITE_ERR] == 1 and: "No updates for success metrics" @@ -111,7 +90,7 @@ class CacheStorageSpec extends ModuleBaseSpec { def "PBS should update metrics for new saved text storage cache when no cached requests"() { given: "Current value of metric prebid cache" - def okInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_WRITE_OK) + def okInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_WRITE_OK) and: "Default BidRequest with cache and device info" def randomIfa = PBSUtils.randomString @@ -124,17 +103,17 @@ class CacheStorageSpec extends ModuleBaseSpec { accountDao.save(account) and: "Mocked external request" - def targetingResult = storedCache.setTargetingResponse(bidRequest, targetingConfig) + storedCache.setTargetingResponse(bidRequest, targetingConfig) storedCache.setCachingResponse() and: "Flash metrics" - flushMetrics(prebidServerStoredCacheService) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - prebidServerStoredCacheService.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should update metrics for new saved text storage cache" - def metrics = prebidServerStoredCacheService.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[METRIC_CREATIVE_SIZE_TEXT] != 0 assert metrics[METRIC_CREATIVE_WRITE_OK] == okInitialValue + 1 @@ -144,11 +123,11 @@ class CacheStorageSpec extends ModuleBaseSpec { def "PBS should update metrics for stored cached requests cache when proper record present"() { given: "Current value of metric prebid cache" - def textInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_SIZE_TEXT) - def ttlInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_TTL_TEXT) - def writeInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_WRITE_OK) - def readErrorInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_READ_ERR) - def writeErrorInitialValue = getCurrentMetricValue(prebidServerStoredCacheService, METRIC_CREATIVE_WRITE_ERR) + def textInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_SIZE_TEXT) + def ttlInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_TTL_TEXT) + def writeInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_WRITE_OK) + def readErrorInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_READ_ERR) + def writeErrorInitialValue = getCurrentMetricValue(pbsServiceWithMultipleModules, METRIC_CREATIVE_WRITE_ERR) and: "Default BidRequest with cache and device info" def randomIfa = PBSUtils.randomString @@ -165,13 +144,13 @@ class CacheStorageSpec extends ModuleBaseSpec { storedCache.setCachingResponse() and: "Flash metrics" - flushMetrics(prebidServerStoredCacheService) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - prebidServerStoredCacheService.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should update metrics for stored cached requests" - def metrics = prebidServerStoredCacheService.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[METRIC_CREATIVE_READ_OK] == 1 and: "No updates for new saved text storage metrics" @@ -199,9 +178,8 @@ class CacheStorageSpec extends ModuleBaseSpec { private static Account createAccountWithRequestCorrectionConfig(BidRequest bidRequest, OptableTargetingConfig optableTargetingConfig) { - def pbsModulesConfig = new PbsModulesConfig(optableTargeting: optableTargetingConfig) - def accountHooksConfig = new AccountHooksConfiguration(modules: pbsModulesConfig) - def accountConfig = new AccountConfig(hooks: accountHooksConfig) - new Account(uuid: bidRequest.accountId, config: accountConfig) + getAccountWithModuleConfig(bidRequest.accountId, [(PROCESSED_AUCTION_REQUEST) : [OPTABLE_TARGETING]]).tap { + it.config.hooks.modules.optableTargeting = optableTargetingConfig + } } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbortb2blocking/PbOrtb2BlockingSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbortb2blocking/PbOrtb2BlockingSpec.groovy index 29e45b86955..4351fa61e5a 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbortb2blocking/PbOrtb2BlockingSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbortb2blocking/PbOrtb2BlockingSpec.groovy @@ -3,25 +3,21 @@ package org.prebid.server.functional.tests.module.pbortb2blocking import org.prebid.server.functional.model.bidder.BidderName import org.prebid.server.functional.model.bidder.Generic import org.prebid.server.functional.model.config.AccountAuctionConfig -import org.prebid.server.functional.model.config.AccountConfig -import org.prebid.server.functional.model.config.AccountHooksConfiguration -import org.prebid.server.functional.model.config.ExecutionPlan import org.prebid.server.functional.model.config.Ortb2BlockingActionOverride -import org.prebid.server.functional.model.config.Ortb2BlockingAttributeConfig import org.prebid.server.functional.model.config.Ortb2BlockingAttribute +import org.prebid.server.functional.model.config.Ortb2BlockingAttributeConfig import org.prebid.server.functional.model.config.Ortb2BlockingConditions import org.prebid.server.functional.model.config.Ortb2BlockingConfig import org.prebid.server.functional.model.config.Ortb2BlockingOverride -import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.Asset import org.prebid.server.functional.model.request.auction.Audio import org.prebid.server.functional.model.request.auction.Banner +import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.BidderControls import org.prebid.server.functional.model.request.auction.GenericPreferredBidder -import org.prebid.server.functional.model.request.auction.Ix -import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Imp +import org.prebid.server.functional.model.request.auction.Ix import org.prebid.server.functional.model.request.auction.Video import org.prebid.server.functional.model.response.auction.Adm import org.prebid.server.functional.model.response.auction.Bid @@ -29,19 +25,17 @@ import org.prebid.server.functional.model.response.auction.BidMediaType import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.MediaType import org.prebid.server.functional.model.response.auction.SeatBid -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils -import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.IX -import static org.prebid.server.functional.model.config.HookHttpEndpoint.AUCTION +import static org.prebid.server.functional.model.config.ModuleName.PB_ORTB2_BLOCKING import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.AUDIO_BATTR import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BADV -import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BANNER_BATTR +import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BAPP import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BCAT import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.BTYPE import static org.prebid.server.functional.model.config.Ortb2BlockingAttribute.VIDEO_BATTR @@ -51,22 +45,9 @@ import static org.prebid.server.functional.model.response.auction.BidRejectionRe import static org.prebid.server.functional.model.response.auction.MediaType.AUDIO import static org.prebid.server.functional.model.response.auction.MediaType.BANNER import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO -import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer class PbOrtb2BlockingSpec extends ModuleBaseSpec { - private static final String WILDCARD = '*' - private static final Map IX_CONFIG = ["adapters.ix.enabled" : "true", - "adapters.ix.endpoint": "$networkServiceContainer.rootUri/auction".toString()] - private static final Map PBS_CONFIG = getOrtb2BlockingSettings() + IX_CONFIG + - ['adapter-defaults.ortb.multiformat-supported': 'false'] - - private static final PrebidServerService pbsServiceWithEnabledOrtb2Blocking = pbsServiceFactory.getService(PBS_CONFIG) - - def cleanupSpec() { - pbsServiceFactory.removeContainer(PBS_CONFIG) - } - def "PBS should send original array ortb2 attribute to bidder when enforce blocking is disabled"() { given: "Default bid request with proper ortb attribute" def bidRequest = getBidRequestForOrtbAttribute(attributeName) @@ -82,7 +63,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should contain proper ortb2 attributes from account config" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -121,7 +102,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes the auction request" - pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should contain proper ortb2 attributes from account config" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -151,7 +132,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request shouldn't contain ortb2 attributes from account config for any media-type" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -196,7 +177,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request shouldn't contain ortb2 attributes from account config for any media-type" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -242,7 +223,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request shouldn't contain ortb2 attributes from account config for any media-type" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -281,7 +262,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain seatNonBid for the called bidder" assert response.ext.prebid.modules.errors.pbOrtb2Blocking["${PB_ORTB2_BLOCKING.code}-${BIDDER_REQUEST.value}-hook"].first @@ -314,7 +295,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain seatNonBid for the called bidder" assert response.ext.prebid.modules.errors.pbOrtb2Blocking["${PB_ORTB2_BLOCKING.code}-${BIDDER_REQUEST.value}-hook"].first @@ -356,7 +337,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response shouldn't contain any seatbid" assert !response.seatbid @@ -396,7 +377,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -462,7 +443,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -500,7 +481,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain proper seatbid" assert getOrtb2Attributes(response.seatbid.first.bid.first, attributeName) == [ortb2Attributes]*.toString() @@ -547,7 +528,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -578,7 +559,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -621,7 +602,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -652,7 +633,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -688,7 +669,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only allowed seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -729,7 +710,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response shouldn't contain any seatbid" assert !response.seatbid.bid.flatten().size() @@ -773,7 +754,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only openx seatbid" assert response.seatbid.size() == 1 @@ -821,7 +802,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only banner seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -871,7 +852,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain banner seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -925,7 +906,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response shouldn't contain any seatbid" assert !response.seatbid.bid.flatten().size() @@ -968,7 +949,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only seatbid with proper deal id" assert response.seatbid.bid.flatten().size() == 1 @@ -1017,7 +998,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should override blocked ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1060,7 +1041,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should override blocked ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1109,7 +1090,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only ix seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -1146,7 +1127,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain banner seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -1185,7 +1166,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only ix seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -1220,7 +1201,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain banner seatbid" assert response.seatbid.bid.flatten().size() == 1 @@ -1255,7 +1236,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only seatbid with proper deal id" assert response.seatbid.bid.flatten().size() == 1 @@ -1298,7 +1279,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should override blocked ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1348,7 +1329,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should override blocked ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1391,7 +1372,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should override blocked ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1436,7 +1417,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain only seatbid with proper deal id" assert response.seatbid.bid.flatten().size() == 1 @@ -1472,7 +1453,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS request should contain original ortb2 attribute" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -1514,7 +1495,7 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes the auction request" - def response = pbsServiceWithEnabledOrtb2Blocking.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS response should contain seatNonBid for the called bidder" assert response.ext.seatnonbid.size() == 1 @@ -1525,17 +1506,20 @@ class PbOrtb2BlockingSpec extends ModuleBaseSpec { assert seatNonBid.nonBid[0].statusCode == RESPONSE_REJECTED_ADVERTISER_BLOCKED } - private static Account getAccountWithOrtb2BlockingConfig(String accountId, Object ortb2Attributes, Ortb2BlockingAttribute attributeName) { + private static Account getAccountWithOrtb2BlockingConfig(String accountId, + Object ortb2Attributes, + Ortb2BlockingAttribute attributeName) { + getAccountWithOrtb2BlockingConfig(accountId, [(attributeName): Ortb2BlockingAttributeConfig.getDefaultConfig(ortb2Attributes, attributeName)]) } - private static Account getAccountWithOrtb2BlockingConfig(String accountId, Map attributes) { - def blockingConfig = new Ortb2BlockingConfig(attributes: attributes) - def executionPlan = ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, PB_ORTB2_BLOCKING, [BIDDER_REQUEST, RAW_BIDDER_RESPONSE]) - def moduleConfig = new PbsModulesConfig(pbOrtb2Blocking: blockingConfig) - def accountHooksConfig = new AccountHooksConfiguration(executionPlan: executionPlan, modules: moduleConfig) - def accountConfig = new AccountConfig(hooks: accountHooksConfig) - new Account(uuid: accountId, config: accountConfig) + private static Account getAccountWithOrtb2BlockingConfig(String accountId, + Map attributes) { + + getAccountWithModuleConfig(accountId, [(BIDDER_REQUEST) : [PB_ORTB2_BLOCKING], (RAW_BIDDER_RESPONSE) : [PB_ORTB2_BLOCKING]]).tap { + it.config.hooks.modules.pbOrtb2Blocking = new Ortb2BlockingConfig(attributes: attributes) + } } private static BidRequest getBidRequestForOrtbAttribute(Ortb2BlockingAttribute attribute, List attributeValue = null) { diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbrequestcorrection/PbRequestCorrectionSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbrequestcorrection/PbRequestCorrectionSpec.groovy index d64b5cd2637..1d1d7bb2043 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbrequestcorrection/PbRequestCorrectionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbrequestcorrection/PbRequestCorrectionSpec.groovy @@ -5,16 +5,17 @@ import org.prebid.server.functional.model.config.AccountHooksConfiguration import org.prebid.server.functional.model.config.PbRequestCorrectionConfig import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.db.Account -import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.AppExt import org.prebid.server.functional.model.request.auction.AppPrebid +import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Device import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.OperationState -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils +import static org.prebid.server.functional.model.config.ModuleName.PB_REQUEST_CORRECTION +import static org.prebid.server.functional.model.config.Stage.PROCESSED_AUCTION_REQUEST import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP import static org.prebid.server.functional.model.request.auction.OperationState.YES @@ -27,12 +28,6 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { private static final String ANDROID = "android" private static final String IOS = "IOS" - private static final PrebidServerService pbsServiceWithRequestCorrectionModule = pbsServiceFactory.getService(getRequestCorrectionSettings()) - - def cleanupSpec() { - pbsServiceFactory.removeContainer(getRequestCorrectionSettings()) - } - def "PBS should remove positive instl from imps for android app when request correction is enabled for account"() { given: "Android APP bid request with version lover then version threshold" def prebid = new AppPrebid(source: PBSUtils.getRandomCase(PREBID_MOBILE), version: ACCEPTABLE_DEVICE_INSTL_VERSION_THRESHOLD) @@ -47,7 +42,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request shouldn't contain imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -80,7 +75,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -108,7 +103,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -138,7 +133,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -167,7 +162,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -189,7 +184,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -211,7 +206,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -241,7 +236,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain original imp.instl" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -261,7 +256,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request shouldn't contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -289,7 +284,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -319,7 +314,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -348,7 +343,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -377,7 +372,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -398,7 +393,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -419,7 +414,7 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain device.ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) @@ -441,18 +436,16 @@ class PbRequestCorrectionSpec extends ModuleBaseSpec { accountDao.save(account) when: "PBS processes auction request" - pbsServiceWithRequestCorrectionModule.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bidder request should contain request device ua" def bidderRequest = bidder.getBidderRequest(bidRequest.id) assert bidderRequest.device.ua == deviceUa } - private static Account createAccountWithRequestCorrectionConfig(BidRequest bidRequest, - PbRequestCorrectionConfig requestCorrectionConfig) { - def pbsModulesConfig = new PbsModulesConfig(pbRequestCorrection: requestCorrectionConfig) - def accountHooksConfig = new AccountHooksConfiguration(modules: pbsModulesConfig) - def accountConfig = new AccountConfig(hooks: accountHooksConfig) - new Account(uuid: bidRequest.accountId, config: accountConfig) + private static Account createAccountWithRequestCorrectionConfig(BidRequest bidRequest, PbRequestCorrectionConfig requestCorrectionConfig) { + getAccountWithModuleConfig(bidRequest.accountId, [(PROCESSED_AUCTION_REQUEST): [PB_REQUEST_CORRECTION]]).tap { + it.config.hooks.modules.pbRequestCorrection = requestCorrectionConfig + } } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbresponsecorrenction/PbResponseCorrectionSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbresponsecorrenction/PbResponseCorrectionSpec.groovy index fb7ca93eb9f..b9743e29c19 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbresponsecorrenction/PbResponseCorrectionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbresponsecorrenction/PbResponseCorrectionSpec.groovy @@ -2,11 +2,8 @@ package org.prebid.server.functional.tests.module.pbresponsecorrenction import org.prebid.server.functional.model.config.AccountAuctionConfig import org.prebid.server.functional.model.config.AccountCacheConfig -import org.prebid.server.functional.model.config.AccountConfig -import org.prebid.server.functional.model.config.AccountHooksConfiguration import org.prebid.server.functional.model.config.AppVideoHtml import org.prebid.server.functional.model.config.PbResponseCorrection -import org.prebid.server.functional.model.config.PbsModulesConfig import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.Imp @@ -15,13 +12,14 @@ import org.prebid.server.functional.model.response.auction.BidExt import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.Meta import org.prebid.server.functional.model.response.auction.Prebid -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils import java.time.Instant import static org.prebid.server.functional.model.bidder.BidderName.GENERIC +import static org.prebid.server.functional.model.config.ModuleName.PB_RESPONSE_CORRECTION +import static org.prebid.server.functional.model.config.Stage.ALL_PROCESSED_BID_RESPONSES import static org.prebid.server.functional.model.request.auction.BidRequest.getDefaultBidRequest import static org.prebid.server.functional.model.request.auction.BidRequest.getDefaultVideoRequest import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP @@ -35,15 +33,6 @@ import static org.prebid.server.functional.model.response.auction.MediaType.VIDE class PbResponseCorrectionSpec extends ModuleBaseSpec { private final static int OPTIMAL_MAX_LENGTH = 20 - private static final Map PBS_CONFIG = ["adapter-defaults.modifying-vast-xml-allowed": "false", - "adapters.generic.modifying-vast-xml-allowed": "false"] + - getResponseCorrectionConfig() - - private static final PrebidServerService pbsServiceWithResponseCorrectionModule = pbsServiceFactory.getService(PBS_CONFIG) - - def cleanupSpec() { - pbsServiceFactory.removeContainer(PBS_CONFIG) - } def "PBS shouldn't modify response when in account correction module disabled"() { given: "Start up time" @@ -59,14 +48,16 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { bidder.setResponse(bidRequest.id, bidResponse) and: "Save account with enabled response correction module" - def accountWithResponseCorrectionModule = accountConfigWithResponseCorrectionModule(bidRequest, responseCorrectionEnabled, appVideoHtmlEnabled) + def accountWithResponseCorrectionModule = accountConfigWithResponseCorrectionModule(bidRequest, + responseCorrectionEnabled, + appVideoHtmlEnabled) accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -106,10 +97,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -148,10 +139,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -183,10 +174,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection[0].contains("Bid $bidId of bidder generic has an JSON ADM, that appears to be native" as String) @@ -222,10 +213,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -265,10 +256,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection[0].contains("Bid $bidId of bidder generic has an JSON ADM, that appears to be native" as String) @@ -306,10 +297,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -343,10 +334,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS shouldn't emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, bidResponse.seatbid[0].bid[0].id).size() == 0 and: "Response should contain seatBid" @@ -390,10 +381,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection.size() == 1 @@ -445,10 +436,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection.size() == 1 @@ -500,10 +491,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection.size() == 1 @@ -548,10 +539,10 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" - def logsByTime = pbsServiceWithResponseCorrectionModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) def bidId = bidResponse.seatbid[0].bid[0].id def responseCorrection = getLogsByText(logsByTime, bidId) assert responseCorrection.size() == 2 @@ -595,11 +586,11 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { accountDao.save(accountWithResponseCorrectionModule) when: "PBS processes auction request" - def response = pbsServiceWithResponseCorrectionModule.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBS should emit log" def responseCorrectionLog = "Bid ${bidResponse.seatbid[0].bid[0].id} of bidder generic: changing media type to banner" - assert pbsServiceWithResponseCorrectionModule.isContainLogsByValue(responseCorrectionLog) + assert pbsServiceWithMultipleModules.isContainLogsByValue(responseCorrectionLog) and: "Response should contain seatBid" assert response.seatbid.size() == 1 @@ -625,10 +616,13 @@ class PbResponseCorrectionSpec extends ModuleBaseSpec { ] } - private static Account accountConfigWithResponseCorrectionModule(BidRequest bidRequest, Boolean enabledResponseCorrection = true, Boolean enabledAppVideoHtml = true) { - def modulesConfig = new PbsModulesConfig(pbResponseCorrection: new PbResponseCorrection( - enabled: enabledResponseCorrection, appVideoHtml: new AppVideoHtml(enabled: enabledAppVideoHtml))) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: modulesConfig)) - new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + private static Account accountConfigWithResponseCorrectionModule(BidRequest bidRequest, + Boolean enabledResponseCorrection = true, + Boolean enabledAppVideoHtml = true) { + + getAccountWithModuleConfig(bidRequest.accountId, [(ALL_PROCESSED_BID_RESPONSES): [PB_RESPONSE_CORRECTION]]).tap { + it.config.hooks.modules.pbResponseCorrection = new PbResponseCorrection( + enabled: enabledResponseCorrection, appVideoHtml: new AppVideoHtml(enabled: enabledAppVideoHtml)) + } } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbrichmedia/PbRichMediaFilterSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbrichmedia/PbRichMediaFilterSpec.groovy index 037a38fb922..42da9f9b976 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbrichmedia/PbRichMediaFilterSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbrichmedia/PbRichMediaFilterSpec.groovy @@ -13,6 +13,7 @@ import org.prebid.server.functional.model.request.auction.StoredBidResponse import org.prebid.server.functional.model.response.auction.AnalyticResult import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils @@ -27,16 +28,22 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { private static final String PATTERN_NAME = PBSUtils.randomString private static final String PATTERN_NAME_ACCOUNT = PBSUtils.randomString - private static final Map DISABLED_FILTER_SPECIFIC_PATTERN_NAME_CONFIG = getRichMediaFilterSettings(PATTERN_NAME, false) - private static final Map SPECIFIC_PATTERN_NAME_CONFIG = getRichMediaFilterSettings(PATTERN_NAME) - private static final Map SNAKE_SPECIFIC_PATTERN_NAME_CONFIG = (getRichMediaFilterSettings(PATTERN_NAME) + + private static final PbsContainerConfig DISABLED_FILTER_SPECIFIC_PATTERN_NAME_CONFIG = getRichMediaFilterSettings(PATTERN_NAME, false) + private static final PbsContainerConfig SPECIFIC_PATTERN_NAME_CONFIG = getRichMediaFilterSettings(PATTERN_NAME) + private static final PbsContainerConfig SNAKE_SPECIFIC_PATTERN_NAME_CONFIG = getRichMediaFilterSettings(PATTERN_NAME) + ["hooks.host-execution-plan": encode(ExecutionPlan.getSingleEndpointExecutionPlan(AUCTION, PB_RICHMEDIA_FILTER, [ALL_PROCESSED_BID_RESPONSES]).tap { endpoints.values().first().stages.values().first().groups.first.hookSequenceSnakeCase = [new HookId(moduleCodeSnakeCase: PB_RICHMEDIA_FILTER.code, hookImplCodeSnakeCase: "${PB_RICHMEDIA_FILTER.code}-${ALL_PROCESSED_BID_RESPONSES.value}-hook")] - })]).collectEntries { key, value -> [(key.toString()): value.toString()] } + })] - private static final PrebidServerService pbsServiceWithDisabledMediaFilter = pbsServiceFactory.getService(DISABLED_FILTER_SPECIFIC_PATTERN_NAME_CONFIG) - private static final PrebidServerService pbsServiceWithEnabledMediaFilter = pbsServiceFactory.getService(SPECIFIC_PATTERN_NAME_CONFIG) - private static final PrebidServerService pbsServiceWithEnabledMediaFilterAndDifferentCaseStrategy = pbsServiceFactory.getService(SNAKE_SPECIFIC_PATTERN_NAME_CONFIG) + private static PrebidServerService pbsServiceWithDisabledMediaFilter + private static PrebidServerService pbsServiceWithEnabledMediaFilter + private static PrebidServerService pbsServiceWithEnabledMediaFilterAndDifferentCaseStrategy + + def setupSpec() { + pbsServiceWithDisabledMediaFilter = pbsServiceFactory.getService(DISABLED_FILTER_SPECIFIC_PATTERN_NAME_CONFIG) + pbsServiceWithEnabledMediaFilter = pbsServiceFactory.getService(SPECIFIC_PATTERN_NAME_CONFIG) + pbsServiceWithEnabledMediaFilterAndDifferentCaseStrategy = pbsServiceFactory.getService(SNAKE_SPECIFIC_PATTERN_NAME_CONFIG) + } def cleanupSpec() { pbsServiceFactory.removeContainer(DISABLED_FILTER_SPECIFIC_PATTERN_NAME_CONFIG) @@ -45,10 +52,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { } def "PBS should process request without rich media module when host config have empty settings"() { - given: "Prebid server with empty settings for module" - def prebidServerService = pbsServiceFactory.getService(pbsConfig) - - and: "BidRequest with stored response" + given: "BidRequest with stored response" def storedResponseId = PBSUtils.randomNumber def bidRequest = BidRequest.defaultBidRequest.tap { ext.prebid.returnAllBidStatus = true @@ -63,12 +67,12 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { def storedResponse = new StoredResponse(responseId: storedResponseId, storedBidResponse: storedBidResponse) storedResponseDao.save(storedResponse) - and: "Account in the DB" - def account = new Account(uuid: bidRequest.getAccountId()) + and: "Account with enabled richMedia config in the DB" + def account = getAccountWithRichmediaFilter(bidRequest.accountId, filterMraid, mraidScriptPattern) accountDao.save(account) when: "PBS processes auction request" - def response = prebidServerService.sendAuctionRequest(bidRequest) + def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Response header should contain seatbid" assert response.seatbid.size() == 1 @@ -79,14 +83,12 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { and: "Response shouldn't contain analytics" assert !getAnalyticResults(response) - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsConfig) - where: - pbsConfig << [getRichMediaFilterSettings(PBSUtils.randomString, null), - getRichMediaFilterSettings(null, true), - getRichMediaFilterSettings(null, false), - getRichMediaFilterSettings(null, null)] + filterMraid | mraidScriptPattern + true | PBSUtils.randomString + true | null + false | null + null | null } def "PBS should process request without analytics when adm matches with pattern name and filter set to disabled in host config"() { @@ -106,7 +108,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { storedResponseDao.save(storedResponse) and: "Account in the DB" - def account = new Account(uuid: bidRequest.getAccountId()) + def account = new Account(uuid: bidRequest.accountId) accountDao.save(account) when: "PBS processes auction request" @@ -125,7 +127,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { admValue << [PATTERN_NAME, "${PBSUtils.randomString}-${PATTERN_NAME}", "${PATTERN_NAME}-${PBSUtils.randomString}"] } - def "PBS should reject request with error and provide analytic when adm matches with pattern name and filter set to enabled in host config"() { + def "PBS should reject request with error and provide analytic when adm matches with pattern name and filter set to enabled in config"() { given: "BidRequest with stored response" def storedResponseId = PBSUtils.randomNumber def bidRequest = BidRequest.defaultBidRequest.tap { @@ -142,7 +144,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { storedResponseDao.save(storedResponse) and: "Account in the DB" - def account = new Account(uuid: bidRequest.getAccountId()) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, true, PATTERN_NAME) accountDao.save(account) when: "PBS processes auction request" @@ -169,7 +171,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { admValue << [PATTERN_NAME, "${PBSUtils.randomString}-${PATTERN_NAME}", "${PATTERN_NAME}.${PBSUtils.randomString}"] } - def "PBS should process request without analytics when adm is #admValue and filter enabled in host config"() { + def "PBS should process request without analytics when adm is #admValue and filter enabled in config"() { given: "BidRequest with stored response" def storedResponseId = PBSUtils.randomNumber def bidRequest = BidRequest.defaultBidRequest.tap { @@ -186,9 +188,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { storedResponseDao.save(storedResponse) and: "Account with enabled richMedia config in the DB" - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: true)) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, true, null) accountDao.save(account) when: "PBS processes auction request" @@ -217,9 +217,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { } and: "Account with enabled richMedia config in the DB" - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME)) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, true, PATTERN_NAME) accountDao.save(account) and: "Stored bid response in DB" @@ -263,9 +261,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { } and: "Account with disabled richMedia config in the DB" - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: false, mraidScriptPattern: PATTERN_NAME)) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, false, PATTERN_NAME) accountDao.save(account) and: "Stored bid response in DB" @@ -301,9 +297,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { } and: "Account with enabled richMedia config in the DB" - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME_ACCOUNT)) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, true, PATTERN_NAME_ACCOUNT) accountDao.save(account) and: "Stored bid response in DB" @@ -344,9 +338,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { } and: "Account with enabled richMedia config in the DB" - def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME_ACCOUNT)) - def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = getAccountWithRichmediaFilter(bidRequest.accountId, true, PATTERN_NAME_ACCOUNT) accountDao.save(account) and: "Stored bid response in DB" @@ -371,7 +363,10 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { def "PBS should process any request without analytics and errors when pb-richmedia-filter hook is disabled"() { given: "PBS with disabled pb-richmedia-filter hook" - def pbsServiceWithDisabledMediaFilterHook = pbsServiceFactory.getService(getDisabledRichMediaFilterSettings(PATTERN_NAME)) + def pbsConfig = getRichMediaFilterSettings(PATTERN_NAME) + + getModuleBaseSettings(PB_RICHMEDIA_FILTER, false) + + ["hooks.host-execution-plan": null] + def pbsServiceWithDisabledMediaFilterHook = pbsServiceFactory.getService(pbsConfig) and: "BidRequest with stored response" def storedResponseId = PBSUtils.randomNumber @@ -384,7 +379,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { and: "Account with enabled richMedia config in the DB" def richMediaFilterConfig = new PbsModulesConfig(pbRichmediaFilter: new RichmediaFilter(filterMraid: true, mraidScriptPattern: PATTERN_NAME_ACCOUNT)) def accountConfig = new AccountConfig(hooks: new AccountHooksConfiguration(modules: richMediaFilterConfig)) - def account = new Account(uuid: bidRequest.getAccountId(), config: accountConfig) + def account = new Account(uuid: bidRequest.accountId, config: accountConfig) accountDao.save(account) and: "Stored bid response in DB" @@ -427,7 +422,7 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { storedResponseDao.save(storedResponse) and: "Account in the DB" - def account = new Account(uuid: bidRequest.getAccountId()) + def account = new Account(uuid: bidRequest.accountId) accountDao.save(account) when: "PBS processes auction request" @@ -453,4 +448,12 @@ class PbRichMediaFilterSpec extends ModuleBaseSpec { where: admValue << [PATTERN_NAME, "${PBSUtils.randomString}-${PATTERN_NAME}", "${PATTERN_NAME}.${PBSUtils.randomString}"] } + + private static Account getAccountWithRichmediaFilter(String accountId, + Boolean filterMraid, + String mraidScriptPattern) { + getAccountWithModuleConfig(accountId, [(ALL_PROCESSED_BID_RESPONSES): [PB_RICHMEDIA_FILTER]]).tap { + it.config.hooks.modules.pbRichmediaFilter = new RichmediaFilter(filterMraid: filterMraid, mraidScriptPattern: mraidScriptPattern) + } + } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineAliasSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineAliasSpec.groovy index 9eb712715d5..c319db50ab5 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineAliasSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineAliasSpec.groovy @@ -2,16 +2,16 @@ package org.prebid.server.functional.tests.module.pbruleengine import org.prebid.server.functional.model.request.auction.Imp -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.OPENX_ALIAS +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithExcludeResult import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithIncludeResult -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE class PbRuleEngineAliasSpec extends PbRuleEngineBaseSpec { @@ -35,7 +35,7 @@ class PbRuleEngineAliasSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.size() == 1 @@ -97,7 +97,7 @@ class PbRuleEngineAliasSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -157,7 +157,7 @@ class PbRuleEngineAliasSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seat" assert bidResponse.seatbid.seat == [ALIAS] @@ -219,7 +219,7 @@ class PbRuleEngineAliasSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineBaseSpec.groovy index 494a44f8460..739cd9b1b7c 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineBaseSpec.groovy @@ -3,10 +3,9 @@ package org.prebid.server.functional.tests.module.pbruleengine import org.prebid.server.functional.model.bidder.BidderName import org.prebid.server.functional.model.bidder.Generic import org.prebid.server.functional.model.bidder.Openx -import org.prebid.server.functional.model.config.AccountConfig -import org.prebid.server.functional.model.config.AccountHooksConfiguration +import org.prebid.server.functional.model.config.ModuleName import org.prebid.server.functional.model.config.PbRulesEngine -import org.prebid.server.functional.model.config.PbsModulesConfig +import org.prebid.server.functional.model.config.Stage import org.prebid.server.functional.model.db.Account import org.prebid.server.functional.model.pricefloors.Country import org.prebid.server.functional.model.request.auction.Amx @@ -16,10 +15,8 @@ import org.prebid.server.functional.model.request.auction.DistributionChannel import org.prebid.server.functional.model.request.auction.Geo import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.ImpUnitCode -import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.tests.module.ModuleBaseSpec import org.prebid.server.functional.util.PBSUtils -import spock.lang.Retry import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.AMX @@ -35,22 +32,17 @@ import static org.prebid.server.functional.model.request.auction.ImpUnitCode.PB_ import static org.prebid.server.functional.model.request.auction.ImpUnitCode.STORED_REQUEST import static org.prebid.server.functional.model.request.auction.ImpUnitCode.TAG_ID import static org.prebid.server.functional.model.request.auction.TraceLevel.VERBOSE -import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer -import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID abstract class PbRuleEngineBaseSpec extends ModuleBaseSpec { protected static final List MULTI_BID_ADAPTERS = [GENERIC, OPENX, AMX].sort() - protected static final Integer OPENX_VENDOR_ID = PBSUtils.getRandomNumber(0, 65534) - protected static final Integer AMX_VENDOR_ID = PBSUtils.getRandomNumber(0, 65534) - protected static final String APPLIED_FOR_ALL_IMPS = "*" protected static final String DEFAULT_CONDITIONS = "default" + protected final static Closure INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING = { accountId, functionType -> "Failed to parse rule-engine config for account $accountId: " + "Function '$functionType' configuration is invalid: " + "Field '$functionType.fieldName' is required and has to be an array of strings" } - protected final static Closure INVALID_CONFIGURATION_FOR_SINGLE_STRING_LOG_WARNING = { accountId, functionType -> "Failed to parse rule-engine config for account $accountId: " + "Function '$functionType' configuration is invalid: " + @@ -69,25 +61,6 @@ abstract class PbRuleEngineBaseSpec extends ModuleBaseSpec { "Field '$functionType.fieldName' is required and has to be an array of integers" } - protected static final Map ENABLED_DEBUG_LOG_MODE = ["logging.level.root": "debug"] - protected static final Map OPENX_CONFIG = ["adapters.${OPENX}.enabled" : "true", - "adapters.${OPENX}.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.${OPENX}.meta-info.vendor-id": OPENX_VENDOR_ID as String] - protected static final Map AMX_CONFIG = ["adapters.${AMX}.enabled" : "true", - "adapters.${AMX}.endpoint" : "$networkServiceContainer.rootUri/auction".toString(), - "adapters.${AMX}.meta-info.vendor-id": AMX_VENDOR_ID as String] - protected static final Map OPENX_ALIAS_CONFIG = ["adapters.${OPENX}.aliases.${OPENX_ALIAS}.enabled" : "true", - "adapters.${OPENX}.aliases.${OPENX_ALIAS}.meta-info.vendor-id": "0", - "adapters.${OPENX}.aliases.${OPENX_ALIAS}.endpoint" : "$networkServiceContainer.rootUri/auction".toString()] - protected static final String CONFIG_DATA_CENTER = PBSUtils.randomString - private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync" - private static final Map GENERIC_CONFIG = [ - "adapters.${GENERIC.value}.usersync.redirect.url" : USER_SYNC_URL, - "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String] - protected static final PrebidServerService pbsServiceWithRulesEngineModule = pbsServiceFactory.getService(GENERIC_CONFIG + - getRulesEngineSettings() + AMX_CONFIG + OPENX_CONFIG + OPENX_ALIAS_CONFIG + ['datacenter-region': CONFIG_DATA_CENTER] + - ENABLED_DEBUG_LOG_MODE) - protected static BidRequest getDefaultBidRequestWithMultiplyBidders(DistributionChannel distributionChannel = SITE) { BidRequest.getDefaultBidRequest(distributionChannel).tap { it.imp[0].ext.prebid.bidder.amx = new Amx() @@ -114,8 +87,10 @@ abstract class PbRuleEngineBaseSpec extends ModuleBaseSpec { } protected static Account getAccountWithRulesEngine(String accountId, PbRulesEngine ruleEngine) { - def accountHooksConfiguration = new AccountHooksConfiguration(modules: new PbsModulesConfig(pbRuleEngine: ruleEngine)) - new Account(uuid: accountId, config: new AccountConfig(hooks: accountHooksConfiguration)) + + getAccountWithModuleConfig(accountId, [(Stage.PROCESSED_AUCTION_REQUEST) : [ModuleName.PB_RULE_ENGINE]]).tap { + it.config.hooks.modules.pbRuleEngine = ruleEngine + } } protected static BidRequest createBidRequestWithDomains(DistributionChannel type, String domain, boolean usePublisher = true) { @@ -178,15 +153,15 @@ abstract class PbRuleEngineBaseSpec extends ModuleBaseSpec { protected static waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) { PBSUtils.waitUntil({ - pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) - pbsServiceWithRulesEngineModule.isContainLogsByValue("Successfully parsed rule-engine config for account $bidRequest.accountId") + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.isContainLogsByValue("Successfully parsed rule-engine config for account $bidRequest.accountId") }) } protected static waitUntilFailedParsedAndCacheAccount(bidRequest) { PBSUtils.waitUntil({ - pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) - pbsServiceWithRulesEngineModule.isContainLogsByValue("Failed to parse rule-engine config for account $bidRequest.accountId") + pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) + pbsServiceWithMultipleModules.isContainLogsByValue("Failed to parse rule-engine config for account $bidRequest.accountId") }) } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineContextSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineContextSpec.groovy index 02820762c87..d0a2f3d9a3b 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineContextSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineContextSpec.groovy @@ -16,10 +16,10 @@ import org.prebid.server.functional.util.PBSUtils import java.time.Instant import static org.prebid.server.functional.model.ChannelType.WEB -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineFunction.AD_UNIT_CODE import static org.prebid.server.functional.model.config.RuleEngineFunction.AD_UNIT_CODE_IN @@ -30,10 +30,10 @@ import static org.prebid.server.functional.model.config.RuleEngineFunction.DOMAI import static org.prebid.server.functional.model.config.RuleEngineFunction.DOMAIN_IN import static org.prebid.server.functional.model.config.RuleEngineFunction.MEDIA_TYPE_IN import static org.prebid.server.functional.model.pricefloors.MediaType.BANNER +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP import static org.prebid.server.functional.model.request.auction.DistributionChannel.DOOH import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.ImpUnitCode.GPID import static org.prebid.server.functional.model.request.auction.ImpUnitCode.PB_AD_SLOT import static org.prebid.server.functional.model.request.auction.ImpUnitCode.STORED_REQUEST @@ -62,7 +62,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -122,7 +122,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -164,7 +164,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -229,7 +229,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -274,7 +274,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -293,7 +293,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, DOMAIN_IN)) where: @@ -339,7 +339,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -405,7 +405,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -468,7 +468,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -530,7 +530,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -574,7 +574,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -593,7 +593,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { assert !bidResponse.ext?.errors then: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, BUNDLE_IN)) } @@ -620,7 +620,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -682,7 +682,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -724,7 +724,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -743,7 +743,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) then: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, MEDIA_TYPE_IN)) where: @@ -774,7 +774,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -834,7 +834,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -882,7 +882,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -953,7 +953,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -1006,7 +1006,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -1025,7 +1025,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, AD_UNIT_CODE_IN)) where: @@ -1062,7 +1062,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -1125,7 +1125,7 @@ class PbRuleEngineContextSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineCoreSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineCoreSpec.groovy index ab986d3bc3a..e32525ea0d3 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineCoreSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineCoreSpec.groovy @@ -1,6 +1,5 @@ package org.prebid.server.functional.tests.module.pbruleengine - import org.prebid.server.functional.model.config.RuleEngineModelDefault import org.prebid.server.functional.model.config.RuleEngineModelDefaultArgs import org.prebid.server.functional.model.config.RuleSet @@ -9,11 +8,11 @@ import org.prebid.server.functional.model.config.Stage import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.util.PBSUtils -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX import static org.prebid.server.functional.model.bidder.BidderName.UNKNOWN +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.ResultFunction.LOG_A_TAG import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithExcludeResult @@ -21,7 +20,7 @@ import static org.prebid.server.functional.model.config.RuleEngineModelRuleResul import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithLogATagResult import static org.prebid.server.functional.model.config.Stage.PROCESSED_AUCTION_REQUEST import static org.prebid.server.functional.model.pricefloors.Country.BULGARIA -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.TraceLevel.VERBOSE import static org.prebid.server.functional.model.response.auction.BidRejectionReason.ERROR_NO_BID import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE @@ -45,10 +44,10 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) and: "Flush metric" - flushMetrics(pbsServiceWithRulesEngineModule) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Response should contain seat bid" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -64,7 +63,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { assert !bidResponse.ext?.errors and: "PBs should populate call and update metrics" - def metrics = pbsServiceWithRulesEngineModule.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[CALL_METRIC(PB_RULE_ENGINE, PROCESSED_AUCTION_REQUEST)] == 1 assert metrics[UPDATE_METRIC(PB_RULE_ENGINE, PROCESSED_AUCTION_REQUEST)] == 1 @@ -95,7 +94,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [OPENX, AMX].sort() @@ -159,7 +158,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [OPENX, AMX].sort() @@ -212,7 +211,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.size() == 0 @@ -245,7 +244,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -278,7 +277,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat == [OPENX] @@ -338,7 +337,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seatBids" assert bidResponse.seatbid.seat.sort() == [OPENX, AMX].sort() @@ -397,7 +396,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat == [GENERIC] @@ -455,7 +454,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -487,7 +486,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { it.values.resultFunction == groups.rules.first.results.first.function.value it.values.conditionFired == groups.rules.first.conditions.first - it.appliedTo.impIds == [APPLIED_FOR_ALL_IMPS] + it.appliedTo.impIds == [WILDCARD] } verifyAll(impResult) { @@ -514,7 +513,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Response should contain seat bid" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -578,7 +577,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Response should contain seat bid" assert bidResponse.seatbid.seat.sort() == [GENERIC, OPENX].sort() @@ -646,7 +645,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [OPENX, AMX].sort() @@ -706,7 +705,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -766,7 +765,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -797,7 +796,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { it.values.analyticsValue == analyticsValue it.values.resultFunction == LOG_A_TAG.value it.values.conditionFired == DEFAULT_CONDITIONS - it.appliedTo.impIds == [APPLIED_FOR_ALL_IMPS] + it.appliedTo.impIds == [WILDCARD] } and: "Analytics imp result shouldn't contain remove info" @@ -826,7 +825,7 @@ class PbRuleEngineCoreSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain two seat" assert bidResponse.seatbid.size() == 2 diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineDeviceSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineDeviceSpec.groovy index fabcab27548..3c934969609 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineDeviceSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineDeviceSpec.groovy @@ -9,17 +9,17 @@ import org.prebid.server.functional.util.PBSUtils import java.time.Instant -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineFunction.DEVICE_COUNTRY import static org.prebid.server.functional.model.config.RuleEngineFunction.DEVICE_COUNTRY_IN import static org.prebid.server.functional.model.config.RuleEngineFunction.DEVICE_TYPE import static org.prebid.server.functional.model.config.RuleEngineFunction.DEVICE_TYPE_IN import static org.prebid.server.functional.model.pricefloors.Country.USA -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { @@ -46,7 +46,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -108,7 +108,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -150,7 +150,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -213,7 +213,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -257,7 +257,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -276,7 +276,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, DEVICE_COUNTRY_IN)) } @@ -305,7 +305,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -324,7 +324,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_INTEGERS_LOG_WARNING(bidRequest.accountId, DEVICE_TYPE_IN)) } @@ -351,7 +351,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -413,7 +413,7 @@ class PbRuleEngineDeviceSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineInfrastructureSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineInfrastructureSpec.groovy index ba125f07a3a..cd69eb4c602 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineInfrastructureSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineInfrastructureSpec.groovy @@ -6,14 +6,14 @@ import org.prebid.server.functional.util.PBSUtils import java.time.Instant -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineFunction.DATA_CENTER import static org.prebid.server.functional.model.config.RuleEngineFunction.DATA_CENTER_IN -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { @@ -29,7 +29,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { def pbRuleEngine = createRulesEngineWithRule().tap { it.ruleSets[0].modelGroups[0].schema[0].tap { it.function = DATA_CENTER_IN - it.args = new RuleEngineFunctionArgs(countries: [CONFIG_DATA_CENTER]) + it.args = new RuleEngineFunctionArgs(countries: [RANDOM_DATACENTER_REGION]) } } @@ -41,7 +41,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -60,7 +60,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, DATA_CENTER_IN)) } @@ -72,7 +72,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { def pbRuleEngine = createRulesEngineWithRule().tap { it.ruleSets[0].modelGroups[0].schema[0].tap { it.function = DATA_CENTER_IN - it.args = new RuleEngineFunctionArgs(datacenters: [CONFIG_DATA_CENTER]) + it.args = new RuleEngineFunctionArgs(datacenters: [RANDOM_DATACENTER_REGION]) } } @@ -84,7 +84,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -144,7 +144,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -171,7 +171,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { def pbRuleEngine = createRulesEngineWithRule().tap { it.ruleSets[0].modelGroups[0].tap { schema = [new RuleEngineModelSchema(function: DATA_CENTER)] - rules[0].conditions = [CONFIG_DATA_CENTER] + rules[0].conditions = [RANDOM_DATACENTER_REGION] } } @@ -183,7 +183,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -243,7 +243,7 @@ class PbRuleEngineInfrastructureSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEnginePrivacySpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEnginePrivacySpec.groovy index 64106286821..f16ee54284d 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEnginePrivacySpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEnginePrivacySpec.groovy @@ -19,10 +19,10 @@ import org.prebid.server.functional.util.privacy.TcfConsent import java.time.Instant -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineFunction.EID_AVAILABLE import static org.prebid.server.functional.model.config.RuleEngineFunction.EID_IN @@ -32,8 +32,8 @@ import static org.prebid.server.functional.model.config.RuleEngineFunction.GPP_S import static org.prebid.server.functional.model.config.RuleEngineFunction.TCF_IN_SCOPE import static org.prebid.server.functional.model.config.RuleEngineFunction.USER_FPD_AVAILABLE import static org.prebid.server.functional.model.request.GppSectionId.TCF_EU_V2 +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.BASIC_ADS @@ -67,7 +67,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -129,7 +129,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -176,7 +176,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -195,7 +195,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_STRINGS_LOG_WARNING(bidRequest.accountId, EID_IN)) } @@ -222,7 +222,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -284,7 +284,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -322,7 +322,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -386,7 +386,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -425,7 +425,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -501,7 +501,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -563,7 +563,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -622,7 +622,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -669,7 +669,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -688,7 +688,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_INTEGERS_LOG_WARNING(bidRequest.accountId, GPP_SID_IN)) } @@ -714,7 +714,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -779,7 +779,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -828,7 +828,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -900,7 +900,7 @@ class PbRuleEnginePrivacySpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSpecialSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSpecialSpec.groovy index 8d9a53d13f0..60d8a19aac2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSpecialSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSpecialSpec.groovy @@ -5,14 +5,14 @@ import org.prebid.server.functional.util.PBSUtils import java.time.Instant -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineFunction.PERCENT import static org.prebid.server.functional.model.config.RuleEngineFunction.PREBID_KEY -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { @@ -40,7 +40,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -59,7 +59,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { assert !bidResponse.ext?.errors and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_SINGLE_INTEGER_LOG_WARNING(bidRequest.accountId, PERCENT)) } @@ -83,7 +83,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -143,7 +143,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -188,7 +188,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -207,7 +207,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, INVALID_CONFIGURATION_FOR_SINGLE_STRING_LOG_WARNING(bidRequest.accountId, PREBID_KEY)) } @@ -236,7 +236,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [GENERIC, AMX].sort() @@ -300,7 +300,7 @@ class PbRuleEngineSpecialSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSyncSpec.groovy index 3128e047aae..3b571ceebce 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSyncSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineSyncSpec.groovy @@ -3,14 +3,14 @@ package org.prebid.server.functional.tests.module.pbruleengine import org.prebid.server.functional.model.UidsCookie import org.prebid.server.functional.util.HttpUtil -import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.bidder.BidderName.AMX import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.bidder.BidderName.OPENX +import static org.prebid.server.functional.model.config.ModuleName.PB_RULE_ENGINE import static org.prebid.server.functional.model.config.PbRulesEngine.createRulesEngineWithRule import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithExcludeResult import static org.prebid.server.functional.model.config.RuleEngineModelRuleResult.createRuleEngineModelRuleWithIncludeResult -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.BidRejectionReason.REQUEST_BIDDER_REMOVED_BY_RULE_ENGINE_MODULE class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { @@ -35,7 +35,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest, cookieHeader) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest, cookieHeader) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == [OPENX, AMX] @@ -92,7 +92,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest, cookieHeader) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest, cookieHeader) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -128,7 +128,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -167,7 +167,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest, cookieHeader) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest, cookieHeader) then: "Bid response shouldn't contain seat" assert bidResponse.seatbid.seat == [GENERIC] @@ -227,7 +227,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest, cookieHeader) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest, cookieHeader) then: "Bid response shouldn't contain seat" assert !bidResponse.seatbid.seat @@ -277,7 +277,7 @@ class PbRuleEngineSyncSpec extends PbRuleEngineBaseSpec { accountDao.save(accountWithRulesEngine) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS diff --git a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineValidationSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineValidationSpec.groovy index d43a5114f5d..ce5726a6cb1 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineValidationSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/module/pbruleengine/PbRuleEngineValidationSpec.groovy @@ -37,10 +37,10 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) and: "Flush metrics" - flushMetrics(pbsServiceWithRulesEngineModule) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -59,7 +59,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "PBs should populate call and noop metrics" - def metrics = pbsServiceWithRulesEngineModule.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[CALL_METRIC(PB_RULE_ENGINE, PROCESSED_AUCTION_REQUEST)] == 1 assert metrics[NOOP_METRIC(PB_RULE_ENGINE,PROCESSED_AUCTION_REQUEST)] == 1 @@ -91,10 +91,10 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) and: "Flush metrics" - flushMetrics(pbsServiceWithRulesEngineModule) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -113,7 +113,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "PBs should populate noop metrics" - def metrics = pbsServiceWithRulesEngineModule.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[NOOP_METRIC(PB_RULE_ENGINE,PROCESSED_AUCTION_REQUEST)] == 1 } @@ -132,10 +132,10 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) and: "Flush metrics" - flushMetrics(pbsServiceWithRulesEngineModule) + flushMetrics(pbsServiceWithMultipleModules) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -151,7 +151,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS and: "PBs should populate failer metrics" - def metrics = pbsServiceWithRulesEngineModule.sendCollectedMetricsRequest() + def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest() assert metrics[NOOP_METRIC(PB_RULE_ENGINE,PROCESSED_AUCTION_REQUEST)] == 1 } @@ -173,7 +173,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -189,7 +189,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS and: "PBs should emit failed logs" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, "Failed to parse rule-engine config for account $bidRequest.accountId:" + " Weighted list cannot be empty") } @@ -211,7 +211,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -241,7 +241,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { accountDao.save(accountWithRulesEngine) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -280,7 +280,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilSuccessfullyParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -314,7 +314,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { accountDao.save(accountWithRulesEngine) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -333,7 +333,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "PBs should emit failed logs" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, "Parsing rule for account $bidRequest.accountId").size() == 1 } @@ -359,7 +359,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "Bid response should contain seats" assert bidResponse.seatbid.seat.sort() == MULTI_BID_ADAPTERS @@ -378,7 +378,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert !getAnalyticResults(bidResponse) and: "PBS should emit log" - def logsByTime = pbsServiceWithRulesEngineModule.getLogsByTime(start) + def logsByTime = pbsServiceWithMultipleModules.getLogsByTime(start) assert getLogsByText(logsByTime, "Failed to parse rule-engine config for account $bidRequest.accountId:" + " Weight must be greater than zero") @@ -409,7 +409,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { waitUntilFailedParsedAndCacheAccount(bidRequest) when: "PBS processes auction request" - def bidResponse = pbsServiceWithRulesEngineModule.sendAuctionRequest(bidRequest) + def bidResponse = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest) then: "PBs should perform bidder request" assert bidder.getBidderRequests(bidRequest.id) @@ -428,7 +428,7 @@ class PbRuleEngineValidationSpec extends PbRuleEngineBaseSpec { assert !bidResponse.ext?.errors and: "Logs should contain error" - def logs = pbsServiceWithRulesEngineModule.getLogsByTime(startTime) + def logs = pbsServiceWithMultipleModules.getLogsByTime(startTime) assert getLogsByText(logs, "Failed to parse rule-engine config for account ${bidRequest.accountId}: " + "Function '${function.value}' configuration is invalid: No arguments allowed") diff --git a/src/test/groovy/org/prebid/server/functional/tests/postgres/PostgresBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/postgres/PostgresBaseSpec.groovy index 05b5e054cc0..d5b59b702ee 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/postgres/PostgresBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/postgres/PostgresBaseSpec.groovy @@ -8,6 +8,7 @@ import org.prebid.server.functional.repository.dao.StoredResponseDao import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.Dependencies import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.BaseSpec import org.testcontainers.lifecycle.Startables @@ -29,7 +30,7 @@ class PostgresBaseSpec extends BaseSpec { storedImpDao = repository.storedImpDao storedRequestDao = repository.storedRequestDao storedResponseDao = repository.storedResponseDao - pbsServiceWithPostgres = pbsServiceFactory.getService(PbsConfig.postgreSqlConfig) + pbsServiceWithPostgres = pbsServiceFactory.getService(new PbsContainerConfig(PbsConfig.postgreSqlConfig)) } void cleanup() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsAdjustmentSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsAdjustmentSpec.groovy index 57f368f46a3..af910fe5699 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsAdjustmentSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsAdjustmentSpec.groovy @@ -27,6 +27,7 @@ import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.MediaType import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.CurrencyUtil import org.prebid.server.functional.util.PBSUtils @@ -61,7 +62,7 @@ class PriceFloorsAdjustmentSpec extends PriceFloorsBaseSpec { private static final Integer MAX_STATIC_ADJUST_VALUE = Integer.MAX_VALUE private static final String WILDCARD = '*' - private static final Map PBS_CONFIG = PbsConfig.currencyConverterConfig + + private static final PbsContainerConfig PBS_CONFIG = new PbsContainerConfig(PbsConfig.currencyConverterConfig) + FLOORS_CONFIG + GENERIC_ALIAS_CONFIG + ["adapters.openx.enabled" : "true", diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsBaseSpec.groovy index 95ef1318637..d4d0bafbab2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsBaseSpec.groovy @@ -10,14 +10,15 @@ import org.prebid.server.functional.model.pricefloors.Country import org.prebid.server.functional.model.pricefloors.MediaType import org.prebid.server.functional.model.pricefloors.Rule import org.prebid.server.functional.model.request.amp.AmpRequest +import org.prebid.server.functional.model.request.auction.AnalyticTagStatus import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.BidRequestExt import org.prebid.server.functional.model.request.auction.DistributionChannel import org.prebid.server.functional.model.request.auction.ExtPrebidFloors -import org.prebid.server.functional.model.request.auction.FetchStatus import org.prebid.server.functional.model.request.auction.Prebid import org.prebid.server.functional.model.request.auction.Video import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.CurrencyConversion import org.prebid.server.functional.testcontainers.scaffolding.FloorsProvider import org.prebid.server.functional.tests.BaseSpec @@ -25,16 +26,16 @@ import org.prebid.server.functional.util.PBSUtils import java.math.RoundingMode +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.INPROGRESS import static org.prebid.server.functional.model.request.auction.DebugCondition.ENABLED import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE -import static org.prebid.server.functional.model.request.auction.FetchStatus.INPROGRESS import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer abstract class PriceFloorsBaseSpec extends BaseSpec { public static final BigDecimal FLOOR_MIN = 0.5 public static final BigDecimal FLOOR_MAX = 2 - public static final Map FLOORS_CONFIG = ["price-floors.enabled": "true"] + public static final PbsContainerConfig FLOORS_CONFIG = new PbsContainerConfig(["price-floors.enabled": "true"]) protected static final FloorsProvider floorsProvider = new FloorsProvider(networkServiceContainer) @@ -136,7 +137,7 @@ abstract class PriceFloorsBaseSpec extends BaseSpec { protected void cacheFloorsProviderRules(BidRequest bidRequest, PrebidServerService pbsService = floorsPbsService, BidderName bidderName = BidderName.GENERIC, - FetchStatus fetchStatus = INPROGRESS) { + AnalyticTagStatus fetchStatus = INPROGRESS) { PBSUtils.waitUntil({ getRequests(pbsService.sendAuctionRequest(bidRequest))[bidderName.value]?.first?.ext?.prebid?.floors?.fetchStatus != fetchStatus }, 5000, 1000) diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsCurrencySpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsCurrencySpec.groovy index b569514d0c4..2d8f361feb1 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsCurrencySpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsCurrencySpec.groovy @@ -9,6 +9,7 @@ import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.testcontainers.PbsConfig +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.CurrencyUtil import org.prebid.server.functional.util.PBSUtils @@ -17,8 +18,8 @@ import static org.prebid.server.functional.model.Currency.EUR import static org.prebid.server.functional.model.Currency.GBP import static org.prebid.server.functional.model.Currency.JPY import static org.prebid.server.functional.model.Currency.USD -import static org.prebid.server.functional.model.request.auction.FetchStatus.NONE -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.NONE +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.Location.FETCH import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID @@ -26,14 +27,15 @@ class PriceFloorsCurrencySpec extends PriceFloorsBaseSpec { private static final String GENERAL_ERROR_METRIC = "price-floors.general.err" + private static final PbsContainerConfig PBS_CONFIG = FLOORS_CONFIG + PbsConfig.currencyConverterConfig private static PrebidServerService currencyFloorsPbsService def setupSpec() { - currencyFloorsPbsService = pbsServiceFactory.getService(FLOORS_CONFIG + PbsConfig.currencyConverterConfig) + currencyFloorsPbsService = pbsServiceFactory.getService(PBS_CONFIG) } def cleanupSpec() { - pbsServiceFactory.removeContainer(FLOORS_CONFIG + PbsConfig.currencyConverterConfig) + pbsServiceFactory.removeContainer(PBS_CONFIG) } def "PBS should update bidFloor, bidFloorCur for signalling when request.cur is specified"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsFetchingSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsFetchingSpec.groovy index fcfa39f6e9d..19218b1e184 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsFetchingSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsFetchingSpec.groovy @@ -20,12 +20,12 @@ import static org.prebid.server.functional.model.Currency.JPY import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.pricefloors.Country.MULTIPLE import static org.prebid.server.functional.model.pricefloors.MediaType.BANNER +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.ERROR +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.INPROGRESS +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.NONE +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE -import static org.prebid.server.functional.model.request.auction.FetchStatus.ERROR -import static org.prebid.server.functional.model.request.auction.FetchStatus.INPROGRESS -import static org.prebid.server.functional.model.request.auction.FetchStatus.NONE -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.Location.FETCH import static org.prebid.server.functional.model.request.auction.Location.NO_DATA import static org.prebid.server.functional.model.request.auction.Location.REQUEST diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsRulesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsRulesSpec.groovy index bd892ca8746..4dac38952c2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsRulesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsRulesSpec.groovy @@ -56,10 +56,10 @@ import static org.prebid.server.functional.model.pricefloors.PriceFloorField.MED import static org.prebid.server.functional.model.pricefloors.PriceFloorField.PUB_DOMAIN import static org.prebid.server.functional.model.pricefloors.PriceFloorField.SITE_DOMAIN import static org.prebid.server.functional.model.pricefloors.PriceFloorField.SIZE +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.ERROR import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP import static org.prebid.server.functional.model.request.auction.DistributionChannel.DOOH import static org.prebid.server.functional.model.request.auction.DistributionChannel.SITE -import static org.prebid.server.functional.model.request.auction.FetchStatus.ERROR import static org.prebid.server.functional.model.request.auction.Location.NO_DATA import static org.prebid.server.functional.model.response.auction.BidRejectionReason.RESPONSE_REJECTED_DUE_TO_PRICE_FLOOR import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer diff --git a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsSignalingSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsSignalingSpec.groovy index 9ad4114c212..ee2a681d432 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsSignalingSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/pricefloors/PriceFloorsSignalingSpec.groovy @@ -16,9 +16,9 @@ import org.prebid.server.functional.model.request.auction.Imp import org.prebid.server.functional.model.request.auction.Video import org.prebid.server.functional.model.response.auction.BidResponse import org.prebid.server.functional.model.response.auction.MediaType +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils -import java.math.RoundingMode import java.time.Instant import static org.apache.http.HttpStatus.SC_BAD_REQUEST @@ -29,8 +29,8 @@ import static org.prebid.server.functional.model.pricefloors.MediaType.MULTIPLE import static org.prebid.server.functional.model.pricefloors.MediaType.VIDEO import static org.prebid.server.functional.model.pricefloors.PriceFloorField.MEDIA_TYPE import static org.prebid.server.functional.model.pricefloors.PriceFloorField.SITE_DOMAIN +import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS import static org.prebid.server.functional.model.request.auction.DistributionChannel.APP -import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID class PriceFloorsSignalingSpec extends PriceFloorsBaseSpec { @@ -666,8 +666,8 @@ class PriceFloorsSignalingSpec extends PriceFloorsBaseSpec { def accountConfig = getDefaultAccountConfigSettings().tap { auction.priceFloors.maxSchemaDims = MAX_SCHEMA_DIMENSIONS_SIZE } - def pbsFloorConfig = GENERIC_ALIAS_CONFIG + ["price-floors.enabled" : "true", - "settings.default-account-config": encode(accountConfig)] + def pbsFloorConfig = new PbsContainerConfig(GENERIC_ALIAS_CONFIG + ["price-floors.enabled" : "true", + "settings.default-account-config": encode(accountConfig)]) and: "Prebid server with floor config" def floorsPbsService = pbsServiceFactory.getService(pbsFloorConfig) @@ -707,9 +707,6 @@ class PriceFloorsSignalingSpec extends PriceFloorsBaseSpec { def metrics = floorsPbsService.sendCollectedMetricsRequest() assert metrics[INVALID_CONFIG_METRIC(bidRequest.accountId) as String] == 1 assert metrics[ALERT_GENERAL] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsFloorConfig) } def "PBS should emit warning when request has more schema.fields than default-account.fetch.max-schema-dims"() { @@ -723,8 +720,8 @@ class PriceFloorsSignalingSpec extends PriceFloorsBaseSpec { auction.priceFloors.fetch.maxSchemaDims = MAX_SCHEMA_DIMENSIONS_SIZE auction.priceFloors.maxSchemaDims = MAX_SCHEMA_DIMENSIONS_SIZE } - def pbsFloorConfig = GENERIC_ALIAS_CONFIG + ["price-floors.enabled" : "true", - "settings.default-account-config": encode(accountConfig)] + def pbsFloorConfig = new PbsContainerConfig(GENERIC_ALIAS_CONFIG + ["price-floors.enabled" : "true", + "settings.default-account-config": encode(accountConfig)]) and: "Prebid server with floor config" def floorsPbsService = pbsServiceFactory.getService(pbsFloorConfig) @@ -760,9 +757,6 @@ class PriceFloorsSignalingSpec extends PriceFloorsBaseSpec { def metrics = floorsPbsService.sendCollectedMetricsRequest() assert metrics[INVALID_CONFIG_METRIC(bidRequest.accountId) as String] == 1 assert metrics[ALERT_GENERAL] == 1 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(pbsFloorConfig) } def "PBS should emit warning when request has more schema.fields than fetch.max-schema-dims"() { 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 79ed11c5856..cc22da62876 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 @@ -38,6 +38,7 @@ import org.prebid.server.functional.model.request.auction.User import org.prebid.server.functional.model.request.auction.UserExt import org.prebid.server.functional.model.request.auction.UserExtData import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.VendorList import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils @@ -111,15 +112,15 @@ abstract class PrivacyBaseSpec extends BaseSpec { protected static final Integer MAX_INVALID_TCF_POLICY_VERSION = 63 protected static final Integer MIN_INVALID_TCF_POLICY_VERSION = 6 - protected static final Map GENERAL_PRIVACY_CONFIG = - GENERIC_CONFIG + GDPR_VENDOR_LIST_CONFIG + GENERIC_VENDOR_CONFIG + RETRY_POLICY_EXPONENTIAL_CONFIG + protected static final PbsContainerConfig GENERAL_PRIVACY_CONFIG = new PbsContainerConfig( + GENERIC_CONFIG + GDPR_VENDOR_LIST_CONFIG + GENERIC_VENDOR_CONFIG + RETRY_POLICY_EXPONENTIAL_CONFIG) protected static PrebidServerService privacyPbsService protected static PrebidServerService activityPbsService def setupSpec() { privacyPbsService = pbsServiceFactory.getService(GENERAL_PRIVACY_CONFIG + GDPR_EEA_COUNTRY) - activityPbsService = pbsServiceFactory.getService(OPENX_CONFIG + SETTING_CONFIG + GENERAL_PRIVACY_CONFIG) + activityPbsService = pbsServiceFactory.getService(GENERAL_PRIVACY_CONFIG + OPENX_CONFIG + SETTING_CONFIG) vendorListResponse.setResponse() } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/dsa/DsaSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/dsa/DsaSpec.groovy index ddb2cd9dcfd..39087cac877 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/dsa/DsaSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/dsa/DsaSpec.groovy @@ -16,7 +16,6 @@ import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.TcfConsent - import static org.prebid.server.functional.model.request.auction.DsaPubRender.PUB_CANT_RENDER import static org.prebid.server.functional.model.request.auction.DsaPubRender.PUB_WILL_RENDER import static org.prebid.server.functional.model.request.auction.DsaRequired.NOT_REQUIRED diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAmpSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAmpSpec.groovy index e24e8fdc563..e49c813a20b 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAmpSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAmpSpec.groovy @@ -12,6 +12,7 @@ import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.model.request.auction.DistributionChannel import org.prebid.server.functional.model.request.auction.Regs import org.prebid.server.functional.model.request.auction.RegsExt +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.BogusConsent @@ -320,7 +321,7 @@ class GdprAmpSpec extends PrivacyBaseSpec { def startTime = Instant.now() and: "Create new container" - def config = GDPR_VENDOR_LIST_CONFIG + ["adapters.generic.meta-info.vendor-id": GENERIC_VENDOR_ID as String] + def config = new PbsContainerConfig(GDPR_VENDOR_LIST_CONFIG + ["adapters.generic.meta-info.vendor-id": GENERIC_VENDOR_ID]) def defaultPrivacyPbsService = pbsServiceFactory.getService(config) and: "Prepare tcf consent string" @@ -359,9 +360,6 @@ class GdprAmpSpec extends PrivacyBaseSpec { assert getLogsByText(logs, "Created new TCF 2 vendor list for version " + "v${tcfPolicyVersion.vendorListVersion}.${tcfPolicyVersion.vendorListVersion}") - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(config) - where: tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5] } @@ -469,9 +467,6 @@ class GdprAmpSpec extends PrivacyBaseSpec { and: "Reset vendor list response" vendorListResponse.reset() - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(GENERAL_PRIVACY_CONFIG) - where: tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5] } @@ -703,9 +698,6 @@ class GdprAmpSpec extends PrivacyBaseSpec { def vendorList = defaultPrivacyPbsService.getValueFromContainer(properVendorListPath, VendorListConsent.class) assert vendorList.gvlSpecificationVersion == V3 - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(GENERAL_PRIVACY_CONFIG) - where: tcfPolicyVersion << [TCF_POLICY_V4, TCF_POLICY_V5] } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAuctionSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAuctionSpec.groovy index ffbbbcbbd79..c2439b34f3d 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAuctionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprAuctionSpec.groovy @@ -16,6 +16,7 @@ import org.prebid.server.functional.model.request.auction.RegsExt import org.prebid.server.functional.model.response.auction.ErrorType import org.prebid.server.functional.model.response.auction.NoBidResponse import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.scaffolding.VendorList import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils @@ -63,7 +64,7 @@ class GdprAuctionSpec extends PrivacyBaseSpec { private static final String LIVE_GVL_FILE_NAME = "live-gvl-vendor-list.json" private static final VENDOR_LIST_VERSION = PBSUtils.getRandomNumber(2, 4094) - private static final Map REFRESH_LIVE_VENDOR_LIST_CONFIG = GENERAL_PRIVACY_CONFIG + + private static final PbsContainerConfig REFRESH_LIVE_VENDOR_LIST_CONFIG = GENERAL_PRIVACY_CONFIG + ["gdpr.vendorlist.live.url": "$networkServiceContainer.rootUri/v3/$LIVE_GVL_FILE_NAME".toString()] private static final VendorList liveVendorListResponse = new VendorList(networkServiceContainer, LIVE_GVL_FILE_NAME) @@ -305,7 +306,7 @@ class GdprAuctionSpec extends PrivacyBaseSpec { def startTime = Instant.now() and: "Create new container" - def config = GDPR_VENDOR_LIST_CONFIG + ["adapters.generic.meta-info.vendor-id": GENERIC_VENDOR_ID as String] + def config = new PbsContainerConfig(GDPR_VENDOR_LIST_CONFIG + ["adapters.generic.meta-info.vendor-id": GENERIC_VENDOR_ID]) def defaultPrivacyPbsService = pbsServiceFactory.getService(config) and: "Tcf consent setup" @@ -337,9 +338,6 @@ class GdprAuctionSpec extends PrivacyBaseSpec { assert getLogsByText(logs, "Created new TCF 2 vendor list for version " + "v${tcfPolicyVersion.vendorListVersion}.${tcfPolicyVersion.vendorListVersion}") - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(config) - where: tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5] } @@ -440,9 +438,6 @@ class GdprAuctionSpec extends PrivacyBaseSpec { and: "Reset vendor list response" vendorListResponse.reset() - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(GENERAL_PRIVACY_CONFIG) - where: tcfPolicyVersion << [TCF_POLICY_V2, TCF_POLICY_V4, TCF_POLICY_V5] } @@ -855,9 +850,6 @@ class GdprAuctionSpec extends PrivacyBaseSpec { def vendorList = defaultPrivacyPbsService.getValueFromContainer(properVendorListPath, VendorListConsent.class) assert vendorList.gvlSpecificationVersion == V3 - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(GENERAL_PRIVACY_CONFIG) - where: tcfPolicyVersion << [TCF_POLICY_V4, TCF_POLICY_V5] } @@ -1369,9 +1361,6 @@ class GdprAuctionSpec extends PrivacyBaseSpec { and: "Disallowed metrics shouldn't be updated" def metrics = pbsWithLiveGvlSetup.sendCollectedMetricsRequest() assert metrics[TEMPLATE_ADAPTER_DISALLOWED_COUNT.getValue(bidRequest, FETCH_BIDS)] == 0 - - cleanup: "Stop and remove pbs container" - pbsServiceFactory.removeContainer(config) } private static void downloadLiveGvtList( diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprSetUidSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprSetUidSpec.groovy index a4ff12f45bd..08a5e0cf43c 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprSetUidSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gdpr/GdprSetUidSpec.groovy @@ -11,7 +11,7 @@ import org.prebid.server.functional.model.request.setuid.SetuidRequest import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.testcontainers.Dependencies +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.TcfConsent @@ -25,20 +25,25 @@ import static org.prebid.server.functional.model.config.PurposeEnforcement.FULL import static org.prebid.server.functional.model.config.PurposeEnforcement.NO import static org.prebid.server.functional.model.request.setuid.UidWithExpiry.getDefaultUidWithExpiry import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT +import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.DEVICE_ACCESS class GdprSetUidSpec extends PrivacyBaseSpec { - private static final String USER_SYNC_URL = "$Dependencies.networkServiceContainer.rootUri/generic-usersync" + private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync" private static final UserSyncInfo.Type USER_SYNC_TYPE = REDIRECT - private static final Map VENDOR_GENERIC_PBS_CONFIG = GENERIC_VENDOR_CONFIG + - ["gdpr.purposes.p1.enforce-purpose" : NO.value, - "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url" : USER_SYNC_URL] + private static final PbsContainerConfig VENDOR_GENERIC_PBS_CONFIG = new PbsContainerConfig(GENERIC_VENDOR_CONFIG + + ["gdpr.purposes.p1.enforce-purpose" : NO.value, + "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url": USER_SYNC_URL]) private static final String TCF_ERROR_MESSAGE = "The gdpr_consent param prevents cookies from being saved" private static final int UNAVAILABLE_FOR_LEGAL_REASONS_CODE = 451 - private static final PrebidServerService prebidServerService = pbsServiceFactory.getService(VENDOR_GENERIC_PBS_CONFIG) + private static PrebidServerService prebidServerService + + def setupSpec() { + prebidServerService = pbsServiceFactory.getService(VENDOR_GENERIC_PBS_CONFIG) + } def cleanupSpec() { pbsServiceFactory.removeContainer(VENDOR_GENERIC_PBS_CONFIG) diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAmpSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAmpSpec.groovy index 73e966d61db..ff0aa98f3c2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAmpSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAmpSpec.groovy @@ -8,8 +8,8 @@ import org.prebid.server.functional.model.request.auction.Regs import org.prebid.server.functional.model.request.auction.RegsExt import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils -import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import org.prebid.server.functional.util.privacy.gpp.v1.UspV1Consent +import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import static org.prebid.server.functional.model.request.GppSectionId.TCF_EU_V2 import static org.prebid.server.functional.model.request.GppSectionId.USP_V1 diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAuctionSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAuctionSpec.groovy index 3e944af63fc..d9745039cb1 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAuctionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppAuctionSpec.groovy @@ -9,8 +9,8 @@ import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.CcpaConsent import org.prebid.server.functional.util.privacy.TcfConsent -import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import org.prebid.server.functional.util.privacy.gpp.v1.UspV1Consent +import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import static org.prebid.server.functional.model.request.GppSectionId.TCF_EU_V2 import static org.prebid.server.functional.model.request.GppSectionId.USP_V1 diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppCookieSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppCookieSyncSpec.groovy index 46369e28503..d5c2efe3512 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppCookieSyncSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppCookieSyncSpec.groovy @@ -11,15 +11,15 @@ import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest import org.prebid.server.functional.model.response.cookiesync.UserSyncInfo import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.testcontainers.Dependencies +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.HttpUtil import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.CcpaConsent import org.prebid.server.functional.util.privacy.TcfConsent import org.prebid.server.functional.util.privacy.gpp.v1.UsNatV1Consent -import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import org.prebid.server.functional.util.privacy.gpp.v1.UspV1Consent +import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import static org.prebid.server.functional.model.bidder.BidderName.ALIAS import static org.prebid.server.functional.model.bidder.BidderName.GENERIC @@ -29,6 +29,7 @@ import static org.prebid.server.functional.model.request.GppSectionId.TCF_EU_V2 import static org.prebid.server.functional.model.request.GppSectionId.USP_V1 import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.IFRAME import static org.prebid.server.functional.model.response.cookiesync.UserSyncInfo.Type.REDIRECT +import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer import static org.prebid.server.functional.util.privacy.CcpaConsent.Signal.ENFORCED import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.DEVICE_ACCESS @@ -36,18 +37,18 @@ import static org.prebid.server.functional.util.privacy.TcfConsent.PurposeId.DEV class GppCookieSyncSpec extends BaseSpec { private static final UserSyncInfo.Type USER_SYNC_TYPE = REDIRECT - private static final String USER_SYNC_URL = "$Dependencies.networkServiceContainer.rootUri/generic-usersync" + private static final String USER_SYNC_URL = "$networkServiceContainer.rootUri/generic-usersync" private static final GppSectionId FIRST_GPP_SECTION = PBSUtils.getRandomEnum(GppSectionId.class) private static final GppSectionId SECOND_GPP_SECTION = PBSUtils.getRandomEnum(GppSectionId.class, [FIRST_GPP_SECTION]) - private static final Map GENERIC_CONFIG = [ - "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, - "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url" : USER_SYNC_URL] - private static final Map GENERIC_WITH_SKIP_CONFIG = [ - "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, - "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url" : "$Dependencies.networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), - "adapters.${GENERIC.value}.usersync.skipwhen.gdpr" : 'true', - "adapters.${GENERIC.value}.usersync.skipwhen.gpp_sid" : "${FIRST_GPP_SECTION.value}, ${SECOND_GPP_SECTION.value}".toString()] + private static final PbsContainerConfig GENERIC_CONFIG = new PbsContainerConfig([ + "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, + "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url": USER_SYNC_URL]) + private static final PbsContainerConfig GENERIC_WITH_SKIP_CONFIG = new PbsContainerConfig([ + "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, + "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url": "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString(), + "adapters.${GENERIC.value}.usersync.skipwhen.gdpr" : 'true', + "adapters.${GENERIC.value}.usersync.skipwhen.gpp_sid" : "${FIRST_GPP_SECTION.value}, ${SECOND_GPP_SECTION.value}".toString()]) private static PrebidServerService prebidServerService = pbsServiceFactory.getService(GENERIC_CONFIG) private static PrebidServerService prebidServerServiceWithSkipConfig = pbsServiceFactory.getService(GENERIC_WITH_SKIP_CONFIG + GENERIC_ALIAS_CONFIG) @@ -227,7 +228,8 @@ class GppCookieSyncSpec extends BaseSpec { def "PBS should return empty gpp and gppSid in usersync url when gpp and gppSid is not present in request"() { given: "Pbs config with usersync.#userSyncFormat.url" - def pbsConfig = ["adapters.generic.usersync.${userSyncFormat.value}.url" : "$Dependencies.networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()] + def pbsConfig = new PbsContainerConfig( + ["adapters.generic.usersync.${userSyncFormat.value}.url": "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()]) def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest without gpp and gppSid" @@ -253,7 +255,8 @@ class GppCookieSyncSpec extends BaseSpec { def "PBS should populate gpp and gppSid in usersync url when gpp and gppSid is present in request"() { given: "Pbs config with usersync.#userSyncFormat.url" - def pbsConfig = ["adapters.generic.usersync.${userSyncFormat.value}.url" : "$Dependencies.networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()] + def pbsConfig = new PbsContainerConfig( + ["adapters.generic.usersync.${userSyncFormat.value}.url": "$networkServiceContainer.rootUri/generic-usersync&redir={redirect_url}".toString()]) def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest with gpp and gppSid" @@ -404,10 +407,10 @@ class GppCookieSyncSpec extends BaseSpec { def "PBS shouldn't emit error message when request does contain gdpr config and global skip gdpr config disabled for adapter"() { given: "Pbs config with usersync.#userSyncFormat.url" - def pbsConfig = [ - "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, - "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url" : USER_SYNC_URL, - "adapters.${GENERIC.value}.usersync.skipwhen.gdpr" : 'false'] + def pbsConfig = new PbsContainerConfig([ + "adapters.${GENERIC.value}.meta-info.vendor-id" : GENERIC_VENDOR_ID as String, + "adapters.${GENERIC.value}.usersync.${USER_SYNC_TYPE.value}.url": USER_SYNC_URL, + "adapters.${GENERIC.value}.usersync.skipwhen.gdpr" : 'false']) def prebidServerService = pbsServiceFactory.getService(pbsConfig) and: "Default CookieSyncRequest with gdpr config" diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppSetUidSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppSetUidSpec.groovy index eafafeaea33..7cd673396e6 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppSetUidSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppSetUidSpec.groovy @@ -6,8 +6,8 @@ import org.prebid.server.functional.model.request.setuid.SetuidRequest import org.prebid.server.functional.service.PrebidServerException import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils -import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import org.prebid.server.functional.util.privacy.gpp.v1.UspV1Consent +import org.prebid.server.functional.util.privacy.gpp.v2.TcfEuV2Consent import static org.prebid.server.functional.model.bidder.BidderName.GENERIC import static org.prebid.server.functional.model.request.GppSectionId.US_NAT_V1 diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitTidActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitTidActivitiesSpec.groovy index f91df7acd50..c72ca4a5d74 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitTidActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitTidActivitiesSpec.groovy @@ -13,10 +13,10 @@ import org.prebid.server.functional.util.PBSUtils import java.time.Instant -import static org.prebid.server.functional.model.privacy.Metric.TEMPLATE_ACCOUNT_DISALLOWED_COUNT import static org.prebid.server.functional.model.privacy.Metric.ACCOUNT_PROCESSED_RULES_COUNT -import static org.prebid.server.functional.model.privacy.Metric.TEMPLATE_ADAPTER_DISALLOWED_COUNT import static org.prebid.server.functional.model.privacy.Metric.PROCESSED_ACTIVITY_RULES_COUNT +import static org.prebid.server.functional.model.privacy.Metric.TEMPLATE_ACCOUNT_DISALLOWED_COUNT +import static org.prebid.server.functional.model.privacy.Metric.TEMPLATE_ADAPTER_DISALLOWED_COUNT import static org.prebid.server.functional.model.privacy.Metric.TEMPLATE_REQUEST_DISALLOWED_COUNT import static org.prebid.server.functional.model.request.auction.ActivityType.TRANSMIT_TID import static org.prebid.server.functional.model.request.auction.TraceLevel.VERBOSE diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitUfpdActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitUfpdActivitiesSpec.groovy index 74cdcdce28b..89449671462 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitUfpdActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/gpp/GppTransmitUfpdActivitiesSpec.groovy @@ -15,6 +15,7 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsNationalV1ChildSensitiveData +import org.prebid.server.functional.model.privacy.gpp.UsNationalV1SensitiveData import org.prebid.server.functional.model.privacy.gpp.UsNationalV2ChildSensitiveData import org.prebid.server.functional.model.privacy.gpp.UsNationalV2SensitiveData import org.prebid.server.functional.model.request.amp.AmpRequest @@ -34,7 +35,6 @@ import org.prebid.server.functional.util.privacy.gpp.v1.UsCtV1Consent import org.prebid.server.functional.util.privacy.gpp.v1.UsNatV1Consent import org.prebid.server.functional.util.privacy.gpp.v1.UsUtV1Consent import org.prebid.server.functional.util.privacy.gpp.v1.UsVaV1Consent -import org.prebid.server.functional.model.privacy.gpp.UsNationalV1SensitiveData import org.prebid.server.functional.util.privacy.gpp.v2.UsNatV2Consent import java.time.Instant diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfBaseSpec.groovy index e51e71c1b7a..20176c3c17a 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfBaseSpec.groovy @@ -8,7 +8,7 @@ import org.prebid.server.functional.model.request.auction.Activity import org.prebid.server.functional.model.request.auction.ActivityRule import org.prebid.server.functional.model.request.auction.AllowActivities import org.prebid.server.functional.model.request.auction.Condition -import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.privacy.PrivacyBaseSpec import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.TcfUtils @@ -26,26 +26,33 @@ import static org.prebid.server.functional.util.privacy.TcfConsent.RestrictionTy class TcfBaseSpec extends PrivacyBaseSpec { - private static String prepareEncodeResponseBodyWithPurposesOnly = getVendorListContent(true, false, false) - private static String prepareEncodeResponseBodyWithLegIntPurposes = getVendorListContent(false, true, false) - private static String prepareEncodeResponseBodyWithLegIntAndFlexiblePurposes = getVendorListContent(false, true, true) - private static String prepareEncodeResponseBodyWithPurposesAndFlexiblePurposes = getVendorListContent(true, false, true) - protected static final int PURPOSES_ONLY_GVL_VERSION = PBSUtils.getRandomNumber(0, 4095) protected static final int LEG_INT_PURPOSES_ONLY_GVL_VERSION = PBSUtils.getRandomNumberWithExclusion(PURPOSES_ONLY_GVL_VERSION, 0, 4095) - protected static final int LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION = PBSUtils.getRandomNumberWithExclusion([PURPOSES_ONLY_GVL_VERSION, LEG_INT_PURPOSES_ONLY_GVL_VERSION], 0, 4095) - protected static final int PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION = PBSUtils.getRandomNumberWithExclusion([PURPOSES_ONLY_GVL_VERSION, LEG_INT_PURPOSES_ONLY_GVL_VERSION, LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION], 0, 4095) - protected static Map GLV_LISTS_FILES = [(getVendorListPath(PURPOSES_ONLY_GVL_VERSION)) : Transferable.of(prepareEncodeResponseBodyWithPurposesOnly), - (getVendorListPath(LEG_INT_PURPOSES_ONLY_GVL_VERSION)) : Transferable.of(prepareEncodeResponseBodyWithLegIntPurposes), - (getVendorListPath(LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION)): Transferable.of(prepareEncodeResponseBodyWithLegIntAndFlexiblePurposes), - (getVendorListPath(PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION)): Transferable.of(prepareEncodeResponseBodyWithPurposesAndFlexiblePurposes) - ] - - private static final Map GDPR_RESTRICTION_CONFIG = ["gdpr.strict-disclosed-vendors-treatment": 'false'] - protected static final Map VENDOR_LIST_EMPTY_CONFIG = ["gdpr.vendorlist.v2.http-endpoint-template": null, - "gdpr.vendorlist.v3.http-endpoint-template": null] - - protected static final Map TCF_BASE_CONFIG = SETTING_CONFIG + GENERIC_VENDOR_CONFIG + GENERIC_CONFIG + GDPR_RESTRICTION_CONFIG + protected static final int LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION = PBSUtils.getRandomNumberWithExclusion( + [PURPOSES_ONLY_GVL_VERSION, LEG_INT_PURPOSES_ONLY_GVL_VERSION], 0, 4095) + protected static final int PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION = PBSUtils.getRandomNumberWithExclusion( + [PURPOSES_ONLY_GVL_VERSION, LEG_INT_PURPOSES_ONLY_GVL_VERSION, LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION], 0, 4095) + + protected static final Map GVL_LISTS_FILES = [ + (getVendorListPath(PURPOSES_ONLY_GVL_VERSION)) : Transferable.of(getVendorListContent(true, false, false)), + (getVendorListPath(LEG_INT_PURPOSES_ONLY_GVL_VERSION)) : Transferable.of(getVendorListContent(false, true, false)), + (getVendorListPath(LEG_INT_AND_FLEXIBLE_PURPOSES_GVL_VERSION)) : Transferable.of(getVendorListContent(false, true, true)), + (getVendorListPath(PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION)): Transferable.of(getVendorListContent(true, false, true)) + ].asImmutable() + + private static final Map GDPR_RESTRICTION_CONFIG = ['gdpr.strict-disclosed-vendors-treatment': 'false'] + + protected static final PbsContainerConfig VENDOR_LIST_EMPTY_CONFIG = new PbsContainerConfig([ + 'gdpr.vendorlist.v2.http-endpoint-template': null, + 'gdpr.vendorlist.v3.http-endpoint-template': null + ]) + + protected static final PbsContainerConfig TCF_BASE_CONFIG = new PbsContainerConfig( + [:] << SETTING_CONFIG + << GENERIC_VENDOR_CONFIG + << GENERIC_CONFIG + << GDPR_RESTRICTION_CONFIG + ) protected static List getBasicTcfCompanyBasedEnforcementRequirements(Purpose purpose) { [new EnforcementRequirement(purpose: purpose, @@ -115,13 +122,13 @@ class TcfBaseSpec extends PrivacyBaseSpec { vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [UNDEFINED], vendorConsentBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [REQUIRE_CONSENT], vendorConsentBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), ] } @@ -180,7 +187,7 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [UNDEFINED], purposesLITransparency: true, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -188,7 +195,7 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [UNDEFINED], purposesLITransparency: true, vendorLegitimateInterestBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -196,14 +203,14 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [REQUIRE_LEGITIMATE_INTEREST], purposesLITransparency: true, vendorLegitimateInterestBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [REQUIRE_LEGITIMATE_INTEREST], purposesLITransparency: true, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]) ] } @@ -301,27 +308,27 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [UNDEFINED], enforcePurpose: NO, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [UNDEFINED], enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [UNDEFINED], enforcePurpose: NO, vendorConsentBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [UNDEFINED], enforcePurpose: NO, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -329,20 +336,20 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [REQUIRE_CONSENT], enforcePurpose: NO, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [REQUIRE_CONSENT], enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, vendorIdGvl: GENERIC_VENDOR_ID, restrictionType: [REQUIRE_CONSENT], enforcePurpose: NO, vendorConsentBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -350,7 +357,7 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [REQUIRE_LEGITIMATE_INTEREST], enforcePurpose: NO, enforceVendor: false, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -393,7 +400,7 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [UNDEFINED], enforcePurpose: NO, vendorLegitimateInterestBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]), new EnforcementRequirement(purpose: isPurposeExcludedAndListRandom ? getRandomPurposeWithExclusion(purpose) : purpose, @@ -401,7 +408,7 @@ class TcfBaseSpec extends PrivacyBaseSpec { restrictionType: [REQUIRE_LEGITIMATE_INTEREST], enforcePurpose: NO, vendorLegitimateInterestBitField: GENERIC_VENDOR_ID, - vendorListVersion: PURPOSES_AND_LEG_INT_PURPOSES_GVL_VERSION, + vendorListVersion: PURPOSES_AND_FLEXIBLE_PURPOSES_GVL_VERSION, disclosedVendorsId: [GENERIC_VENDOR_ID]) ] } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfFullTransmitEidsActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfFullTransmitEidsActivitiesSpec.groovy index 476cc206f3b..7894049de99 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfFullTransmitEidsActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfFullTransmitEidsActivitiesSpec.groovy @@ -1,6 +1,5 @@ package org.prebid.server.functional.tests.privacy.tcf - import org.prebid.server.functional.model.request.auction.Eid import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.util.privacy.TcfUtils @@ -21,7 +20,7 @@ class TcfFullTransmitEidsActivitiesSpec extends TcfBaseSpec { private static PrebidServerService privacyPbsServiceWithMultipleGvl def setupSpec() { - privacyPbsServiceWithMultipleGvl = pbsServiceFactory.getService(GENERAL_PRIVACY_CONFIG, GLV_LISTS_FILES) + privacyPbsServiceWithMultipleGvl = pbsServiceFactory.getService(GENERAL_PRIVACY_CONFIG.withFiles(GVL_LISTS_FILES)) } def cleanupSpec() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfGeneralSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfGeneralSpec.groovy index 4892e19fc37..34346d73dd0 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfGeneralSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TcfGeneralSpec.groovy @@ -7,6 +7,7 @@ import org.prebid.server.functional.model.config.PurposeConfig import org.prebid.server.functional.model.privacy.EnforcementRequirement import org.prebid.server.functional.model.response.auction.NoBidResponse import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.PBSUtils import org.prebid.server.functional.util.privacy.TcfConsent import org.prebid.server.functional.util.privacy.TcfUtils @@ -20,22 +21,25 @@ import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDO class TcfGeneralSpec extends TcfBaseSpec { - private final static ZonedDateTime TCF_2_3_ENFORCEMENT_DATE = ZonedDateTime.parse("2026-03-01T00:00:00Z") - private final static Map STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG = TCF_BASE_CONFIG + ["gdpr.strict-disclosed-vendors-treatment": 'true'] + private static final ZonedDateTime TCF_2_3_ENFORCEMENT_DATE = ZonedDateTime.parse("2026-03-01T00:00:00Z") private final static TCF_NO_DISCLOSED_VENDORS_METRIC = 'privacy.tcf.no-disclosed-vendors' private final static DISCLOSED_VENDORS_MESSAGE = 'Invalid TCF string: `disclosedVendors` list is empty.' + private static final PbsContainerConfig STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG = TCF_BASE_CONFIG + ['gdpr.strict-disclosed-vendors-treatment': 'true'] + private static final PbsContainerConfig BASE_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG = STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG + VENDOR_LIST_EMPTY_CONFIG + private static final PbsContainerConfig FULL_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG = STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG.withFiles(GVL_LISTS_FILES) + private static PrebidServerService pbsWithoutGvlVendorsWithStrictDvTreatment private static PrebidServerService pbsWithMultipleGvlListsWithStrictDvTreatment def setupSpec() { - pbsWithoutGvlVendorsWithStrictDvTreatment = pbsServiceFactory.getService(STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG + VENDOR_LIST_EMPTY_CONFIG) - pbsWithMultipleGvlListsWithStrictDvTreatment = pbsServiceFactory.getService(STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG, GLV_LISTS_FILES) + pbsWithoutGvlVendorsWithStrictDvTreatment = pbsServiceFactory.getService(BASE_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG) + pbsWithMultipleGvlListsWithStrictDvTreatment = pbsServiceFactory.getService(FULL_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG) } def cleanupSpec() { - pbsServiceFactory.removeContainer(STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG + VENDOR_LIST_EMPTY_CONFIG) - pbsServiceFactory.removeContainer(STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG) + pbsServiceFactory.removeContainer(BASE_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG) + pbsServiceFactory.removeContainer(FULL_STRICT_DISCLOSED_VENDOR_TREATMENT_CONFIG) } def "PBS should accept base consent when disclosedVendors includes vendor after TCF v2.3 enforcement"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TransmitEidsOrtbConverterActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TransmitEidsOrtbConverterActivitiesSpec.groovy index a1871f090e3..0f1429e78f7 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TransmitEidsOrtbConverterActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/tcf/TransmitEidsOrtbConverterActivitiesSpec.groovy @@ -7,6 +7,7 @@ import org.prebid.server.functional.model.request.auction.AllowActivities import org.prebid.server.functional.model.request.auction.Condition import org.prebid.server.functional.model.request.auction.Eid import org.prebid.server.functional.service.PrebidServerService +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.util.privacy.TcfUtils import static org.prebid.server.functional.model.bidder.BidderName.GENERIC @@ -25,18 +26,19 @@ import static org.prebid.server.functional.model.request.auction.TraceLevel.VERB class TransmitEidsOrtbConverterActivitiesSpec extends TcfBaseSpec { - private final static Map ORTB_2_5_TCF_CONFIG = TCF_BASE_CONFIG + ["adapters.generic.ortb-version": "2.5"] + private final static PbsContainerConfig ORTB_2_5_TCF_CONFIG = TCF_BASE_CONFIG + ["adapters.generic.ortb-version": "2.5"] + private final static PbsContainerConfig ORTB_2_5_FULL_TCF_CONFIG = TCF_BASE_CONFIG.withFiles(GVL_LISTS_FILES) + ["adapters.generic.ortb-version": "2.5"] private static PrebidServerService activityPbsServiceExcludeGvlWithElderOrtb private static PrebidServerService privacyPbsServiceWithMultipleGvlWithElderOrtb def setupSpec() { activityPbsServiceExcludeGvlWithElderOrtb = pbsServiceFactory.getService(ORTB_2_5_TCF_CONFIG + VENDOR_LIST_EMPTY_CONFIG) - privacyPbsServiceWithMultipleGvlWithElderOrtb = pbsServiceFactory.getService(ORTB_2_5_TCF_CONFIG, GLV_LISTS_FILES) + privacyPbsServiceWithMultipleGvlWithElderOrtb = pbsServiceFactory.getService(ORTB_2_5_FULL_TCF_CONFIG) } def cleanupSpec() { pbsServiceFactory.removeContainer(ORTB_2_5_TCF_CONFIG + VENDOR_LIST_EMPTY_CONFIG) - pbsServiceFactory.removeContainer(ORTB_2_5_TCF_CONFIG) + pbsServiceFactory.removeContainer(ORTB_2_5_FULL_TCF_CONFIG) } def "PPBS should leave ext.eids for older ORTB versions when requireConsent is enabled and #enforcementRequirements.purpose have any basic consent"() { diff --git a/src/test/groovy/org/prebid/server/functional/tests/prometheus/PrometheusSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/prometheus/PrometheusSpec.groovy index a4ff6ed63d5..4140503f254 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/prometheus/PrometheusSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/prometheus/PrometheusSpec.groovy @@ -1,6 +1,7 @@ package org.prebid.server.functional.tests.prometheus import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.testcontainers.container.PrebidServerContainer import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils @@ -122,17 +123,17 @@ class PrometheusSpec extends BaseSpec { serviceFailedToStartTimeoutMs) } - private Map getBasePrometheusConfig() { - ["metrics.prometheus.enabled": "true", - "metrics.prometheus.port" : PROMETHEUS_PORT as String] + private static PbsContainerConfig getBasePrometheusConfig() { + new PbsContainerConfig(["metrics.prometheus.enabled": "true", + "metrics.prometheus.port" : PROMETHEUS_PORT as String]) } - private Map getNamespaceSubsystemConfig(String namespace, String subsystem) { + private static Map getNamespaceSubsystemConfig(String namespace, String subsystem) { ["metrics.prometheus.namespace": namespace, "metrics.prometheus.subsystem": subsystem] } - private String normalizeMetricName(String metricName) { + private static String normalizeMetricName(String metricName) { metricName.replace(".", "_") .replace("-", "_") } diff --git a/src/test/groovy/org/prebid/server/functional/tests/storage/StorageBaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/storage/StorageBaseSpec.groovy index 583d6d97e06..94ed9fa2ab2 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/storage/StorageBaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/storage/StorageBaseSpec.groovy @@ -4,6 +4,7 @@ import org.prebid.server.functional.service.PrebidServerService import org.prebid.server.functional.service.S3Service import org.prebid.server.functional.testcontainers.Dependencies import org.prebid.server.functional.testcontainers.PbsServiceFactory +import org.prebid.server.functional.testcontainers.container.PbsContainerConfig import org.prebid.server.functional.tests.BaseSpec import org.prebid.server.functional.util.PBSUtils @@ -23,7 +24,7 @@ class StorageBaseSpec extends BaseSpec { s3Service.deleteBucket(DEFAULT_BUCKET) } - protected static Map s3StorageConfig = [ + protected static PbsContainerConfig s3StorageConfig = new PbsContainerConfig([ 'settings.s3.accessKeyId' : s3Service.accessKeyId, 'settings.s3.secretAccessKey' : s3Service.secretKeyId, 'settings.s3.endpoint' : s3Service.endpoint, @@ -33,10 +34,9 @@ class StorageBaseSpec extends BaseSpec { 'settings.s3.accounts-dir' : S3Service.DEFAULT_ACCOUNT_DIR, 'settings.s3.stored-imps-dir' : S3Service.DEFAULT_IMPS_DIR, 'settings.s3.stored-requests-dir' : S3Service.DEFAULT_REQUEST_DIR, - 'settings.s3.stored-responses-dir': S3Service.DEFAULT_RESPONSE_DIR, - ] + 'settings.s3.stored-responses-dir': S3Service.DEFAULT_RESPONSE_DIR]) - protected static Map mySqlDisabledConfig = + protected static PbsContainerConfig mySqlDisabledConfig = new PbsContainerConfig( ['settings.database.type' : null, 'settings.database.host' : null, 'settings.database.port' : null, @@ -48,9 +48,7 @@ class StorageBaseSpec extends BaseSpec { 'settings.database.account-query' : null, 'settings.database.stored-requests-query' : null, 'settings.database.amp-stored-requests-query': null, - 'settings.database.stored-responses-query' : null - ].asImmutable() as Map - + 'settings.database.stored-responses-query' : null]) protected PrebidServerService s3StoragePbsService = PbsServiceFactory.getService(s3StorageConfig + mySqlDisabledConfig) } diff --git a/src/test/groovy/org/prebid/server/functional/util/ContainerFileUtil.groovy b/src/test/groovy/org/prebid/server/functional/util/ContainerFileUtil.groovy new file mode 100644 index 00000000000..709ee5a9470 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/util/ContainerFileUtil.groovy @@ -0,0 +1,20 @@ +package org.prebid.server.functional.util + +import org.testcontainers.images.builder.Transferable + +class ContainerFileUtil implements ObjectMapperWrapper { + + static Map yamlFile(String path, Object content) { + [(path): Transferable.of(encodeYaml(content))] + } + + static Map jsonFile(String path, Object content) { + [(path): Transferable.of(encode(content))] + } + + static Map emptyFolders(String... paths) { + paths.collectEntries { path -> + [("$path/.keep".toString()): Transferable.of(new byte[0], 010755)] + } + } +} diff --git a/src/test/groovy/org/prebid/server/functional/util/HttpUtil.groovy b/src/test/groovy/org/prebid/server/functional/util/HttpUtil.groovy index c1f60516abf..1417bdb4558 100644 --- a/src/test/groovy/org/prebid/server/functional/util/HttpUtil.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/HttpUtil.groovy @@ -7,7 +7,6 @@ import static java.nio.charset.StandardCharsets.UTF_8 class HttpUtil implements ObjectMapperWrapper { - public static final String ACCEPT_HEADER = "Authorization" public static final String CONTENT_TYPE_HEADER = "Content-Type" public static final String COOKIE_HEADER = "cookie" diff --git a/src/test/groovy/org/prebid/server/functional/util/SystemProperties.groovy b/src/test/groovy/org/prebid/server/functional/util/SystemProperties.groovy index 410f9736991..765f03187db 100644 --- a/src/test/groovy/org/prebid/server/functional/util/SystemProperties.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/SystemProperties.groovy @@ -4,6 +4,8 @@ class SystemProperties { public static final String PBS_VERSION = System.getProperty("pbs.version")?.split("-")?.first() public static final boolean USE_FIXED_CONTAINER_PORTS = getPropertyOrDefault("tests.fixed-container-ports", false) + public static final boolean DEBUG_ENABLED = getPropertyOrDefault("tests.debug.enable", false) + public static final int MAX_CONTAINER = getPropertyOrDefault("tests.max-container-count", 5) public static final int DEFAULT_TIMEOUT = 5000 static int getPropertyOrDefault(String property, int defaultValue) { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/TcfUtils.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/TcfUtils.groovy index 5100c01fde8..72b7f8f1bb7 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/TcfUtils.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/TcfUtils.groovy @@ -63,7 +63,6 @@ class TcfUtils { } } - static ConsentString getConsentString(EnforcementRequirement requirement) { def purposeConsent = requirement.enforcePurpose != NO ? requirement.purpose : null def purposeId = purposeConsent ? PurposeId.convertPurposeToPurposeId(purposeConsent) : null diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCaV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCaV1Consent.groovy index 9b256e8b2f8..261c4bd6cb3 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCaV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCaV1Consent.groovy @@ -6,8 +6,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsCaliforniaV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsCaliforniaV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsCaV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCoV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCoV1Consent.groovy index 2903be57f36..d39705f79f8 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCoV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCoV1Consent.groovy @@ -5,8 +5,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsColoradoV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsColoradoV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsCoV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCtV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCtV1Consent.groovy index 5f832b08d1e..b343da6b80a 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCtV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsCtV1Consent.groovy @@ -5,8 +5,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsConnecticutV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsConnecticutV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsCtV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsNatV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsNatV1Consent.groovy index eaa1a49c333..9483e132c34 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsNatV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsNatV1Consent.groovy @@ -7,8 +7,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsNationalV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsNationalV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsNatV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsUtV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsUtV1Consent.groovy index 8b8dde2ad02..43c0a0e896b 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsUtV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsUtV1Consent.groovy @@ -5,8 +5,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsUtahV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsUtahV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsUtV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsVaV1Consent.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsVaV1Consent.groovy index 596bcbf1da0..197ae4a03fc 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsVaV1Consent.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/gpp/v1/UsVaV1Consent.groovy @@ -5,8 +5,8 @@ import org.prebid.server.functional.model.privacy.gpp.MspaMode import org.prebid.server.functional.model.privacy.gpp.Notice import org.prebid.server.functional.model.privacy.gpp.OptOut import org.prebid.server.functional.model.privacy.gpp.UsVirginiaV1ChildSensitiveData -import org.prebid.server.functional.util.privacy.gpp.GppConsent import org.prebid.server.functional.model.privacy.gpp.UsVirginiaV1SensitiveData +import org.prebid.server.functional.util.privacy.gpp.GppConsent class UsVaV1Consent extends GppConsent { diff --git a/src/test/groovy/org/prebid/server/functional/util/privacy/model/State.groovy b/src/test/groovy/org/prebid/server/functional/util/privacy/model/State.groovy index 9af51dceea3..1e56f4a4d88 100644 --- a/src/test/groovy/org/prebid/server/functional/util/privacy/model/State.groovy +++ b/src/test/groovy/org/prebid/server/functional/util/privacy/model/State.groovy @@ -8,8 +8,7 @@ enum State { //USA states ALABAMA("AL"), ALASKA("AK"), ARIZONA("AZ"); - - final String abbreviation; + final String abbreviation State(String abbreviation) { this.abbreviation = abbreviation