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

Remove invalid user EIDs and UIDs from bid request #3891

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
59 changes: 50 additions & 9 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,23 +1277,64 @@ func (deps *endpointDeps) validateUser(req *openrtb_ext.RequestWrapper, aliases
}

// Check Universal User ID
for eidIndex, eid := range req.User.EIDs {
if len(req.User.EIDs) > 0 {

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick; Please remove the leading empty line.

validEids, eidErrors := validateEIDs(req.User.EIDs)

if len(eidErrors) > 0 {
errL = append(errL, eidErrors...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely fine to keep this logic here for now. We want to separate validation from fixing in the future. We can refactor this new logic along with the rest later. Thoughts @bsardo?

req.User.EIDs = validEids
}

return errL
}

func validateEIDs(eids []openrtb2.EID) ([]openrtb2.EID, []error) {
var errorsList []error
validEIDs := make([]openrtb2.EID, 0, len(eids))

for eidIndex, eid := range eids {
if eid.Source == "" {
return append(errL, fmt.Errorf("request.user.eids[%d] missing required field: \"source\"", eidIndex))
errorsList = append(errorsList, &errortypes.Warning{
Message: fmt.Sprintf("request.user.eids[%d] missing required field: source", eidIndex),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: can we change the error message a bit so that all of the messages in this function have similar wording?
request.user.eids[%d] removed due to missing 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.

Done

WarningCode: errortypes.InvalidUserEIDsWarningCode,
})
continue
}
validUIDs, uidErrors := validateUIDs(eid.UIDs, eidIndex)
errorsList = append(errorsList, uidErrors...)

if len(eid.UIDs) == 0 {
return append(errL, fmt.Errorf("request.user.eids[%d].uids must contain at least one element or be undefined", eidIndex))
if len(validUIDs) > 0 {
eid.UIDs = validUIDs
validEIDs = append(validEIDs, eid)
} else {
errorsList = append(errorsList, &errortypes.Warning{
Message: fmt.Sprintf("request.user.eids[%d] (source: %s) contains only empty uids and is removed from the request", eidIndex, eid.Source),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: can we change the error message a bit so that all of the messages in this function have similar wording and so it is a bit more concise?
request.user.eids[%d] (%s) removed due to empty uids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

WarningCode: errortypes.InvalidUserEIDsWarningCode,
})
}
}

for uidIndex, uid := range eid.UIDs {
if uid.ID == "" {
return append(errL, fmt.Errorf("request.user.eids[%d].uids[%d] missing required field: \"id\"", eidIndex, uidIndex))
}
return validEIDs, errorsList
}

func validateUIDs(uids []openrtb2.UID, eidIndex int) ([]openrtb2.UID, []error) {
var validUIDs []openrtb2.UID
var uidErrors []error

for uidIndex, uid := range uids {
if uid.ID != "" {
validUIDs = append(validUIDs, uid)
} else {
uidErrors = append(uidErrors, &errortypes.Warning{
Message: fmt.Sprintf("request.user.eids[%d].uids[%d] contains empty ids and is removed from the request", eidIndex, uidIndex),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: can we change the error message a bit so that all of the messages in this function have similar wording and so it is a bit more concise?
request.user.eids[%d].uids[%d] removed due to empty ids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

WarningCode: errortypes.InvalidUserUIDsWarningCode,
})
}
}

return errL
return validUIDs, uidErrors
}

func validateRegs(req *openrtb_ext.RequestWrapper, gpp gpplib.GppContainer) []error {
Expand Down
Loading
Loading