@@ -10,14 +10,19 @@ import org.prebid.server.functional.model.request.auction.Site
1010import org.prebid.server.functional.service.PrebidServerException
1111import org.prebid.server.functional.util.PBSUtils
1212
13+ import java.time.Instant
14+
1315import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED
1416
1517class AccountSpec extends BaseSpec {
1618
1719 def " PBS should reject request with inactive account" () {
18- given : " Pbs config with enforce-valid-account and default-account-config"
19- def pbsService = pbsServiceFactory. getService(
20- [" settings.enforce-valid-account" : enforceValidAccount as String ])
20+ given : " Start up time"
21+ def start = Instant . now()
22+
23+ and : " Pbs config with enforce-valid-account"
24+ def pbsConfig = [" settings.enforce-valid-account" : enforceValidAccount as String ]
25+ def pbsService = pbsServiceFactory. getService(pbsConfig)
2126
2227 and : " Inactive account id"
2328 def accountId = PBSUtils . randomNumber
@@ -34,13 +39,56 @@ class AccountSpec extends BaseSpec {
3439
3540 then : " PBS should reject the entire auction"
3641 def exception = thrown(PrebidServerException )
42+ def warningMessage = " Account $accountId is inactive"
3743 assert exception. statusCode == UNAUTHORIZED . code()
38- assert exception. responseBody == " Account $accountId is inactive"
44+ assert exception. responseBody == warningMessage
45+
46+ and : " PBs should emit warning logs"
47+ def logsByTime = pbsService. getLogsByTime(start)
48+ assert getLogsByText(logsByTime, warningMessage). size() == 1
49+
50+ cleanup : " Stop and remove pbs container"
51+ pbsServiceFactory. removeContainer(pbsConfig)
3952
4053 where :
4154 enforceValidAccount << [true , false ]
4255 }
4356
57+ def " PBS shouldn't emit warning in logs when reject request with inactive account amd sampling-rate is disabled" () {
58+ given : " Start up time"
59+ def start = Instant . now()
60+
61+ and : " Pbs config with logging.sampling-rate"
62+ def pbsConfig = [" logging.sampling-rate" : " 0" ]
63+ def pbsService = pbsServiceFactory. getService(pbsConfig)
64+
65+ and : " Inactive account id"
66+ def accountId = PBSUtils . randomNumber
67+ def account = new Account (uuid : accountId, config : new AccountConfig (status : AccountStatus . INACTIVE ))
68+ accountDao. save(account)
69+
70+ and : " Default basic BidRequest with inactive account id"
71+ def bidRequest = BidRequest . defaultBidRequest. tap {
72+ site. publisher. id = accountId
73+ }
74+
75+ when : " PBS processes auction request"
76+ pbsService. sendAuctionRequest(bidRequest)
77+
78+ then : " PBS should reject the entire auction"
79+ def exception = thrown(PrebidServerException )
80+ def warningMessage = " Account $accountId is inactive"
81+ assert exception. statusCode == UNAUTHORIZED . code()
82+ assert exception. responseBody == warningMessage
83+
84+ and : " PBs shouldn't emit warning logs"
85+ def logsByTime = pbsService. getLogsByTime(start)
86+ assert ! getLogsByText(logsByTime, warningMessage)
87+
88+ cleanup : " Stop and remove pbs container"
89+ pbsServiceFactory. removeContainer(pbsConfig)
90+ }
91+
4492 def " PBS should reject request with unknown account when settings.enforce-valid-account = true" () {
4593 given : " Pbs config with enforce-valid-account and default-account-config"
4694 def pbsService = pbsServiceFactory. getService(
0 commit comments