caddy/caddytest/integration
prettysunflower 7dedd1486c
fix(caddyfile): {block} in snippet (#7558)
* fix(caddyfile): {block} in snippet

Resolve issue #7557

So, here is the situation:
- Pull request #7206 included some changes to the doImport's function of
  Caddyfile's parser. What it does is that if there is no token within a
  block that follows the import, and the import contains `{block}`, then
  the `{block}` token is discarded.
- After this pull request:
  - Issue #7518 noticed that in cases that `{block}` was not imported,
    a runtime error was raised due to the assumption that tokens were
    always added to `tokensCopy` on every iteration of `importedTokens`.
    This was fixed by pull request #7543.
  - Issue #7557 notices that {block} can be ignored when imported from a
    certain file. There, it's again an issue with how the import works.
    When `import snippets` is called, this import instruction doesn't
    contains any nested blocks. And when the argument replacer that is
    the `importedTokens` loop is called and finds `{block}`, it uses the
    block from the file's import (which in this case is nothing),
    `{block}` is erased, and unavailable when the import directive is
    called for the imported snippet.

The changed in this commit addresses the second issue by checking before
replacing `{block}` if we're currently in a snippet definition, and
appending the `{block}` token to `tokensCopy` if we are.

With this changes, when importing those snippets, the `{block}` token
will be available to be replaced by the nested blocks in `tokensToAdd`
if needed, or erased if there are no nested blocks and `tokensToAdd` is empty.

Tests added in pull requests #7206 and #7543 passes with this new
implementation, confirming that unused `{block}` are accepted if nothing
is passed to `import`, as well as the other usual tests.
A new test was also added based on issue #7557 reporting, and also passes.

Signed-off-by: prettysunflower <me@prettysunflower.moe>

* caddyfile: add imported snippet block placeholder coverage

---------

Signed-off-by: prettysunflower <me@prettysunflower.moe>
Co-authored-by: Zen Dodd <mail@steadytao.com>
2026-04-15 02:58:53 -04:00
..
caddyfile_adapt fix(caddyfile): {block} in snippet (#7558) 2026-04-15 02:58:53 -04:00
testdata fix(caddyfile): {block} in snippet (#7558) 2026-04-15 02:58:53 -04:00
acme_test.go logging: Ensure slog error level logs don't print stack traces (#7512) 2026-03-03 14:44:42 -07:00
acmeserver_test.go chore: Add nolints to work around haywire linters (#7493) 2026-02-17 16:52:54 -07:00
autohttps_test.go http: Sort auto-HTTPS redirect routes by host specificity (fixes #7390) (#7502) 2026-02-21 21:42:40 -05:00
caddyfile_adapt_test.go httpcaddyfile: Validates TLS DNS challenge options (#7099) 2025-06-30 23:58:16 +00:00
caddyfile_test.go httpcaddyfile: Prevent error handler from overriding sub-handler matchers (#6999) 2025-06-06 11:46:39 -06:00
forwardauth_test.go root: introduce down-propagating Helper.BlockState for other directives/plugins to use (#7594) 2026-03-28 17:44:42 +00:00
h2listener_test.go caddyhttp: wrap accepted connection to suppress tls.ConnectionState (#7247) 2025-10-16 03:13:40 +00:00
handler_test.go staticresp: Use the evaluated response body for sniffing JSON content-type (#6249) 2024-04-18 20:31:00 +00:00
intercept_test.go intercept: fix http.intercept.header.* placeholder (#6429) 2024-07-03 08:43:13 -06:00
leafcertloaders_test.go ci: fix the integration test TestLeafCertLoaders (#6149) 2024-03-06 02:09:13 +03:00
listener_test.go use math/rand/v2 instead of math/rand (#7413) 2026-02-11 09:15:51 -07:00
map_test.go ci: fix integration tests (#5079) 2022-09-24 19:00:55 +00:00
mockdns_test.go httpcaddyfile: Add missing DNS challenge check for acme_dns (#7270) 2025-10-03 14:05:46 -06:00
pki_test.go admin: Fix tests locally, properly isolate storage (#7486) 2026-02-17 13:14:06 -07:00
proxyprotocol_test.go proxyproto: Generated test coverage (#7540) 2026-03-03 15:08:09 -07:00
reverseproxy_test.go reverseproxy: Fix health_port being ignored in health checks (#7533) 2026-03-03 13:10:54 -05:00
sni_test.go filesystem: Globally declared filesystems, fs directive (#5833) 2024-01-13 20:12:43 +00:00
stream_test.go chore: upgrade .golangci.yml and workflow to v2 (#6924) 2025-06-03 02:24:32 +03:00