diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index 8c178ff3c0b..4f014b963d1 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -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 { @@ -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)) diff --git a/endpoints/openrtb2/auction_test.go b/endpoints/openrtb2/auction_test.go index af6f4a1b86a..ee82ffdf9f4 100644 --- a/endpoints/openrtb2/auction_test.go +++ b/endpoints/openrtb2/auction_test.go @@ -3769,51 +3769,51 @@ 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"}}, @@ -3821,7 +3821,7 @@ func TestValidateEidPermissions(t *testing.T) { 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"}}, @@ -3829,7 +3829,7 @@ func TestValidateEidPermissions(t *testing.T) { expectedError: errors.New(`request.ext.prebid.data.eidpermissions[1] missing required field: "source"`), }, { - description: "Invalid - Duplicate Source", + name: "invalid-duplicate-source", 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"}}, @@ -3837,7 +3837,7 @@ func TestValidateEidPermissions(t *testing.T) { 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"}, @@ -3845,7 +3845,7 @@ func TestValidateEidPermissions(t *testing.T) { 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{}}, @@ -3853,7 +3853,7 @@ func TestValidateEidPermissions(t *testing.T) { 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"}}, @@ -3861,7 +3861,7 @@ func TestValidateEidPermissions(t *testing.T) { 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"}}, }}}}, @@ -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) + }) } } diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/user-ext-eids-source-duplicate.json b/endpoints/openrtb2/sample-requests/invalid-whole/user-ext-eids-source-duplicate.json deleted file mode 100644 index 05cd7f34f8c..00000000000 --- a/endpoints/openrtb2/sample-requests/invalid-whole/user-ext-eids-source-duplicate.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "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": 300 - } - ] - } - }], - "tmax": 1000, - "user": { - "ext": { - "eids": [{ - "source": "source1", - "uids": [{ - "id": "A" - }] - }, { - "source": "source1", - "uids": [{ - "id": "B" - }] - }] - } - } - }, - "expectedReturnCode": 400, - "expectedErrorMessage": "Invalid request: request.user.ext.eids must contain unique sources\n" -} \ No newline at end of file diff --git a/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-empty.json b/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-empty.json index 9f047613277..ab633724e11 100644 --- a/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-empty.json +++ b/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-empty.json @@ -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 } \ No newline at end of file diff --git a/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-source-duplicate.json b/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-source-duplicate.json new file mode 100644 index 00000000000..e4ee6c72e49 --- /dev/null +++ b/endpoints/openrtb2/sample-requests/valid-whole/exemplary/user-ext-eids-source-duplicate.json @@ -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 +} \ No newline at end of file