Skip to content

Commit

Permalink
Test: bidder aliases (#3655)
Browse files Browse the repository at this point in the history
* Add functional tests for bidder aliases
  • Loading branch information
marki1an authored Jan 8, 2025
1 parent b481e3e commit 5346b90
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum BidderName {
ALIAS_CAMEL_CASE("AlIaS"),
GENERIC_CAMEL_CASE("GeNerIc"),
GENERIC("generic"),
GENER_X("gener_x"),
RUBICON("rubicon"),
APPNEXUS("appnexus"),
RUBICON_ALIAS("rubiconAlias"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Bidder {

Generic alias
Generic generic
@JsonProperty("gener_x")
Generic generX
@JsonProperty("GeNerIc")
Generic genericCamelCase
Rubicon rubicon
Expand Down
103 changes: 102 additions & 1 deletion src/test/groovy/org/prebid/server/functional/tests/AliasSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.prebid.server.functional.tests

import org.prebid.server.functional.model.bidder.Generic
import org.prebid.server.functional.model.bidder.Openx
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.testcontainers.Dependencies
import org.prebid.server.functional.util.PBSUtils

import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST
import static org.prebid.server.functional.model.bidder.BidderName.ALIAS
import static org.prebid.server.functional.model.bidder.BidderName.BOGUS
import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
import static org.prebid.server.functional.model.bidder.BidderName.GENER_X
import static org.prebid.server.functional.model.bidder.BidderName.OPENX
import static org.prebid.server.functional.model.bidder.CompressionType.GZIP
import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer
import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer
import static org.prebid.server.functional.util.HttpUtil.CONTENT_ENCODING_HEADER

class AliasSpec extends BaseSpec {
Expand Down Expand Up @@ -144,4 +148,101 @@ class AliasSpec extends BaseSpec {
def bidderRequests = bidder.getBidderRequests(bidRequest.id)
assert bidderRequests.size() == 2
}

def "PBS should ignore alias logic when hardcoded alias endpoints are present"() {
given: "PBs server with aliases config"
def pbsConfig = ["adapters.generic.aliases.alias.enabled" : "true",
"adapters.generic.aliases.alias.endpoint": "$networkServiceContainer.rootUri/alias/auction".toString(),
"adapters.openx.enabled" : "true",
"adapters.openx.endpoint" : "$networkServiceContainer.rootUri/openx/auction".toString()]
def pbsService = pbsServiceFactory.getService(pbsConfig)

and: "Default bid request with openx and alias bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.bidder.alias = new Generic()
imp[0].ext.prebid.bidder.generic = new Generic()
imp[0].ext.prebid.bidder.openx = new Openx()
ext.prebid.aliases = [(ALIAS.value): OPENX]
}

when: "PBS processes auction request"
def bidResponse = pbsService.sendAuctionRequest(bidRequest)

then: "PBS should call only generic bidder"
def responseDebug = bidResponse.ext.debug
assert responseDebug.httpcalls[GENERIC.value]

and: "PBS shouldn't call only opexn,alias bidder"
assert !responseDebug.httpcalls[OPENX.value]
assert !responseDebug.httpcalls[ALIAS.value]

and: "PBS should call only generic bidder"
assert bidder.getBidderRequest(bidRequest.id)

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should ignore aliases for requests with a base adapter"() {
given: "PBs server with aliases config"
def pbsConfig = ["adapters.openx.enabled" : "true",
"adapters.openx.endpoint": "$networkServiceContainer.rootUri/openx/auction".toString()]
def pbsService = pbsServiceFactory.getService(pbsConfig)

and: "Default bid request with openx and alias bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.bidder.openx = Openx.defaultOpenx
imp[0].ext.prebid.bidder.generic = new Generic()
ext.prebid.aliases = [(OPENX.value): GENERIC]
}

when: "PBS processes auction request"
def bidResponse = pbsService.sendAuctionRequest(bidRequest)

then: "PBS contain two http calls and the different url for both"
def responseDebug = bidResponse.ext.debug
assert responseDebug.httpcalls.size() == 2
assert responseDebug.httpcalls[OPENX.value]*.uri == ["$networkServiceContainer.rootUri/openx/auction"]
assert responseDebug.httpcalls[GENERIC.value]*.uri == ["$networkServiceContainer.rootUri/auction"]

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should invoke as aliases when alias is unknown and core bidder is specified"() {
given: "Default bid request with generic and alias bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.bidder.generX = new Generic()
ext.prebid.aliases = [(GENER_X.value): GENERIC]
}

when: "PBS processes auction request"
def bidResponse = defaultPbsService.sendAuctionRequest(bidRequest)

then: "PBS contain two http calls and the same url for both"
def responseDebug = bidResponse.ext.debug
assert responseDebug.httpcalls.size() == 2
assert responseDebug.httpcalls[GENER_X.value]*.uri == responseDebug.httpcalls[GENERIC.value]*.uri

and: "Bidder request should contain request per-alies"
def bidderRequests = bidder.getBidderRequests(bidRequest.id)
assert bidderRequests.size() == 2
}

def "PBS should invoke aliases when alias is unknown and no core bidder is specified"() {
given: "Default bid request with generic and alias bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.bidder.generX = new Generic()
imp[0].ext.prebid.bidder.generic = null
ext.prebid.aliases = [(GENER_X.value): GENERIC]
}

when: "PBS processes auction request"
def bidResponse = defaultPbsService.sendAuctionRequest(bidRequest)

then: "PBS contain two http calls and the same url for both"
def responseDebug = bidResponse.ext.debug
assert responseDebug.httpcalls.size() == 1
assert responseDebug.httpcalls[GENER_X.value]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.functional.tests

import org.prebid.server.functional.model.bidder.Generic
import org.prebid.server.functional.model.bidder.Openx
import org.prebid.server.functional.model.db.StoredImp
import org.prebid.server.functional.model.request.auction.BidRequest
Expand Down Expand Up @@ -103,8 +104,10 @@ class ImpRequestSpec extends BaseSpec {
imp.first.tap {
pmp = Pmp.defaultPmp
ext.prebid.imp = [(aliasName): new Imp(pmp: extPmp)]
ext.prebid.bidder.generic = null
ext.prebid.bidder.alias = new Generic()
}
ext.prebid.aliases = [(aliasName.value): GENERIC]
ext.prebid.aliases = [(aliasName.value): bidderName]
}

when: "Requesting PBS auction"
Expand Down

0 comments on commit 5346b90

Please sign in to comment.