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

update cookie sync endpoint to be case insensitive #3103

Merged
merged 6 commits into from
Oct 17, 2023
Merged

Conversation

gargcreation1992
Copy link
Contributor

@gargcreation1992 gargcreation1992 commented Sep 14, 2023

Tested locally with /cookie_sync POST endpoint with following body -

{
"bidders": ["AppnexUs"],
"coopsync": false,
"limit": 1
}

and got this sample response -

{
  "status" : "no_cookie",
  "bidder_status" : [
    {
      "no_cookie" : true,
      "bidder" : "AppnexUs",
      "usersync" : {
        "url" : "https://ib.adnxs.com/getuid?http%3A%2F%2Flocalhost%3A8000%2Fsetuid%3Fbidder%3Dappnexus%26gdpr%3D%26gdpr_consent%3D%26gpp%3D%26gpp_sid%3D%26f%3Di%26uid%3D%24UID",
        "type" : "redirect"
      }
    }
  ]
}

partially resolves #2400

Comment on lines 145 to 150
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder}
}

syncer, exists := c.bidderSyncerLookup[coreBidder.String()]
if !exists {
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder}
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@onkarvhanumante onkarvhanumante left a 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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@gargcreation1992
Copy link
Contributor Author

@bsardo Requesting you to please comment on the reason for the blocked label on this PR.

@bsardo
Copy link
Collaborator

bsardo commented Sep 28, 2023

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.

@SyntaxNode
Copy link
Contributor

Unblocking. This is higher priority than the other PR.

@SyntaxNode SyntaxNode removed the blocked label Oct 6, 2023
Copy link
Contributor

@SyntaxNode SyntaxNode left a 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.

bidderSyncerLookup: bidderSyncerLookup,
biddersAvailable: bidders,
bidderChooser: standardBidderChooser{shuffler: randomShuffler{}},
normalizedBidderNamesLookup: openrtb_ext.NormalizeBidderName,
Copy link
Contributor

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 145 to 150
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder}
}

syncer, exists := c.bidderSyncerLookup[coreBidder.String()]
if !exists {
return nil, BidderEvaluation{Status: StatusUnknownBidder, Bidder: bidder}
Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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{},
},
},
}
Copy link
Contributor

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.

Copy link
Contributor Author

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},
},
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SyntaxNode
Copy link
Contributor

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.

@AlexBVolcy
Copy link
Contributor

I think there's a problem in evaluate(), I left a comment describing the issue.

@gargcreation1992
Copy link
Contributor Author

gargcreation1992 commented Oct 10, 2023

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.

For sync type filter - 88209d7
For UserSyncPrivacy - 176b887

@@ -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))) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

@SyntaxNode SyntaxNode self-assigned this Oct 16, 2023
@gargcreation1992 gargcreation1992 merged commit 1384564 into master Oct 17, 2023
3 checks passed
@gargcreation1992 gargcreation1992 deleted the PBS-1254 branch October 17, 2023 06:30
svamiftah pushed a commit to sovrn/prebid-server that referenced this pull request Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bidder names should be case insensitive
6 participants