Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Additonal coverage for geo #3080

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 200 additions & 8 deletions src/test/groovy/org/prebid/server/functional/tests/GeoSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GeoSpec extends BaseSpec {
"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"() {
def "PBS should populate geo with country and region when geo location enabled in host and account config and ip present in device.id"() {
given: "PBS service with geolocation and default account configs"
def config = AccountConfig.defaultAccountConfig.tap {
settings = new AccountSetting(geoLookup: defaultAccountGeoLookup)
Expand All @@ -54,7 +54,7 @@ class GeoSpec extends BaseSpec {
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)
def account = new Account(status: ACTIVE, uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
Expand All @@ -78,7 +78,57 @@ class GeoSpec extends BaseSpec {
true | null
}

def "PBS shouldn't populate geo with country and region when geo location disable in host and account config enabled"() {
def "PBS should populate geo with country and region when geo location enabled in host and account config and ip present in header"() {
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: null,
ipv6: null,
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.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4])

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 and ip present in device.ip"() {
given: "PBS service with geolocation and default account configs"
def config = AccountConfig.defaultAccountConfig.tap {
settings = new AccountSetting(geoLookup: defaultAccountGeoLookupConfig)
Expand All @@ -104,7 +154,7 @@ class GeoSpec extends BaseSpec {
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)
def account = new Account(status: ACTIVE, uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
Expand All @@ -129,7 +179,58 @@ class GeoSpec extends BaseSpec {
false | "true" | false
}

def "PBS shouldn't populate geo with country, region and emit error in log and metric when geo look up failed"() {
def "PBS shouldn't populate geo with country and region when geo location disable in host and account config enabled and ip present in header"() {
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: null,
ipv6: null,
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.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4])

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 and ip present in device.id"() {
given: "Test start time"
def startTime = Instant.now()

Expand All @@ -155,7 +256,7 @@ class GeoSpec extends BaseSpec {
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)
def account = new Account(status: ACTIVE, uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
Expand All @@ -180,7 +281,58 @@ class GeoSpec extends BaseSpec {
"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"() {
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"() {
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: null,
ipv6: null,
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.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4])

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 and ip present in device.id"() {
given: "PBS service with geolocation"
def defaultPbsService = pbsServiceFactory.getService(
["geolocation.enabled": "true"] + GEO_LOCATION)
Expand All @@ -202,7 +354,7 @@ class GeoSpec extends BaseSpec {
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)
def account = new Account(status: ACTIVE, uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
Expand All @@ -219,4 +371,44 @@ class GeoSpec extends BaseSpec {
assert !metrics[GEO_LOCATION_SUCCESSFUL]
assert !metrics[GEO_LOCATION_FAIL]
}

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)

and: "Default bid request with device and geo data"
def bidRequest = BidRequest.defaultBidRequest.tap {
device = new Device(
ip: null,
ipv6: null,
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.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request"
defaultPbsService.sendAuctionRequest(bidRequest, ["X-Forwarded-For": USA_IP.v4])

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]
}
}
Loading