-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
355 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/test/groovy/org/prebid/server/functional/model/config/AccountSetting.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/groovy/org/prebid/server/functional/model/request/auction/PublicCountryIp.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
222 changes: 222 additions & 0 deletions
222
src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.