Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.functional.tests

import org.prebid.server.functional.model.db.StoredRequest
import org.prebid.server.functional.model.request.amp.Targeting
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.Format
import org.prebid.server.functional.model.request.auction.Imp
Expand All @@ -13,6 +14,8 @@ import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.util.PBSUtils
import spock.lang.PendingFeature

import java.nio.charset.StandardCharsets

import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID

class GeneralGetInterfaceImpSpec extends BaseSpec {
Expand Down Expand Up @@ -1675,4 +1678,60 @@ class GeneralGetInterfaceImpSpec extends BaseSpec {
it.nvol == audioImp.audio.nvol
}
}

def "PBS get request should move targeting key to imp.ext.data"() {
given: "Create targeting"
def targeting = new Targeting().tap {
any = PBSUtils.randomString
}

and: "Encode Targeting to String"
def encodeTargeting = URLEncoder.encode(encode(targeting), StandardCharsets.UTF_8)

and: "Amp request with targeting"
def generalGetRequest = GeneralGetRequest.default.tap {
it.targeting = encodeTargeting
}

and: "Default BidRequest"
def bidRequest = BidRequest.defaultBidRequest

and: "Create and save stored request into DB"
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, bidRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
defaultPbsService.sendGeneralGetRequest(generalGetRequest)

then: "Amp response should contain value from targeting in imp.ext.data"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not amp response.

def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.imp[0].ext.data.any == targeting.any
}

def "PBS should throw exception when general get request linked to stored request with several imps"() {
given: "Stored request with several imps"
def request = BidRequest.getDefaultBidRequest().tap {
addImp(Imp.defaultImpression)
setAccountId(accountId)
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
storedRequestDao.save(storedRequest)

when: "PBS processes general get request"
defaultPbsService.sendGeneralGetRequest(generalGetRequest)

then: "PBs should throw error due to invalid request"
def exception = thrown(PrebidServerException)
assert exception.statusCode == 400
assert exception.responseBody == "data for tag_id '${generalGetRequest.resolveStoredRequestId()}' includes '${request.imp.size()}'" +
" imp elements. Only one is allowed"

where:
generalGetRequest << [
new GeneralGetRequest(storedRequestId: PBSUtils.randomNumber),
new GeneralGetRequest(storedRequestIdLegacy: PBSUtils.randomNumber)
]
}
}
106 changes: 50 additions & 56 deletions src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1519,32 +1519,61 @@ class ProfileSpec extends BaseSpec {
]
}

def "PBS should throw exception when profiles are not configured for filesystem and request contain profileId"() {
def "PBS should process request when profiles are not configured for filesystem and request contain profileId"() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process request with a warning

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)
pbsContainer.withCopyToContainer(Transferable.of(encode(fileRequestProfileWithEmptyMerge)), "$PROFILES_PATH/${fileRequestProfileWithEmptyMerge.fileName}")
def accountsConfig = new FileSystemAccountsConfig(accounts: [new AccountConfig(id: ACCOUNT_ID_FILE_STORAGE, status: ACTIVE)])
pbsContainer.withCopyToContainer(Transferable.of(encodeYaml(accountsConfig)),
SETTINGS_FILENAME)
pbsContainer.start()
def pbsWithStoredProfiles = new PrebidServerService(pbsContainer)

and: "BidRequest with profile"
def requestWithProfile = BidRequest.getDefaultBidRequest().tap {
it.ext.prebid.profileNames = [PBSUtils.randomString]
}
def requestWithProfile = getRequestWithProfiles(ACCOUNT_ID_FILE_STORAGE.toString(), [fileRequestProfileWithEmptyMerge]).tap {
it.device = Device.default
} as BidRequest

when: "PBS processes auction request"
pbsWithStoredProfiles.sendAuctionRequest(requestWithProfile)
def response = pbsWithStoredProfiles.sendAuctionRequest(requestWithProfile)

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
then: "PBS should emit proper warning"
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_REQUEST_PROFILE_MESSAGE.formatted(fileRequestProfileWithEmptyMerge.id)]

and: "Response should contain error"
assert !response.ext?.errors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should or not?


and: "Missing metric should increments"
def metrics = pbsWithStoredProfiles.sendCollectedMetricsRequest()
assert metrics[MISSING_ACCOUNT_PROFILE_METRIC.formatted(ACCOUNT_ID_FILE_STORAGE)] == 1

and: "Bidder request should contain data from profile"
verifyAll(bidder.getBidderRequest(requestWithProfile.id)) {
it.site.id == requestWithProfile.site.id
it.site.name == requestWithProfile.site.name
it.site.domain == requestWithProfile.site.domain
it.site.cat == requestWithProfile.site.cat
it.site.sectionCat == requestWithProfile.site.sectionCat
it.site.pageCat == requestWithProfile.site.pageCat
it.site.page == requestWithProfile.site.page
it.site.ref == requestWithProfile.site.ref
it.site.search == requestWithProfile.site.search
it.site.keywords == requestWithProfile.site.keywords

it.device.didsha1 == requestWithProfile.device.didsha1
it.device.didmd5 == requestWithProfile.device.didmd5
it.device.dpidsha1 == requestWithProfile.device.dpidsha1
it.device.ifa == requestWithProfile.device.ifa
it.device.macsha1 == requestWithProfile.device.macsha1
it.device.macmd5 == requestWithProfile.device.macmd5
it.device.dpidmd5 == requestWithProfile.device.dpidmd5
}

cleanup: "Stop and remove pbs container"
pbsContainer.stop()
Expand All @@ -1563,15 +1592,16 @@ class ProfileSpec extends BaseSpec {

and: "Default stored request"
def request = BidRequest.getDefaultBidRequest().tap {
it.device = Device.default
setAccountId(accountId)
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getStoredRequest(getRequest.resolveStoredRequestId(), request)
def storedRequest = StoredRequest.getStoredRequest(getRequest.storedRequestId, request)
storedRequestDao.save(storedRequest)

when: "PBS processes general get request"
def response = pbsWithStoredProfiles.(getRequest)
def response = pbsWithStoredProfiles.sendGeneralGetRequest(getRequest)

then: "Response should not contain errors and warnings"
assert !response.ext?.errors
Expand All @@ -1589,7 +1619,6 @@ class ProfileSpec extends BaseSpec {
it.site.ref == requestProfile.body.site.ref
it.site.search == requestProfile.body.site.search
it.site.keywords == requestProfile.body.site.keywords
it.site.ext.data == requestProfile.body.site.ext.data

it.device.didsha1 == requestProfile.body.device.didsha1
it.device.didmd5 == requestProfile.body.device.didmd5
Expand Down Expand Up @@ -1723,6 +1752,7 @@ class ProfileSpec extends BaseSpec {

and: "Default stored request"
def request = BidRequest.getDefaultBidRequest().tap {
it.device = Device.default
setAccountId(accountId)
}

Expand Down Expand Up @@ -1756,7 +1786,6 @@ class ProfileSpec extends BaseSpec {
it.site.ref == request.site.ref
it.site.search == request.site.search
it.site.keywords == request.site.keywords
it.site.ext.data == request.site.ext.data

it.device.didsha1 == request.device.didsha1
it.device.didmd5 == request.device.didmd5
Expand Down Expand Up @@ -1816,19 +1845,20 @@ class ProfileSpec extends BaseSpec {
and: "Default stored request"
def accountId = PBSUtils.randomNumber as String
def request = BidRequest.getDefaultBidRequest().tap {
it.device = Device.default
setAccountId(accountId)
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, request)
storedRequestDao.save(storedRequest)

when: "PBS processes general get request"
def response = pbsWithStoredProfiles.sendGeneralGetRequest(generalGetRequest)

then: "PBS should emit proper warning"
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_PROFILE_MESSAGE.formatted(requestProfile)]
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_REQUEST_PROFILE_MESSAGE.formatted(requestProfile)]

and: "Response should contain error"
assert !response.ext?.errors
Expand All @@ -1849,7 +1879,6 @@ class ProfileSpec extends BaseSpec {
it.site.ref == request.site.ref
it.site.search == request.site.search
it.site.keywords == request.site.keywords
it.site.ext.data == request.site.ext.data

it.device.didsha1 == request.device.didsha1
it.device.didmd5 == request.device.didmd5
Expand All @@ -1871,14 +1900,15 @@ class ProfileSpec extends BaseSpec {

def "PBS should emit error and metrics when imp profile missing for profile general get parameter"() {
given: "Default GeneralGetRequest"
def impProfile = PBSUtils.randomString
def impProfileId = PBSUtils.randomString
def generalGetRequest = GeneralGetRequest.default.tap {
it.impProfiles = [impProfile]
it.impProfiles = [impProfileId]
}

and: "Default stored request"
def accountId = PBSUtils.randomNumber as String
def request = BidRequest.getDefaultBidRequest().tap {
it.device = Device.default
setAccountId(accountId)
}

Expand All @@ -1891,7 +1921,7 @@ class ProfileSpec extends BaseSpec {

then: "PBS should emit proper warning"
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_PROFILE_MESSAGE.formatted(impProfile.id)]
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_IMP_PROFILE_MESSAGE.formatted(impProfileId)]

and: "Response should contain error"
assert !response.ext?.errors
Expand All @@ -1912,7 +1942,6 @@ class ProfileSpec extends BaseSpec {
it.site.ref == request.site.ref
it.site.search == request.site.search
it.site.keywords == request.site.keywords
it.site.ext.data == request.site.ext.data

it.device.didsha1 == request.device.didsha1
it.device.didmd5 == request.device.didmd5
Expand Down Expand Up @@ -2022,7 +2051,7 @@ class ProfileSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.getStoredAuctionResponseId(), request)
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, request)
storedRequestDao.save(storedRequest)

when: "PBS processes general get request"
Expand Down Expand Up @@ -2091,41 +2120,6 @@ class ProfileSpec extends BaseSpec {
}
}

def "PBS should apply imp profile for all imps when profile included as parameter for with multi-imps general get request"() {
given: "Default profile in database"
def accountId = PBSUtils.randomNumber as String
def impProfile = ImpProfile.getProfile(accountId)
profileImpDao.save(StoredProfileImp.getProfile(impProfile))

and: "Default GeneralGetRequest"
def generalGetRequest = GeneralGetRequest.default.tap {
it.impProfiles = [impProfile.id]
}

and: "Default stored request"
def request = BidRequest.getDefaultBidRequest().tap {
addImp(Imp.defaultImpression)
setAccountId(accountId)
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
storedRequestDao.save(storedRequest)

when: "PBS processes general get request"
def response = pbsWithStoredProfiles.sendGeneralGetRequest(generalGetRequest)

then: "Response should not contain errors and warnings"
assert !response.ext?.errors
assert !response.ext?.warnings

and: "Bidder request imp should contain data from profile"
verifyAll(bidder.getBidderRequest(request.id).imp) {
it.id == [impProfile.body.id] * 2
it.banner == [impProfile.body.banner] * 2
}
}

private static BidRequest getRequestWithProfiles(String accountId, List<Profile> profiles) {
BidRequest.getDefaultBidRequest().tap {
it.imp.first.ext.prebid.profileNames = profiles.findAll { it.type == ProfileType.IMP }*.id
Expand Down