mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-12-06 16:22:15 +00:00
feat(pdf): tell whether a PDF is signed in the info route
This commit is contained in:
2
go.mod
2
go.mod
@@ -11,7 +11,7 @@ require (
|
||||
github.com/dlclark/regexp2/v2 v2.12.0
|
||||
github.com/gomarkdown/markdown v0.0.0-20261105214116-27ca101938a9
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gotenberg/litho v0.0.10
|
||||
github.com/gotenberg/litho v0.0.11
|
||||
github.com/hashicorp/go-retryablehttp v0.7.8
|
||||
github.com/labstack/echo/v5 v5.4.4
|
||||
github.com/labstack/gommon v0.5.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -118,8 +118,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
|
||||
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
|
||||
github.com/gotenberg/litho v0.0.10 h1:DGDNrkJhbAOMCEqW9a2mCY0C5+5sIaJaRQ4xb/jDLrM=
|
||||
github.com/gotenberg/litho v0.0.10/go.mod h1:BYtOYpLnI02JzPt4FbeozPgTz1OrCPyyao5kAoEpn4Y=
|
||||
github.com/gotenberg/litho v0.0.11 h1:p/MAuogCVSVz7NdVmj+wOHcOWpf8rCe9YM/ddvW4/00=
|
||||
github.com/gotenberg/litho v0.0.11/go.mod h1:BYtOYpLnI02JzPt4FbeozPgTz1OrCPyyao5kAoEpn4Y=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.33.0 h1:5T5Ns3kMpWr+z3s5ZA0e7ljVyWNVNxK76sHPAxi5D1k=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.33.0/go.mod h1:oWNYw09cH8wl8fFgC5hKlBLxR4XfKy2KQpP8MJjeCcc=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
||||
|
||||
@@ -236,6 +236,7 @@ type documentInfo struct {
|
||||
Tagged bool `json:"tagged"`
|
||||
Linearized bool `json:"linearized"`
|
||||
FormFields bool `json:"formFields"`
|
||||
Signed bool `json:"signed"`
|
||||
}
|
||||
|
||||
func infoRoute(processor *Processor) api.Route {
|
||||
@@ -255,6 +256,11 @@ func infoRoute(processor *Processor) api.Route {
|
||||
return nil, fmt.Errorf("read form fields: %w", err)
|
||||
}
|
||||
|
||||
signed, err := r.HasSignatures(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read signatures: %w", err)
|
||||
}
|
||||
|
||||
return documentInfo{
|
||||
Pages: pages,
|
||||
Version: r.Version(),
|
||||
@@ -262,6 +268,7 @@ func infoRoute(processor *Processor) api.Route {
|
||||
Tagged: tagged,
|
||||
Linearized: r.IsLinearized(),
|
||||
FormFields: formFields,
|
||||
Signed: signed,
|
||||
}, nil
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ func TestReadRoutes(t *testing.T) {
|
||||
t.Fatalf("decode %s: %v", rec.Body.String(), err)
|
||||
}
|
||||
|
||||
if info["pages_12.pdf"].Pages != 12 {
|
||||
t.Fatalf("info = %+v, want 12 pages", info)
|
||||
if info["pages_12.pdf"].Pages != 12 || info["pages_12.pdf"].Signed {
|
||||
t.Fatalf("info = %+v, want 12 pages, unsigned", info)
|
||||
}
|
||||
|
||||
_, _, err = serve(t, validateRoute(testProcessor()), map[string][]string{"profile": {"PDF/X-4"}}, "page_1.pdf")
|
||||
|
||||
@@ -17,7 +17,8 @@ Feature: PDF corpus
|
||||
"encrypted": false,
|
||||
"tagged": false,
|
||||
"linearized": false,
|
||||
"formFields": false
|
||||
"formFields": false,
|
||||
"signed": false
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -18,7 +18,8 @@ Feature: /forms/pdf/{info|validate}
|
||||
"encrypted": false,
|
||||
"tagged": false,
|
||||
"linearized": false,
|
||||
"formFields": false
|
||||
"formFields": false,
|
||||
"signed": false
|
||||
},
|
||||
"page_1.pdf": {
|
||||
"pages": 1,
|
||||
@@ -27,6 +28,29 @@ Feature: /forms/pdf/{info|validate}
|
||||
}
|
||||
"""
|
||||
|
||||
Scenario: POST /forms/pdf/info (Signed PDF)
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/pdf/sign" endpoint with the following form data and header(s):
|
||||
| files | testdata/page_1.pdf | file |
|
||||
| files | testdata/pem/cert.pem | file |
|
||||
| files | testdata/pem/key.pem | file |
|
||||
| certificate | cert.pem | field |
|
||||
| key | key.pem | field |
|
||||
| Gotenberg-Output-Filename | foo | header |
|
||||
Then the response status code should be 200
|
||||
When I make a "POST" request to Gotenberg at the "/forms/pdf/info" endpoint with the following form data and header(s):
|
||||
| files | teststore/foo.pdf | file |
|
||||
Then the response status code should be 200
|
||||
Then the response body should match JSON:
|
||||
"""
|
||||
{
|
||||
"foo.pdf": {
|
||||
"pages": 1,
|
||||
"signed": true
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
Scenario: POST /forms/pdf/info (Encrypted PDF)
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/pdf/encrypt" endpoint with the following form data and header(s):
|
||||
|
||||
Reference in New Issue
Block a user