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

EIDs Should Not Require Unique Sources #3607

Merged
merged 3 commits into from
Apr 9, 2024
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
7 changes: 2 additions & 5 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,7 @@ func (deps *endpointDeps) validateUser(req *openrtb_ext.RequestWrapper, aliases
if err != nil {
return append(errL, fmt.Errorf("request.user.ext object is not valid: %v", err))
}

// Check if the buyeruids are valid
prebid := userExt.GetPrebid()
if prebid != nil {
Expand All @@ -1849,19 +1850,15 @@ func (deps *endpointDeps) validateUser(req *openrtb_ext.RequestWrapper, aliases
}
}
}

// Check Universal User ID
eids := userExt.GetEid()
if eids != nil {
eidsValue := *eids
uniqueSources := make(map[string]struct{}, len(eidsValue))
for eidIndex, eid := range eidsValue {
if eid.Source == "" {
return append(errL, fmt.Errorf("request.user.ext.eids[%d] missing required field: \"source\"", eidIndex))
}
if _, ok := uniqueSources[eid.Source]; ok {
return append(errL, errors.New("request.user.ext.eids must contain unique sources"))
}
uniqueSources[eid.Source] = struct{}{}

if len(eid.UIDs) == 0 {
return append(errL, fmt.Errorf("request.user.ext.eids[%d].uids must contain at least one element or be undefined", eidIndex))
Expand Down
36 changes: 19 additions & 17 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3769,99 +3769,99 @@ func TestValidateEidPermissions(t *testing.T) {
knownAliases := map[string]string{"b": "b"}

testCases := []struct {
description string
name string
request *openrtb_ext.ExtRequest
expectedError error
}{
{
description: "Valid - Empty ext",
name: "valid-empty-ext",
request: &openrtb_ext.ExtRequest{},
expectedError: nil,
},
{
description: "Valid - Nil ext.prebid.data",
name: "valid-nil-ext.prebid.data",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{}},
expectedError: nil,
},
{
description: "Valid - Empty ext.prebid.data",
name: "valid-empty-ext.prebid.data",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{}}},
expectedError: nil,
},
{
description: "Valid - Nil ext.prebid.data.eidpermissions",
name: "valid-nil-ext.prebid.data.eidpermissions",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: nil}}},
expectedError: nil,
},
{
description: "Valid - None",
name: "valid-none",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{}}}},
expectedError: nil,
},
{
description: "Valid - One",
name: "valid-one",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
}}}},
expectedError: nil,
},
{
description: "Valid - One - Case Insensitive",
name: "valid-one-case-insensitive",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"A"}},
}}}},
expectedError: nil,
},
{
description: "Valid - Many",
name: "valid-many",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Source: "sourceB", Bidders: []string{"a"}},
}}}},
expectedError: nil,
},
{
description: "Invalid - Missing Source",
name: "invalid-missing-source",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Bidders: []string{"a"}},
}}}},
expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] missing required field: "source"`),
},
{
description: "Invalid - Duplicate Source",
name: "invalid-duplicate-source",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still a valid check since this is for eid permissions, which still makes sense to enforce a unique source to avoid unclear direction.

request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Source: "sourceA", Bidders: []string{"a"}},
}}}},
expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] duplicate entry with field: "source"`),
},
{
description: "Invalid - Missing Bidders - Nil",
name: "invalid-missing-bidders-nil",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Source: "sourceB"},
}}}},
expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] missing or empty required field: "bidders"`),
},
{
description: "Invalid - Missing Bidders - Empty",
name: "invalid-missing-bidders-empty",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Source: "sourceB", Bidders: []string{}},
}}}},
expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] missing or empty required field: "bidders"`),
},
{
description: "Invalid - Invalid Bidders",
name: "invalid-invalid-bidders",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"a"}},
{Source: "sourceB", Bidders: []string{"z"}},
}}}},
expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] contains unrecognized bidder "z"`),
},
{
description: "Valid - Alias Case Sensitive",
name: "invalid-alias-case-sensitive",
request: &openrtb_ext.ExtRequest{Prebid: openrtb_ext.ExtRequestPrebid{Data: &openrtb_ext.ExtRequestPrebidData{EidPermissions: []openrtb_ext.ExtRequestPrebidDataEidPermission{
{Source: "sourceA", Bidders: []string{"B"}},
}}}},
Expand All @@ -3871,8 +3871,10 @@ func TestValidateEidPermissions(t *testing.T) {

endpoint := &endpointDeps{bidderMap: knownBidders, normalizeBidderName: fakeNormalizeBidderName}
for _, test := range testCases {
result := endpoint.validateEidPermissions(test.request.Prebid.Data, knownAliases)
assert.Equal(t, test.expectedError, result, test.description)
t.Run(test.name, func(t *testing.T) {
result := endpoint.validateEidPermissions(test.request.Prebid.Data, knownAliases)
assert.Equal(t, test.expectedError, result)
})
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
{
"description": "Bid request with empty eids array in user.ext",
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "prebid.org"
"description": "Bid request with empty eids array in user.ext",
"mockBidRequest": {
"id": "anyRequestID",
"site": {
"page": "prebid.org",
"publisher": {
"id": "anyPublisher"
}
},
"imp": [
{
"id": "anyImpID",
"ext": {
"appnexus": {
"placementId": 42
}
},
"imp": [
"banner": {
"format": [
{
"id": "some-impression-id",
"ext": {
"appnexus": {
"placementId": 123456
}
},
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
}
}
],
"tmax": 1000,
"user": {
"ext": {
"eids": []
}
}
},
"expectedBidResponse": {
"id": "some-request-id",
"seatbid": [
"w": 300,
"h": 250
},
{
"bid": [
{
"id": "appnexus-bid",
"impid": "some-impression-id",
"price": 0
}
],
"seat": "appnexus"
"w": 300,
"h": 600
}
]
}
}
],
"tmax": 1000,
"user": {
"ext": {
"eids": []
}
}
},
"expectedBidResponse": {
"id": "anyRequestID",
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "anyImpID",
"price": 0
}
],
"bidid": "test bid id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
"seat": "appnexus"
}
],
"bidid": "test bid id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"description": "Bid request where more than one request.user.ext.eids array elements share the same source field value",
"mockBidRequest": {
"id": "anyRequestID",
"site": {
"page": "prebid.org",
"publisher": {
"id": "anyPublisher"
}
},
"imp": [
{
"id": "anyImpID",
"ext": {
"appnexus": {
"placementId": 42
}
},
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
}
}
],
"tmax": 1000,
"user": {
"ext": {
"eids": [
{
"source": "source1",
"uids": [
{
"id": "A"
}
]
},
{
"source": "source1",
"uids": [
{
"id": "B"
}
]
}
]
}
}
},
"expectedBidResponse": {
"id": "anyRequestID",
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "anyImpID",
"price": 0
}
],
"seat": "appnexus"
}
],
"bidid": "test bid id",
"cur": "USD",
"nbr": 0
},
"expectedReturnCode": 200
}
Loading