From 7fe0e05050cba8960c2ff5fdd136e8f854020b3a Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Tue, 8 Apr 2025 18:51:51 +0200 Subject: [PATCH] test(webhook): add integration testing for the webhook feature - testing the custom Content-Disposition header from #1165 --- test/integration/features/webhook.feature | 33 +++++++++++++++++++++++ test/integration/scenario/server.go | 12 ++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/integration/features/webhook.feature diff --git a/test/integration/features/webhook.feature b/test/integration/features/webhook.feature new file mode 100644 index 00000000..e77c1f81 --- /dev/null +++ b/test/integration/features/webhook.feature @@ -0,0 +1,33 @@ +# TODO: +# 1. Other HTTP Methods +# 2. Errors + +Feature: Webhook + + Scenario: Default + Given I have a default Gotenberg container + Given I have a webhook server + When I make a "POST" request to Gotenberg at the "/forms/pdfengines/flatten" endpoint with the following form data and header(s): + | files | testdata/page_1.pdf | file | + | Gotenberg-Webhook-Url | http://host.docker.internal:%d/webhook | header | + | Gotenberg-Webhook-Error-Url | http://host.docker.internal:%d/webhook/error | header | + Then the response status code should be 204 + When I wait for the asynchronous request to the webhook + Then the webhook request header "Content-Type" should be "application/pdf" + Then there should be 1 PDF(s) in the webhook request + + Scenario: Extra HTTP Headers + Given I have a default Gotenberg container + Given I have a webhook server + When I make a "POST" request to Gotenberg at the "/forms/pdfengines/flatten" endpoint with the following form data and header(s): + | files | testdata/page_1.pdf | file | + | Gotenberg-Webhook-Url | http://host.docker.internal:%d/webhook | header | + | Gotenberg-Webhook-Error-Url | http://host.docker.internal:%d/webhook/error | header | + | Gotenberg-Webhook-Extra-Http-Headers | {"X-Foo":"bar","Content-Disposition":"inline"} | header | + Then the response status code should be 204 + When I wait for the asynchronous request to the webhook + Then the webhook request header "Content-Type" should be "application/pdf" + Then the webhook request header "X-Foo" should be "bar" + # https://github.com/gotenberg/gotenberg/issues/1165 + Then the webhook request header "Content-Disposition" should be "inline" + Then there should be 1 PDF(s) in the webhook request diff --git a/test/integration/scenario/server.go b/test/integration/scenario/server.go index ddf2f0a1..d4912113 100644 --- a/test/integration/scenario/server.go +++ b/test/integration/scenario/server.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/cucumber/godog" + "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/mholt/archives" ) @@ -62,7 +63,16 @@ func newServer(ctx context.Context, workdir string) (*server, error) { filename, ok := params["filename"] if !ok { - return webhookErr(errors.New("no filename in Content-Disposition header")) + filename = uuid.NewString() + contentType := s.req.Header.Get("Content-Type") + switch contentType { + case "application/zip": + filename = fmt.Sprintf("%s.zip", filename) + case "application/pdf": + filename = fmt.Sprintf("%s.pdf", filename) + default: + return webhookErr(errors.New("no filename in Content-Disposition header")) + } } dirPath := fmt.Sprintf("%s/%s", workdir, s.req.Header.Get("Gotenberg-Trace"))