Skip to content

Commit d2ea3a7

Browse files
tests/models: Support x509-ca-cert MIME type for DER credentials
- Added a test to validate the handling of `application/x-x509-ca-cert` MIME type for DER certificate and private key uploads in `PdfSignPayload`. - Updated `_internal.py` to allow `application/x-x509-ca-cert` and other relevant MIME types for DER credentials to maintain compatibility with provider/browser file type detection. Assisted-by: Codex
1 parent a78ab27 commit d2ea3a7

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/pdfrest/models/_internal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,8 @@ class PdfSignPayload(BaseModel):
11051105
),
11061106
BeforeValidator(_ensure_list),
11071107
BeforeValidator(
1108+
# DER cert/key uploads are frequently tagged as x509-ca-cert (or octet-stream
1109+
# in some environments), so we intentionally keep this allowlist broad.
11081110
_allowed_mime_types(
11091111
"application/pkix-cert",
11101112
"application/x-x509-ca-cert",
@@ -1126,7 +1128,10 @@ class PdfSignPayload(BaseModel):
11261128
),
11271129
BeforeValidator(_ensure_list),
11281130
BeforeValidator(
1131+
# Keep parity with provider/browser MIME detection for DER private keys.
11291132
_allowed_mime_types(
1133+
"application/pkix-cert",
1134+
"application/x-x509-ca-cert",
11301135
"application/pkcs8",
11311136
"application/x-pem-file",
11321137
"application/octet-stream",

tests/test_sign_pdf.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,41 @@ def test_sign_payload_allows_existing_without_location() -> None:
338338
}
339339
)
340340
assert payload.signature_configuration.type == "existing"
341+
342+
343+
def test_sign_payload_accepts_x509_ca_cert_mime_for_der_credentials() -> None:
344+
input_pdf = make_pdf_file(str(PdfRestFileID.generate()))
345+
certificate_file = PdfRestFile.model_validate(
346+
build_file_info_payload(
347+
str(PdfRestFileID.generate()),
348+
"certificate.der",
349+
"application/x-x509-ca-cert",
350+
)
351+
)
352+
private_key_file = PdfRestFile.model_validate(
353+
build_file_info_payload(
354+
str(PdfRestFileID.generate()),
355+
"private_key.der",
356+
"application/x-x509-ca-cert",
357+
)
358+
)
359+
360+
payload = PdfSignPayload.model_validate(
361+
{
362+
"files": [input_pdf],
363+
"signature_configuration": {
364+
"type": "new",
365+
"name": "sig",
366+
"location": make_signature_location(),
367+
},
368+
"credentials": {
369+
"certificate": certificate_file,
370+
"private_key": private_key_file,
371+
},
372+
}
373+
)
374+
375+
assert payload.certificate is not None
376+
assert payload.private_key is not None
377+
assert payload.certificate[0].type == "application/x-x509-ca-cert"
378+
assert payload.private_key[0].type == "application/x-x509-ca-cert"

0 commit comments

Comments
 (0)