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

Adapter Name Case Insensitive: EID Permissions #3187

Merged
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
1 change: 1 addition & 0 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func NewAmpEndpoint(
storedRespFetcher,
hookExecutionPlanBuilder,
tmaxAdjustments,
openrtb_ext.NormalizeBidderName,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. I hate to add yet another parameter here, but I can't test it properly otherwise.

}).AmpAuction), nil

}
Expand Down
40 changes: 20 additions & 20 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ func NewEndpoint(
ipValidator,
storedRespFetcher,
hookExecutionPlanBuilder,
tmaxAdjustments}).Auction), nil
tmaxAdjustments,
openrtb_ext.NormalizeBidderName}).Auction), nil
}

type normalizeBidderName func(name string) (openrtb_ext.BidderName, bool)

type endpointDeps struct {
uuidGenerator uuidutil.UUIDGenerator
ex exchange.Exchange
Expand All @@ -149,6 +152,7 @@ type endpointDeps struct {
storedRespFetcher stored_requests.Fetcher
hookExecutionPlanBuilder hooks.ExecutionPlanBuilder
tmaxAdjustments *exchange.TmaxAdjustmentsPreprocessed
normalizeBidderName normalizeBidderName
}

func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand Down Expand Up @@ -765,7 +769,7 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
}
}

var aliases map[string]string
var requestAliases map[string]string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making clear these are request aliases, not hardcoded aliases. Request alias names are still case sensitive.

reqExt, err := req.GetRequestExt()
if err != nil {
return []error{fmt.Errorf("request.ext is invalid: %v", err)}
Expand All @@ -777,25 +781,25 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
}

if reqPrebid != nil {
aliases = reqPrebid.Aliases
requestAliases = reqPrebid.Aliases

if err := deps.validateAliases(aliases); err != nil {
if err := deps.validateAliases(requestAliases); err != nil {
return []error{err}
}

if err := deps.validateAliasesGVLIDs(reqPrebid.AliasGVLIDs, aliases); err != nil {
if err := deps.validateAliasesGVLIDs(reqPrebid.AliasGVLIDs, requestAliases); err != nil {
return []error{err}
}

if err := deps.validateBidAdjustmentFactors(reqPrebid.BidAdjustmentFactors, aliases); err != nil {
if err := deps.validateBidAdjustmentFactors(reqPrebid.BidAdjustmentFactors, requestAliases); err != nil {
return []error{err}
}

if err := validateSChains(reqPrebid.SChains); err != nil {
return []error{err}
}

if err := deps.validateEidPermissions(reqPrebid.Data, aliases); err != nil {
if err := deps.validateEidPermissions(reqPrebid.Data, requestAliases); err != nil {
return []error{err}
}

Expand Down Expand Up @@ -844,7 +848,7 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
}
}

if errs := deps.validateUser(req, aliases, gpp); errs != nil {
if errs := deps.validateUser(req, requestAliases, gpp); errs != nil {
if len(errs) > 0 {
errL = append(errL, errs...)
}
Expand All @@ -871,7 +875,7 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
if errortypes.ContainsFatalError([]error{err}) {
return errL
}
} else if _, err := ccpaPolicy.Parse(exchange.GetValidBidders(aliases)); err != nil {
} else if _, err := ccpaPolicy.Parse(exchange.GetValidBidders(requestAliases)); err != nil {
if _, invalidConsent := err.(*errortypes.Warning); invalidConsent {
errL = append(errL, &errortypes.Warning{
Message: fmt.Sprintf("CCPA consent is invalid and will be ignored. (%v)", err),
Expand All @@ -894,7 +898,7 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
}
impIDs[imp.ID] = i

errs := deps.validateImp(imp, aliases, i, hasStoredResponses, storedBidResp)
errs := deps.validateImp(imp, requestAliases, i, hasStoredResponses, storedBidResp)
if len(errs) > 0 {
errL = append(errL, errs...)
}
Expand Down Expand Up @@ -986,7 +990,7 @@ func validateSChains(sChains []*openrtb_ext.ExtRequestPrebidSChain) error {
return err
}

func (deps *endpointDeps) validateEidPermissions(prebid *openrtb_ext.ExtRequestPrebidData, aliases map[string]string) error {
func (deps *endpointDeps) validateEidPermissions(prebid *openrtb_ext.ExtRequestPrebidData, requestAliases map[string]string) error {
if prebid == nil {
return nil
}
Expand All @@ -1006,28 +1010,24 @@ func (deps *endpointDeps) validateEidPermissions(prebid *openrtb_ext.ExtRequestP
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 {
if err := deps.validateBidders(eid.Bidders, deps.bidderMap, requestAliases); 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 {
func (deps *endpointDeps) validateBidders(bidders []string, knownBidders map[string]openrtb_ext.BidderName, knownRequestAliases map[string]string) error {
for _, bidder := range bidders {
if bidder == "*" {
if len(bidders) > 1 {
return errors.New(`bidder wildcard "*" mixed with specific bidders`)
}
} else {
bidderName := bidder
normalizedCoreBidder, ok := openrtb_ext.NormalizeBidderName(bidderName)
if ok {
bidderName = normalizedCoreBidder.String()
}
_, isCoreBidder := knownBidders[bidderName]
_, isAlias := knownAliases[bidder]
bidderNormalized, _ := deps.normalizeBidderName(bidder)
_, isCoreBidder := knownBidders[bidderNormalized.String()]
_, isAlias := knownRequestAliases[bidder]
if !isCoreBidder && !isAlias {
return fmt.Errorf(`unrecognized bidder "%v"`, bidder)
}
Expand Down
Loading