mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 12:42:16 +01:00
fix(pdfengines): return a 400 Bad Request if no metadata to write
This commit is contained in:
@@ -238,6 +238,9 @@ func writeMetadataRoute(engine gotenberg.PdfEngine) api.Route {
|
|||||||
return fmt.Errorf("unmarshal metadata: %w", err)
|
return fmt.Errorf("unmarshal metadata: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(metadata) == 0 {
|
||||||
|
return errors.New("no metadata")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}).
|
}).
|
||||||
Validate()
|
Validate()
|
||||||
|
|||||||
@@ -591,6 +591,25 @@ func TestWriteMetadataHandler(t *testing.T) {
|
|||||||
expectHttpStatus: http.StatusBadRequest,
|
expectHttpStatus: http.StatusBadRequest,
|
||||||
expectOutputPathsCount: 0,
|
expectOutputPathsCount: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
scenario: "no metadata",
|
||||||
|
ctx: func() *api.ContextMock {
|
||||||
|
ctx := &api.ContextMock{Context: new(api.Context)}
|
||||||
|
ctx.SetFiles(map[string]string{
|
||||||
|
"document.docx": "/document.docx",
|
||||||
|
})
|
||||||
|
ctx.SetValues(map[string][]string{
|
||||||
|
"metadata": {
|
||||||
|
"{}",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ctx
|
||||||
|
}(),
|
||||||
|
expectError: true,
|
||||||
|
expectHttpError: true,
|
||||||
|
expectHttpStatus: http.StatusBadRequest,
|
||||||
|
expectOutputPathsCount: 0,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
scenario: "error from PDF engine",
|
scenario: "error from PDF engine",
|
||||||
ctx: func() *api.ContextMock {
|
ctx: func() *api.ContextMock {
|
||||||
|
|||||||
Reference in New Issue
Block a user