@@ -4,6 +4,7 @@ import org.prebid.server.functional.model.config.AccountAuctionConfig
44import org.prebid.server.functional.model.config.AccountCacheConfig
55import org.prebid.server.functional.model.config.AccountConfig
66import org.prebid.server.functional.model.config.AccountEventsConfig
7+ import org.prebid.server.functional.model.config.AccountVtrackConfig
78import org.prebid.server.functional.model.db.Account
89import org.prebid.server.functional.model.request.auction.Asset
910import org.prebid.server.functional.model.request.auction.BidRequest
@@ -13,8 +14,10 @@ import org.prebid.server.functional.model.request.vtrack.VtrackRequest
1314import org.prebid.server.functional.model.request.vtrack.xml.Vast
1415import org.prebid.server.functional.model.response.auction.Adm
1516import org.prebid.server.functional.model.response.auction.BidResponse
17+ import org.prebid.server.functional.service.PrebidServerException
1618import org.prebid.server.functional.util.PBSUtils
1719
20+ import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST
1821import static org.prebid.server.functional.model.response.auction.ErrorType.CACHE
1922import static org.prebid.server.functional.model.AccountStatus.ACTIVE
2023import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
@@ -607,7 +610,7 @@ class CacheSpec extends BaseSpec {
607610 assert prebidCache. getRequestCount(bidRequest. imp[0 ]. id) == 1
608611
609612 and : " Bid response targeting should contain value"
610- verifyAll (bidResponse?. seatbid[0 ]?. bid[0 ]?. ext?. prebid?. targeting as Map ) {
613+ verifyAll(bidResponse?. seatbid[0 ]?. bid[0 ]?. ext?. prebid?. targeting as Map ) {
611614 it. get(" hb_cache_id" )
612615 it. get(" hb_cache_id_generic" )
613616 it. get(" hb_cache_path" ) == CACHE_PATH
@@ -643,7 +646,7 @@ class CacheSpec extends BaseSpec {
643646 assert prebidCache. getRequestCount(bidRequest. imp[0 ]. id) == 1
644647
645648 and : " Bid response targeting should contain value"
646- verifyAll (bidResponse. seatbid[0 ]. bid[0 ]. ext. prebid. targeting) {
649+ verifyAll(bidResponse. seatbid[0 ]. bid[0 ]. ext. prebid. targeting) {
647650 it. get(" hb_cache_id" )
648651 it. get(" hb_cache_id_generic" )
649652 it. get(" hb_cache_path" ) == INTERNAL_CACHE_PATH
@@ -785,4 +788,119 @@ class CacheSpec extends BaseSpec {
785788 where :
786789 enabledCacheConcfig << [null , false , true ]
787790 }
791+
792+ def " PBS should failed VTrack request when sending request without account" () {
793+ given : " Default VtrackRequest"
794+ def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
795+ def request = VtrackRequest . getDefaultVtrackRequest(creative)
796+
797+ and : " Flush metrics"
798+ flushMetrics(defaultPbsService)
799+
800+ when : " PBS processes vtrack request"
801+ defaultPbsService. sendVtrackRequest(request, null )
802+
803+ then : " Request should fail with an error"
804+ def exception = thrown(PrebidServerException )
805+ assert exception. statusCode == BAD_REQUEST . code()
806+ assert exception. responseBody == " Account 'a' is required query parameter and can't be empty"
807+ }
808+
809+ def " PBS shouldn't use negative value in tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl" () {
810+ given : " Default VtrackRequest"
811+ def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
812+ def request = VtrackRequest . getDefaultVtrackRequest(creative). tap {
813+ puts[0 ]. ttlseconds = requestedTtl
814+ }
815+
816+ and : " Create and save vtrack in account"
817+ def accountId = PBSUtils . randomNumber. toString()
818+ def account = new Account (). tap {
819+ it. uuid = accountId
820+ it. config = new AccountConfig (). tap {
821+ it. vtrack = new AccountVtrackConfig (ttl : accountTtl)
822+ }
823+ }
824+ accountDao. save(account)
825+
826+ and : " Flush metrics"
827+ flushMetrics(defaultPbsService)
828+
829+ when : " PBS processes vtrack request"
830+ defaultPbsService. sendVtrackRequest(request, accountId)
831+
832+ then : " Pbs should emit creative_ttl.xml with lowest value"
833+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
834+ assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC . formatted(accountId)]
835+ == [requestedTtl, accountTtl]. findAll { it -> it > 0 }. min()
836+
837+ where :
838+ requestedTtl | accountTtl
839+ PBSUtils . getRandomNumber(300 , 1500 ) as Integer | PBSUtils . getRandomNegativeNumber(-1500 , 300 ) as Integer
840+ PBSUtils . getRandomNegativeNumber(-1500 , 300 ) as Integer | PBSUtils . getRandomNumber(300 , 1500 ) as Integer
841+ PBSUtils . getRandomNegativeNumber(-1500 , 300 ) as Integer | PBSUtils . getRandomNegativeNumber(-1500 , 300 ) as Integer
842+ }
843+
844+ def " PBS should use lowest tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl" () {
845+ given : " Default VtrackRequest"
846+ def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
847+ def request = VtrackRequest . getDefaultVtrackRequest(creative). tap {
848+ puts[0 ]. ttlseconds = requestedTtl
849+ }
850+
851+ and : " Create and save vtrack in account"
852+ def accountId = PBSUtils . randomNumber. toString()
853+ def account = new Account (). tap {
854+ it. uuid = accountId
855+ it. config = new AccountConfig (). tap {
856+ it. vtrack = new AccountVtrackConfig (ttl : accountTtl)
857+ }
858+ }
859+ accountDao. save(account)
860+
861+ and : " Flush metrics"
862+ flushMetrics(defaultPbsService)
863+
864+ when : " PBS processes vtrack request"
865+ defaultPbsService. sendVtrackRequest(request, accountId)
866+
867+ then : " Pbs should emit creative_ttl.xml with lowest value"
868+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
869+ assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC . formatted(accountId)] == [requestedTtl, accountTtl]. min()
870+
871+ where :
872+ requestedTtl | accountTtl
873+ null | null
874+ null | PBSUtils . getRandomNumber(300 , 1500 ) as Integer
875+ PBSUtils . getRandomNumber(300 , 1500 ) as Integer | null
876+ PBSUtils . getRandomNumber(300 , 1500 ) as Integer | PBSUtils . getRandomNumber(300 , 1500 ) as Integer
877+ }
878+
879+ def " PBS should proceed request when account ttl and request ttl second are empty" () {
880+ given : " Default VtrackRequest"
881+ def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
882+ def request = VtrackRequest . getDefaultVtrackRequest(creative). tap {
883+ puts[0 ]. ttlseconds = null
884+ }
885+
886+ and : " Create and save vtrack in account"
887+ def accountId = PBSUtils . randomNumber. toString()
888+ def account = new Account (). tap {
889+ it. uuid = accountId
890+ it. config = new AccountConfig (). tap {
891+ it. vtrack = new AccountVtrackConfig (ttl : null )
892+ }
893+ }
894+ accountDao. save(account)
895+
896+ and : " Flush metrics"
897+ flushMetrics(defaultPbsService)
898+
899+ when : " PBS processes vtrack request"
900+ defaultPbsService. sendVtrackRequest(request, accountId)
901+
902+ then : " Pbs shouldn't emit creative_ttl.xml"
903+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
904+ assert ! metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC . formatted(accountId)]
905+ }
788906}
0 commit comments