Skip to content

Commit aef7c45

Browse files
authored
Merge pull request #1170 from python-openapi/test/multipart-binary-composed-schema-xfails
Add xfail coverage for multipart binary composed-schema matching
2 parents 97a466e + 5ad1853 commit aef7c45

2 files changed

Lines changed: 175 additions & 0 deletions

File tree

tests/integration/unmarshalling/test_request_unmarshaller.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from base64 import b64encode
3+
from email.generator import _make_boundary
34

45
import pytest
56

@@ -467,3 +468,79 @@ def test_request_body_with_object_default(self):
467468

468469
assert result.errors == []
469470
assert result.body == {"tags": []}
471+
472+
@pytest.mark.xfail(
473+
reason=(
474+
"multipart composed-schema branch selection is not binary-aware"
475+
),
476+
strict=True,
477+
)
478+
def test_request_body_multipart_oneof_binary_field(self):
479+
from openapi_core import OpenAPI
480+
481+
boundary = _make_boundary()
482+
spec = OpenAPI.from_dict(
483+
{
484+
"openapi": "3.1.0",
485+
"info": {"version": "0", "title": "test"},
486+
"paths": {
487+
"/test": {
488+
"post": {
489+
"requestBody": {
490+
"required": True,
491+
"content": {
492+
"multipart/form-data": {
493+
"schema": {
494+
"oneOf": [
495+
{
496+
"type": "object",
497+
"properties": {
498+
"label": {
499+
"type": "string"
500+
}
501+
},
502+
"required": ["label"],
503+
},
504+
{
505+
"type": "object",
506+
"properties": {
507+
"file": {
508+
"type": "string",
509+
"format": "binary",
510+
}
511+
},
512+
"required": ["file"],
513+
},
514+
]
515+
}
516+
}
517+
},
518+
},
519+
"responses": {"200": {"description": ""}},
520+
}
521+
}
522+
},
523+
}
524+
)
525+
data = (
526+
(
527+
f"--{boundary}\n"
528+
"Content-Type: application/octet-stream\n"
529+
"MIME-Version: 1.0\n"
530+
'Content-Disposition: form-data; name="file"\n\n'
531+
).encode("ascii")
532+
+ b"\xff\xfe\n"
533+
+ (f"--{boundary}--\n").encode("ascii")
534+
)
535+
request = MockRequest(
536+
"http://localhost",
537+
"post",
538+
"/test",
539+
content_type=f"multipart/form-data; boundary={boundary}",
540+
data=data,
541+
)
542+
543+
result = spec.unmarshal_request(request)
544+
545+
assert result.errors == []
546+
assert result.body == {"file": b"\xff\xfe"}

tests/unit/deserializing/test_media_types_deserializers.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,101 @@ def test_urlencoded_form_with_array_default(self, deserializer_factory):
656656
result = deserializer.deserialize(value)
657657

658658
assert result == {"tags": []}
659+
660+
@pytest.mark.xfail(
661+
reason=(
662+
"multipart composed-schema branch selection is not binary-aware"
663+
),
664+
strict=True,
665+
)
666+
def test_multipart_oneof_binary_field(self, spec, deserializer_factory):
667+
mimetype = "multipart/form-data"
668+
schema_dict = {
669+
"oneOf": [
670+
{
671+
"type": "object",
672+
"properties": {
673+
"label": {"type": "string"},
674+
},
675+
"required": ["label"],
676+
},
677+
{
678+
"type": "object",
679+
"properties": {
680+
"file": {"type": "string", "format": "binary"},
681+
},
682+
"required": ["file"],
683+
},
684+
]
685+
}
686+
schema = SchemaPath.from_dict(schema_dict)
687+
schema_validator = oas31_schema_validators_factory.create(spec, schema)
688+
parameters = {
689+
"boundary": "===============2872712225071193122==",
690+
}
691+
deserializer = deserializer_factory(
692+
mimetype,
693+
schema=schema,
694+
schema_validator=schema_validator,
695+
parameters=parameters,
696+
)
697+
value = (
698+
b"--===============2872712225071193122==\n"
699+
b"Content-Type: application/octet-stream\nMIME-Version: 1.0\n"
700+
b'Content-Disposition: form-data; name="file"\n\n\xff\xfe\n'
701+
b"--===============2872712225071193122==--\n"
702+
)
703+
704+
result = deserializer.deserialize(value)
705+
706+
assert result == {
707+
"file": b"\xff\xfe",
708+
}
709+
710+
@pytest.mark.xfail(
711+
reason=(
712+
"multipart composed-schema branch selection is not binary-aware"
713+
),
714+
strict=True,
715+
)
716+
def test_multipart_anyof_binary_field(self, spec, deserializer_factory):
717+
mimetype = "multipart/form-data"
718+
schema_dict = {
719+
"anyOf": [
720+
{
721+
"type": "object",
722+
"properties": {
723+
"file": {"type": "string", "format": "binary"},
724+
},
725+
},
726+
{
727+
"type": "object",
728+
"properties": {
729+
"label": {"type": "string"},
730+
},
731+
},
732+
]
733+
}
734+
schema = SchemaPath.from_dict(schema_dict)
735+
schema_validator = oas31_schema_validators_factory.create(spec, schema)
736+
parameters = {
737+
"boundary": "===============2872712225071193122==",
738+
}
739+
deserializer = deserializer_factory(
740+
mimetype,
741+
schema=schema,
742+
schema_validator=schema_validator,
743+
parameters=parameters,
744+
)
745+
value = (
746+
b"--===============2872712225071193122==\n"
747+
b"Content-Type: application/octet-stream\nMIME-Version: 1.0\n"
748+
b'Content-Disposition: form-data; name="file"\n\n\xff\xfe\n'
749+
b"--===============2872712225071193122==--\n"
750+
)
751+
752+
result = deserializer.deserialize(value)
753+
754+
assert result == {
755+
"file": b"\xff\xfe",
756+
}

0 commit comments

Comments
 (0)