11package org.prebid.server.functional.tests
22
3+ import org.prebid.server.functional.model.bidder.AppNexus
34import org.prebid.server.functional.model.bidder.Generic
45import org.prebid.server.functional.model.bidder.Openx
56import org.prebid.server.functional.model.request.auction.BidRequest
67import org.prebid.server.functional.service.PrebidServerException
7- import org.prebid.server.functional.testcontainers.Dependencies
8+ import org.prebid.server.functional.service.PrebidServerService
89import org.prebid.server.functional.util.PBSUtils
910
1011import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST
1112import static org.prebid.server.functional.model.bidder.BidderName.ALIAS
13+ import static org.prebid.server.functional.model.bidder.BidderName.APPNEXUS
1214import static org.prebid.server.functional.model.bidder.BidderName.BOGUS
1315import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
1416import static org.prebid.server.functional.model.bidder.BidderName.GENER_X
1517import static org.prebid.server.functional.model.bidder.BidderName.OPENX
1618import static org.prebid.server.functional.model.bidder.CompressionType.GZIP
19+ import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID
1720import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer
1821import static org.prebid.server.functional.util.HttpUtil.CONTENT_ENCODING_HEADER
1922
2023class AliasSpec extends BaseSpec {
2124
25+ private static final Map<String , String > ADDITIONAL_BIDDERS_CONFIG = [" adapters.${ OPENX.value} .enabled" : " true" ,
26+ " adapters.${ OPENX.value} .endpoint" : " $networkServiceContainer . rootUri /${ OPENX.value} /auction" . toString(),
27+ " adapters.${ APPNEXUS.value} .enabled" : " true" ,
28+ " adapters.${ APPNEXUS.value} .endpoint" : " $networkServiceContainer . rootUri /${ APPNEXUS.value} /auction" . toString()]
29+ private static PrebidServerService pbsServiceWithAdditionalBidders
30+
31+ def setupSpec () {
32+ pbsServiceWithAdditionalBidders = pbsServiceFactory. getService(ADDITIONAL_BIDDERS_CONFIG + GENERIC_ALIAS_CONFIG )
33+ }
34+
35+ def cleanupSpec () {
36+ pbsServiceFactory. removeContainer(ADDITIONAL_BIDDERS_CONFIG + GENERIC_ALIAS_CONFIG )
37+ }
38+
2239 def " PBS should be able to take alias from request" () {
2340 given : " Default bid request with alias"
2441 def bidRequest = BidRequest . defaultBidRequest. tap {
@@ -133,56 +150,19 @@ class AliasSpec extends BaseSpec {
133150 }
134151
135152 def " PBS aliased bidder config should be independently from parent" () {
136- given : " Pbs config"
137- def prebidServerService = pbsServiceFactory. getService(GENERIC_ALIAS_CONFIG )
138-
139- and : " Default bid request with alias"
153+ given : " Default bid request with alias"
140154 def bidRequest = BidRequest . defaultBidRequest. tap {
141155 imp[0 ]. ext. prebid. bidder. alias = new Generic ()
142156 }
143157
144158 when : " PBS processes auction request"
145- prebidServerService . sendAuctionRequest(bidRequest)
159+ pbsServiceWithAdditionalBidders . sendAuctionRequest(bidRequest)
146160
147161 then : " Bidder request should contain request per-alies"
148162 def bidderRequests = bidder. getBidderRequests(bidRequest. id)
149163 assert bidderRequests. size() == 2
150164 }
151165
152- def " PBS should ignore alias logic when hardcoded alias endpoints are present" () {
153- given : " PBs server with aliases config"
154- def pbsConfig = [" adapters.generic.aliases.alias.enabled" : " true" ,
155- " adapters.generic.aliases.alias.endpoint" : " $networkServiceContainer . rootUri /alias/auction" . toString(),
156- " adapters.openx.enabled" : " true" ,
157- " adapters.openx.endpoint" : " $networkServiceContainer . rootUri /openx/auction" . toString()]
158- def pbsService = pbsServiceFactory. getService(pbsConfig)
159-
160- and : " Default bid request with openx and alias bidder"
161- def bidRequest = BidRequest . defaultBidRequest. tap {
162- imp[0 ]. ext. prebid. bidder. alias = new Generic ()
163- imp[0 ]. ext. prebid. bidder. generic = new Generic ()
164- imp[0 ]. ext. prebid. bidder. openx = new Openx ()
165- ext. prebid. aliases = [(ALIAS . value): OPENX ]
166- }
167-
168- when : " PBS processes auction request"
169- def bidResponse = pbsService. sendAuctionRequest(bidRequest)
170-
171- then : " PBS should call only generic bidder"
172- def responseDebug = bidResponse. ext. debug
173- assert responseDebug. httpcalls[GENERIC . value]
174-
175- and : " PBS shouldn't call only opexn,alias bidder"
176- assert ! responseDebug. httpcalls[OPENX . value]
177- assert ! responseDebug. httpcalls[ALIAS . value]
178-
179- and : " PBS should call only generic bidder"
180- assert bidder. getBidderRequest(bidRequest. id)
181-
182- cleanup : " Stop and remove pbs container"
183- pbsServiceFactory. removeContainer(pbsConfig)
184- }
185-
186166 def " PBS should ignore aliases for requests with a base adapter" () {
187167 given : " PBs server with aliases config"
188168 def pbsConfig = [" adapters.openx.enabled" : " true" ,
@@ -209,6 +189,53 @@ class AliasSpec extends BaseSpec {
209189 pbsServiceFactory. removeContainer(pbsConfig)
210190 }
211191
192+ def " PBS should validate request as alias request and without any warnings when required properties in place" () {
193+ given : " Default bid request with openx and alias bidder"
194+ def bidRequest = BidRequest . defaultBidRequest. tap {
195+ imp[0 ]. ext. prebid. bidder. appNexus = AppNexus . default
196+ imp[0 ]. ext. prebid. bidder. generic = null
197+ ext. prebid. aliases = [(APPNEXUS . value): OPENX ]
198+ }
199+
200+ when : " PBS processes auction request"
201+ def bidResponse = pbsServiceWithAdditionalBidders. sendAuctionRequest(bidRequest)
202+
203+ then : " PBS contain http call for specific bidder"
204+ def responseDebug = bidResponse. ext. debug
205+ assert responseDebug. httpcalls. size() == 1
206+ assert responseDebug. httpcalls[APPNEXUS . value]* . uri == [" $networkServiceContainer . rootUri /${ APPNEXUS.value} /auction" ]
207+
208+ and : " PBS should not contain any warnings"
209+ assert ! bidResponse. ext. warnings
210+ }
211+
212+ def " PBS should validate request as alias request and emit proper warnings when validation fails for request" () {
213+ given : " Default bid request with openx and alias bidder"
214+ def bidRequest = BidRequest . defaultBidRequest. tap {
215+ imp[0 ]. ext. prebid. bidder. appNexus = new AppNexus ()
216+ imp[0 ]. ext. prebid. bidder. generic = null
217+ ext. prebid. aliases = [(APPNEXUS . value): OPENX ]
218+ }
219+
220+ when : " PBS processes auction request"
221+ def bidResponse = pbsServiceWithAdditionalBidders. sendAuctionRequest(bidRequest)
222+
223+ then : " PBS shouldn't contain http calls"
224+ assert ! bidResponse. ext. debug. httpcalls
225+
226+ and : " Bid response should contain warning"
227+ assert bidResponse. ext?. warnings[PREBID ]?. code == [999 , 999 ]
228+ assert bidResponse. ext?. warnings[PREBID ]* . message ==
229+ [" WARNING: request.imp[0].ext.prebid.bidder.${ APPNEXUS.value} was dropped with a reason: " +
230+ " request.imp[0].ext.prebid.bidder.${ APPNEXUS.value} failed validation.\n " +
231+ " \$ .placement_id: is missing but it is required\n " +
232+ " \$ .member: is missing but it is required\n " +
233+ " \$ .placementId: is missing but it is required\n " +
234+ " \$ .inv_code: is missing but it is required\n " +
235+ " \$ .invCode: is missing but it is required" ,
236+ " WARNING: request.imp[0].ext must contain at least one valid bidder" ]
237+ }
238+
212239 def " PBS should invoke as aliases when alias is unknown and core bidder is specified" () {
213240 given : " Default bid request with generic and alias bidder"
214241 def bidRequest = BidRequest . defaultBidRequest. tap {
0 commit comments