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

Validate native inputs #353

Merged
merged 16 commits into from
Mar 7, 2018
Merged

Validate native inputs #353

merged 16 commits into from
Mar 7, 2018

Conversation

dbemiller
Copy link
Contributor

@dbemiller dbemiller commented Feb 20, 2018

This fixes most of #218, and some of #295.

OpenRTB Native v1.2 support was added in mxmCherry/openrtb#20, but the 10.0.0 release of that library included some other breaking changes... so in the interest of moving this along, I'll save those changes for another PR.

Most of these changes are just refactoring so that my native test payloads don't add contribute to the tech debt of #295. I pulled many of the existing test payloads out into their own *.json files.

"11": json.RawMessage(validRequest(t, "app.json")),
"12": json.RawMessage(validRequest(t, "timeout.json")),
"100": json.RawMessage("5"),
"101": json.RawMessage("5"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, that was a bug in the original AMP tests, should have been testing all the invalid requests. Not terribly important though, since this shares code with openrtb, and the invalid requests should be handled there anyway. I had failed to advance the index in invalidRequests[] on each line.

Copy link
Contributor Author

@dbemiller dbemiller Feb 20, 2018

Choose a reason for hiding this comment

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

ah... I see. Yeah, I didn't pay much attention to the semantics of these tests, but I'll clean them up here so that they make sense again.

if err := validateNativeAsset(assets[i], impIndex, i); err != nil {
return err
}
assets[i].ID = int64(i)
Copy link
Collaborator

@hhhjort hhhjort Feb 20, 2018

Choose a reason for hiding this comment

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

From the spec: "Typically a counter for the array." This enforces that it will be a counter. I don't know of any use cases for ID being anything else, so its probably good. But potentially will break something that stretches the spec here.

Oh, I see below that we are changing the spec that we don't want anyone else filling asset IDs. So any breaking changes should not be a surprise, but still could potentially block some funky implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah... to be honest I'm not 100% sure how to handle this. I saw the following:

Unique asset ID, assigned by exchange.

Since Prebid is the exchange, in this context, I don't think we're breaking the spec here. We just decided that the "typical" implementation is the one we'll be using.

I decided to return 4xx on IDs sent by the Publisher just to prevent all sorts of nasty logic/confusion. As a general rule, we never overwrite anything which the Publisher gives us. So if we allowed IDs, then we'd have to make sure that the ones we added weren't duplicates, which gets... messy.

Decided to just reject those requests to keep things simple.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am fine with that then.

}

func validateNativeAssetData(data *nativeRequests.Data, impIndex int, assetIndex int) error {
if data.Type < 1 || data.Type > 11 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

12 is a valid data type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! haha 12 was on a separate page in the spec, so I must have missed it.

Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

Need to fix the allowed range of native data asset types.

@dbemiller dbemiller assigned ndhimehta and unassigned nhedley Feb 20, 2018
hhhjort
hhhjort previously approved these changes Feb 23, 2018
Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

LGTM

hhhjort
hhhjort previously approved these changes Feb 26, 2018
Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

More test cases are good.

@dbemiller dbemiller mentioned this pull request Mar 1, 2018
Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

LGTM ... basically just removing the dupe directory since my last review.

@dbemiller
Copy link
Contributor Author

been way longer than 5 days, so... merging.

@dbemiller dbemiller merged commit 8272666 into master Mar 7, 2018
@dbemiller dbemiller deleted the validate-native-inputs branch March 7, 2018 16:25
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 1, 2020
* Upgraded the openrtb library to 9.2.0.

* Moved invalid request payloads into their own directory.

* Added a bad native request.

* Added lots of invalid native bid payloads, to make tests fail.

* Moved some files around. Implemented all the logic to make the tests pass.

* Moved valid requests into directories.

* Deleted some duplicate files. Added some new ones to beef up code coverage.

* Removed some unnecessary code.

* Added an issue number to the TODO statement.

* Fixed the range on data asset types.

* Fixed the amp auction tests, which were buggy before.

* Moved tests from other PR into their own .json files.

* Deleted duplicate directory... not sure how that got added.
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 2, 2020
* Upgraded the openrtb library to 9.2.0.

* Moved invalid request payloads into their own directory.

* Added a bad native request.

* Added lots of invalid native bid payloads, to make tests fail.

* Moved some files around. Implemented all the logic to make the tests pass.

* Moved valid requests into directories.

* Deleted some duplicate files. Added some new ones to beef up code coverage.

* Removed some unnecessary code.

* Added an issue number to the TODO statement.

* Fixed the range on data asset types.

* Fixed the amp auction tests, which were buggy before.

* Moved tests from other PR into their own .json files.

* Deleted duplicate directory... not sure how that got added.
StarWindMoonCloud added a commit to ParticleMedia/prebid-server that referenced this pull request Jun 5, 2024
Co-authored-by: Qili Chen <[email protected]@Qilis-MacBook-Pro.local>
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.

6 participants