@@ -31,7 +31,6 @@ import org.prebid.server.functional.util.privacy.gpp.data.UsUtahSensitiveData
3131
3232import java.time.Instant
3333
34- import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST
3534import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
3635import static org.prebid.server.functional.model.config.DataActivity.CONSENT
3736import static org.prebid.server.functional.model.config.DataActivity.NOTICE_NOT_PROVIDED
@@ -483,8 +482,11 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
483482 ]
484483 }
485484
486- def " PBS cookie sync call when privacy module contain invalid GPP string should exclude bidders URLs" () {
487- given : " Cookie sync request with link to account"
485+ def " PBS cookie sync call when privacy module contain invalid GPP segment should respond with required bidder URL and emit error log" () {
486+ given : " Test start time"
487+ def startTime = Instant . now()
488+
489+ and : " Cookie sync request with link to account"
488490 def accountId = PBSUtils . randomString
489491 def cookieSyncRequest = CookieSyncRequest . defaultCookieSyncRequest. tap {
490492 it. gppSid = US_NAT_V1 . value
@@ -506,14 +508,68 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
506508 def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
507509 accountDao. save(account)
508510
511+ and : " Flush metrics"
512+ flushMetrics(activityPbsService)
513+
509514 when : " PBS processes cookie sync request"
510515 def response = activityPbsService. sendCookieSyncRequest(cookieSyncRequest)
511516
512- then : " Response should not contain any URLs for bidders"
513- assert ! response. bidderStatus. userSync. url
517+ then : " Response should contain bidders userSync.urls"
518+ assert response. getBidderUserSync(GENERIC ). userSync. url
519+
520+ and : " Metrics processed across activities should be updated"
521+ def metrics = activityPbsService. sendCollectedMetricsRequest()
522+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(cookieSyncRequest, SYNC_USER )] == 1
523+ assert metrics[ALERT_GENERAL . value] == 1
514524
515- and : " Response should not contain any warning "
525+ and : " Response shouldn't contain warnings "
516526 assert ! response. warnings
527+
528+ and : " Logs should contain error"
529+ def logs = activityPbsService. getLogsByTime(startTime)
530+ assert getLogsByText(logs, " UsNat privacy module creation failed: Unable to decode UsNatCoreSegment " +
531+ " '${ INVALID_GPP_SEGMENT} '. Activity: SYNC_USER. Section: ${ US_NAT_V1.value} . Gpp: $INVALID_GPP_STRING " ). size() == 1
532+ }
533+
534+ def " PBS cookie sync call when privacy module contain invalid GPP string should respond with required bidder URL and emit warning in response" () {
535+ given : " Cookie sync request with link to account"
536+ def accountId = PBSUtils . randomString
537+ def invalidGpp = PBSUtils . randomString
538+ def cookieSyncRequest = CookieSyncRequest . defaultCookieSyncRequest. tap {
539+ it. gppSid = US_NAT_V1 . value
540+ it. account = accountId
541+ it. gpp = invalidGpp
542+ }
543+
544+ and : " Activities set for cookie sync with allowing privacy regulation"
545+ def rule = new ActivityRule (). tap {
546+ it. privacyRegulation = [IAB_US_GENERAL ]
547+ }
548+
549+ def activities = AllowActivities . getDefaultAllowActivities(SYNC_USER , Activity . getDefaultActivity([rule]))
550+
551+ and : " Account gpp configuration"
552+ def accountGppConfig = new AccountGppConfig (code : IAB_US_GENERAL , enabled : true )
553+
554+ and : " Existed account with cookie sync and privacy regulation setup"
555+ def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
556+ accountDao. save(account)
557+
558+ and : " Flush metrics"
559+ flushMetrics(activityPbsService)
560+
561+ when : " PBS processes cookie sync request"
562+ def response = activityPbsService. sendCookieSyncRequest(cookieSyncRequest)
563+
564+ then : " Response should contain bidders userSync.urls"
565+ assert response. getBidderUserSync(GENERIC ). userSync. url
566+
567+ and : " Metrics processed across activities should be updated"
568+ def metrics = activityPbsService. sendCollectedMetricsRequest()
569+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(cookieSyncRequest, SYNC_USER )] == 1
570+
571+ and : " Should add a warning when in debug mode"
572+ assert response. warnings == [" GPP string invalid: Unable to decode '$invalidGpp '" ]
517573 }
518574
519575 def " PBS cookie sync call when request have different gpp consent but match and rejecting should exclude bidders URLs" () {
@@ -613,14 +669,27 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
613669 def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
614670 accountDao. save(account)
615671
672+ and : " Flush metrics"
673+ flushMetrics(activityPbsService)
674+
616675 when : " PBS processes cookie sync request"
617676 def response = activityPbsService. sendCookieSyncRequest(cookieSyncRequest)
618677
619678 then : " Response should contain bidders userSync.urls"
620679 assert response. getBidderUserSync(GENERIC ). userSync. url
621680
681+ and : " Response shouldn't contain warnings"
682+ assert ! response. warnings
683+
684+ and : " Metrics processed across activities should be updated"
685+ def metrics = activityPbsService. sendCollectedMetricsRequest()
686+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(cookieSyncRequest, SYNC_USER )] == 1
687+
688+ and : " General alert metric shouldn't be updated"
689+ ! metrics[ALERT_GENERAL . getValue()]
690+
622691 where :
623- regsGpp << [" " , new UsNatV1Consent.Builder (). build(), new UsNatV1Consent.Builder (). setGpc(false ). build()]
692+ regsGpp << [null , " " , new UsNatV1Consent.Builder (). build(), new UsNatV1Consent.Builder (). setGpc(false ). build()]
624693 }
625694
626695 def " PBS cookie sync call when privacy regulation have duplicate should include proper responded with bidders URLs" () {
@@ -776,7 +845,10 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
776845 }
777846
778847 def " PBS cookie sync call when custom privacy regulation empty and normalize is disabled should respond with an error and update metric" () {
779- given : " Generic BidRequest with gpp and account setup"
848+ given : " Test start time"
849+ def startTime = Instant . now()
850+
851+ and : " Generic BidRequest with gpp and account setup"
780852 def gppConsent = new UsNatV1Consent.Builder (). setGpc(true ). build()
781853 def accountId = PBSUtils . randomNumber as String
782854 def cookieSyncRequest = CookieSyncRequest . defaultCookieSyncRequest. tap {
@@ -807,17 +879,18 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
807879 accountDao. save(account)
808880
809881 when : " PBS processes auction requests"
810- activityPbsService. sendCookieSyncRequest(cookieSyncRequest)
882+ def response = activityPbsService. sendCookieSyncRequest(cookieSyncRequest)
811883
812- then : " Response should contain error"
813- def error = thrown(PrebidServerException )
814- assert error. statusCode == BAD_REQUEST . code()
815- assert error. responseBody == " Invalid account configuration: JsonLogic exception: " +
816- " objects must have exactly 1 key defined, found 0"
884+ then : " Response should contain bidders userSync.urls"
885+ assert response. getBidderUserSync(GENERIC ). userSync. url
817886
818887 and : " Metrics for disallowed activities should be updated"
819888 def metrics = activityPbsService. sendCollectedMetricsRequest()
820889 assert metrics[ALERT_GENERAL . getValue()] == 1
890+
891+ and : " Logs should contain error"
892+ def logs = activityPbsService. getLogsByTime(startTime)
893+ assert getLogsByText(logs, ' USCustomLogic creation failed: objects must have exactly 1 key defined, found 0' ). size() == 1
821894 }
822895
823896 def " PBS cookie sync when custom privacy regulation with normalizing should exclude bidders URLs" () {
@@ -1359,8 +1432,11 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
13591432 ]
13601433 }
13611434
1362- def " PBS setuid request when privacy module contain invalid GPP string should reject bidders with status code invalidStatusCode" () {
1363- given : " Cookie sync SetuidRequest with accountId"
1435+ def " PBS setuid request when privacy module contain invalid GPP segment should respond with valid bidders UIDs cookies" () {
1436+ given : " Test start time"
1437+ def startTime = Instant . now()
1438+
1439+ and : " Cookie sync SetuidRequest with accountId"
13641440 def accountId = PBSUtils . randomString
13651441 def setuidRequest = SetuidRequest . defaultSetuidRequest. tap {
13661442 it. account = accountId
@@ -1385,13 +1461,66 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
13851461 def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
13861462 accountDao. save(account)
13871463
1464+ and : " Flush metrics"
1465+ flushMetrics(activityPbsService)
1466+
13881467 when : " PBS processes cookie sync request"
1389- activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
1468+ def response = activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
13901469
1391- then : " Request should fail with error"
1392- def exception = thrown(PrebidServerException )
1393- assert exception. statusCode == INVALID_STATUS_CODE
1394- assert exception. responseBody == INVALID_STATUS_MESSAGE
1470+ then : " Response should contain uids cookie"
1471+ assert response. uidsCookie
1472+ assert response. responseBody
1473+
1474+ and : " Metrics processed across activities should be updated"
1475+ def metrics = activityPbsService. sendCollectedMetricsRequest()
1476+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(setuidRequest, SYNC_USER )] == 1
1477+ assert metrics[ALERT_GENERAL . value] == 1
1478+
1479+ and : " Logs should contain error"
1480+ def logs = activityPbsService. getLogsByTime(startTime)
1481+ assert getLogsByText(logs, " UsNat privacy module creation failed: Unable to decode UsNatCoreSegment " +
1482+ " '${ INVALID_GPP_SEGMENT} '. Activity: SYNC_USER. Section: ${ US_NAT_V1.value} . Gpp: $INVALID_GPP_STRING " ). size() == 1
1483+ }
1484+
1485+ def " PBS setuid request when privacy module contain invalid GPP string should respond with valid bidders UIDs cookies" () {
1486+ given : " Cookie sync SetuidRequest with accountId"
1487+ def accountId = PBSUtils . randomString
1488+ def setuidRequest = SetuidRequest . defaultSetuidRequest. tap {
1489+ it. account = accountId
1490+ it. gppSid = US_NAT_V1 . value
1491+ it. gpp = PBSUtils . randomString
1492+ }
1493+
1494+ and : " UIDS Cookie"
1495+ def uidsCookie = UidsCookie . defaultUidsCookie
1496+
1497+ and : " Activities set for cookie sync with allowing privacy regulation"
1498+ def rule = new ActivityRule (). tap {
1499+ it. privacyRegulation = [IAB_US_GENERAL ]
1500+ }
1501+
1502+ def activities = AllowActivities . getDefaultAllowActivities(SYNC_USER , Activity . getDefaultActivity([rule]))
1503+
1504+ and : " Account gpp configuration"
1505+ def accountGppConfig = new AccountGppConfig (code : IAB_US_GENERAL , enabled : true )
1506+
1507+ and : " Existed account with cookie sync and allow activities setup"
1508+ def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
1509+ accountDao. save(account)
1510+
1511+ and : " Flush metrics"
1512+ flushMetrics(activityPbsService)
1513+
1514+ when : " PBS processes cookie sync request"
1515+ def response = activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
1516+
1517+ then : " Response should contain uids cookie"
1518+ assert response. uidsCookie
1519+ assert response. responseBody
1520+
1521+ and : " Metrics processed across activities should be updated"
1522+ def metrics = activityPbsService. sendCollectedMetricsRequest()
1523+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(setuidRequest, SYNC_USER )] == 1
13951524 }
13961525
13971526 def " PBS setuid request when request have different gpp consent but match and rejecting should reject bidders with status code invalidStatusCode" () {
@@ -1502,15 +1631,25 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
15021631 def account = getAccountWithAllowActivitiesAndPrivacyModule(accountId, activities, [accountGppConfig])
15031632 accountDao. save(account)
15041633
1634+ and : " Flush metrics"
1635+ flushMetrics(activityPbsService)
1636+
15051637 when : " PBS processes cookie sync request"
15061638 def response = activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
15071639
15081640 then : " Response should contain uids cookie"
15091641 assert response. uidsCookie
15101642 assert response. responseBody
15111643
1644+ and : " Metrics processed across activities should be updated"
1645+ def metrics = activityPbsService. sendCollectedMetricsRequest()
1646+ assert metrics[PROCESSED_ACTIVITY_RULES_COUNT . getValue(setuidRequest, SYNC_USER )] == 1
1647+
1648+ and : " General alert metric shouldn't be updated"
1649+ ! metrics[ALERT_GENERAL . getValue()]
1650+
15121651 where :
1513- regsGpp << [" " , new UsNatV1Consent.Builder (). build(), new UsNatV1Consent.Builder (). setGpc(false ). build()]
1652+ regsGpp << [null , " " , new UsNatV1Consent.Builder (). build(), new UsNatV1Consent.Builder (). setGpc(false ). build()]
15141653 }
15151654
15161655 def " PBS setuid request when privacy regulation have duplicate should respond with valid bidders UIDs cookies" () {
@@ -1680,8 +1819,11 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
16801819 new EqualityValueRule (PERSONAL_DATA_CONSENTS , NOTICE_NOT_PROVIDED )]
16811820 }
16821821
1683- def " PBS setuid call when custom privacy regulation empty and normalize is disabled should respond with an error and update metric" () {
1684- given : " Cookie sync SetuidRequest with accountId"
1822+ def " PBS setuid call when custom privacy regulation empty and normalize is disabled should respond with required UIDs cookies" () {
1823+ given : " Test start time"
1824+ def startTime = Instant . now()
1825+
1826+ and : " Cookie sync SetuidRequest with accountId"
16851827 def accountId = PBSUtils . randomString
16861828 def gppConsent = new UsNatV1Consent.Builder (). setGpc(true ). build()
16871829 def setuidRequest = SetuidRequest . defaultSetuidRequest. tap {
@@ -1715,17 +1857,18 @@ class GppSyncUserActivitiesSpec extends PrivacyBaseSpec {
17151857 accountDao. save(account)
17161858
17171859 when : " PBS processes setuid request"
1718- activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
1860+ def response = activityPbsService. sendSetUidRequest(setuidRequest, uidsCookie)
17191861
1720- then : " Response should contain error"
1721- def error = thrown(PrebidServerException )
1722- assert error. statusCode == BAD_REQUEST . code()
1723- assert error. responseBody == " Invalid account configuration: JsonLogic exception: " +
1724- " objects must have exactly 1 key defined, found 0"
1862+ then : " Response should contain uids cookie"
1863+ assert response. responseBody
17251864
17261865 and : " Metrics for disallowed activities should be updated"
17271866 def metrics = activityPbsService. sendCollectedMetricsRequest()
17281867 assert metrics[ALERT_GENERAL . getValue()] == 1
1868+
1869+ and : " Logs should contain error"
1870+ def logs = activityPbsService. getLogsByTime(startTime)
1871+ assert getLogsByText(logs, ' USCustomLogic creation failed: objects must have exactly 1 key defined, found 0' ). size() == 1
17291872 }
17301873
17311874 def " PBS setuid call when custom privacy regulation with normalizing should reject bidders with status code invalidStatusCode" () {
0 commit comments