mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-12-06 16:22:15 +00:00
test(integration): require every canary in the controls and wait for late requests
This commit is contained in:
@@ -102,7 +102,8 @@ Available tags:
|
||||
- `all concurrent responses should have <N> PDF(s)`
|
||||
- `at least one concurrent response status code should be <code>`
|
||||
- `the (webhook request|file request|server request) method should be "<method>"`
|
||||
- `the helper server (should|should NOT) have received a canary request` (any request to `{helper}/canary/`; pair a `should NOT` with a control scenario that proves the canary is reachable)
|
||||
- `the helper server (should|should NOT) have received a canary request` (any request to `{helper}/canary/`; `should NOT` waits 2 seconds for a request still in flight, and pairs with a control scenario that proves the canary is reachable)
|
||||
- `the helper server should have received the following canary request(s):` (one path under `{helper}/canary/` per row, whatever the method; a control scenario lists every resource its `should NOT` counterpart covers)
|
||||
- `all sequential response status codes should be <code>`
|
||||
- `all probe response status codes should be <code>`
|
||||
- `the "<name>" image should be <width>x<height> pixels`
|
||||
|
||||
@@ -595,19 +595,16 @@ Feature: /forms/chromium/convert/html
|
||||
# background, script, frame or fetch reaches the helper server, even with
|
||||
# no filter configured. The page's own canary scenarios prove that
|
||||
# Chromium reaches the helper server, and the rendered header proves that
|
||||
# the downloaded template is in use. Should a Chromium upgrade start
|
||||
# loading template resources, this scenario fails before anyone assumes
|
||||
# the outbound filters cover them.
|
||||
@chromium-ssrf
|
||||
# the downloaded template is in use.
|
||||
Scenario: POST /forms/chromium/convert/html (Canary resources in the header and footer never leave)
|
||||
Given I have a static server
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
|
||||
| files | testdata/page-1-html/index.html | file |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-header-footer/header.html"},{"url":"{helper}/canary-page/testdata/canary-header-footer/footer.html"}] | field |
|
||||
| marginTop | 1 | field |
|
||||
| marginBottom | 1 | field |
|
||||
| Gotenberg-Output-Filename | foo | header |
|
||||
| files | testdata/page-1-html/index.html | file |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-header-footer-html/header.html"},{"url":"{helper}/canary-page/testdata/canary-header-footer-html/footer.html"}] | field |
|
||||
| marginTop | 1 | field |
|
||||
| marginBottom | 1 | field |
|
||||
| Gotenberg-Output-Filename | foo | header |
|
||||
Then the response status code should be 200
|
||||
Then the "foo.pdf" PDF should have content matching "Canary header" at page 1, artifacts included
|
||||
Then the "foo.pdf" PDF should have content matching "Canary footer" at page 1, artifacts included
|
||||
@@ -615,18 +612,13 @@ Feature: /forms/chromium/convert/html
|
||||
|
||||
# A style sheet a print template links fails the print instead of loading:
|
||||
# the request never reaches the helper server. @font-face behaves the same.
|
||||
@chromium-ssrf
|
||||
Scenario: POST /forms/chromium/convert/html (Canary style sheet in the header fails the print, never leaves)
|
||||
Given I have a static server
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
|
||||
| files | testdata/page-1-html/index.html | file |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-header-stylesheet/header.html"}] | field |
|
||||
| files | testdata/page-1-html/index.html | file |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-header-stylesheet-html/header.html"}] | field |
|
||||
Then the response status code should be 400
|
||||
Then the response body should match string:
|
||||
"""
|
||||
Chromium failed to print the PDF; this usually happens when the page is too large
|
||||
"""
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
# Control for the WebSocket scenario below. An ordinary fetch to a loopback
|
||||
|
||||
@@ -482,7 +482,17 @@ Feature: /forms/chromium/convert/url
|
||||
| url | {helper}/canary-page/testdata/canary-html/index.html | field |
|
||||
| waitDelay | 1s | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should have received a canary request
|
||||
Then the helper server should have received the following canary request(s):
|
||||
| style.css |
|
||||
| script.js |
|
||||
| font.woff2 |
|
||||
| background.png |
|
||||
| image.png |
|
||||
| frame.html |
|
||||
| fetch |
|
||||
| xhr |
|
||||
| beacon |
|
||||
| eventsource |
|
||||
|
||||
# The deny-list names every canary resource: style sheet, script, font,
|
||||
# background, image, frame, fetch, XHR, beacon and EventSource. A logged
|
||||
@@ -491,20 +501,33 @@ Feature: /forms/chromium/convert/url
|
||||
Scenario: POST /forms/chromium/convert/url (Canary resources in the deny-list never leave)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| CHROMIUM_DENY_LIST | ^http://{helper-host}/canary/ |
|
||||
| CHROMIUM_DENY_LIST | ^{helper}/canary/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s):
|
||||
| url | {helper}/canary-page/testdata/canary-html/index.html | field |
|
||||
| waitDelay | 1s | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
# Pins a known limitation. The pinning proxy sees only the host and port of
|
||||
# a WebSocket tunnel, so a deny-list rule that names a path cannot sever the
|
||||
# handshake: the conversion fails with a 403, but the handshake has already
|
||||
# reached the target. Flip the last step once the handshake is refused
|
||||
# before it leaves. See listenForEventWebSocketCreated.
|
||||
# Control for the WebSocket canary scenarios below: with no filter in the
|
||||
# way, the handshake reaches the helper server.
|
||||
@chromium-ssrf
|
||||
Scenario: POST /forms/chromium/convert/url (Canary WebSocket in a path deny-list rule fails the conversion, after the handshake)
|
||||
Scenario: POST /forms/chromium/convert/url (Canary WebSocket loads when no filter refuses it)
|
||||
Given I have a static server
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s):
|
||||
| url | {helper}/canary-page/testdata/canary-websocket-html/index.html | field |
|
||||
| waitDelay | 1s | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should have received the following canary request(s):
|
||||
| websocket |
|
||||
|
||||
# The pinning proxy sees only the host and port of a WebSocket tunnel, so a
|
||||
# deny-list rule that names a path cannot sever the handshake. The
|
||||
# conversion fails with a 403 instead, so that nothing the page read
|
||||
# through the WebSocket reaches the client. See
|
||||
# listenForEventWebSocketCreated.
|
||||
@chromium-ssrf
|
||||
Scenario: POST /forms/chromium/convert/url (Canary WebSocket in a path deny-list rule fails the conversion)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| CHROMIUM_DENY_LIST | ^ws://{helper-host}/canary/ |
|
||||
@@ -512,7 +535,6 @@ Feature: /forms/chromium/convert/url
|
||||
| url | {helper}/canary-page/testdata/canary-websocket-html/index.html | field |
|
||||
| waitDelay | 1s | field |
|
||||
Then the response status code should be 403
|
||||
Then the helper server should have received a canary request
|
||||
|
||||
# The allow-list admits the page but not its WebSocket: the pinning proxy
|
||||
# refuses the tunnel, so the handshake never reaches the helper server.
|
||||
@@ -520,7 +542,7 @@ Feature: /forms/chromium/convert/url
|
||||
Scenario: POST /forms/chromium/convert/url (Canary WebSocket outside the allow-list never leaves)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| CHROMIUM_ALLOW_LIST | ^http://{helper-host}/canary-page/ |
|
||||
| CHROMIUM_ALLOW_LIST | ^{helper}/canary-page/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s):
|
||||
| url | {helper}/canary-page/testdata/canary-websocket-html/index.html | field |
|
||||
| waitDelay | 1s | field |
|
||||
@@ -533,7 +555,7 @@ Feature: /forms/chromium/convert/url
|
||||
Scenario: POST /forms/chromium/convert/url (Redirect to a canary in the deny-list never leaves)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| CHROMIUM_DENY_LIST | ^http://{helper-host}/canary/ |
|
||||
| CHROMIUM_DENY_LIST | ^{helper}/canary/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s):
|
||||
| url | {helper}/canary-redirect/main | field |
|
||||
Then the response status code should be 200
|
||||
|
||||
@@ -1191,14 +1191,15 @@ Feature: /forms/libreoffice/convert
|
||||
Scenario: POST /forms/libreoffice/convert (Download From In The Deny-List)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| API_DOWNLOAD_FROM_DENY_LIST | ^{helper}/static/ |
|
||||
| API_DOWNLOAD_FROM_DENY_LIST | ^{helper}/canary/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/static/testdata/page_1.docx"}] | field |
|
||||
| downloadFrom | [{"url":"{helper}/canary/page_1.docx"}] | field |
|
||||
Then the response status code should be 403
|
||||
Then the response body should match string:
|
||||
"""
|
||||
Forbidden
|
||||
"""
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
@webhook
|
||||
Scenario: POST /forms/libreoffice/convert (Webhook)
|
||||
@@ -1299,9 +1300,10 @@ Feature: /forms/libreoffice/convert
|
||||
Given I have a static server
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-libreoffice/index.html"}] | field |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-stylesheet-html/index.html"}] | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should have received a canary request
|
||||
Then the helper server should have received the following canary request(s):
|
||||
| style.css |
|
||||
|
||||
@libreoffice-ssrf
|
||||
Scenario: POST /forms/libreoffice/convert (Canary in the deny-list never leaves)
|
||||
@@ -1309,7 +1311,7 @@ Feature: /forms/libreoffice/convert
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| LIBREOFFICE_DENY_LIST | ^{helper}/canary/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-libreoffice/index.html"}] | field |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-stylesheet-html/index.html"}] | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
@@ -1322,34 +1324,10 @@ Feature: /forms/libreoffice/convert
|
||||
| LIBREOFFICE_ALLOW_LIST | |
|
||||
| LIBREOFFICE_DENY_PRIVATE_IPS | true |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-libreoffice/index.html"}] | field |
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-stylesheet-html/index.html"}] | field |
|
||||
Then the response status code should be 200
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
# An uploaded document loads from an untrusted location, so LibreOffice
|
||||
# refuses an image it links by URL, with no filter configured.
|
||||
@libreoffice-ssrf
|
||||
Scenario: POST /forms/libreoffice/convert (Canary image linked by URL never leaves)
|
||||
Given I have a static server
|
||||
Given I have a default Gotenberg container
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/canary-page/testdata/canary-libreoffice/linked-image.fodt"}] | field |
|
||||
| Gotenberg-Output-Filename | foo | header |
|
||||
Then the response status code should be 200
|
||||
Then the "foo.pdf" PDF should have 0 image(s)
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
# The deny-list names the download URL itself.
|
||||
@download-from
|
||||
Scenario: POST /forms/libreoffice/convert (Download From canary in the deny-list never leaves)
|
||||
Given I have a static server
|
||||
Given I have a Gotenberg container with the following environment variable(s):
|
||||
| API_DOWNLOAD_FROM_DENY_LIST | ^{helper}/canary/ |
|
||||
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
|
||||
| downloadFrom | [{"url":"{helper}/canary/page_1.docx"}] | field |
|
||||
Then the response status code should be 403
|
||||
Then the helper server should NOT have received a canary request
|
||||
|
||||
# The workbook was saved scrolled down to row 37. Without the topLeftCell
|
||||
# reset, singlePage would start the page there and drop the header rows,
|
||||
# so the "Meteor" column header only appears when the whole sheet is rendered.
|
||||
|
||||
@@ -138,6 +138,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
|
||||
ctx.Then(`^at least one concurrent response status code should be (\d+)$`, s.someConcurrentResponseStatusCodeShouldBe)
|
||||
ctx.Then(`^the (webhook request|file request|server request) method should be "([^"]*)"$`, s.theRequestMethodShouldBe)
|
||||
ctx.Then(`^the helper server (should|should NOT) have received a canary request$`, s.theHelperServerShouldHaveReceivedACanaryRequest)
|
||||
ctx.Then(`^the helper server should have received the following canary request\(s\):$`, s.theHelperServerShouldHaveReceivedTheFollowingCanaryRequests)
|
||||
ctx.Then(`^all probe response status codes should be (\d+)$`, s.allProbeResponseStatusCodesShouldBe)
|
||||
ctx.Then(`^all sequential response status codes should be (\d+)$`, s.allSequentialResponseStatusCodesShouldBe)
|
||||
ctx.Then(`^all concurrent responses should have (\d+) PDF\(s\)$`, s.allConcurrentResponsesShouldHavePdfs)
|
||||
|
||||
@@ -195,16 +195,18 @@ func newServer(ctx context.Context, workdir string) (*server, error) {
|
||||
// WebSocket handshake included, so a filter that logs a refusal but lets
|
||||
// the request through still fails the scenario.
|
||||
srv.Any("/canary/*", func(c *echo.Context) error {
|
||||
// Recorded first: a request counts once it arrives, even if reading
|
||||
// its body fails.
|
||||
r := c.Request()
|
||||
s.mu.Lock()
|
||||
s.canaries = append(s.canaries, r.Method+" "+r.URL.Path)
|
||||
s.mu.Unlock()
|
||||
|
||||
_, err := io.Copy(io.Discard, r.Body)
|
||||
if err != nil {
|
||||
return c.String(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.canaries = append(s.canaries, r.Method+" "+r.URL.Path)
|
||||
s.mu.Unlock()
|
||||
|
||||
return c.String(http.StatusOK, "canary")
|
||||
})
|
||||
// A redirect to a canary, for a filter that checks the URL it is given
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -73,25 +74,81 @@ func (s *scenario) theRequestMethodShouldBe(kind, expected string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// canaryGrace is how long the canary steps wait for a request still in
|
||||
// flight once Gotenberg has answered, such as a beacon or an asynchronous
|
||||
// webhook.
|
||||
const canaryGrace = 2 * time.Second
|
||||
|
||||
// theHelperServerShouldHaveReceivedACanaryRequest checks whether a request
|
||||
// reached the helper server's /canary/ routes. A filter's 403 or log line only
|
||||
// tells what Gotenberg decided; an empty canary list tells that no request left.
|
||||
// The negative form waits canaryGrace before it concludes.
|
||||
func (s *scenario) theHelperServerShouldHaveReceivedACanaryRequest(should string) error {
|
||||
if s.server == nil {
|
||||
return errors.New("no helper server: add \"I have a webhook server\" before this step")
|
||||
}
|
||||
|
||||
canaries := s.server.canaryRequests()
|
||||
invert := should == "should NOT"
|
||||
|
||||
if invert && len(canaries) > 0 {
|
||||
return fmt.Errorf("expected no canary request, but the helper server received %d: %s", len(canaries), strings.Join(canaries, ", "))
|
||||
}
|
||||
if !invert && len(canaries) == 0 {
|
||||
return errors.New("expected a canary request, but the helper server received none")
|
||||
if should == "should NOT" {
|
||||
deadline := time.Now().Add(canaryGrace)
|
||||
for {
|
||||
canaries := s.server.canaryRequests()
|
||||
if len(canaries) > 0 {
|
||||
return fmt.Errorf("expected no canary request, but the helper server received %d: %s", len(canaries), strings.Join(canaries, ", "))
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return s.waitForCanaries(func(canaries []string) error {
|
||||
if len(canaries) == 0 {
|
||||
return errors.New("expected a canary request, but the helper server received none")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// theHelperServerShouldHaveReceivedTheFollowingCanaryRequests checks that a
|
||||
// request reached each of the given paths under /canary/, whatever its method,
|
||||
// so that a control scenario fails as soon as one resource stops loading.
|
||||
func (s *scenario) theHelperServerShouldHaveReceivedTheFollowingCanaryRequests(pathsTable *godog.Table) error {
|
||||
if s.server == nil {
|
||||
return errors.New("no helper server: add \"I have a webhook server\" before this step")
|
||||
}
|
||||
|
||||
return s.waitForCanaries(func(canaries []string) error {
|
||||
var missing []string
|
||||
for _, row := range pathsTable.Rows {
|
||||
path := "/canary/" + strings.TrimPrefix(row.Cells[0].Value, "/")
|
||||
found := slices.ContainsFunc(canaries, func(canary string) bool {
|
||||
_, got, _ := strings.Cut(canary, " ")
|
||||
return got == path
|
||||
})
|
||||
if !found {
|
||||
missing = append(missing, path)
|
||||
}
|
||||
}
|
||||
|
||||
if len(missing) > 0 {
|
||||
return fmt.Errorf("expected canary requests to %s, but the helper server received: %s", strings.Join(missing, ", "), strings.Join(canaries, ", "))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// waitForCanaries retries check against the canary requests for up to
|
||||
// canaryGrace, as some may still be in flight.
|
||||
func (s *scenario) waitForCanaries(check func(canaries []string) error) error {
|
||||
deadline := time.Now().Add(canaryGrace)
|
||||
for {
|
||||
err := check(s.server.canaryRequests())
|
||||
if err == nil || time.Now().After(deadline) {
|
||||
return err
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *scenario) allConcurrentResponseStatusCodesShouldBe(expected int) error {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||
<office:body><office:text>
|
||||
<text:p>An image linked by an external URL must not load.</text:p>
|
||||
<text:p><draw:frame text:anchor-type="as-char" svg:width="3cm" svg:height="3cm"><draw:image xlink:href="{canary}/image.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame></text:p>
|
||||
</office:text></office:body>
|
||||
</office:document>
|
||||
@@ -7,6 +7,5 @@
|
||||
</head>
|
||||
<body>
|
||||
<p>LibreOffice requests the style sheet this page links.</p>
|
||||
<img src="{canary}/image.png" alt="" />
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user