Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TID activity #3012

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/prebid/prebid-server/hooks"
"github.com/prebid/prebid-server/hooks/hookexecution"
"github.com/prebid/prebid-server/ortb"
"github.com/prebid/prebid-server/privacy"
jsonpatch "gopkg.in/evanphx/json-patch.v4"

accountService "github.com/prebid/prebid-server/account"
Expand Down Expand Up @@ -302,6 +303,15 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re
return
}

activities, activitiesErr := privacy.NewActivityControl(account.Privacy)
if activitiesErr != nil {
errL = append(errL, activitiesErr)
if errortypes.ContainsFatalError(errL) {
handleError(&labels, w, errL, &vo, &debugLog)
return
}
}

secGPC := r.Header.Get("Sec-GPC")
auctionRequest := &exchange.AuctionRequest{
BidRequestWrapper: bidReqWrapper,
Expand All @@ -314,6 +324,7 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re
PubID: labels.PubID,
HookExecutor: hookexecution.EmptyHookExecutor{},
TmaxAdjustments: deps.tmaxAdjustments,
Activities: activities,
}

auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, &debugLog)
Expand Down
48 changes: 48 additions & 0 deletions endpoints/openrtb2/video_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ func TestVideoEndpointImpressionsNumber(t *testing.T) {
assert.Equal(t, resp.AdPods[0].Targeting[0].HbDeal, "ABC_123", "If DealID exists in bid response, hb_deal targeting needs to be added to resp")
}

func TestVideoEndpointInvalidPrivacyConfig(t *testing.T) {
ex := &mockExchangeVideo{}
reqBody := readVideoTestFile(t, "sample-requests/video/video_valid_sample.json")
req := httptest.NewRequest("POST", "/openrtb2/video", strings.NewReader(reqBody))
recorder := httptest.NewRecorder()

deps := mockDepsInvalidPrivacy(t, ex)
deps.VideoAuctionEndpoint(recorder, req, nil)

respBytes := recorder.Body.Bytes()
expectedErrorMessage := "Critical error while running the video endpoint: unable to parse condition: bidderA.BidderB.bidderC"
assert.Equal(t, expectedErrorMessage, string(respBytes), "error message is incorrect")
}

func TestVideoEndpointImpressionsDuration(t *testing.T) {
ex := &mockExchangeVideo{}
reqBody := readVideoTestFile(t, "sample-requests/video/video_valid_sample_different_durations.json")
Expand Down Expand Up @@ -1275,6 +1289,40 @@ func mockDeps(t *testing.T, ex *mockExchangeVideo) *endpointDeps {
}
}

func mockDepsInvalidPrivacy(t *testing.T, ex *mockExchangeVideo) *endpointDeps {
return &endpointDeps{
fakeUUIDGenerator{},
ex,
mockBidderParamValidator{},
&mockVideoStoredReqFetcher{},
&mockVideoStoredReqFetcher{},
&mockAccountFetcher{data: mockVideoAccountData},
&config.Configuration{MaxRequestSize: maxSize,
AccountDefaults: config.Account{
Privacy: &config.AccountPrivacy{
AllowActivities: config.AllowActivities{
TransmitPreciseGeo: config.Activity{Rules: []config.ActivityRule{
{Condition: config.ActivityCondition{ComponentName: []string{"bidderA.BidderB.bidderC"}}},
}},
},
},
},
},
&metricsConfig.NilMetricsEngine{},
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
map[string]string{},
false,
[]byte{},
openrtb_ext.BuildBidderMap(),
ex.cache,
regexp.MustCompile(`[<>]`),
hardcodedResponseIPValidator{response: true},
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
}
}

func mockDepsAppendBidderNames(t *testing.T, ex *mockExchangeAppendBidderNames) *endpointDeps {
deps := &endpointDeps{
fakeUUIDGenerator{},
Expand Down
8 changes: 8 additions & 0 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
metricsConfig "github.com/prebid/prebid-server/metrics/config"
"github.com/prebid/prebid-server/openrtb_ext"
pbc "github.com/prebid/prebid-server/prebid_cache_client"
"github.com/prebid/prebid-server/privacy"
"github.com/prebid/prebid-server/stored_requests"
"github.com/prebid/prebid-server/stored_requests/backends/file_fetcher"
"github.com/prebid/prebid-server/usersync"
Expand Down Expand Up @@ -2351,6 +2352,11 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
impExtInfoMap[impID] = ImpExtInfo{}
}

activityControl, err := privacy.NewActivityControl(spec.AccountPrivacy)
if err != nil {
t.Errorf("%s: Exchange returned an unexpected error. Got %s", filename, err.Error())
}

auctionRequest := &AuctionRequest{
BidRequestWrapper: &openrtb_ext.RequestWrapper{BidRequest: &spec.IncomingRequest.OrtbRequest},
Account: config.Account{
Expand All @@ -2366,6 +2372,7 @@ func runSpec(t *testing.T, filename string, spec *exchangeSpec) {
ImpExtInfoMap: impExtInfoMap,
HookExecutor: &hookexecution.EmptyHookExecutor{},
TCF2Config: gdpr.NewTCF2Config(privacyConfig.GDPR.TCF2, config.AccountGDPR{}),
Activities: activityControl,
}

if spec.MultiBid != nil {
Expand Down Expand Up @@ -5187,6 +5194,7 @@ type exchangeSpec struct {
FledgeEnabled bool `json:"fledge_enabled,omitempty"`
MultiBid *multiBidSpec `json:"multiBid,omitempty"`
Server exchangeServer `json:"server,omitempty"`
AccountPrivacy *config.AccountPrivacy `json:"accountPrivacy,omitempty"`
}

type multiBidSpec struct {
Expand Down
85 changes: 85 additions & 0 deletions exchange/exchangetest/activity-tid-off.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"accountPrivacy": {
"allowactivities": {
"transmitTid": {
"default": true,
"rules": [
{
"allow": true,
"condition": {
"componentName": ["appnexus"],
"componentType":["bidder"]
}
}
]
}
}
},
"incomingRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"tid": "extTestTID",
"prebid": {
"bidder": {
"appnexus": {
"placementId": 1
}
}
}
}
}
],
"source": {
"tid": "sourceTestTID"
}
}
},
"outgoingRequests": {
"appnexus": {
"expectRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"tid": "extTestTID",
"bidder": {
"placementId": 1
}
}
}
],
"source": {
"tid": "sourceTestTID"
}
}
},
"mockResponse": {
"errors": [
"appnexus-error"
]
}
}
}
}
82 changes: 82 additions & 0 deletions exchange/exchangetest/activity-tid-on.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"accountPrivacy": {
"allowactivities": {
"transmitTid": {
"default": true,
"rules": [
{
"allow": false,
"condition": {
"componentName": ["appnexus"],
"componentType":["bidder"]
}
}
]
}
}
},
"incomingRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"tid": "extTestTID",
"prebid": {
"bidder": {
"appnexus": {
"placementId": 1
}
}
}
}
}
],
"source": {
"tid": "sourceTestTID"
}
}
},
"outgoingRequests": {
"appnexus": {
"expectRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"bidder": {
"placementId": 1
}
}
}
],
"source": {}
}
},
"mockResponse": {
"errors": [
"appnexus-error"
]
}
}
}
}
2 changes: 2 additions & 0 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
applyFPD(auctionReq.FirstPartyData[bidderRequest.BidderName], bidderRequest.BidRequest)
}

privacyEnforcement.TID = !auctionReq.Activities.Allow(privacy.ActivityTransmitTids, scopedName)

privacyEnforcement.Apply(bidderRequest.BidRequest)
allowedBidderRequests = append(allowedBidderRequests, bidderRequest)

Expand Down
Loading