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

DSA: Remove bids missing DSA object when required #3487

Merged
merged 13 commits into from
Feb 20, 2024
Merged

Conversation

bsardo
Copy link
Collaborator

@bsardo bsardo commented Feb 12, 2024

Implements #3367

For requests, pass through behavior was already supported but this adds an exchange test to verify.
For bid responses, validation is added and bids are discarded if DSA objects are required in bids.

Comment on lines 4748 to 4779
description: "Validation is enforced, and one bid out of the two is invalid based on dimensions",
name: "One_of_two_bids_is_invalid_based_on_DSA_object_presence",
givenBidRequestExt: json.RawMessage(`{"dsa": {"dsarequired": 2}}`),
givenValidations: config.Validations{},
givenBids: []*entities.PbsOrtbBid{{Bid: &openrtb2.Bid{Ext: json.RawMessage(`{"dsa": {}}`)}}, {Bid: &openrtb2.Bid{}}},
givenSeat: "pubmatic",
expectedNumOfBids: 1,
expectedNonBids: &nonBids{
seatNonBidsMap: map[string][]openrtb_ext.NonBid{
"pubmatic": {
{
StatusCode: 300,
Ext: openrtb_ext.NonBidExt{
Prebid: openrtb_ext.ExtResponseNonBidPrebid{
Bid: openrtb_ext.NonBidObject{},
},
},
},
},
},
},
expectedNumDebugWarnings: 1,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this test case to verify bids were removed with respect to DSA but I also updated other test cases here with properly formatted, accurate test descriptions.

if dataType == jsonparser.Object && err == nil {
return true
} else if err != nil && err != jsonparser.KeyPathNotFoundError {
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this line is not covered, is it possible to cover this, or it hard because of JSON?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I tried to add coverage but I'm having trouble forcing it down this path. I looked at other instances where we call jsonparser.Get and we don't have coverage for similar logic in those instances either.

dsa/validate.go Outdated

// Validate determines whether a given bid is valid from a DSA perspective.
// A bid is considered valid unless the bid request indicates that a DSA object is required
// in bid responses and it the object happens to be missing from the specified bid.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I think the word it can be removed from this comment so it'll look like:

// in bid responses and the object happens to be missing from the specified bid.

@@ -6,7 +6,8 @@ package exchange
type NonBidReason int

const (
NoBidUnknownError NonBidReason = 0 // No Bid - General
NoBidUnknownError NonBidReason = 0 // No Bid - General
ResponseRejectedGeneral NonBidReason = 300
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own understanding: Why is the non bid reason not specific to referencing DSA?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The non bid reason codes are defined in the seat nonbid community extension documentation, section List: Non Bid Status Codes. There isn't a DSA specific code at this time so we agreed to use the generic bid response rejected 300 code for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually we agreed that the status code should now be 305, Response Rejected - Privacy, so I pushed an update.

@@ -1186,6 +1189,16 @@ func (re *RegExt) unmarshal(extJson json.RawMessage) error {
return err
}

dsaJson, hasDSA := re.ext[dsaKey]
if hasDSA {
re.dsa = &ExtRegsDSA{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to add a test to cover this line?

Comment on lines +1221 to +1230
if re.dsa != nil {
rawjson, err := jsonutil.Marshal(re.dsa)
if err != nil {
return nil, err
}
re.ext[dsaKey] = rawjson
} else {
delete(re.ext, dsaKey)
}
re.dsaDirty = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to cover some of these lines?

Comment on lines +1283 to +1294
func (re *RegExt) GetDSA() *ExtRegsDSA {
if re.dsa == nil {
return nil
}
dsa := *re.dsa
return &dsa
}

func (re *RegExt) SetDSA(dsa *ExtRegsDSA) {
re.dsa = dsa
re.dsaDirty = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add tests for these?

@bsardo bsardo merged commit a06a2eb into prebid:master Feb 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants