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 a malformed pattern #386

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

karenetheridge
Copy link
Member

I noticed we had no tests for bad patterns.

@karenetheridge karenetheridge requested review from Julian and a team June 3, 2020 16:27
{
"description": "invalid regex does not match",
"data": "hello",
"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.

For drafts pre-2019-09 this is (potentially) incorrect I think -- it depends whether the metaschema it's run under is validating formats or treating them as annotations or whatever. So for those this'd need to go in optional. For 2019-09 I don't remember what changed -- do you enable format via a vocabulary and then it has to be respected, or what?

(Also this is invalid JSON but probably you'll notice that part)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not assuming/expecting the metaschema to use a format validation. Even if no validation is done on the schema at all, it should still return a non-valid result at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

invalid json fixed -- and the test suite is now happy, so it looks like the json was just parsing badly before.

Copy link
Member

Choose a reason for hiding this comment

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

That may not be the case. An implementation is free to blow up entirely in this case if you give it an invalid schema and it isn't validating it.

Copy link
Member

Choose a reason for hiding this comment

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

(i.e. it's valid for the result here to be "my validator blows up" rather than returning invalid)

Copy link
Member

Choose a reason for hiding this comment

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

As well, assuming that “valid=false” for failed schemas changes the meaning of “valid” for the tests in that suite. It’s also bad practice to have meanings of fields change depending on other variables.

Copy link
Member

@ChALkeR ChALkeR Jun 4, 2020

Choose a reason for hiding this comment

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

Perhaps there should be another flag to indicate invalid schemas (apart from valid: false on tests), perhaps in a separate directory/subdir, where the impl is free to blow up on schema compilation (like it should imo)?

That would be different from valid: false, as the impl can either follow this and return false, because none strings match invalid pattern, or it can as well reject the schema alltogehter which should also be a valid behavior. Per schema, pattern should be a regex, and this is not a regex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we've been discussing this across a few different PRs and in slack. There hasn't been any consensus yet as to how to declare this in tests (with an extra flag? a new directory under optional/? both of these?) or how to document how implementations should deal with it.

Copy link
Member

Choose a reason for hiding this comment

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

I want to merge the outstanding PRs on tests in the "normal" category before addressing this. I.e. #354 and the PRs being split off of it. Let's get those merged, then we can hit cases that may require a structural change. Could definitely use more eyes reviewing those PRs so we can get them off the queue.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, my implementation gives an (arguably incorrect) error, but doesn't blow up:

The string value was not a match for the indicated regular expression

(Interestingly, .Net doesn't think this is an invalid pattern.)

I think this is one of the things I had to account for in some other regex test where .Net didn't support something. I switch from deserializing the regex directly to just deserializing a string and lazily parsing the regex.

@awwright
Copy link
Member

awwright commented Jun 3, 2020

An invalid schema doesn't return either valid or invalid; the validity of the instance is indeterminate.

@karenetheridge
Copy link
Member Author

karenetheridge commented Jun 3, 2020

@karenetheridge
Copy link
Member Author

Putting on hold until we can figure out how to test schemas that would cause an implementation to throw an exception / send up an error / do something other than return validated=true/false.

@karenetheridge karenetheridge added the on hold changes that should not be applied just yet, but maybe later label Nov 16, 2020
@Julian
Copy link
Member

Julian commented Nov 17, 2020

It's going to be more backwards compatible for users of the suite to put these kinds of tests in a separate folder (because one wouldn't know to reference the flag until after we add such a thing).

So there's seemingly little disadvantage to doing it in a separate folder which we can bikeshed on (neither-valid-nor-invalid-tests/); I think I once discussed some of this with @ssilverman and put some notes in a doc.

But yes we should decide how to handle that "once" and then do it here, agreed.

@awwright
Copy link
Member

I don't anticipate many compatibility problems, depending on how the tests are written. Especially if the "tests" property is empty or missing, that should not pose a compatibility problem.

However, I think the most intuitive way to write this would be to use tests: null to indicate the schema itself is malformed:

[
    {
        "description": "enum range error",
        "schema": { "enum": 4 },
        "tests": null
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold changes that should not be applied just yet, but maybe later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants