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

New arguments to from_schema() to constrain generated strings #101

Closed
Zac-HD opened this issue Feb 20, 2023 · 0 comments · Fixed by #103
Closed

New arguments to from_schema() to constrain generated strings #101

Zac-HD opened this issue Feb 20, 2023 · 0 comments · Fixed by #103

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Feb 20, 2023

In principle, implementations ought to handle any representable data. In practice... practicality sometimes beats purity. I therefore propose that we should add two new arguments to from_schema(), and plumb them through.

allow_x00: bool = True

Requests containing the zero codepoint, "\x00", are rejected as invalid by many servers (see e.g. schemathesis/schemathesis#1286, schemathesis/schemathesis#1562, schemathesis/schemathesis#1668). Arguably they should, but in the meantime it seems useful to offer Schemathesis a mechanism to exclude the zero codepoint and schema-level granularity seems sufficient.

This is a fairly simple matter of passing through the argument, and then adding min_codepoint=1 if it's False. I'm unsure what we should name it; leading candidates are allow_x00 to emphasize the low-level nature or allow_codepoint_zero to spell it out.

codec: str | None ="utf-8"

Per schemathesis/schemathesis#1142 (comment) and schemathesis/schemathesis#1286, users often want to restrict inputs to the ASCII range. This is fundamentally kinda wrong, but we live in a broken world and sometimes harm reduction (i.e. allowing people to use advanced testing tools anyway) is the best option left to us.

Implementation here is easy in hypothesis-jsonschema, but requires upstream issues as a prerequisite: HypothesisWorks/hypothesis#1664 and HypothesisWorks/hypothesis#3479.

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 a pull request may close this issue.

1 participant