-
Notifications
You must be signed in to change notification settings - Fork 748
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
update cookie sync endpoint to be case insensitive #3103
Conversation
usersync/chooser.go
Outdated
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder} | ||
} | ||
|
||
syncer, exists := c.bidderSyncerLookup[coreBidder.String()] | ||
if !exists { | ||
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder} |
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.
Line 145 and 150 returns same error. How about changing Line 150 to syncerKeyNotFound
status
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.
syncerKeyNotFound
seems irrelevant to me here since this check is not related with syncher keys.
This is actually checking if there is a coreBidder exists for the provided bidder in the request to which we are returning UnknownBidder
if there is no coreBidder found for the provided bidder and that sounds ok to me.
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.
Line 150 will become StatusUnconfiguredBidder
in #3107.
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.
one suggestion. otherwise looks good to me 👍🏼
@@ -87,7 +87,7 @@ func TestNewCookieSyncEndpoint(t *testing.T) { | |||
assert.IsType(t, &cookieSyncEndpoint{}, endpoint) | |||
|
|||
assert.Equal(t, expected.config, result.config) | |||
assert.Equal(t, expected.chooser, result.chooser) | |||
assert.ObjectsAreEqualValues(expected.chooser, result.chooser) |
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.
For my own understanding, why was this 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.
When we mocked normalizedBidderNamesLookup
field in standardChooser - apparently, go changes the address of the struct by copying the values to a new struct. Hence, the address are different however the values are same and that is what the assert statement is doing.
@bsardo Requesting you to please comment on the reason for the |
This one is marked as blocked because it was determined that it conflicts with #3107 and the team came to the conclusion that we should try to merge that in first. It would be nice to get this in 2.0 but it isn't essential. |
Unblocking. This is higher priority than the other PR. |
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.
You also need to add case insensitivity for type filters and account for privacy checks in the usersyncPrivacy methods. Please add tests for those areas too.
usersync/chooser.go
Outdated
bidderSyncerLookup: bidderSyncerLookup, | ||
biddersAvailable: bidders, | ||
bidderChooser: standardBidderChooser{shuffler: randomShuffler{}}, | ||
normalizedBidderNamesLookup: openrtb_ext.NormalizeBidderName, |
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.
Can shorten to normalizeBidderName
, or perhaps to express this includes both normalization and validation. Something like: normalizeValidBidderName
, normalizeAndValidateBidder
, etc...
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.
usersync/chooser.go
Outdated
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder} | ||
} | ||
|
||
syncer, exists := c.bidderSyncerLookup[coreBidder.String()] | ||
if !exists { | ||
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder} |
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.
Line 150 will become StatusUnconfiguredBidder
in #3107.
usersync/chooser.go
Outdated
@@ -136,7 +140,12 @@ func (c standardChooser) Choose(request Request, cookie *Cookie) Result { | |||
} | |||
|
|||
func (c standardChooser) evaluate(bidder string, syncersSeen map[string]struct{}, syncTypeFilter SyncTypeFilter, privacy Privacy, cookie *Cookie) (Syncer, BidderEvaluation) { | |||
syncer, exists := c.bidderSyncerLookup[bidder] | |||
coreBidder, exists := c.normalizedBidderNamesLookup(bidder) |
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.
This is not a coreBidder
because it could also be an alias. Consider renaming to something like bidderNormalized
.
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.
There's an issue here where the original-cased bidder name is passed to GDPRAllowsBidderSync
further below, which checks the original-cased bidder name against a list of all lowercased bidder names. So it means this function always returns false.
Should we just pass the coreBidder
to these functions instead? To preserve the case insensitivity.
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.
BiddersEvaluated: []BidderEvaluation{{Bidder: "a", Status: StatusUnknownBidder}}, | ||
SyncersChosen: []SyncerChoice{}, | ||
}, | ||
}, | ||
} |
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.
Please add test cases for case insensitivity. We're not yet testing the new normalizedBidderNamesLookup call.
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.
expectedSyncer: nil, | ||
expectedEvaluation: BidderEvaluation{Bidder: "a", SyncerKey: "keyA", Status: StatusBlockedByPrivacy}, | ||
expectedEvaluation: BidderEvaluation{Bidder: "a", Status: StatusUnknownBidder}, | ||
}, |
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.
Same here. Please add a case insensitivity test.
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.
Please also add a test for the chooser StatusDuplicate case, to make sure a duplicated bidder name triggers this code where the bidder name in the evaluated list matches what was provided in the request. |
I think there's a problem in |
Test cases for case insensitive bidder names and duplicate bidder names
@@ -147,7 +159,7 @@ func (c standardChooser) evaluate(bidder string, syncersSeen map[string]struct{} | |||
} | |||
syncersSeen[syncer.Key()] = struct{}{} | |||
|
|||
if !syncer.SupportsType(syncTypeFilter.ForBidder(bidder)) { | |||
if !syncer.SupportsType(syncTypeFilter.ForBidder(strings.ToLower(bidder))) { |
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.
Can't this line also use bidderNormalized.String()
? And we don't have include the strings
package into this file?
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.
We cannot use normalised bidder name here and the reason is there is biddersLookup map that is created in NewSpecificBidderFilter
function with key of the map being lower cased. . This map is used when we call syncTypeFilter.ForBidder
function. Hope this clarifies.
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 see, but when I subbed in bidderNomarlized.String()
for strings.ToLower(bidder)
, all of the tests still passed. This is more of a nitpick if anything, so I'm happy to approve if you want to stick with the current code.
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.
@AlexBVolcy It is because test cases are setup that way. If you setup a test case where you use suntContent
as bidder name, you will be able to fail your test. In fact I have updated one of the test to reflect this - c124abb
Tested locally with
/cookie_sync
POST endpoint with following body -and got this sample response -
partially resolves #2400