From 27b2ff663be24a71c7e9e6f79045272a2e78f1f0 Mon Sep 17 00:00:00 2001 From: Veronika Solovei Date: Tue, 16 Jan 2024 11:50:12 -0800 Subject: [PATCH] Added TransmitPreciseGeo activity handling in modules (#3348) --- endpoints/openrtb2/amp_auction.go | 1 + endpoints/openrtb2/auction.go | 1 + hooks/hookexecution/execution.go | 40 ++++++++---- hooks/hookexecution/execution_test.go | 91 +++++++++++++++++++++++++-- hooks/hookexecution/executor_test.go | 79 +++++++---------------- 5 files changed, 142 insertions(+), 70 deletions(-) diff --git a/endpoints/openrtb2/amp_auction.go b/endpoints/openrtb2/amp_auction.go index db427f380ed..ab93ad3c29d 100644 --- a/endpoints/openrtb2/amp_auction.go +++ b/endpoints/openrtb2/amp_auction.go @@ -235,6 +235,7 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h activityControl = privacy.NewActivityControl(&account.Privacy) hookExecutor.SetActivityControl(activityControl) + hookExecutor.SetAccount(account) secGPC := r.Header.Get("Sec-GPC") diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index eb3f5c02ccb..ff5e54688a4 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -206,6 +206,7 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http activityControl = privacy.NewActivityControl(&account.Privacy) hookExecutor.SetActivityControl(activityControl) + hookExecutor.SetAccount(account) ctx := context.Background() diff --git a/hooks/hookexecution/execution.go b/hooks/hookexecution/execution.go index 05cc5fb5943..ac9e9c2c802 100644 --- a/hooks/hookexecution/execution.go +++ b/hooks/hookexecution/execution.go @@ -3,7 +3,9 @@ package hookexecution import ( "context" "fmt" + "github.com/prebid/prebid-server/v2/config" "github.com/prebid/prebid-server/v2/ortb" + "github.com/prebid/prebid-server/v2/util/iputil" "strings" "sync" "time" @@ -68,7 +70,7 @@ func executeGroup[H any, P any]( for _, hook := range group.Hooks { mCtx := executionCtx.getModuleContext(hook.Module) - newPayload := handleModuleActivities(hook.Code, executionCtx.activityControl, payload) + newPayload := handleModuleActivities(hook.Code, executionCtx.activityControl, payload, executionCtx.account) wg.Add(1) go func(hw hooks.HookWrapper[H], moduleCtx hookstage.ModuleInvocationContext) { defer wg.Done() @@ -315,7 +317,7 @@ func handleHookMutations[P any]( return payload } -func handleModuleActivities[P any](hookCode string, activityControl privacy.ActivityControl, payload P) P { +func handleModuleActivities[P any](hookCode string, activityControl privacy.ActivityControl, payload P, account *config.Account) P { payloadData, ok := any(&payload).(hookstage.RequestUpdater) if !ok { return payload @@ -323,20 +325,36 @@ func handleModuleActivities[P any](hookCode string, activityControl privacy.Acti scopeGeneral := privacy.Component{Type: privacy.ComponentTypeGeneral, Name: hookCode} transmitUserFPDActivityAllowed := activityControl.Allow(privacy.ActivityTransmitUserFPD, scopeGeneral, privacy.ActivityRequest{}) + transmitPreciseGeoActivityAllowed := activityControl.Allow(privacy.ActivityTransmitPreciseGeo, scopeGeneral, privacy.ActivityRequest{}) - if !transmitUserFPDActivityAllowed { - // changes need to be applied to new payload and leave original payload unchanged - bidderReq := payloadData.GetBidderRequestPayload() + if transmitUserFPDActivityAllowed && transmitPreciseGeoActivityAllowed { + return payload + } - bidderReqCopy := ortb.CloneBidderReq(bidderReq.BidRequest) + // changes need to be applied to new payload and leave original payload unchanged + bidderReq := payloadData.GetBidderRequestPayload() + bidderReqCopy := ortb.CloneBidderReq(bidderReq.BidRequest) + + if !transmitUserFPDActivityAllowed { privacy.ScrubUserFPD(bidderReqCopy) + } + if !transmitPreciseGeoActivityAllowed { + ipConf := privacy.IPConf{} + if account != nil { + ipConf = privacy.IPConf{IPV6: account.Privacy.IPv6Config, IPV4: account.Privacy.IPv4Config} + } else { + ipConf = privacy.IPConf{ + IPV6: config.IPv6{AnonKeepBits: iputil.IPv6DefaultMaskingBitSize}, + IPV4: config.IPv4{AnonKeepBits: iputil.IPv4DefaultMaskingBitSize}} + } - var newPayload = payload - var np = any(&newPayload).(hookstage.RequestUpdater) - np.SetBidderRequestPayload(bidderReqCopy) - return newPayload + privacy.ScrubGeoAndDeviceIP(bidderReqCopy, ipConf) } - return payload + var newPayload = payload + var np = any(&newPayload).(hookstage.RequestUpdater) + np.SetBidderRequestPayload(bidderReqCopy) + return newPayload + } diff --git a/hooks/hookexecution/execution_test.go b/hooks/hookexecution/execution_test.go index a12175e30a0..0986742e506 100644 --- a/hooks/hookexecution/execution_test.go +++ b/hooks/hookexecution/execution_test.go @@ -10,6 +10,13 @@ import ( "testing" ) +const ( + testIpv6 = "1111:2222:3333:4444:5555:6666:7777:8888" + testIPv6Scrubbed = "1111:2222::" + testIPv6ScrubbedDefault = "1111:2222:3333:4400::" + testIPv6ScrubBytes = 32 +) + func TestHandleModuleActivitiesBidderRequestPayload(t *testing.T) { testCases := []struct { @@ -49,13 +56,43 @@ func TestHandleModuleActivitiesBidderRequestPayload(t *testing.T) { }}, }, }, + { + description: "payload should change when transmitPreciseGeo is blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.BidderRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", false), + expectedPayloadData: hookstage.BidderRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIPv6ScrubbedDefault}, + }, + }}, + }, + { + description: "payload should not change when transmitPreciseGeo is not blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.BidderRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", true), + expectedPayloadData: hookstage.BidderRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + }, } for _, test := range testCases { t.Run(test.description, func(t *testing.T) { //check input payload didn't change origInPayloadData := test.inPayloadData activityControl := privacy.NewActivityControl(test.privacyConfig) - newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData) + newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData, nil) assert.Equal(t, test.expectedPayloadData.Request.BidRequest, newPayload.Request.BidRequest) assert.Equal(t, origInPayloadData, test.inPayloadData) }) @@ -101,13 +138,45 @@ func TestHandleModuleActivitiesProcessedAuctionRequestPayload(t *testing.T) { }}, }, }, + + { + description: "payload should change when transmitPreciseGeo is blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.ProcessedAuctionRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", false), + expectedPayloadData: hookstage.ProcessedAuctionRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIPv6Scrubbed}, + }}, + }, + }, + { + description: "payload should not change when transmitPreciseGeo is not blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.ProcessedAuctionRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", true), + expectedPayloadData: hookstage.ProcessedAuctionRequestPayload{ + Request: &openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{ + Device: &openrtb2.Device{IPv6: testIpv6}, + }}, + }, + }, } for _, test := range testCases { t.Run(test.description, func(t *testing.T) { //check input payload didn't change origInPayloadData := test.inPayloadData activityControl := privacy.NewActivityControl(test.privacyConfig) - newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData) + account := &config.Account{Privacy: config.AccountPrivacy{IPv6Config: config.IPv6{testIPv6ScrubBytes}}} + newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData, account) assert.Equal(t, test.expectedPayloadData.Request.BidRequest, newPayload.Request.BidRequest) assert.Equal(t, origInPayloadData, test.inPayloadData) }) @@ -124,7 +193,7 @@ func TestHandleModuleActivitiesNoBidderRequestPayload(t *testing.T) { expectedPayloadData hookstage.RawAuctionRequestPayload }{ { - description: "payload should change when userFPD is blocked by activity", + description: "payload should not change when userFPD is blocked by activity", hookCode: "foo", inPayloadData: hookstage.RawAuctionRequestPayload{}, privacyConfig: getTransmitUFPDActivityConfig("foo", false), @@ -137,13 +206,27 @@ func TestHandleModuleActivitiesNoBidderRequestPayload(t *testing.T) { privacyConfig: getTransmitUFPDActivityConfig("foo", true), expectedPayloadData: hookstage.RawAuctionRequestPayload{}, }, + { + description: "payload should not change when transmitPreciseGeo is blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.RawAuctionRequestPayload{}, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", false), + expectedPayloadData: hookstage.RawAuctionRequestPayload{}, + }, + { + description: "payload should not change when transmitPreciseGeo is not blocked by activity", + hookCode: "foo", + inPayloadData: hookstage.RawAuctionRequestPayload{}, + privacyConfig: getTransmitPreciseGeoActivityConfig("foo", true), + expectedPayloadData: hookstage.RawAuctionRequestPayload{}, + }, } for _, test := range testCases { t.Run(test.description, func(t *testing.T) { //check input payload didn't change origInPayloadData := test.inPayloadData activityControl := privacy.NewActivityControl(test.privacyConfig) - newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData) + newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData, &config.Account{}) assert.Equal(t, test.expectedPayloadData, newPayload) assert.Equal(t, origInPayloadData, test.inPayloadData) }) diff --git a/hooks/hookexecution/executor_test.go b/hooks/hookexecution/executor_test.go index 1fb299204ec..a427949a9ab 100644 --- a/hooks/hookexecution/executor_test.go +++ b/hooks/hookexecution/executor_test.go @@ -26,7 +26,6 @@ import ( func TestEmptyHookExecutor(t *testing.T) { executor := EmptyHookExecutor{} - executor.SetAccount(&config.Account{}) body := []byte(`{"foo": "bar"}`) reader := bytes.NewReader(body) @@ -419,14 +418,12 @@ func TestExecuteRawAuctionStage(t *testing.T) { const urlString string = "https://prebid.com/openrtb2/auction" foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} testCases := []struct { description string givenBody string givenUrl string givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account expectedBody string expectedReject *RejectError expectedModuleContexts *moduleContexts @@ -437,7 +434,6 @@ func TestExecuteRawAuctionStage(t *testing.T) { givenBody: body, givenUrl: urlString, givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, expectedBody: body, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{}}, @@ -448,7 +444,6 @@ func TestExecuteRawAuctionStage(t *testing.T) { givenBody: body, givenUrl: urlString, givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, expectedBody: bodyUpdated, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -507,7 +502,6 @@ func TestExecuteRawAuctionStage(t *testing.T) { givenBody: body, givenUrl: urlString, givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, expectedBody: bodyUpdated, expectedReject: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "bar"}, hooks.StageRawAuctionRequest.String()}, expectedModuleContexts: foobarModuleCtx, @@ -568,7 +562,6 @@ func TestExecuteRawAuctionStage(t *testing.T) { givenBody: body, givenUrl: urlString, givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, expectedBody: bodyUpdated, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -617,7 +610,6 @@ func TestExecuteRawAuctionStage(t *testing.T) { givenBody: body, givenUrl: urlString, givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, expectedBody: body, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{ @@ -677,10 +669,10 @@ func TestExecuteRawAuctionStage(t *testing.T) { t.Run(test.description, func(t *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) + newBody, reject := exec.ExecuteRawAuctionStage([]byte(test.givenBody)) assert.Equal(t, test.expectedReject, reject, "Unexpected stage reject.") @@ -699,14 +691,12 @@ func TestExecuteRawAuctionStage(t *testing.T) { func TestExecuteProcessedAuctionStage(t *testing.T) { foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} req := openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}} reqUpdated := openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id", Yob: 2000, Consent: "true"}} testCases := []struct { description string givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account givenRequest openrtb_ext.RequestWrapper expectedRequest openrtb2.BidRequest expectedErr error @@ -716,7 +706,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { { description: "Request not changed if hook execution plan empty", givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, givenRequest: openrtb_ext.RequestWrapper{BidRequest: &req}, expectedRequest: req, expectedErr: nil, @@ -726,7 +715,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { { description: "Request changed if hooks return mutations", givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, givenRequest: openrtb_ext.RequestWrapper{BidRequest: &req}, expectedRequest: reqUpdated, expectedErr: nil, @@ -760,7 +748,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { { description: "Stage execution can be rejected - and later hooks rejected", givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, givenRequest: openrtb_ext.RequestWrapper{BidRequest: &req}, expectedRequest: req, expectedErr: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "foo"}, hooks.StageProcessedAuctionRequest.String()}, @@ -793,7 +780,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { { description: "Request can be changed when a hook times out", givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, givenRequest: openrtb_ext.RequestWrapper{BidRequest: &req}, expectedRequest: reqUpdated, expectedErr: nil, @@ -841,7 +827,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { { description: "Modules contexts are preserved and correct", givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, givenRequest: openrtb_ext.RequestWrapper{BidRequest: &req}, expectedRequest: req, expectedErr: nil, @@ -902,10 +887,9 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { t.Run(test.description, func(ti *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) err := exec.ExecuteProcessedAuctionStage(&test.givenRequest) @@ -926,7 +910,6 @@ func TestExecuteProcessedAuctionStage(t *testing.T) { func TestExecuteBidderRequestStage(t *testing.T) { bidderName := "the-bidder" foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} expectedBidderRequest := &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}} expectedUpdatedBidderRequest := &openrtb2.BidRequest{ @@ -942,7 +925,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description string givenBidderRequest *openrtb2.BidRequest givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account expectedBidderRequest *openrtb2.BidRequest expectedReject *RejectError expectedModuleContexts *moduleContexts @@ -953,7 +935,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description: "Payload not changed if hook execution plan empty", givenBidderRequest: &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}}, givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, expectedBidderRequest: expectedBidderRequest, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{}}, @@ -963,7 +944,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description: "Payload changed if hooks return mutations", givenBidderRequest: &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}}, givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, expectedBidderRequest: expectedUpdatedBidderRequest, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -1021,7 +1001,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description: "Stage execution can be rejected - and later hooks rejected", givenBidderRequest: &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}}, givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, expectedBidderRequest: expectedBidderRequest, expectedReject: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "foo"}, hooks.StageBidderRequest.String()}, expectedModuleContexts: foobarModuleCtx, @@ -1073,7 +1052,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description: "Stage execution can be timed out", givenBidderRequest: &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}}, givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, expectedBidderRequest: expectedUpdatedBidderRequest, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -1125,7 +1103,6 @@ func TestExecuteBidderRequestStage(t *testing.T) { description: "Modules contexts are preserved and correct", givenBidderRequest: &openrtb2.BidRequest{ID: "some-id", User: &openrtb2.User{ID: "user-id"}}, givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, expectedBidderRequest: expectedBidderRequest, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{ @@ -1179,10 +1156,9 @@ func TestExecuteBidderRequestStage(t *testing.T) { for _, test := range testCases { t.Run(test.description, func(t *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) reject := exec.ExecuteBidderRequestStage(&openrtb_ext.RequestWrapper{BidRequest: test.givenBidderRequest}, bidderName) @@ -1200,6 +1176,15 @@ func TestExecuteBidderRequestStage(t *testing.T) { } } +func getModuleActivities(componentName string, allowTransmitUserFPD, allowTransmitPreciseGeo bool) *config.AccountPrivacy { + return &config.AccountPrivacy{ + AllowActivities: &config.AllowActivities{ + TransmitUserFPD: buildDefaultActivityConfig(componentName, allowTransmitUserFPD), + TransmitPreciseGeo: buildDefaultActivityConfig(componentName, allowTransmitPreciseGeo), + }, + } +} + func getTransmitUFPDActivityConfig(componentName string, allow bool) *config.AccountPrivacy { return &config.AccountPrivacy{ AllowActivities: &config.AllowActivities{ @@ -1208,6 +1193,14 @@ func getTransmitUFPDActivityConfig(componentName string, allow bool) *config.Acc } } +func getTransmitPreciseGeoActivityConfig(componentName string, allow bool) *config.AccountPrivacy { + return &config.AccountPrivacy{ + AllowActivities: &config.AllowActivities{ + TransmitPreciseGeo: buildDefaultActivityConfig(componentName, allow), + }, + } +} + func buildDefaultActivityConfig(componentName string, allow bool) config.Activity { return config.Activity{ Default: ptrutil.ToPtr(true), @@ -1225,7 +1218,6 @@ func buildDefaultActivityConfig(componentName string, allow bool) config.Activit func TestExecuteRawBidderResponseStage(t *testing.T) { foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} resp := adapters.BidderResponse{Bids: []*adapters.TypedBid{{DealPriority: 1}}} expResp := adapters.BidderResponse{Bids: []*adapters.TypedBid{{DealPriority: 10}}} vEntity := entity("the-bidder") @@ -1233,7 +1225,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { testCases := []struct { description string givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account givenBidderResponse adapters.BidderResponse expectedBidderResponse adapters.BidderResponse expectedReject *RejectError @@ -1243,7 +1234,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { { description: "Payload not changed if hook execution plan empty", givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, givenBidderResponse: resp, expectedBidderResponse: resp, expectedReject: nil, @@ -1253,7 +1243,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { { description: "Payload changed if hooks return mutations", givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, givenBidderResponse: resp, expectedBidderResponse: expResp, expectedReject: nil, @@ -1286,7 +1275,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { { description: "Stage execution can be rejected", givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, givenBidderResponse: resp, expectedBidderResponse: resp, expectedReject: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "foo"}, hooks.StageRawBidderResponse.String()}, @@ -1319,7 +1307,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { { description: "Response can be changed when a hook times out", givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, givenBidderResponse: resp, expectedBidderResponse: expResp, expectedReject: nil, @@ -1366,7 +1353,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { { description: "Modules contexts are preserved and correct", givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, givenBidderResponse: resp, expectedBidderResponse: expResp, expectedReject: nil, @@ -1427,10 +1413,9 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { t.Run(test.description, func(ti *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) reject := exec.ExecuteRawBidderResponseStage(&test.givenBidderResponse, "the-bidder") @@ -1450,7 +1435,6 @@ func TestExecuteRawBidderResponseStage(t *testing.T) { func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} expectedAllProcBidResponses := map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{ "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, @@ -1463,7 +1447,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { description string givenBiddersResponse map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account expectedBiddersResponse map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid expectedReject *RejectError expectedModuleContexts *moduleContexts @@ -1475,7 +1458,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, }, givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, expectedBiddersResponse: expectedAllProcBidResponses, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{}}, @@ -1487,7 +1469,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, }, givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, expectedBiddersResponse: expectedUpdatedAllProcBidResponses, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -1546,7 +1527,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, }, givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, expectedBiddersResponse: expectedUpdatedAllProcBidResponses, expectedReject: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "foo"}, hooks.StageAllProcessedBidResponses.String()}, expectedModuleContexts: foobarModuleCtx, @@ -1611,7 +1591,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, }, givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, expectedBiddersResponse: expectedUpdatedAllProcBidResponses, expectedReject: nil, expectedModuleContexts: foobarModuleCtx, @@ -1660,7 +1639,6 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { "some-bidder": {Bids: []*entities.PbsOrtbBid{{DealPriority: 1}}}, }, givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, expectedBiddersResponse: expectedAllProcBidResponses, expectedReject: nil, expectedModuleContexts: &moduleContexts{ctxs: map[string]hookstage.ModuleContext{ @@ -1710,10 +1688,9 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { t.Run(test.description, func(t *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) exec.ExecuteAllProcessedBidResponsesStage(test.givenBiddersResponse) @@ -1732,14 +1709,12 @@ func TestExecuteAllProcessedBidResponsesStage(t *testing.T) { func TestExecuteAuctionResponseStage(t *testing.T) { foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}} - account := &config.Account{} resp := &openrtb2.BidResponse{CustomData: "some-custom-data"} expResp := &openrtb2.BidResponse{CustomData: "new-custom-data"} testCases := []struct { description string givenPlanBuilder hooks.ExecutionPlanBuilder - givenAccount *config.Account givenResponse *openrtb2.BidResponse expectedResponse *openrtb2.BidResponse expectedReject *RejectError @@ -1749,7 +1724,6 @@ func TestExecuteAuctionResponseStage(t *testing.T) { { description: "Payload not changed if hook execution plan empty", givenPlanBuilder: hooks.EmptyPlanBuilder{}, - givenAccount: account, givenResponse: resp, expectedResponse: resp, expectedReject: nil, @@ -1759,7 +1733,6 @@ func TestExecuteAuctionResponseStage(t *testing.T) { { description: "Payload changed if hooks return mutations", givenPlanBuilder: TestApplyHookMutationsBuilder{}, - givenAccount: account, givenResponse: resp, expectedResponse: expResp, expectedReject: nil, @@ -1792,7 +1765,6 @@ func TestExecuteAuctionResponseStage(t *testing.T) { { description: "Stage execution can't be rejected - stage doesn't support rejection", givenPlanBuilder: TestRejectPlanBuilder{}, - givenAccount: nil, givenResponse: resp, expectedResponse: expResp, expectedReject: &RejectError{0, HookID{ModuleCode: "foobar", HookImplCode: "foo"}, hooks.StageAuctionResponse.String()}, @@ -1855,7 +1827,6 @@ func TestExecuteAuctionResponseStage(t *testing.T) { { description: "Request can be changed when a hook times out", givenPlanBuilder: TestWithTimeoutPlanBuilder{}, - givenAccount: account, givenResponse: resp, expectedResponse: expResp, expectedReject: nil, @@ -1902,7 +1873,6 @@ func TestExecuteAuctionResponseStage(t *testing.T) { { description: "Modules contexts are preserved and correct", givenPlanBuilder: TestWithModuleContextsPlanBuilder{}, - givenAccount: account, givenResponse: resp, expectedResponse: resp, expectedReject: nil, @@ -1963,10 +1933,9 @@ func TestExecuteAuctionResponseStage(t *testing.T) { t.Run(test.description, func(t *testing.T) { exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{}) - privacyConfig := getTransmitUFPDActivityConfig("foo", false) + privacyConfig := getModuleActivities("foo", false, false) ac := privacy.NewActivityControl(privacyConfig) exec.SetActivityControl(ac) - exec.SetAccount(test.givenAccount) exec.ExecuteAuctionResponseStage(test.givenResponse)