Prevent generating non-UTF8 content in body / deterministic generation? #3531
-
|
Connexion has a problem with dealing with non-UTF8 content in a request body, and I would like to bypass that when testing with Schemathesis, but I cannot figure out how to do it. (This relates to upgrading to Schemathesis 4). Previously I have successfully filtered out out some path parameters (to bypass another Connexion bug) with Neither does the setting This setup demonstrates the issue: # rest.py
def my_method(body):
return {}, 200, {"Content-Type": "application/json"}# test_connexion.py
import schemathesis
import connexion
def create_app():
app = connexion.FlaskApp(__name__, specification_dir=".")
app.add_api("myspec.yaml")
return app
app = create_app()
schema = schemathesis.openapi.from_asgi("openapi.json", app=app)
#schema.config.generation.codec = "utf-8" # This does not work either
#schema.config.generation.deterministic = True
@schemathesis.hook("filter_body")
def filter_body(context, body):
if body is None or isinstance(body, (dict, list, str, int, float, bool)):
return True
elif isinstance(body, (bytes, bytearray)):
try:
_ = body.decode("utf-8")
except UnicodeDecodeError:
return False
return True
@schema.parametrize()
def test_openapi_fuzzy(case):
case.call_and_validate()Running Also, this failure does not show every time, only about every other time. I have tried setting At the moment I have just set schema.config.checks.not_a_server_error.enabled = False
schema.config.checks.status_code_conformance.enabled = Falsebut this reduces the benefit of using Schemathesis quite much. Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I noticed the answer in Discord channel:
|
Beta Was this translation helpful? Give feedback.
In 4.11.0 it could be resolved with filters, but
codecis still ignored because it has "utf8" as the default value, and I am reluctant to generate UTF-8 bytes by default as it will decrease bug discovery rate :( I need to think about this one a bit moreAlso, thank you very much for all the details you've provided - it really helped me :)