@@ -17,10 +17,9 @@ import (
17
17
)
18
18
19
19
// permissionsMock mocks the Permissions interface for tests
20
- //
21
- // It only allows appnexus for GDPR consent
22
20
type permissionsMock struct {
23
- allowBidRequest bool
21
+ allowAllBidders bool
22
+ allowedBidders []openrtb_ext.BidderName
24
23
passGeo bool
25
24
passID bool
26
25
activitiesError error
@@ -35,7 +34,17 @@ func (p *permissionsMock) BidderSyncAllowed(ctx context.Context, bidder openrtb_
35
34
}
36
35
37
36
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
- return p .allowBidRequest , p .passGeo , p .passID , p .activitiesError
37
+ if p .allowAllBidders {
38
+ return true , p .passGeo , p .passID , p .activitiesError
39
+ }
40
+
41
+ for _ , allowedBidder := range p .allowedBidders {
42
+ if bidder == allowedBidder {
43
+ allowBidRequest = true
44
+ }
45
+ }
46
+
47
+ return allowBidRequest , p .passGeo , p .passID , p .activitiesError
39
48
}
40
49
41
50
func assertReq (t * testing.T , bidderRequests []BidderRequest ,
@@ -467,7 +476,7 @@ func TestCleanOpenRTBRequests(t *testing.T) {
467
476
}
468
477
469
478
for _ , test := range testCases {
470
- permissions := permissionsMock {allowBidRequest : true , passGeo : true , passID : true }
479
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
471
480
bidderRequests , _ , err := cleanOpenRTBRequests (context .Background (), test .req , nil , & permissions , true , privacyConfig , nil )
472
481
if test .hasError {
473
482
assert .NotNil (t , err , "Error shouldn't be nil" )
@@ -623,7 +632,7 @@ func TestCleanOpenRTBRequestsCCPA(t *testing.T) {
623
632
context .Background (),
624
633
auctionReq ,
625
634
nil ,
626
- & permissionsMock {allowBidRequest : true , passGeo : true , passID : true },
635
+ & permissionsMock {allowAllBidders : true , passGeo : true , passID : true },
627
636
true ,
628
637
privacyConfig ,
629
638
nil )
@@ -684,7 +693,7 @@ func TestCleanOpenRTBRequestsCCPAErrors(t *testing.T) {
684
693
Enforce : true ,
685
694
},
686
695
}
687
- permissions := permissionsMock {allowBidRequest : true , passGeo : true , passID : true }
696
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
688
697
_ , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , & reqExtStruct , & permissions , true , privacyConfig , nil )
689
698
690
699
assert .ElementsMatch (t , []error {test .expectError }, errs , test .description )
@@ -725,7 +734,7 @@ func TestCleanOpenRTBRequestsCOPPA(t *testing.T) {
725
734
UserSyncs : & emptyUsersync {},
726
735
}
727
736
728
- permissions := permissionsMock {allowBidRequest : true , passGeo : true , passID : true }
737
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
729
738
bidderRequests , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissions , true , config.Privacy {}, nil )
730
739
result := bidderRequests [0 ]
731
740
@@ -833,7 +842,7 @@ func TestCleanOpenRTBRequestsSChain(t *testing.T) {
833
842
UserSyncs : & emptyUsersync {},
834
843
}
835
844
836
- permissions := permissionsMock {allowBidRequest : true , passGeo : true , passID : true }
845
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
837
846
bidderRequests , _ , errs := cleanOpenRTBRequests (context .Background (), auctionReq , extRequest , & permissions , true , config.Privacy {}, nil )
838
847
if test .hasError == true {
839
848
assert .NotNil (t , errs )
@@ -1415,7 +1424,7 @@ func TestCleanOpenRTBRequestsLMT(t *testing.T) {
1415
1424
},
1416
1425
}
1417
1426
1418
- permissions := permissionsMock {allowBidRequest : true , passGeo : true , passID : true }
1427
+ permissions := permissionsMock {allowAllBidders : true , passGeo : true , passID : true }
1419
1428
results , privacyLabels , errs := cleanOpenRTBRequests (context .Background (), auctionReq , nil , & permissions , true , privacyConfig , nil )
1420
1429
result := results [0 ]
1421
1430
@@ -1631,7 +1640,7 @@ func TestCleanOpenRTBRequestsGDPRScrub(t *testing.T) {
1631
1640
context .Background (),
1632
1641
auctionReq ,
1633
1642
nil ,
1634
- & permissionsMock {allowBidRequest : true , passGeo : ! test .gdprScrub , passID : ! test .gdprScrub , activitiesError : test .permissionsError },
1643
+ & permissionsMock {allowAllBidders : true , passGeo : ! test .gdprScrub , passID : ! test .gdprScrub , activitiesError : test .permissionsError },
1635
1644
test .userSyncIfAmbiguous ,
1636
1645
privacyConfig ,
1637
1646
nil )
@@ -1656,19 +1665,28 @@ func TestCleanOpenRTBRequestsGDPRScrub(t *testing.T) {
1656
1665
1657
1666
func TestCleanOpenRTBRequestsGDPRBlockBidRequest (t * testing.T ) {
1658
1667
testCases := []struct {
1659
- description string
1660
- gdprBlockBidRequest bool
1661
- expectRequestsCount int
1668
+ description string
1669
+ gdprEnforced bool
1670
+ gdprAllowedBidders []openrtb_ext.BidderName
1671
+ expectedBidders []openrtb_ext.BidderName
1662
1672
}{
1663
1673
{
1664
- description : "GDPR allows bid request" ,
1665
- gdprBlockBidRequest : false ,
1666
- expectRequestsCount : 1 ,
1674
+ description : "gdpr enforced, one request allowed and one request blocked" ,
1675
+ gdprEnforced : true ,
1676
+ gdprAllowedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus },
1677
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus },
1678
+ },
1679
+ {
1680
+ description : "gdpr enforced, two requests allowed and no requests blocked" ,
1681
+ gdprEnforced : true ,
1682
+ gdprAllowedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1683
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1667
1684
},
1668
1685
{
1669
- description : "GDPR blocks bid request" ,
1670
- gdprBlockBidRequest : true ,
1671
- expectRequestsCount : 0 ,
1686
+ description : "gdpr not enforced, two requests allowed and no requests blocked" ,
1687
+ gdprEnforced : false ,
1688
+ gdprAllowedBidders : []openrtb_ext.BidderName {},
1689
+ expectedBidders : []openrtb_ext.BidderName {openrtb_ext .BidderAppnexus , openrtb_ext .BidderRubicon },
1672
1690
},
1673
1691
}
1674
1692
@@ -1677,10 +1695,11 @@ func TestCleanOpenRTBRequestsGDPRBlockBidRequest(t *testing.T) {
1677
1695
req .Regs = & openrtb2.Regs {
1678
1696
Ext : json .RawMessage (`{"gdpr":1}` ),
1679
1697
}
1698
+ req .Imp [0 ].Ext = json .RawMessage (`{"appnexus": {"placementId": 1}, "rubicon": {}}` )
1680
1699
1681
1700
privacyConfig := config.Privacy {
1682
1701
GDPR : config.GDPR {
1683
- Enabled : true ,
1702
+ Enabled : test . gdprEnforced ,
1684
1703
UsersyncIfAmbiguous : true ,
1685
1704
TCF2 : config.TCF2 {
1686
1705
Enabled : true ,
@@ -1704,13 +1723,19 @@ func TestCleanOpenRTBRequestsGDPRBlockBidRequest(t *testing.T) {
1704
1723
context .Background (),
1705
1724
auctionReq ,
1706
1725
nil ,
1707
- & permissionsMock {allowBidRequest : ! test .gdprBlockBidRequest , passGeo : true , passID : true , activitiesError : nil },
1726
+ & permissionsMock {allowedBidders : test .gdprAllowedBidders , passGeo : true , passID : true , activitiesError : nil },
1708
1727
true ,
1709
1728
privacyConfig ,
1710
1729
nil )
1711
1730
1712
- assert .Equal (t , test .expectRequestsCount , len (results ), test .description )
1713
- assert .Equal (t , 0 , len (errs ), test .description )
1731
+ // extract bidder name from each request in the results
1732
+ bidders := []openrtb_ext.BidderName {}
1733
+ for _ , req := range results {
1734
+ bidders = append (bidders , req .BidderName )
1735
+ }
1736
+
1737
+ assert .Empty (t , errs , test .description )
1738
+ assert .ElementsMatch (t , bidders , test .expectedBidders , test .description )
1714
1739
}
1715
1740
}
1716
1741
0 commit comments