GitHub
05/18/2023, 8:24 AMmultipart/form-data upload, PDF file should be detected as application/pdf or application/octet-stream
Actual behaviour
The uploaded PDF file is detected as text/plain.
Moreover on Azure DevOps agent running Ubuntu, the same file is detected as text/x-tex
I'm not 100% sure but I think it is related to mime type detection logic here
Steps to reproduce
Clone https://github.com/spawluk-zartis/pact-multipart-form-data-upload
npm install
npm test
Relevant log files
```
pact-multipart-form-data-upload@1.0.0 test
jestRUNS tests/UploadPdf.test.ts 2023-05-18T081651.469779Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/transport/http core/transport/https 2023-05-18T081651.470707Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/content-generator/binary core/content-generator/json core/content-matcher/json core/content-matcher/multipart-form-data core/content-matcher/text core/content-matcher/xml 2023-05-18T081651.472088Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/matcher/v1-equality core/matcher/v2-max-type core/matcher/v2-min-type core/matcher/v2-minmax-type core/matcher/v2-regex core/matcher/v2-type core/matcher/v3-content-type core/matcher/v3-date core/matcher/v3-datetime core/matcher/v3-decimal-type core/matcher/v3-includes core/matcher/v3-integer-type core/matcher/v3-null core/matcher/v3-number-type core/matcher/v3-time core/matcher/v4-array-contains core/matcher/v4-equals-ignore-order core/matcher/v4-max-equals-ignore-order core/matcher/v4-min-equals-ignore-order core/matcher/v4-minmax-equals-ignore-order core/matcher/v4-not-empty (node:29032) ExperimentalWarning: buffer.File is an experimental feature and might change at any time (Use
node --trace-warnings ... to show where the warning was created)
RUNS tests/UploadPdf.test.ts
2023-05-18T081651.642547Z DEBUG tokio-runtime-worker hyper:protoh1io parsed 7 headers
2023-05-18T081651.642977Z DEBUG tokio-runtime-worker hyper:protoh1conn incoming body is content-length (981 bytes)
2023-05-18T081651.643376Z DEBUG tokio-runtime-worker hyper:protoh1conn incoming body completed
2023-05-18T081651.643730Z DEBUG tokio-runtime-worker pact_mock_server:hyper server Creating pact request from hyper request
2023-05-18T081651.644197Z DEBUG tokio-runtime-worker pact_mock_server:hyper server Extracting query from uri /api/upload
2023-05-18T081651.644765Z INFO tokio-runtime-worker pact_mock_server:hyper server Received request HTTP Request ( method: POST, path: /api/upload, query: None, headers: Some({"accept": ["application/json", "text/plain",
"*/*"], "content-type": ["multipart/form-data; boundary=axios-1.3.4-boundary-DSxfzSsQnKAavHGBv3Gy-xrx8"], "content-length": ["981"], "host": ["127.0.0.1:54119"], "connection": ["close"], "accept-encoding": ["gzip", "compress", "deflate", "br"], "user-agent": ["axios/1.3.4"]}), body: Present(981 bytes, multipart/form-data;boundary=axios-1.3.4-boundary-DSxfzSsQnKAavHGBv3Gy-xrx8) )
2023-05-18T081651.645823Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: POST, path: /api/upload, query: None, headers: Some({"Content-Type": ["multipart/form-data; boundary=ZLyxFXoU09gGYGlJ"]}), body: Present(924 bytes, multipart/form-data) )
2023-05-18T081651.646343Z DEBUG tokio-runtime-worker pact_matching: body: '2D2D5A4C797846586F553039674759476C4ADA436F6E74656E742D44697370... (924 bytes)'
2023-05-18T081651.646615Z DEBUG tokio-runtime-worker pact_matching: matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("file")], expr: "$.file"
}: RuleList { rules: [ContentType("application/pdf")], rule_logic: And, cascaded: false }} }, PATH: MatchingRuleCategory { name: PATH, rules: {} }, HEADER: MatchingRuleCategory { name: HEADER, rules: {DocPath { path_tokens: [Root, Field("Content-Type")], expr: "Content-Type" }: RuleList { rules: [Regex("multipart/form-data;(\\s*charset=[^;]*;)?\\s*boundary=.*")], rule_logic: And, cascaded: false }} }} }
2023-05-18T081651.647368Z DEBUG tokio-runtime-worker pact_matching: generators: Generators { categories: {} }
2023-05-18T081651.647776Z DEBUG tokio-runtime-worker pact_matching:matchers String -> String: comparing '/api/upload' to '/api/upload' ==> true cascaded=false matcher=Equality
2023-05-18T081651.648105Z DEBUG tokio-runtime-worker pact_matching: expected content type = 'multipart/form-data', actual content type = 'multipart/form-data;boundary=axios-1.3.4-boundary-DSxfzSsQnKAavHGBv3Gy-xrx8'
2023-05-18T081651.648663Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [Regex("multipart/form-data;(\\s*charset=[^;]*;)?\\s*boundary=.*")], rule_logic: And, cascaded: false }'
2023-05-18T081651.649001Z DEBUG tokio-runtime-worker pact_plugin_driver:catalogue manager Looking for a content matcher for multipart/form-data
2023-05-18T081651.649982Z DEBUG tokio-runtime-worker pact_matching: No content matcher defined for content type 'multipart/form-data', using core matcher implementation
2023-05-18T081651.650272Z DEBUG tokio-runtime-worker pact_matching: Using body matcher for content type 'multipart/form-data'
2023-05-18T081651.650549Z DEBUG tokio-runtime-worker pact_matching:binary utils matching MIME multipart contents
2023-05-18T081651.650986Z DEBUG tokio-runtime-worker pact_matching:binary utils Comparing MIME field multipart 'file'
2023-05-18T081651.651291Z DEBUG tokio-runtime-worker pact_matching:binary utils Calling match_values for path $.file
2023-05-18T081651.651574Z DEBUG tokio-runtime-worker pact_matching:binary utils FilePart: comparing binary data to 'Some("application/pdf")' using ContentType("application/pdf")
2023-05-18T081651.652470Z DEBUG tokio-runtime-worker pact_matching:binary utils Matching binary contents by content type: expected 'application/pdf', detected 'text/plain' -> false
2023-05-18T081651.652737Z DEBUG tokio-runtime-worker pact_models:content types Detecting content type from byte contents
2023-05-18T081651.653087Z DEBUG tokio-runtime-worker pact_matching:binary utils Comparing 'MimeFile { name: "file", content_type: Some("application/pdf"), filename: "empty.pdf", data: b"%PDF-1.4\n%\xd3\xeb\xe9\xe1\n1 0 obj\n<</Title (Untitled document)\n/Producer (Skia/PDF m115 Google Docs Renderer)>>\nendobj\n3 0 obj\n<</ca 1\n/BM /Normal>>\nendobj\n4 0 obj\n<</Length 84>> stream\n1 0 0 -1 0 792 cm\nq\n.75 0 0 .75 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G3 gs\n0 0 816 1056 re\nf\nQ\n\nendstream\nendobj\n2 0 obj\n<</Type /Page\n/Resources <</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n/ExtGState <</G3 3 0 R>>>>\n/MediaBox [0 0 612 792]\n/Contents 4 0 R\n/StructParents 0\…
pact-foundation/pact-js