Skip to content

Commit

Permalink
Tests: Add functional tests for support testing label header (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
osulzhenko authored Feb 20, 2024
1 parent 8d498ce commit d3b1b89
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class AccountAuctionConfig {
Targeting targeting
@JsonProperty("preferredmediatype")
Map<BidderName, MediaType> preferredMediaType
@JsonProperty("privacysandbox")
PrivacySandbox privacySandbox
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
import org.prebid.server.functional.util.PBSUtils

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
class CookieDeprecation {

Boolean enabled
@JsonProperty("ttlsec")
Integer ttlSeconds

static CookieDeprecation getDefaultCookieDeprecation(Boolean enabled = true, Integer ttlSeconds = PBSUtils.randomNumber) {
new CookieDeprecation().tap {
it.enabled = enabled
it.ttlSeconds = ttlSeconds
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.functional.model.config

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
class PrivacySandbox {

CookieDeprecation cookieDeprecation

static PrivacySandbox getDefaultPrivacySandbox(Boolean enabled = true, Integer ttlSeconds = PBSUtils.randomNumber) {
new PrivacySandbox().tap {
cookieDeprecation = CookieDeprecation.getDefaultCookieDeprecation(enabled, ttlSeconds)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import groovy.transform.ToString
class DeviceExt {

Atts atts
String cdep

enum Atts {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.prebid.server.functional.model.response.cookiesync

import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
class RawCookieSyncResponse {

String responseBody
Map<String, String> headers
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.model.response.auction.RawAuctionResponse
import org.prebid.server.functional.model.response.biddersparams.BiddersParamsResponse
import org.prebid.server.functional.model.response.cookiesync.CookieSyncResponse
import org.prebid.server.functional.model.response.cookiesync.RawCookieSyncResponse
import org.prebid.server.functional.model.response.currencyrates.CurrencyRatesResponse
import org.prebid.server.functional.model.response.getuids.GetuidResponse
import org.prebid.server.functional.model.response.infobidders.BidderInfoResponse
Expand Down Expand Up @@ -151,6 +152,28 @@ class PrebidServerService implements ObjectMapperWrapper {
response.as(CookieSyncResponse)
}

@Step("[POST RAW] /cookie_sync with uids cookies")
RawCookieSyncResponse sendCookieSyncRequestRaw(CookieSyncRequest request, UidsCookie uidsCookie) {
def response = postCookieSync(request, uidsCookie)

new RawCookieSyncResponse().tap {
it.headers = getHeaders(response)
it.responseBody = response.body.asString()
}
}

@Step("[POST RAW] /cookie_sync with uids and additional cookies")
RawCookieSyncResponse sendCookieSyncRequestRaw(CookieSyncRequest request,
UidsCookie uidsCookie,
Map<String, String> additionalCookies) {
def response = postCookieSync(request, uidsCookie, additionalCookies)

new RawCookieSyncResponse().tap {
it.headers = getHeaders(response)
it.responseBody = response.body.asString()
}
}

@Step("[GET] /setuid")
SetuidResponse sendSetUidRequest(SetuidRequest request, UidsCookie uidsCookie, Map header = [:]) {
def uidsCookieAsJson = encode(uidsCookie)
Expand Down
166 changes: 164 additions & 2 deletions src/test/groovy/org/prebid/server/functional/tests/AuctionSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package org.prebid.server.functional.tests

import org.prebid.server.functional.model.UidsCookie
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.PrivacySandbox
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.DeviceExt
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
Expand All @@ -22,13 +27,16 @@ 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
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.GENERIC
import static org.prebid.server.functional.model.bidder.BidderName.GENERIC_CAMEL_CASE
import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID
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.COOKIE_DEPRECATION_HEADER
import static org.prebid.server.functional.util.SystemProperties.PBS_VERSION

class AuctionSpec extends BaseSpec {
Expand Down Expand Up @@ -306,7 +314,7 @@ class AuctionSpec extends BaseSpec {
def "PBS should move and not populate certain fields when debug enabled"() {
given: "Default bid request with aliases"
def bidRequest = BidRequest.defaultBidRequest.tap {
ext.prebid.aliases = [(PBSUtils.randomString):GENERIC]
ext.prebid.aliases = [(PBSUtils.randomString): GENERIC]
}

when: "Requesting PBS auction"
Expand Down Expand Up @@ -380,7 +388,7 @@ class AuctionSpec extends BaseSpec {
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.bidder.alias = new Generic()
imp[0].ext.prebid.bidder.generic = null
ext.prebid.aliases = [ (ALIAS.value): bidderName]
ext.prebid.aliases = [(ALIAS.value): bidderName]
user = new User(ext: new UserExt(prebid: new UserExtPrebid(buyeruids: [(GENERIC): buyeruid])))
}

Expand Down Expand Up @@ -431,4 +439,158 @@ class AuctionSpec extends BaseSpec {
where:
bidderName << [GENERIC, GENERIC_CAMEL_CASE]
}

def "PBS should set device.ext.cdep from header when cookieDeprecation and Deprecation header is specified"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Account in the DB"
def privacySandbox = PrivacySandbox.defaultPrivacySandbox
def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox)
def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig)
def account = new Account(uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

and: "Sec-Cookie-Deprecation header"
def secCookieDeprecation = [(COOKIE_DEPRECATION_HEADER): PBSUtils.randomString]

when: "PBS processes auction request with header"
defaultPbsService.sendAuctionRequest(bidRequest, secCookieDeprecation)

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

def "PBS shouldn't set device.ext.cdep from header when cookieDeprecation config is #privacySandbox"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Account in the DB"
def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox)
def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig)
def account = new Account(uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request with header"
defaultPbsService.sendAuctionRequest(bidRequest, [(COOKIE_DEPRECATION_HEADER): PBSUtils.randomString])

then: "BidderRequest shouldn't have device.ext.cdep"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert !bidderRequest?.device?.ext?.cdep

where:
privacySandbox << [null,
PrivacySandbox.getDefaultPrivacySandbox(null),
PrivacySandbox.getDefaultPrivacySandbox(false)]
}

def "PBS shouldn't set device.ext.cdep when cookieDeprecation config is specified and request don't have Sec-Cookie-Deprecation header"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Account in the DB"
def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: PrivacySandbox.defaultPrivacySandbox)
def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig)
def account = new Account(uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

when: "PBS processes auction request with header"
defaultPbsService.sendAuctionRequest(bidRequest)

then: "BidderRequest shouldn't have device.ext.cdep"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert !bidderRequest?.device?.ext?.cdep
}

def "PBS shouldn't update device.ext.cdep from Sec-Cookie-Deprecation header when it's present in original request"() {
given: "BidRequest with device.ext.cdep"
def cdep = PBSUtils.randomString
def bidRequest = BidRequest.defaultBidRequest.tap {
device = new Device(ext: new DeviceExt(cdep: cdep))
}

and: "Account in the DB"
def privacySandbox = PrivacySandbox.defaultPrivacySandbox
def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox)
def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig)
def account = new Account(uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

and: "Sec-Cookie-Deprecation header"
def secCookieDeprecation = [(COOKIE_DEPRECATION_HEADER): PBSUtils.randomString]

when: "PBS processes auction request with header"
defaultPbsService.sendAuctionRequest(bidRequest, secCookieDeprecation)

then: "BidderRequest should have original device.ext.cdep"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.device.ext.cdep == cdep
}

def "PBS should set device.ext.cdep from header when default account contain privacy sandbox and request account is empty"() {
given: "Pbs with default account that include privacySandbox configuration"
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: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Sec-Cookie-Deprecation header"
def secCookieDeprecation = [(COOKIE_DEPRECATION_HEADER): PBSUtils.randomString]

when: "PBS processes auction request with header"
pbsService.sendAuctionRequest(bidRequest, secCookieDeprecation)

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

def "PBS shouldn't set device.ext.cdep from header when default account don't contain privacy sandbox and request account is empty"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Sec-Cookie-Deprecation header"
def secCookieDeprecation = [(COOKIE_DEPRECATION_HEADER): PBSUtils.randomString]

when: "PBS processes auction request with header"
defaultPbsService.sendAuctionRequest(bidRequest, secCookieDeprecation)

then: "BidderRequest shouldn't have device.ext.cdep"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert !bidderRequest?.device?.ext?.cdep
}

def "PBS should include warning and don't set device.ext.cdep from header when Deprecation header is longer then 100 chars"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest

and: "Account in the DB"
def privacySandbox = PrivacySandbox.defaultPrivacySandbox
def accountAuctionConfig = new AccountAuctionConfig(privacySandbox: privacySandbox)
def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig)
def account = new Account(uuid: bidRequest.accountId, config: accountConfig)
accountDao.save(account)

and: "Long Sec-Cookie-Deprecation header"
def secCookieDeprecation = [(COOKIE_DEPRECATION_HEADER): PBSUtils.getRandomString(101)]

when: "PBS processes auction request with header"
def response = defaultPbsService.sendAuctionRequest(bidRequest, secCookieDeprecation)

then: "PBS should include warning in responce"
def auctionWarnings = response.ext?.warnings?.get(PREBID)
assert auctionWarnings.size() == 1
assert auctionWarnings[0].code == 999
assert auctionWarnings[0].message == 'Sec-Cookie-Deprecation header has invalid value'

and: "BidderRequest shouldn't have device.ext.cdep"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert !bidderRequest?.device?.ext?.cdep
}
}
Loading

0 comments on commit d3b1b89

Please sign in to comment.