-
Notifications
You must be signed in to change notification settings - Fork 769
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
Added TransmitPreciseGeo activity handling in modules #3348
Changes from 3 commits
484e500
eb06682
bdfec58
28396f8
d409cf5
7b67759
26557fe
f740479
1df492e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,12 @@ import ( | |
"testing" | ||
) | ||
|
||
const ( | ||
testIpv6 = "1111:2222:3333:4444:5555:6666:7777:8888" | ||
testIPv6Scubbed = "1111:2222::" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nitpick: typo Scrubbed |
||
testIPv6ScrubBytes = 32 | ||
) | ||
|
||
func TestHandleModuleActivitiesBidderRequestPayload(t *testing.T) { | ||
|
||
testCases := []struct { | ||
|
@@ -49,13 +55,44 @@ 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: testIPv6Scubbed}, | ||
}, | ||
}}, | ||
}, | ||
{ | ||
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) | ||
accountPrivacy := config.AccountPrivacy{IPv6Config: config.IPv6{testIPv6ScrubBytes}} | ||
newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData, accountPrivacy) | ||
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: testIPv6Scubbed}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
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) | ||
accountPrivacy := config.AccountPrivacy{IPv6Config: config.IPv6{testIPv6ScrubBytes}} | ||
newPayload := handleModuleActivities(test.hookCode, activityControl, test.inPayloadData, accountPrivacy) | ||
assert.Equal(t, test.expectedPayloadData.Request.BidRequest, newPayload.Request.BidRequest) | ||
assert.Equal(t, origInPayloadData, test.inPayloadData) | ||
}) | ||
|
@@ -137,13 +206,27 @@ func TestHandleModuleActivitiesNoBidderRequestPayload(t *testing.T) { | |
privacyConfig: getTransmitUFPDActivityConfig("foo", true), | ||
expectedPayloadData: hookstage.RawAuctionRequestPayload{}, | ||
}, | ||
{ | ||
description: "payload should change when transmitPreciseGeo is blocked by activity", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the test cases in this test have descriptions that indicate the payload should change but it doesn't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, description fixed. Payload should NOT change in any of these cases, because |
||
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.AccountPrivacy{}) | ||
assert.Equal(t, test.expectedPayloadData, newPayload) | ||
assert.Equal(t, origInPayloadData, test.inPayloadData) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ func NewHookExecutor(builder hooks.ExecutionPlanBuilder, endpoint string, me met | |
stageOutcomes: []StageOutcome{}, | ||
moduleContexts: &moduleContexts{ctxs: make(map[string]hookstage.ModuleContext)}, | ||
metricEngine: me, | ||
account: &config.Account{Privacy: config.AccountPrivacy{}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the motivation for creating an empty account here instead of just keeping it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed. I changed |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice there should always be an account if we've gotten this far but perhaps we should add a check here to make sure the account is not nil just to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, in practice we will always have an account because we call
hookExecutor.SetAccount(account)
in auction and amp_auction.In order to add nil check for account, what do we expect to do if for some reason account is nil?
privacy.ScrubGeoAndDeviceIP(bidderReqCopy, ipConf)
account.Privacy.IPv6Config.AnonKeepBits = iputil.IPv6DefaultMaskingBitSize
andaccount.Privacy.IPv4Config.AnonKeepBits = iputil.IPv4DefaultMaskingBitSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest option 2 so that we still scrub given the sensitive nature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated