-
Notifications
You must be signed in to change notification settings - Fork 774
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
Implement EID Permissions #1633
Changes from 6 commits
6b9731f
8c9c600
45f8b09
c937b2f
96c9dc4
085ae36
43a9fc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,6 +331,10 @@ func (deps *endpointDeps) validateRequest(req *openrtb.BidRequest) []error { | |
if err := validateSChains(bidExt); err != nil { | ||
return []error{err} | ||
} | ||
|
||
if err := deps.validateEidPermissions(bidExt, aliases); err != nil { | ||
return []error{err} | ||
} | ||
} | ||
|
||
if (req.Site == nil && req.App == nil) || (req.Site != nil && req.App != nil) { | ||
|
@@ -419,6 +423,51 @@ func validateSChains(req *openrtb_ext.ExtRequest) error { | |
return err | ||
} | ||
|
||
func (deps *endpointDeps) validateEidPermissions(req *openrtb_ext.ExtRequest, aliases map[string]string) error { | ||
if req == nil || req.Prebid.Data == nil { | ||
return nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to issue #1621: "If eidPermissions is not an array, ignore it and emit a 400 error with a reasonable description in the body". We do check the array lenght downstream in
Should we error out when empty instead? If so, should we do it here before it gets downstream?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unmarshaller enforces type correctness. If it's not an array, the core json.Unmarshal method will return an error and we already consider that a fatal error. I don't really see a need to consider an empty array as a validation error. It's silly to pass an empty array.. but is it worth rejecting a request for? |
||
|
||
uniqueSources := make(map[string]struct{}, len(req.Prebid.Data.EidPermissions)) | ||
for i, eid := range req.Prebid.Data.EidPermissions { | ||
if len(eid.Source) == 0 { | ||
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] missing required field: "source"`, i) | ||
} | ||
|
||
if _, exists := uniqueSources[eid.Source]; exists { | ||
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] duplicate entry with field: "source"`, i) | ||
} | ||
uniqueSources[eid.Source] = struct{}{} | ||
|
||
if len(eid.Bidders) == 0 { | ||
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] missing or empty required field: "bidders"`, i) | ||
} | ||
|
||
if err := validateBidders(eid.Bidders, deps.bidderMap, aliases); err != nil { | ||
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] contains %v`, i, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateBidders(bidders []string, knownBidders map[string]openrtb_ext.BidderName, knownAliases map[string]string) error { | ||
for _, bidder := range bidders { | ||
if bidder == "*" { | ||
if len(bidders) > 1 { | ||
return errors.New(`bidder wildcard "*" mixed with specific bidders`) | ||
} | ||
} else { | ||
_, isCoreBidder := knownBidders[bidder] | ||
_, isAlias := knownAliases[bidder] | ||
if !isCoreBidder && !isAlias { | ||
return fmt.Errorf(`unrecognized bidder "%v"`, bidder) | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (deps *endpointDeps) validateImp(imp *openrtb.Imp, aliases map[string]string, index int) []error { | ||
if imp.ID == "" { | ||
return []error{fmt.Errorf("request.imp[%d] missing required field: \"id\"", index)} | ||
|
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.
The first condition will never be false because
validateEidPermissions
only gets called if condition in line 320 ofendpoints/openrtb2/auction.go
evaluates totrue