@@ -14,14 +14,16 @@ import (
14
14
"github.com/prebid/prebid-server/metrics"
15
15
"github.com/prebid/prebid-server/openrtb_ext"
16
16
"github.com/stretchr/testify/assert"
17
+ "github.com/stretchr/testify/mock"
17
18
)
18
19
19
20
// permissionsMock mocks the Permissions interface for tests
20
- //
21
- // It only allows appnexus for GDPR consent
22
21
type permissionsMock struct {
23
- personalInfoAllowed bool
24
- personalInfoAllowedError error
22
+ allowAllBidders bool
23
+ allowedBidders []openrtb_ext.BidderName
24
+ passGeo bool
25
+ passID bool
26
+ activitiesError error
25
27
}
26
28
27
29
func (p * permissionsMock ) HostCookiesAllowed (ctx context.Context , gdpr gdpr.Signal , consent string ) (bool , error ) {
@@ -32,8 +34,18 @@ func (p *permissionsMock) BidderSyncAllowed(ctx context.Context, bidder openrtb_
32
34
return true , nil
33
35
}
34
36
35
- func (p * permissionsMock ) PersonalInfoAllowed (ctx context.Context , bidder openrtb_ext.BidderName , PublisherID string , gdpr gdpr.Signal , consent string , weakVendorEnforcement bool ) (allowGeo bool , allowID bool , err error ) {
36
- return p .personalInfoAllowed , p .personalInfoAllowed , p .personalInfoAllowedError
37
+ func (p * permissionsMock ) AuctionActivitiesAllowed (ctx context.Context , bidder openrtb_ext.BidderName , PublisherID string , gdpr gdpr.Signal , consent string , weakVendorEnforcement bool ) (allowBidRequest bool , passGeo bool , passID bool , err error ) {
38
+ if p .allowAllBidders {
39
+ return true , p .passGeo , p .passID , p .activitiesError
40
+ }
41
+
42
+ for _ , allowedBidder := range p .allowedBidders {
43
+ if bidder == allowedBidder {
44
+ allowBidRequest = true
45
+ }
46
+ }
47
+
48
+ return allowBidRequest , p .passGeo , p .passID , p .activitiesError
37
49
}
38
50
39
51
func assertReq (t * testing.T , bidderRequests []BidderRequest ,
@@ -465,7 +477,9 @@ func TestCleanOpenRTBRequests(t *testing.T) {
465
477
}
466
478
467
479
for _ , test := range testCases {
468
- bidderRequests , _ , err := cleanOpenRTBRequests (context .Background (), test .req , nil , & permissionsMock {personalInfoAllowed : true }, true , privacyConfig , nil )
480
+ metricsMock := metrics.MetricsEngineMock {}
481
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
482
+ bidderRequests , _ , err := cleanOpenRTBRequests (context .Background (), test .req , nil , & permissions , & metricsMock , true , privacyConfig , nil )
469
483
if test .hasError {
470
484
assert .NotNil (t , err , "Error shouldn't be nil" )
471
485
} else {
@@ -620,7 +634,8 @@ func TestCleanOpenRTBRequestsCCPA(t *testing.T) {
620
634
context .Background (),
621
635
auctionReq ,
622
636
nil ,
623
- & permissionsMock {personalInfoAllowed : true },
637
+ & permissionsMock {allowAllBidders : true , passGeo : true , passID : true },
638
+ & metrics.MetricsEngineMock {},
624
639
true ,
625
640
privacyConfig ,
626
641
nil )
@@ -681,7 +696,9 @@ func TestCleanOpenRTBRequestsCCPAErrors(t *testing.T) {
681
696
Enforce : true ,
682
697
},
683
698
}
684
- _ , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , & reqExtStruct , & permissionsMock {personalInfoAllowed : true }, true , privacyConfig , nil )
699
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
700
+ metrics := metrics.MetricsEngineMock {}
701
+ _ , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , & reqExtStruct , & permissions , & metrics , true , privacyConfig , nil )
685
702
686
703
assert .ElementsMatch (t , []error {test .expectError }, errs , test .description )
687
704
}
@@ -721,7 +738,9 @@ func TestCleanOpenRTBRequestsCOPPA(t *testing.T) {
721
738
UserSyncs : & emptyUsersync {},
722
739
}
723
740
724
- bidderRequests , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissionsMock {personalInfoAllowed : true }, true , config.Privacy {}, nil )
741
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
742
+ metrics := metrics.MetricsEngineMock {}
743
+ bidderRequests , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissions , & metrics , true , config.Privacy {}, nil )
725
744
result := bidderRequests [0 ]
726
745
727
746
assert .Nil (t , errs )
@@ -828,7 +847,9 @@ func TestCleanOpenRTBRequestsSChain(t *testing.T) {
828
847
UserSyncs : & emptyUsersync {},
829
848
}
830
849
831
- bidderRequests , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , extRequest , & permissionsMock {}, true , config.Privacy {}, nil )
850
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
851
+ metrics := metrics.MetricsEngineMock {}
852
+ bidderRequests , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , extRequest , & permissions , & metrics , true , config.Privacy {}, nil )
832
853
if test .hasError == true {
833
854
assert .NotNil (t , errs )
834
855
assert .Len (t , bidderRequests , 0 )
@@ -1409,7 +1430,9 @@ func TestCleanOpenRTBRequestsLMT(t *testing.T) {
1409
1430
},
1410
1431
}
1411
1432
1412
- results , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissionsMock {personalInfoAllowed : true }, true , privacyConfig , nil )
1433
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
1434
+ metrics := metrics.MetricsEngineMock {}
1435
+ results , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissions , & metrics , true , privacyConfig , nil )
1413
1436
result := results [0 ]
1414
1437
1415
1438
assert .Nil (t , errs )
@@ -1424,7 +1447,7 @@ func TestCleanOpenRTBRequestsLMT(t *testing.T) {
1424
1447
}
1425
1448
}
1426
1449
1427
- func TestCleanOpenRTBRequestsGDPR (t * testing.T ) {
1450
+ func TestCleanOpenRTBRequestsGDPRScrub (t * testing.T ) {
1428
1451
tcf1Consent := "BONV8oqONXwgmADACHENAO7pqzAAppY"
1429
1452
tcf2Consent := "COzTVhaOzTVhaGvAAAENAiCIAP_AAH_AAAAAAEEUACCKAAA"
1430
1453
trueValue , falseValue := true , false
@@ -1624,7 +1647,8 @@ func TestCleanOpenRTBRequestsGDPR(t *testing.T) {
1624
1647
context .Background (),
1625
1648
auctionReq ,
1626
1649
nil ,
1627
- & permissionsMock {personalInfoAllowed : ! test .gdprScrub , personalInfoAllowedError : test .permissionsError },
1650
+ & permissionsMock {allowAllBidders : true , passGeo : ! test .gdprScrub , passID : ! test .gdprScrub , activitiesError : test .permissionsError },
1651
+ & metrics.MetricsEngineMock {},
1628
1652
test .userSyncIfAmbiguous ,
1629
1653
privacyConfig ,
1630
1654
nil )
@@ -1647,6 +1671,97 @@ func TestCleanOpenRTBRequestsGDPR(t *testing.T) {
1647
1671
}
1648
1672
}
1649
1673
1674
+ func TestCleanOpenRTBRequestsGDPRBlockBidRequest (t * testing.T ) {
1675
+ testCases := []struct {
1676
+ description string
1677
+ gdprEnforced bool
1678
+ gdprAllowedBidders []openrtb_ext.BidderName
1679
+ expectedBidders []openrtb_ext.BidderName
1680
+ expectedBlockedBidders []openrtb_ext.BidderName
1681
+ }{
1682
+ {
1683
+ description : "gdpr enforced, one request allowed and one request blocked" ,
1684
+ gdprEnforced : true ,
1685
+ gdprAllowedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus },
1686
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus },
1687
+ expectedBlockedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderRubicon },
1688
+ },
1689
+ {
1690
+ description : "gdpr enforced, two requests allowed and no requests blocked" ,
1691
+ gdprEnforced : true ,
1692
+ gdprAllowedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1693
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1694
+ expectedBlockedBidders : []openrtb_ext.BidderName {},
1695
+ },
1696
+ {
1697
+ description : "gdpr not enforced, two requests allowed and no requests blocked" ,
1698
+ gdprEnforced : false ,
1699
+ gdprAllowedBidders : []openrtb_ext.BidderName {},
1700
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1701
+ expectedBlockedBidders : []openrtb_ext.BidderName {},
1702
+ },
1703
+ }
1704
+
1705
+ for _ , test := range testCases {
1706
+ req := newBidRequest (t )
1707
+ req .Regs = & openrtb2.Regs {
1708
+ Ext : json .RawMessage (`{"gdpr":1}` ),
1709
+ }
1710
+ req .Imp [0 ].Ext = json .RawMessage (`{"appnexus": {"placementId": 1}, "rubicon": {}}` )
1711
+
1712
+ privacyConfig := config.Privacy {
1713
+ GDPR : config.GDPR {
1714
+ Enabled : test .gdprEnforced ,
1715
+ UsersyncIfAmbiguous : true ,
1716
+ TCF2 : config.TCF2 {
1717
+ Enabled : true ,
1718
+ },
1719
+ },
1720
+ }
1721
+
1722
+ accountConfig := config.Account {
1723
+ GDPR : config.AccountGDPR {
1724
+ Enabled : nil ,
1725
+ },
1726
+ }
1727
+
1728
+ auctionReq := AuctionRequest {
1729
+ BidRequest : req ,
1730
+ UserSyncs : & emptyUsersync {},
1731
+ Account : accountConfig ,
1732
+ }
1733
+
1734
+ metricsMock := metrics.MetricsEngineMock {}
1735
+ metricsMock .Mock .On ("RecordAdapterGDPRRequestBlocked" , mock .Anything ).Return ()
1736
+
1737
+ results , _ , errs := cleanOpenRTBRequests (
1738
+ context .Background (),
1739
+ auctionReq ,
1740
+ nil ,
1741
+ & permissionsMock {allowedBidders : test .gdprAllowedBidders , passGeo : true , passID : true , activitiesError : nil },
1742
+ & metricsMock ,
1743
+ true ,
1744
+ privacyConfig ,
1745
+ nil )
1746
+
1747
+ // extract bidder name from each request in the results
1748
+ bidders := []openrtb_ext.BidderName {}
1749
+ for _ , req := range results {
1750
+ bidders = append (bidders , req .BidderName )
1751
+ }
1752
+
1753
+ assert .Empty (t , errs , test .description )
1754
+ assert .ElementsMatch (t , bidders , test .expectedBidders , test .description )
1755
+
1756
+ for _ , blockedBidder := range test .expectedBlockedBidders {
1757
+ metricsMock .AssertCalled (t , "RecordAdapterGDPRRequestBlocked" , blockedBidder )
1758
+ }
1759
+ for _ , allowedBidder := range test .expectedBidders {
1760
+ metricsMock .AssertNotCalled (t , "RecordAdapterGDPRRequestBlocked" , allowedBidder )
1761
+ }
1762
+ }
1763
+ }
1764
+
1650
1765
// newAdapterAliasBidRequest builds a BidRequest with aliases
1651
1766
func newAdapterAliasBidRequest (t * testing.T ) * openrtb2.BidRequest {
1652
1767
dnt := int8 (1 )
0 commit comments