diff --git a/src/test/groovy/org/prebid/server/functional/model/config/AccountConfig.groovy b/src/test/groovy/org/prebid/server/functional/model/config/AccountConfig.groovy index 08bb7b4d1cf..c7a3c51d6ea 100644 --- a/src/test/groovy/org/prebid/server/functional/model/config/AccountConfig.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/config/AccountConfig.groovy @@ -19,6 +19,7 @@ class AccountConfig { AccountMetricsConfig metrics AccountCookieSyncConfig cookieSync AccountHooksConfiguration hooks + AccountSetting settings static getDefaultAccountConfig() { new AccountConfig(status: AccountStatus.ACTIVE) diff --git a/src/test/groovy/org/prebid/server/functional/model/config/AccountSetting.groovy b/src/test/groovy/org/prebid/server/functional/model/config/AccountSetting.groovy new file mode 100644 index 00000000000..0a056057229 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/model/config/AccountSetting.groovy @@ -0,0 +1,12 @@ +package org.prebid.server.functional.model.config + +import com.fasterxml.jackson.databind.PropertyNamingStrategies +import com.fasterxml.jackson.databind.annotation.JsonNaming +import groovy.transform.ToString + +@ToString(includeNames = true, ignoreNulls = true) +@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy) +class AccountSetting { + + Boolean geoLookup +} diff --git a/src/test/groovy/org/prebid/server/functional/model/pricefloors/Country.groovy b/src/test/groovy/org/prebid/server/functional/model/pricefloors/Country.groovy index b1d4368cf75..c9c55c129d7 100644 --- a/src/test/groovy/org/prebid/server/functional/model/pricefloors/Country.groovy +++ b/src/test/groovy/org/prebid/server/functional/model/pricefloors/Country.groovy @@ -5,23 +5,26 @@ import org.prebid.server.functional.util.privacy.model.State enum Country { - USA("USA"), - CAN("CAN"), - MULTIPLE("*") + USA("USA","US"), + CAN("CAN","CA"), + MULTIPLE("*","*") @JsonValue - final String value + final String ISOAlpha3 - Country(String value) { - this.value = value + final String ISOAlpha2 + + Country(String ISOAlpha3,String ISOAlpha2) { + this.ISOAlpha3 = ISOAlpha3 + this.ISOAlpha2 = ISOAlpha2 } @Override String toString() { - value + ISOAlpha3 } String withState(State state) { - return "${value}.${state.abbreviation}".toString() + return "${ISOAlpha3}.${state.abbreviation}".toString() } } diff --git a/src/test/groovy/org/prebid/server/functional/model/request/auction/PublicCountryIp.groovy b/src/test/groovy/org/prebid/server/functional/model/request/auction/PublicCountryIp.groovy new file mode 100644 index 00000000000..59fb0b34c25 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/model/request/auction/PublicCountryIp.groovy @@ -0,0 +1,16 @@ +package org.prebid.server.functional.model.request.auction + +enum PublicCountryIp { + + USA_IP("209.232.44.21", "d646:2414:17b2:f371:9b62:f176:b4c0:51cd"), + UKR_IP("193.238.111.14", "3080:f30f:e4bc:0f56:41be:6aab:9d0a:58e2"), + CAN_IP("70.71.245.39", "f9b2:c742:1922:7d4b:7122:c7fc:8b75:98c8") + + final String v4 + final String v6 + + PublicCountryIp(String v4, String ipV6) { + this.v4 = v4 + this.v6 = ipV6 + } +} diff --git a/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy new file mode 100644 index 00000000000..3a38deb3ff5 --- /dev/null +++ b/src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy @@ -0,0 +1,222 @@ +package org.prebid.server.functional.tests + +import org.prebid.server.functional.model.config.AccountAuctionConfig +import org.prebid.server.functional.model.config.AccountConfig +import org.prebid.server.functional.model.db.Account +import org.prebid.server.functional.model.pricefloors.Country +import org.prebid.server.functional.model.request.auction.BidRequest +import org.prebid.server.functional.model.config.AccountSetting +import org.prebid.server.functional.model.request.auction.Device +import org.prebid.server.functional.model.request.auction.Geo +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.pricefloors.Country.USA +import static org.prebid.server.functional.model.request.auction.PublicCountryIp.USA_IP +import static org.prebid.server.functional.model.request.auction.TraceLevel.VERBOSE +import static org.prebid.server.functional.util.privacy.model.State.ALABAMA +import static org.prebid.server.functional.util.privacy.model.State.ONTARIO + +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] + + def "PBS should populate geo with country and region when geo location enabled in host and account config"() { + given: "PBS service with geolocation and default account configs" + 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) + + and: "Default bid request with device and geo data" + def bidRequest = BidRequest.defaultBidRequest.tap { + device = new Device( + ip: USA_IP.v4, + ipv6: USA_IP.v6, + geo: new Geo( + country: null, + region: null, + lat: PBSUtils.getRandomDecimal(0, 90), + lon: PBSUtils.getRandomDecimal(0, 90))) + ext.prebid.trace = VERBOSE + } + + and: "Account in the DB" + def accountConfig = new AccountConfig( + auction: new AccountAuctionConfig(debugAllow: true), + settings: new AccountSetting(geoLookup: accountGeoLookup)) + def account = new Account(status: ACTIVE, uuid: bidRequest.site.publisher.id, config: accountConfig) + accountDao.save(account) + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain country and region" + def bidderRequests = bidder.getBidderRequest(bidRequest.id) + assert bidderRequests.device.geo.country == USA + assert bidderRequests.device.geo.region == ALABAMA.abbreviation + + and: "Metrics processed across activities should be updated" + def metrics = defaultPbsService.sendCollectedMetricsRequest() + assert metrics[GEO_LOCATION_REQUESTS] == 1 + assert metrics[GEO_LOCATION_SUCCESSFUL] == 1 + assert !metrics[GEO_LOCATION_FAIL] + + where: + defaultAccountGeoLookup | accountGeoLookup + false | true + true | true + true | null + } + + def "PBS shouldn't populate geo with country and region when geo location disable in host and account config enabled"() { + given: "PBS service with geolocation and default account configs" + 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]) + + and: "Default bid request with device and geo data" + def bidRequest = BidRequest.defaultBidRequest.tap { + device = new Device( + ip: USA_IP.v4, + ipv6: USA_IP.v6, + geo: new Geo( + country: null, + region: null, + lat: PBSUtils.getRandomDecimal(0, 90), + lon: PBSUtils.getRandomDecimal(0, 90))) + ext.prebid.trace = VERBOSE + } + + and: "Account in the DB" + def accountConfig = new AccountConfig( + auction: new AccountAuctionConfig(debugAllow: true), + settings: new AccountSetting(geoLookup: accountGeoLookup)) + def account = new Account(status: ACTIVE, uuid: bidRequest.site.publisher.id, config: accountConfig) + accountDao.save(account) + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request shouldn't contain country and region" + def bidderRequests = bidder.getBidderRequest(bidRequest.id) + assert !bidderRequests.device.geo.country + assert !bidderRequests.device.geo.region + + and: "Metrics processed across geo location shouldn't be updated" + def metrics = defaultPbsService.sendCollectedMetricsRequest() + assert !metrics[GEO_LOCATION_REQUESTS] + assert !metrics[GEO_LOCATION_SUCCESSFUL] + assert !metrics[GEO_LOCATION_FAIL] + + where: + defaultAccountGeoLookupConfig | hostGeolocation | accountGeoLookup + true | "true" | false + true | "false" | true + false | "false" | false + false | "true" | false + } + + def "PBS shouldn't populate geo with country, region and emit error in log and metric when geo look up failed"() { + given: "Test start time" + 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"]) + + and: "Default bid request with device and geo data" + def bidRequest = BidRequest.defaultBidRequest.tap { + device = new Device( + ip: USA_IP.v4, + ipv6: USA_IP.v6, + geo: new Geo( + country: null, + region: null, + lat: PBSUtils.getRandomDecimal(0, 90), + lon: PBSUtils.getRandomDecimal(0, 90))) + ext.prebid.trace = VERBOSE + } + + and: "Account in the DB" + def accountConfig = new AccountConfig( + auction: new AccountAuctionConfig(debugAllow: true), + settings: new AccountSetting(geoLookup: true)) + def account = new Account(status: ACTIVE, uuid: bidRequest.site.publisher.id, config: accountConfig) + accountDao.save(account) + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request shouldn't contain country and region" + def bidderRequests = bidder.getBidderRequest(bidRequest.id) + assert !bidderRequests.device.geo.country + assert !bidderRequests.device.geo.region + + and: "Metrics processed across geo location should be updated" + def metrics = defaultPbsService.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 getLocation = getLogsByText(logs, "GeoLocationServiceWrapper") + assert getLocation.size() == 1 + assert getLocation[0].contains("Geolocation lookup failed: " + + "ConfigurationGeoLocationService: Geo location lookup failed.") + } + + def "PBS shouldn't populate country and region via geo when geo enabled in account and country and region specified in request"() { + given: "PBS service with geolocation" + def defaultPbsService = pbsServiceFactory.getService( + ["geolocation.enabled": "true"] + GEO_LOCATION) + + and: "Default bid request with device and geo data" + def bidRequest = BidRequest.defaultBidRequest.tap { + device = new Device( + ip: USA_IP.v4, + ipv6: USA_IP.v6, + geo: new Geo( + country: Country.CAN, + region: ONTARIO.abbreviation, + lat: PBSUtils.getRandomDecimal(0, 90), + lon: PBSUtils.getRandomDecimal(0, 90))) + ext.prebid.trace = VERBOSE + } + + and: "Account in the DB" + def accountConfig = new AccountConfig( + auction: new AccountAuctionConfig(debugAllow: true), + settings: new AccountSetting(geoLookup: true)) + def account = new Account(status: ACTIVE, uuid: bidRequest.site.publisher.id, config: accountConfig) + accountDao.save(account) + + when: "PBS processes auction request" + defaultPbsService.sendAuctionRequest(bidRequest) + + then: "Bidder request should contain country and region" + def bidderRequests = bidder.getBidderRequest(bidRequest.id) + assert bidderRequests.device.geo.country == Country.CAN + assert bidderRequests.device.geo.region == ONTARIO.abbreviation + + and: "Metrics processed across activities shouldn't be updated" + def metrics = defaultPbsService.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/privacy/ActivityTraceLogSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/ActivityTraceLogSpec.groovy index 09d8c51b0e1..041738cc5ab 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/ActivityTraceLogSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/ActivityTraceLogSpec.groovy @@ -93,7 +93,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentName: GENERIC.value, componentType: BIDDER, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert fetchBidsActivity.ruleConfiguration.every { it == null } assert fetchBidsActivity.allowByDefault.contains(activity.defaultAction) assert fetchBidsActivity.result.contains("DISALLOW") @@ -133,7 +133,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentName: GENERIC.value, componentType: BIDDER, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert fetchBidsActivity.allowByDefault.contains(activity.defaultAction) assert fetchBidsActivity.ruleConfiguration.every { it == null } assert fetchBidsActivity.result.contains("ALLOW") @@ -148,7 +148,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentName: GENERIC.value, componentType: BIDDER, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert transmitUfpdActivity.allowByDefault.contains(activity.defaultAction) assert transmitUfpdActivity.ruleConfiguration.every { it == null } assert transmitUfpdActivity.result.every { it == null } @@ -163,7 +163,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentName: GENERIC.value, componentType: BIDDER, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert transmitPreciseGeoActivity.allowByDefault.contains(activity.defaultAction) assert transmitPreciseGeoActivity.ruleConfiguration.every { it == null } assert transmitPreciseGeoActivity.result.every { it == null } @@ -178,7 +178,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentName: GENERIC.value, componentType: BIDDER, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert transmitTidActivity.allowByDefault.contains(activity.defaultAction) assert transmitTidActivity.ruleConfiguration.every { it == null } assert transmitTidActivity.result.every { it == null } @@ -227,7 +227,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentType: BIDDER, gpc: bidRequest.regs.ext.gpc, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert fetchBidsActivity.ruleConfiguration.contains(new RuleConfiguration( componentNames: condition.componentName, componentTypes: condition.componentType, @@ -265,7 +265,7 @@ class ActivityTraceLogSpec extends PrivacyBaseSpec { componentType: BIDDER, gpc: bidRequest.regs.ext.gpc, region: ALABAMA.abbreviation, - country: USA.value)) + country: USA.ISOAlpha3)) assert transmitPreciseGeoActivity.ruleConfiguration.every { it == null } assert transmitPreciseGeoActivity.allowByDefault.contains(activity.defaultAction) assert transmitPreciseGeoActivity.result.every { it == null } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppFetchBidActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppFetchBidActivitiesSpec.groovy index 8ba421405f7..a2683a8b7ff 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppFetchBidActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppFetchBidActivitiesSpec.groovy @@ -372,7 +372,7 @@ class GppFetchBidActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - null | [USA.value] + null | [USA.ISOAlpha3] new Geo(country: USA) | null new Geo(region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: CAN, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] @@ -419,7 +419,7 @@ class GppFetchBidActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - new Geo(country: USA) | [USA.value] + new Geo(country: USA) | [USA.ISOAlpha3] new Geo(country: USA, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: USA, region: ALABAMA.abbreviation) | [CAN.withState(ONTARIO), USA.withState(ALABAMA)] } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppSyncUserActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppSyncUserActivitiesSpec.groovy index 4229a356033..42a096d2c55 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppSyncUserActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppSyncUserActivitiesSpec.groovy @@ -1,12 +1,17 @@ package org.prebid.server.functional.tests.privacy import org.prebid.server.functional.model.UidsCookie +import org.prebid.server.functional.model.config.AccountCcpaConfig +import org.prebid.server.functional.model.config.AccountConfig import org.prebid.server.functional.model.config.AccountGppConfig +import org.prebid.server.functional.model.config.AccountPrivacyConfig +import org.prebid.server.functional.model.config.AccountSetting import org.prebid.server.functional.model.config.ActivityConfig import org.prebid.server.functional.model.config.EqualityValueRule import org.prebid.server.functional.model.config.InequalityValueRule import org.prebid.server.functional.model.config.LogicalRestrictedRule import org.prebid.server.functional.model.config.GppModuleConfig +import org.prebid.server.functional.model.db.Account 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 @@ -63,6 +68,7 @@ import static org.prebid.server.functional.model.request.auction.ActivityType.SY import static org.prebid.server.functional.model.request.auction.PrivacyModule.ALL import static org.prebid.server.functional.model.request.auction.PrivacyModule.IAB_ALL import static org.prebid.server.functional.model.request.auction.PrivacyModule.IAB_US_CUSTOM_LOGIC +import static org.prebid.server.functional.model.request.auction.PublicCountryIp.USA_IP import static org.prebid.server.functional.util.privacy.model.State.MANITOBA import static org.prebid.server.functional.util.privacy.model.State.ALABAMA import static org.prebid.server.functional.util.privacy.model.State.ALASKA @@ -75,13 +81,15 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec { private static final String DISALLOWED_COUNT_FOR_ACTIVITY_RULE = "requests.activity.${SYNC_USER.metricValue}.disallowed.count" private static final String DISALLOWED_COUNT_FOR_GENERIC_ADAPTER = "adapter.${GENERIC.value}.activity.${SYNC_USER.metricValue}.disallowed.count" private static final String ALERT_GENERAL = "alerts.general" + private static final String GEO_LOCATION_REQUESTS = "geolocation_requests" + private static final String GEO_LOCATION_SUCCESSFUL = "geolocation_successful" private final static int INVALID_STATUS_CODE = 451 private final static String INVALID_STATUS_MESSAGE = "Unavailable For Legal Reasons." private static final Map GEO_LOCATION = ["geolocation.enabled" : "true", "geolocation.type" : "configuration", - "geolocation.configurations.[0].address-pattern": "209."] + "geolocation.configurations.[0].address-pattern": USA_IP.v4] def "PBS cookie sync call when bidder allowed in activities should include proper responded with bidders URLs and update processed metrics"() { given: "Cookie sync request with link to account" @@ -1683,12 +1691,12 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec { assert metrics[ACTIVITY_RULES_PROCESSED_COUNT] == 1 where: - countyConfig | regionConfig | conditionGeo - null | null | ["$USA.value".toString()] - USA.value | ALABAMA.abbreviation | null - CAN.value | ALASKA.abbreviation | [USA.withState(ALABAMA)] - null | MANITOBA.abbreviation | [USA.withState(ALABAMA)] - CAN.value | null | [USA.withState(ALABAMA)] + countyConfig | regionConfig | conditionGeo + null | null | ["$USA.ISOAlpha3".toString()] + USA.ISOAlpha3 | ALABAMA.abbreviation | null + CAN.ISOAlpha3 | ALASKA.abbreviation | [USA.withState(ALABAMA)] + null | MANITOBA.abbreviation | [USA.withState(ALABAMA)] + CAN.ISOAlpha3 | null | [USA.withState(ALABAMA)] } def "PBS setuid should process rule when geo doesn't intersection"() { @@ -1739,11 +1747,11 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec { assert metrics[ACTIVITY_RULES_PROCESSED_COUNT] == 1 where: - countyConfig | regionConfig | conditionGeo - null | null | [USA.value] - CAN.value | ALASKA.abbreviation | [USA.withState(ALABAMA)] - null | MANITOBA.abbreviation | [USA.withState(ALABAMA)] - CAN.value | null | [USA.withState(ALABAMA)] + countyConfig | regionConfig | conditionGeo + null | null | [USA.ISOAlpha3] + CAN.ISOAlpha3 | ALASKA.abbreviation | [USA.withState(ALABAMA)] + null | MANITOBA.abbreviation | [USA.withState(ALABAMA)] + CAN.ISOAlpha3 | null | [USA.withState(ALABAMA)] } def "PBS cookie sync should disallowed rule when device.geo intersection"() { @@ -1792,9 +1800,9 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec { assert metrics[DISALLOWED_COUNT_FOR_GENERIC_ADAPTER] == 1 where: - countyConfig | regionConfig | conditionGeo - USA.value | null | [USA.value] - USA.value | ALABAMA.abbreviation | [USA.withState(ALABAMA)] + countyConfig | regionConfig | conditionGeo + USA.ISOAlpha3 | null | [USA.ISOAlpha3] + USA.ISOAlpha3 | ALABAMA.abbreviation | [USA.withState(ALABAMA)] } def "PBS setuid should disallowed rule when device.geo intersection"() { @@ -1842,8 +1850,60 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec { assert exception.responseBody == INVALID_STATUS_MESSAGE where: - countyConfig | regionConfig | conditionGeo - USA.value | null | [USA.value] - USA.value | ALABAMA.abbreviation | [USA.withState(ALABAMA)] + countyConfig | regionConfig | conditionGeo + USA.ISOAlpha3 | null | [USA.ISOAlpha3] + USA.ISOAlpha3 | ALABAMA.abbreviation | [USA.withState(ALABAMA)] + } + + def "PBS cookie sync should fetch geo once when gpp sync user and account require geo look up"() { + given: "Pbs config with geo location" + def prebidServerService = pbsServiceFactory.getService(PBS_CONFIG + GEO_LOCATION + + ["geolocation.configurations.[0].geo-info.country": USA.ISOAlpha3, + "geolocation.configurations.[0].geo-info.region" : ALABAMA.abbreviation]) + + and: "Cookie sync request with account connection" + def accountId = PBSUtils.randomNumber as String + def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest.tap { + it.account = accountId + it.gppSid = null + it.gdpr = null + } + + and: "Setup condition" + def condition = Condition.baseCondition.tap { + it.componentType = null + it.componentName = null + it.gppSid = null + it.geo = [USA.withState(ALABAMA)] + } + + and: "Set activity" + def activity = Activity.getDefaultActivity([ActivityRule.getDefaultActivityRule(condition, false)]) + def activities = AllowActivities.getDefaultAllowActivities(SYNC_USER, activity) + + and: "Flush metrics" + flushMetrics(prebidServerService) + + and: "Set up account for allow activities" + def privacy = new AccountPrivacyConfig(ccpa: new AccountCcpaConfig(enabled: true), allowActivities: activities) + def accountConfig = new AccountConfig(privacy: privacy, settings: new AccountSetting(geoLookup: true)) + def account = new Account(uuid: accountId, config: accountConfig) + accountDao.save(account) + + when: "PBS processes cookie sync request with header" + def response = prebidServerService + .sendCookieSyncRequest(cookieSyncRequest, ["X-Forwarded-For": USA_IP.v4]) + + then: "Response should not contain any URLs for bidders" + assert !response.bidderStatus.userSync.url + + and: "Metrics for disallowed activities should be updated" + def metrics = prebidServerService.sendCollectedMetricsRequest() + assert metrics[DISALLOWED_COUNT_FOR_ACTIVITY_RULE] == 1 + assert metrics[DISALLOWED_COUNT_FOR_GENERIC_ADAPTER] == 1 + + and: "Metrics processed across activities should be updated" + assert metrics[GEO_LOCATION_REQUESTS] == 1 + assert metrics[GEO_LOCATION_SUCCESSFUL] == 1 } } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitEidsActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitEidsActivitiesSpec.groovy index ffecec814e2..a05f0e64b39 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitEidsActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitEidsActivitiesSpec.groovy @@ -386,7 +386,7 @@ class GppTransmitEidsActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - null | [USA.value] + null | [USA.ISOAlpha3] new Geo(country: USA) | null new Geo(region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: CAN, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] @@ -438,7 +438,7 @@ class GppTransmitEidsActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - new Geo(country: USA) | [USA.value] + new Geo(country: USA) | [USA.ISOAlpha3] new Geo(country: USA, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: USA, region: ALABAMA.abbreviation) | [CAN.withState(ONTARIO), USA.withState(ALABAMA)] } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitPreciseGeoActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitPreciseGeoActivitiesSpec.groovy index 431b66ab6cd..3372d8d0c15 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitPreciseGeoActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitPreciseGeoActivitiesSpec.groovy @@ -471,7 +471,7 @@ class GppTransmitPreciseGeoActivitiesSpec extends PrivacyBaseSpec { it.componentType = null it.componentName = [PBSUtils.randomString] it.gppSid = [USP_V1.intValue] - it.geo = ["$USA.value".toString()] + it.geo = ["$USA.ISOAlpha3".toString()] } and: "Set activity" @@ -561,7 +561,7 @@ class GppTransmitPreciseGeoActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - new Geo(country: USA) | [USA.value] + new Geo(country: USA) | [USA.ISOAlpha3] new Geo(country: USA, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: USA, region: ALABAMA.abbreviation) | [CAN.withState(ONTARIO), USA.withState(ALABAMA)] } diff --git a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitUfpdActivitiesSpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitUfpdActivitiesSpec.groovy index 5cd227ccef1..d056412e225 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitUfpdActivitiesSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/privacy/GppTransmitUfpdActivitiesSpec.groovy @@ -501,7 +501,7 @@ class GppTransmitUfpdActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - null | [USA.value] + null | [USA.ISOAlpha3] new Geo(country: USA) | null new Geo(region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: CAN, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] @@ -564,7 +564,7 @@ class GppTransmitUfpdActivitiesSpec extends PrivacyBaseSpec { where: deviceGeo | conditionGeo - new Geo(country: USA) | [USA.value] + new Geo(country: USA) | [USA.ISOAlpha3] new Geo(country: USA, region: ALABAMA.abbreviation) | [USA.withState(ALABAMA)] new Geo(country: USA, region: ALABAMA.abbreviation) | [CAN.withState(ONTARIO), USA.withState(ALABAMA)] }