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

test for confusing not-identifiers in enums #471

Merged
merged 1 commit into from Apr 12, 2021

Conversation

karenetheridge
Copy link
Member

A naive implementation would add all $id or $anchors to its list of known
resources, without checking if they are actually in subschemas or the value of
a keyword like enum, const or examples.

@karenetheridge karenetheridge requested a review from a team March 31, 2021 22:54
Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

Looking at the $anchor tests, I don't think the second test has any chance of catching bugs. It doesn't match the enum, so it will always fail validation (pass the test) even if the implementation interprets the $anchor as a real identifier.

My implementation works by removing $anchor keywords from the schema when it per-processes the schema and storing them separately. So, a test that has a chance of tripping up an implementation like mine would be { "type": "null" }. It would match the enum and then where #faux_anchor resolves would determine whether the test passes or not.

Another thing to consider is that my implementation processes $anchors in the order they appear in the schema, so the real anchor would overwrite the not-an-anchor and the test would pass. Although the ordering of properties in an array is undefined, I think we will be more likely to catch bugs if we order the $defs in a way that is most likely to make the not-an-anchor be chosen over the real anchor. By a large margin, the most common ordering to expect from parsers is to preserve the ordering from the schema. Therefore, I suggest reordering to $defs. It won't catch all problems, but I think that configuration would be the most likely to catch bugs.

@jdesrosiers
Copy link
Member

I think the same applies to the $id tests, but I haven't thought about those deeply enough yet.

@karenetheridge
Copy link
Member Author

I don't think the second test has any chance of catching bugs.

I'll take a look at rejigging it to make it more likely to be trippable.

Another thing to consider is that my implementation processes $anchors in the order they appear in the schema, so the real anchor would overwrite the not-an-anchor and the test would pass

I was thinking of implementations that worked the other way -- of recording the first anchor it saw, rather than the last. Perhaps there should be a second test with the reverse order, so both implementation choices have a chance of being caught?

@karenetheridge karenetheridge force-pushed the ether/id-anchor-in-enum branch 2 times, most recently from 5c92ccf to 016b11f Compare April 8, 2021 00:34
@karenetheridge
Copy link
Member Author

karenetheridge commented Apr 8, 2021

I made the following changes:

  • renamed identifiers for accuracy
  • changed one of the definitions so that a match would occur if $anchor or $id was stripped
  • added a third definition using const, to allow for implementations that would incorrectly use either the first or the last definition as the location of the identifier (the middle definition is the only location of a real identifier)
  • copied draft7 tests to draft6, draft4
  • fixed $defs -> definitions for draft7, 6, 4

@karenetheridge karenetheridge requested review from jdesrosiers and a team April 8, 2021 00:35
@karenetheridge karenetheridge force-pushed the ether/id-anchor-in-enum branch 4 times, most recently from 195c9d0 to 813bf4e Compare April 8, 2021 23:46
Comment on lines 246 to 252
{
"description": "in implementations that strip $id, this may match either of the $defs",
"data": {
"type": "null"
},
"valid": false
},
Copy link
Member

Choose a reason for hiding this comment

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

You can't just strip out $ids like you can with $anchors, so I don't see this catching bugs the same way it would with $anchor. What I do is replace the entire schema with an object that represents a reference and is not expressible in JSON. Because it's not expressible in JSON, we can't create a test that would catch that. I think we can drop this test for the "id.json" tests and just keep them for "anchor.json" tests.

Suggested change
{
"description": "in implementations that strip $id, this may match either of the $defs",
"data": {
"type": "null"
},
"valid": false
},

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, I removed those tests for id/$id.

Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

lgtm. 👍

A naive implementation would add all $id or $anchors to its list of known
resources, without checking if they are actually in subschemas or the value of
a keyword like enum, const or examples.
@karenetheridge
Copy link
Member Author

rebased and merged!

@karenetheridge karenetheridge merged commit 15ec577 into master Apr 12, 2021
@karenetheridge karenetheridge deleted the ether/id-anchor-in-enum branch April 12, 2021 17:24
Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

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

Found running against my lib.

"id_in_enum": {
"enum": [
{
"id": "https://localhost:1234/my_identifier.json",
Copy link
Member

Choose a reason for hiding this comment

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

Are these suppose to be $id? id was replaced by $id in draft 6.

"id_in_enum": {
"enum": [
{
"id": "https://localhost:1234/my_identifier.json",
Copy link
Member

Choose a reason for hiding this comment

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

Here, too.

davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request Oct 21, 2021
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request Apr 22, 2022
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 15, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 16, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 16, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 22, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 26, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request May 26, 2023
It looks like we were too permissive in: #71

This addresses issues from:

- json-schema-org/JSON-Schema-Test-Suite#471
- json-schema-org/JSON-Schema-Test-Suite#484

The first issue is more important, I think. We were resolving `$id` in
keywords like `enum` and `const`, which is unexpected since those values
are literal.

The second issue is a little trickier. It's possible people are using
non-standard keys to store reference schemas, which will cause issues
since this only looks in `definitions` now.
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.

None yet

3 participants