mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-26 08:42:31 -04:00
Compare commits
173 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72875401e3 | |||
| 704394d9d1 | |||
| 6c675e29f8 | |||
| 77e9ce7404 | |||
| cc58caa109 | |||
| d80774cb3f | |||
| a4a38c3e88 | |||
| 761347aa63 | |||
| 4ba16fe82c | |||
| 0fab9f0f7d | |||
| 5e76b5ee43 | |||
| 9c78b97f9e | |||
| fb324331f4 | |||
| 0780d4489c | |||
| d2172bea61 | |||
| c7c9f3108a | |||
| 7e77eec0ae | |||
| ef496e58ef | |||
| 18ab0f955f | |||
| 6a64bb2ce5 | |||
| 4d6945769d | |||
| 2d33271482 | |||
| c653e7d61a | |||
| c1918ff1ad | |||
| fdbef2a6ef | |||
| 2a3ed96f8c | |||
| 355c178213 | |||
| f6ee80be1b | |||
| 48c08e3890 | |||
| cf42f61566 | |||
| 41aee97386 | |||
| 441d5eb062 | |||
| aed1af5976 | |||
| 4430756d5c | |||
| af89c5ab02 | |||
| bd9f145321 | |||
| 24bebd0a07 | |||
| 7dedd1486c | |||
| 7586e68e27 | |||
| 0c7c91a447 | |||
| 1a3e900b35 | |||
| 0722cf6fd8 | |||
| 8e2dd5079c | |||
| 5f44ea0748 | |||
| c8e4ac2c8c | |||
| 7dcc041eec | |||
| ca0ca67fbd | |||
| 92b62004eb | |||
| 6c23ec2f3c | |||
| 5de1565ff6 | |||
| d7834676aa | |||
| 4f50458866 | |||
| ea4ee3ae5d | |||
| 30b80bece8 | |||
| 7a630f2910 | |||
| 62e9c05264 | |||
| 6f6771aa1d | |||
| acf8d6a1ae | |||
| e98ed6232d | |||
| c35ba5588d | |||
| a4004467aa | |||
| 41d8cea9e6 | |||
| ef3158cac7 | |||
| a5ef0600aa | |||
| 9236eacd35 | |||
| 258a928d27 | |||
| e56b31e3ad | |||
| 435e521203 | |||
| 476d75219c | |||
| 719d879f3d | |||
| 5db80034a8 | |||
| 5d189aff40 | |||
| a2a7fd6671 | |||
| df65455b1f | |||
| 8499e34e10 | |||
| 1fbb28720b | |||
| ffb6ab0644 | |||
| 9371ee67c6 | |||
| 5d20adc7a9 | |||
| 6e5e08cf58 | |||
| fbfb8fc517 | |||
| e06dfcf6ed | |||
| 566e710991 | |||
| a5e7c6e232 | |||
| db2986028f | |||
| 7e83775e3a | |||
| 2dbcdefbbe | |||
| dc36082859 | |||
| 88616e86e6 | |||
| 7b34e3107e | |||
| a6acb3902c | |||
| 45cf61b127 | |||
| d935a6956c | |||
| 2dd3852416 | |||
| 11b56c6cfc | |||
| f283062d37 | |||
| 2ab043b890 | |||
| f145bce553 | |||
| 174fa2ddb9 | |||
| cd9e1660aa | |||
| 06a05e383c | |||
| ce203aa9e1 | |||
| eac02ee98f | |||
| 72eaf2583a | |||
| 9798f6964d | |||
| 9873752978 | |||
| 294dfff443 | |||
| 76b198f586 | |||
| 7ffb640a4d | |||
| d7b21c6104 | |||
| 6610e2f1bd | |||
| 03243e42fe | |||
| cb436f0a0e | |||
| a1081194bf | |||
| eec32a0bb5 | |||
| a2825c5dd9 | |||
| db256b53e5 | |||
| 6772ffb805 | |||
| 95941a71e8 | |||
| 3adcafd4c1 | |||
| 091add5ae3 | |||
| bdcdaf77ba | |||
| 9fe694c79c | |||
| b8b00d9160 | |||
| 68d50020ee | |||
| 8a18acc025 | |||
| 23d07ac89d | |||
| d64c7e67a4 | |||
| ff4f79aebe | |||
| f2213e943e | |||
| affbb99275 | |||
| d6a6b486db | |||
| 929d0e502a | |||
| 6718bd470f | |||
| 80bf81839d | |||
| d42d39b4bc | |||
| 0188ef2e62 | |||
| c0af7b665f | |||
| 72ac479f5d | |||
| 47f3e8f8dc | |||
| 03e6e439dd | |||
| 7c28c0c07a | |||
| 96f142c2a6 | |||
| 5ff50779cc | |||
| 1f43e8566b | |||
| bd374ca9d7 | |||
| 2ae0f7af69 | |||
| 58968b3fd3 | |||
| 42ca010e9d | |||
| 40927d2f75 | |||
| e0f8d9b204 | |||
| 201cba5b66 | |||
| f35ea4665d | |||
| c8bc9971b4 | |||
| 3d6f58bf46 | |||
| c29418e299 | |||
| af3d6b3935 | |||
| 656bfc3111 | |||
| 05504942d8 | |||
| 5d50967a0d | |||
| a0f2922157 | |||
| 7a92274e9c | |||
| 6872a66604 | |||
| c2d586c458 | |||
| c6367fb774 | |||
| fc63a3c3f5 | |||
| 93315eafff | |||
| 0b83afa6a5 | |||
| e86b913567 | |||
| b8e72c6a22 | |||
| be4593bd00 | |||
| a6c64276c1 | |||
| 4a9c83b969 |
+12
-7
@@ -1,15 +1,14 @@
|
||||
# Security Policy
|
||||
|
||||
The Caddy project would like to make sure that it stays on top of all practically-exploitable vulnerabilities.
|
||||
The Caddy project would like to make sure that it stays on top of all relevant and practically-exploitable vulnerabilities.
|
||||
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| -------- | ----------|
|
||||
| 2.latest | ✔️ |
|
||||
| 1.x | :x: |
|
||||
| < 1.x | :x: |
|
||||
| Version | Supported |
|
||||
| ----------- | ----------|
|
||||
| 2.latest | ✔️ |
|
||||
| < 2.latest | :x: |
|
||||
|
||||
|
||||
## Acceptable Scope
|
||||
@@ -18,7 +17,7 @@ A security report must demonstrate a security bug in the source code from this r
|
||||
|
||||
Some security problems are the result of interplay between different components of the Web, rather than a vulnerability in the web server itself. Please only report vulnerabilities in the web server itself, as we cannot coerce the rest of the Web to be fixed (for example, we do not consider IP spoofing, BGP hijacks, or missing/misconfigured HTTP headers a vulnerability in the Caddy web server).
|
||||
|
||||
Vulnerabilities caused by misconfigurations are out of scope. Yes, it is entirely possible to craft and use a configuration that is unsafe, just like with every other web server; we recommend against doing that.
|
||||
Vulnerabilities caused by misconfigurations are out of scope. Yes, it is entirely possible to craft and use a configuration that is unsafe, just like with every other web server; we recommend against doing that. Similarly, external misconfigurations are out of scope. For example, an open or forwarded port from a public network to a Caddy instance intended to serve only internal clients is not a vulnerability in Caddy.
|
||||
|
||||
We do not accept reports if the steps imply or require a compromised system or third-party software, as we cannot control those. We expect that users secure their own systems and keep all their software patched. For example, if untrusted users are able to upload/write/host arbitrary files in the web root directory, it is NOT a security bug in Caddy if those files get served to clients; however, it _would_ be a valid report if a bug in Caddy's source code unintentionally gave unauthorized users the ability to upload unsafe files or delete files without relying on an unpatched system or piece of software.
|
||||
|
||||
@@ -26,6 +25,10 @@ Client-side exploits are out of scope. In other words, it is not a bug in Caddy
|
||||
|
||||
Security bugs in code dependencies (including Go's standard library) are out of scope. Instead, if a dependency has patched a relevant security bug, please feel free to open a public issue or pull request to update that dependency in our code.
|
||||
|
||||
Many reports are not security bugs and can be addressed by updating the documentation.
|
||||
|
||||
We accept security reports and patches, but do not assign CVEs, for code that has not been released with a non-prerelease tag.
|
||||
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
@@ -33,6 +36,8 @@ We get a lot of difficult reports that turn out to be invalid. Clear, obvious re
|
||||
|
||||
First please ensure your report falls within the accepted scope of security bugs (above).
|
||||
|
||||
:warning: **YOU MUST DISCLOSE WHETHER YOU USED LLMs ("AI") IN ANY WAY.** Whether you are using AI for discovery, as part of writing the report or its replies, and/or testing or validating proofs and changes, we require you to mention the extent of it. **FAILURE TO INCLUDE A DISCLOSURE EVEN IF YOU DO NOT USE AI MAY LEAD TO IMMEDIATE DISMISSAL OF YOUR REPORT AND POTENTIAL BLOCKLISTING.** We will not waste our time chatting with bots. But if you're a human, pull up a chair and we'll drink some chocolate milk.
|
||||
|
||||
We'll need enough information to verify the bug and make a patch. To speed things up, please include:
|
||||
|
||||
- Most minimal possible config (without redactions!)
|
||||
|
||||
@@ -16,8 +16,8 @@ jobs:
|
||||
models: read
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
|
||||
- uses: github/ai-moderator@6bcdb2a79c2e564db8d76d7d4439d91a044c4eb6
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
|
||||
- uses: github/ai-moderator@81159c370785e295c97461ade67d7c33576e9319
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
spam-label: 'spam'
|
||||
|
||||
+15
-15
@@ -31,13 +31,13 @@ jobs:
|
||||
- mac
|
||||
- windows
|
||||
go:
|
||||
- '1.25'
|
||||
- '1.26'
|
||||
|
||||
include:
|
||||
# Set the minimum Go patch version for the given Go minor
|
||||
# Usable via ${{ matrix.GO_SEMVER }}
|
||||
- go: '1.25'
|
||||
GO_SEMVER: '~1.25.0'
|
||||
- go: '1.26'
|
||||
GO_SEMVER: '~1.26.0'
|
||||
|
||||
# Set some variables per OS, usable via ${{ matrix.VAR }}
|
||||
# OS_LABEL: the VM label from GitHub Actions (see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories)
|
||||
@@ -65,15 +65,15 @@ jobs:
|
||||
actions: write # to allow uploading artifacts and cache
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
|
||||
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version: ${{ matrix.GO_SEMVER }}
|
||||
check-latest: true
|
||||
@@ -120,7 +120,7 @@ jobs:
|
||||
./caddy stop
|
||||
|
||||
- name: Publish Build Artifact
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
with:
|
||||
name: caddy_${{ runner.os }}_go${{ matrix.go }}_${{ steps.vars.outputs.short_sha }}
|
||||
path: ${{ matrix.CADDY_BIN_PATH }}
|
||||
@@ -162,13 +162,13 @@ jobs:
|
||||
continue-on-error: true # August 2020: s390x VM is down due to weather and power issues
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints: ci-s390x.caddyserver.com:22
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Run Tests
|
||||
run: |
|
||||
set +e
|
||||
@@ -221,27 +221,27 @@ jobs:
|
||||
if: github.event.pull_request.head.repo.full_name == 'caddyserver/caddy' && github.actor != 'dependabot[bot]'
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
|
||||
- uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
|
||||
with:
|
||||
version: latest
|
||||
args: check
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
|
||||
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version: "~1.25"
|
||||
go-version: "~1.26"
|
||||
check-latest: true
|
||||
- name: Install xcaddy
|
||||
run: |
|
||||
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
|
||||
xcaddy version
|
||||
- uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
|
||||
- uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
|
||||
with:
|
||||
version: latest
|
||||
args: build --single-target --snapshot
|
||||
|
||||
@@ -36,13 +36,13 @@ jobs:
|
||||
- 'darwin'
|
||||
- 'netbsd'
|
||||
go:
|
||||
- '1.25'
|
||||
- '1.26'
|
||||
|
||||
include:
|
||||
# Set the minimum Go patch version for the given Go minor
|
||||
# Usable via ${{ matrix.GO_SEMVER }}
|
||||
- go: '1.25'
|
||||
GO_SEMVER: '~1.25.0'
|
||||
- go: '1.26'
|
||||
GO_SEMVER: '~1.26.0'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
@@ -51,15 +51,15 @@ jobs:
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
|
||||
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version: ${{ matrix.GO_SEMVER }}
|
||||
check-latest: true
|
||||
|
||||
+10
-10
@@ -45,18 +45,18 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version: '~1.25'
|
||||
go-version: '~1.26'
|
||||
check-latest: true
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
||||
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
|
||||
with:
|
||||
version: latest
|
||||
|
||||
@@ -73,14 +73,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: govulncheck
|
||||
uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4
|
||||
with:
|
||||
go-version-input: '~1.25.0'
|
||||
go-version-input: '~1.26.0'
|
||||
check-latest: true
|
||||
|
||||
dependency-review:
|
||||
@@ -90,14 +90,14 @@ jobs:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@56339e523c0409420f6c2c9a2f4292bbb3c07dd3 # v4.8.0
|
||||
uses: actions/dependency-review-action@05fe4576374b728f0c523d6a13d64c25081e0803 # v4.8.3
|
||||
with:
|
||||
comment-summary-in-pr: on-failure
|
||||
# https://github.com/actions/dependency-review-action/issues/430#issuecomment-1468975566
|
||||
|
||||
@@ -28,11 +28,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
# Force fetch upstream tags -- because 65 minutes
|
||||
@@ -334,13 +334,13 @@ jobs:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
go:
|
||||
- '1.25'
|
||||
- '1.26'
|
||||
|
||||
include:
|
||||
# Set the minimum Go patch version for the given Go minor
|
||||
# Usable via ${{ matrix.GO_SEMVER }}
|
||||
- go: '1.25'
|
||||
GO_SEMVER: '~1.25.0'
|
||||
- go: '1.26'
|
||||
GO_SEMVER: '~1.26.0'
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
# https://github.com/sigstore/cosign/issues/1258#issuecomment-1002251233
|
||||
@@ -355,23 +355,23 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
|
||||
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version: ${{ matrix.GO_SEMVER }}
|
||||
check-latest: true
|
||||
|
||||
# Force fetch upstream tags -- because 65 minutes
|
||||
# tl;dr: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4.2.2 runs this line:
|
||||
# tl;dr: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 runs this line:
|
||||
# git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +ebc278ec98bb24f2852b61fde2a9bf2e3d83818b:refs/tags/
|
||||
# which makes its own local lightweight tag, losing all the annotations in the process. Our earlier script ran:
|
||||
# git fetch --prune --unshallow
|
||||
@@ -419,7 +419,7 @@ jobs:
|
||||
- name: Cosign version
|
||||
run: cosign version
|
||||
- name: Install Syft
|
||||
uses: anchore/sbom-action/download-syft@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # main
|
||||
uses: anchore/sbom-action/download-syft@17ae1740179002c89186b61233e0f892c3118b11 # main
|
||||
- name: Syft version
|
||||
run: syft version
|
||||
- name: Install xcaddy
|
||||
@@ -428,7 +428,7 @@ jobs:
|
||||
xcaddy version
|
||||
# GoReleaser will take care of publishing those artifacts into the release
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
|
||||
uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
|
||||
with:
|
||||
version: latest
|
||||
args: release --clean --timeout 60m
|
||||
|
||||
@@ -24,12 +24,12 @@ jobs:
|
||||
|
||||
# See https://github.com/peter-evans/repository-dispatch
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Trigger event on caddyserver/dist
|
||||
uses: peter-evans/repository-dispatch@5fc4efd1a4797ddb68ffd0714a238564e4cc0e6f # v4.0.0
|
||||
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
|
||||
with:
|
||||
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
|
||||
repository: caddyserver/dist
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
client-payload: '{"tag": "${{ github.event.release.tag_name }}"}'
|
||||
|
||||
- name: Trigger event on caddyserver/caddy-docker
|
||||
uses: peter-evans/repository-dispatch@5fc4efd1a4797ddb68ffd0714a238564e4cc0e6f # v4.0.0
|
||||
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
|
||||
with:
|
||||
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
|
||||
repository: caddyserver/caddy-docker
|
||||
|
||||
@@ -37,12 +37,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
|
||||
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -72,7 +72,7 @@ jobs:
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -81,6 +81,6 @@ jobs:
|
||||
# Upload the results to GitHub's code scanning dashboard (optional).
|
||||
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
|
||||
uses: github/codeql-action/upload-sarif@89a39a4e59826350b863aa6b6252a07ad50cf83e # v3.29.5
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
@@ -32,6 +32,7 @@ linters:
|
||||
- importas
|
||||
- ineffassign
|
||||
- misspell
|
||||
- modernize
|
||||
- prealloc
|
||||
- promlinter
|
||||
- sloglint
|
||||
|
||||
+3
-1
@@ -13,7 +13,7 @@ before:
|
||||
- cp cmd/caddy/main.go caddy-build/main.go
|
||||
- /bin/sh -c 'cd ./caddy-build && go mod init caddy'
|
||||
# prepare syso files for windows embedding
|
||||
- /bin/sh -c 'for a in amd64 arm arm64; do XCADDY_SKIP_BUILD=1 GOOS=windows GOARCH=$a xcaddy build {{.Env.TAG}}; done'
|
||||
- /bin/sh -c 'for a in amd64 arm64; do XCADDY_SKIP_BUILD=1 GOOS=windows GOARCH=$a xcaddy build {{.Env.TAG}}; done'
|
||||
- /bin/sh -c 'mv /tmp/buildenv_*/*.syso caddy-build'
|
||||
# GoReleaser doesn't seem to offer {{.Tag}} at this stage, so we have to embed it into the env
|
||||
# so we run: TAG=$(git describe --abbrev=0) goreleaser release --rm-dist --skip-publish --skip-validate
|
||||
@@ -67,6 +67,8 @@ builds:
|
||||
goarch: s390x
|
||||
- goos: windows
|
||||
goarch: riscv64
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
- goos: freebsd
|
||||
goarch: ppc64le
|
||||
- goos: freebsd
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
# Caddy Project Guidelines
|
||||
|
||||
## Mission
|
||||
|
||||
**Every site on HTTPS.** Caddy is a security-first, modular, extensible server platform.
|
||||
|
||||
## Code Style
|
||||
|
||||
### Go Idioms
|
||||
|
||||
Follow [Go Code Review Comments](https://go.dev/wiki/CodeReviewComments):
|
||||
|
||||
- **Error flow**: Early return, indent error handling—not else blocks
|
||||
```go
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// normal code
|
||||
```
|
||||
- **Naming**: initialisms (`URL`, `HTTP`, `ID`—not `Url`, `Http`, `Id`)
|
||||
- **Receiver names**: 1–2 letters reflecting type (`c` for `Client`, `h` for `Handler`)
|
||||
- **Error strings**: Lowercase, no trailing punctuation (`"something failed"` not `"Something failed."`)
|
||||
- **Doc comments**: Full sentences starting with the name being documented
|
||||
```go
|
||||
// Handler serves HTTP requests for the file server.
|
||||
type Handler struct { ... }
|
||||
```
|
||||
- **Empty slices**: `var t []string` (nil slice), not `t := []string{}` (non-nil zero-length)
|
||||
- **Don't panic**: Use error returns for normal error handling
|
||||
|
||||
### Caddy Patterns
|
||||
|
||||
**Module registration**:
|
||||
```go
|
||||
func init() {
|
||||
caddy.RegisterModule(MyModule{})
|
||||
}
|
||||
|
||||
func (MyModule) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
ID: "namespace.category.name",
|
||||
New: func() caddy.Module { return new(MyModule) },
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Module lifecycle**: `New()` → JSON unmarshal → `Provision()` → `Validate()` → use → `Cleanup()`
|
||||
|
||||
**Interface guards** — compile-time verification that modules implement required interfaces:
|
||||
```go
|
||||
var (
|
||||
_ caddy.Provisioner = (*MyModule)(nil)
|
||||
_ caddy.Validator = (*MyModule)(nil)
|
||||
_ caddyfile.Unmarshaler = (*MyModule)(nil)
|
||||
)
|
||||
```
|
||||
|
||||
**Structured logging** — use the module-scoped logger from context:
|
||||
```go
|
||||
func (m *MyModule) Provision(ctx caddy.Context) error {
|
||||
m.logger = ctx.Logger()
|
||||
m.logger.Debug("provisioning", zap.String("field", m.Field))
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
**Caddyfile support** — implement `UnmarshalCaddyfile(*caddyfile.Dispenser)` using the `Dispenser` API:
|
||||
```go
|
||||
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
|
||||
//
|
||||
// directive [arg1] [arg2] {
|
||||
// subdir value
|
||||
// }
|
||||
func (m *MyModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
d.Next() // consume directive name
|
||||
for d.NextArg() {
|
||||
// handle inline arguments
|
||||
}
|
||||
for nesting := d.Nesting(); d.NextBlock(nesting); {
|
||||
switch d.Val() {
|
||||
case "subdir":
|
||||
if !d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
m.Field = d.Val()
|
||||
default:
|
||||
return d.Errf("unrecognized subdirective: %s", d.Val())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
**Admin API**: Implement `caddy.AdminRouter` for custom endpoints.
|
||||
|
||||
**Context**: Use `caddy.Context` for accessing other apps/modules and logging—don't store contexts in structs.
|
||||
|
||||
## Architecture
|
||||
|
||||
Caddy is built around a **module system** where everything is a module registered via `caddy.RegisterModule()`:
|
||||
|
||||
- **Apps** (`caddy.App`): Top-level modules like `http`, `tls`, `pki` that Caddy loads and runs
|
||||
- **Modules** (`caddy.Module`): Extensible components with namespaced IDs (e.g., `http.handlers.file_server`)
|
||||
- **Configuration**: Native JSON with adapters (Caddyfile → JSON via `caddyconfig/httpcaddyfile`)
|
||||
|
||||
| Directory | Purpose |
|
||||
|-----------|---------|
|
||||
| `modules/` | All standard modules (HTTP, TLS, PKI, etc.) |
|
||||
| `modules/standard/imports.go` | Standard module registry |
|
||||
| `caddyconfig/httpcaddyfile/` | Caddyfile → JSON adapter for HTTP |
|
||||
| `caddytest/` | Test utilities and integration tests |
|
||||
| `cmd/caddy/` | CLI entry point with module imports |
|
||||
|
||||
### Critical Packages
|
||||
|
||||
`caddyhttp` and `caddytls` require **extra scrutiny** in code review—these are security-critical.
|
||||
|
||||
## Quality Gates
|
||||
|
||||
|
||||
**All required before PR is merge-ready:**
|
||||
|
||||
| Gate | Command | Notes |
|
||||
|------|---------|-------|
|
||||
| Tests pass | `go test -race -short ./...` | Race detection enabled |
|
||||
| Lint clean | `golangci-lint run --timeout 10m` | No warnings in changed files |
|
||||
| Builds | `go build ./...` | Must compile |
|
||||
| Benchmarks | `go test -bench=. -benchmem` | Required for optimizations |
|
||||
|
||||
CI runs tests on **Linux, macOS, and Windows**—ensure cross-platform compatibility.
|
||||
|
||||
### Build & Test
|
||||
|
||||
```bash
|
||||
# Build
|
||||
cd cmd/caddy && go build
|
||||
|
||||
# Tests with race detection (matches CI)
|
||||
go test -race -short ./...
|
||||
|
||||
# Integration tests
|
||||
go test ./caddytest/integration/...
|
||||
|
||||
# Lint (matches CI)
|
||||
golangci-lint run --timeout 10m
|
||||
```
|
||||
|
||||
## Testing Conventions
|
||||
|
||||
**Table-driven tests** (preferred pattern):
|
||||
```go
|
||||
func TestFeature(t *testing.T) {
|
||||
for i, tc := range []struct {
|
||||
input string
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
{input: "valid", expected: "result", wantErr: false},
|
||||
{input: "invalid", expected: "", wantErr: true},
|
||||
} {
|
||||
actual, err := Function(tc.input)
|
||||
if tc.wantErr && err == nil {
|
||||
t.Errorf("Test %d: expected error but got none", i)
|
||||
}
|
||||
if !tc.wantErr && err != nil {
|
||||
t.Errorf("Test %d: unexpected error: %v", i, err)
|
||||
}
|
||||
if actual != tc.expected {
|
||||
t.Errorf("Test %d: expected %q, got %q", i, tc.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Integration tests** use `caddytest.Tester`:
|
||||
```go
|
||||
func TestHTTPFeature(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
}
|
||||
localhost:9080 {
|
||||
respond "hello"
|
||||
}`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "hello")
|
||||
}
|
||||
```
|
||||
|
||||
Use non-standard ports (9080, 9443, 2999) to avoid conflicts with running servers.
|
||||
|
||||
## AI Contribution Policy
|
||||
|
||||
Per [CONTRIBUTING.md](.github/CONTRIBUTING.md), AI-assisted code **MUST** be:
|
||||
|
||||
1. **Disclosed** — Tell reviewers when code was AI-generated or AI-assisted, mentioning which agent/model is used
|
||||
2. **Fully comprehended** — You must be able to explain every line
|
||||
3. **Tested** — Automated tests when feasible, thorough manual tests otherwise
|
||||
4. **Licensed** — Verify AI output doesn't include plagiarized or incompatibly-licensed code
|
||||
5. **Contributor License Agreement (CLA)** — The CLA must be signed by the human user
|
||||
|
||||
**Do NOT submit code you cannot fully explain.** Contributors are responsible for their submissions.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- **Avoid new dependencies** — Justify any additions; tiny deps can be inlined
|
||||
- **No exported dependency types** — Caddy must not export types defined by external packages
|
||||
- Use Go modules; check with `go mod tidy`
|
||||
|
||||
## Further Reading
|
||||
|
||||
- [CONTRIBUTING.md](.github/CONTRIBUTING.md) — Full PR process and expectations
|
||||
- [Extending Caddy](https://caddyserver.com/docs/extending-caddy) — Module development guide
|
||||
- [JSON Config](https://caddyserver.com/docs/json/) — Native configuration reference
|
||||
- [Caddyfile](https://caddyserver.com/docs/caddyfile/concepts) — Caddyfile syntax guide
|
||||
@@ -220,6 +220,6 @@ Matthew Holt began developing Caddy in 2014 while studying computer science at B
|
||||
- _Project on X: [@caddyserver](https://x.com/caddyserver)_
|
||||
- _Author on X: [@mholt6](https://x.com/mholt6)_
|
||||
|
||||
Caddy is a project of [ZeroSSL](https://zerossl.com), a Stack Holdings company.
|
||||
Caddy is a project of [ZeroSSL](https://zerossl.com), an HID Global company.
|
||||
|
||||
Debian package repository hosting is graciously provided by [Cloudsmith](https://cloudsmith.com). Cloudsmith is the only fully hosted, cloud-native, universal package management solution, that enables your organization to create, store and share packages in any format, to any place, with total confidence.
|
||||
|
||||
@@ -45,8 +45,16 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/internal"
|
||||
)
|
||||
|
||||
// testCertMagicStorageOverride is a package-level test hook. Tests may set
|
||||
// this variable to provide a temporary certmagic.Storage so that cert
|
||||
// management in tests does not hit the real default storage on disk.
|
||||
// This must NOT be set in production code.
|
||||
var testCertMagicStorageOverride certmagic.Storage
|
||||
|
||||
func init() {
|
||||
// The hard-coded default `DefaultAdminListen` can be overridden
|
||||
// by setting the `CADDY_ADMIN` environment variable.
|
||||
@@ -112,10 +120,6 @@ type AdminConfig struct {
|
||||
//
|
||||
// EXPERIMENTAL: This feature is subject to change.
|
||||
Remote *RemoteAdmin `json:"remote,omitempty"`
|
||||
|
||||
// Holds onto the routers so that we can later provision them
|
||||
// if they require provisioning.
|
||||
routers []AdminRouter
|
||||
}
|
||||
|
||||
// ConfigSettings configures the management of configuration.
|
||||
@@ -204,8 +208,8 @@ type AdminAccess struct {
|
||||
// AdminPermissions specifies what kinds of requests are allowed
|
||||
// to be made to the admin endpoint.
|
||||
type AdminPermissions struct {
|
||||
// The API paths allowed. Paths are simple prefix matches.
|
||||
// Any subpath of the specified paths will be allowed.
|
||||
// The API paths allowed. A request path must either equal an
|
||||
// allowed path or be a subpath with a path-segment boundary.
|
||||
Paths []string `json:"paths,omitempty"`
|
||||
|
||||
// The HTTP methods allowed for the given paths.
|
||||
@@ -214,7 +218,7 @@ type AdminPermissions struct {
|
||||
|
||||
// newAdminHandler reads admin's config and returns an http.Handler suitable
|
||||
// for use in an admin endpoint server, which will be listening on listenAddr.
|
||||
func (admin *AdminConfig) newAdminHandler(addr NetworkAddress, remote bool, _ Context) adminHandler {
|
||||
func (admin *AdminConfig) newAdminHandler(addr NetworkAddress, remote bool, ctx Context) (adminHandler, error) {
|
||||
muxWrap := adminHandler{mux: http.NewServeMux()}
|
||||
|
||||
// secure the local or remote endpoint respectively
|
||||
@@ -271,34 +275,21 @@ func (admin *AdminConfig) newAdminHandler(addr NetworkAddress, remote bool, _ Co
|
||||
// register third-party module endpoints
|
||||
for _, m := range GetModules("admin.api") {
|
||||
router := m.New().(AdminRouter)
|
||||
|
||||
// provision the router before registering its routes, so
|
||||
// handlers have access to all provisioned state
|
||||
if provisioner, ok := router.(Provisioner); ok {
|
||||
if err := provisioner.Provision(ctx); err != nil {
|
||||
return adminHandler{}, fmt.Errorf("provisioning admin router module %s: %v", m.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, route := range router.Routes() {
|
||||
addRoute(route.Pattern, handlerLabel, route.Handler)
|
||||
}
|
||||
admin.routers = append(admin.routers, router)
|
||||
}
|
||||
|
||||
return muxWrap
|
||||
}
|
||||
|
||||
// provisionAdminRouters provisions all the router modules
|
||||
// in the admin.api namespace that need provisioning.
|
||||
func (admin *AdminConfig) provisionAdminRouters(ctx Context) error {
|
||||
for _, router := range admin.routers {
|
||||
provisioner, ok := router.(Provisioner)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
err := provisioner.Provision(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// We no longer need the routers once provisioned, allow for GC
|
||||
admin.routers = nil
|
||||
|
||||
return nil
|
||||
return muxWrap, nil
|
||||
}
|
||||
|
||||
// allowedOrigins returns a list of origins that are allowed.
|
||||
@@ -422,11 +413,7 @@ func replaceLocalAdminServer(cfg *Config, ctx Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
handler := cfg.Admin.newAdminHandler(addr, false, ctx)
|
||||
|
||||
// run the provisioners for loaded modules to make sure local
|
||||
// state is properly re-initialized in the new admin server
|
||||
err = cfg.Admin.provisionAdminRouters(ctx)
|
||||
handler, err := cfg.Admin.newAdminHandler(addr, false, ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -550,11 +537,7 @@ func replaceRemoteAdminServer(ctx Context, cfg *Config) error {
|
||||
|
||||
// make the HTTP handler but disable Host/Origin enforcement
|
||||
// because we are using TLS authentication instead
|
||||
handler := cfg.Admin.newAdminHandler(addr, true, ctx)
|
||||
|
||||
// run the provisioners for loaded modules to make sure local
|
||||
// state is properly re-initialized in the new admin server
|
||||
err = cfg.Admin.provisionAdminRouters(ctx)
|
||||
handler, err := cfg.Admin.newAdminHandler(addr, true, ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -633,8 +616,19 @@ func (ident *IdentityConfig) certmagicConfig(logger *zap.Logger, makeCache bool)
|
||||
// certmagic config, although it'll be mostly useless for remote management
|
||||
ident = new(IdentityConfig)
|
||||
}
|
||||
// Choose storage: prefer the package-level test override when present,
|
||||
// otherwise use the configured DefaultStorage. Tests may set an override
|
||||
// to divert storage into a temporary location. Otherwise, in production
|
||||
// we use the DefaultStorage since we don't want to act as part of a
|
||||
// cluster; this storage is for the server's local identity only.
|
||||
var storage certmagic.Storage
|
||||
if testCertMagicStorageOverride != nil {
|
||||
storage = testCertMagicStorageOverride
|
||||
} else {
|
||||
storage = DefaultStorage
|
||||
}
|
||||
template := certmagic.Config{
|
||||
Storage: DefaultStorage, // do not act as part of a cluster (this is for the server's local identity)
|
||||
Storage: storage,
|
||||
Logger: logger,
|
||||
Issuers: ident.issuers,
|
||||
}
|
||||
@@ -699,7 +693,7 @@ func (remote RemoteAdmin) enforceAccessControls(r *http.Request) error {
|
||||
// verify path
|
||||
pathFound := accessPerm.Paths == nil
|
||||
for _, allowedPath := range accessPerm.Paths {
|
||||
if strings.HasPrefix(r.URL.Path, allowedPath) {
|
||||
if adminPathAllowed(r.URL.Path, allowedPath) {
|
||||
pathFound = true
|
||||
break
|
||||
}
|
||||
@@ -728,14 +722,31 @@ func (remote RemoteAdmin) enforceAccessControls(r *http.Request) error {
|
||||
}
|
||||
}
|
||||
|
||||
func adminPathAllowed(reqPath, allowedPath string) bool {
|
||||
if allowedPath == "" || allowedPath == "/" {
|
||||
return strings.HasPrefix(reqPath, allowedPath)
|
||||
}
|
||||
if reqPath == allowedPath {
|
||||
return true
|
||||
}
|
||||
if strings.HasSuffix(allowedPath, "/") {
|
||||
return strings.HasPrefix(reqPath, allowedPath)
|
||||
}
|
||||
return strings.HasPrefix(reqPath, allowedPath+"/")
|
||||
}
|
||||
|
||||
func stopAdminServer(srv *http.Server) error {
|
||||
if srv == nil {
|
||||
return fmt.Errorf("no admin server")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := context.WithTimeoutCause(context.Background(), timeout, fmt.Errorf("stopping admin server: %ds timeout", int(timeout.Seconds())))
|
||||
defer cancel()
|
||||
err := srv.Shutdown(ctx)
|
||||
if err != nil {
|
||||
if cause := context.Cause(ctx); cause != nil && errors.Is(err, context.DeadlineExceeded) {
|
||||
err = cause
|
||||
}
|
||||
return fmt.Errorf("shutting down admin server: %v", err)
|
||||
}
|
||||
Log().Named("admin").Info("stopped previous server", zap.String("address", srv.Addr))
|
||||
@@ -779,7 +790,7 @@ func (h adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
zap.String("uri", r.RequestURI),
|
||||
zap.String("remote_ip", ip),
|
||||
zap.String("remote_port", port),
|
||||
zap.Reflect("headers", r.Header),
|
||||
zap.Object("headers", internal.LoggableHTTPHeader{Header: r.Header}),
|
||||
)
|
||||
if r.TLS != nil {
|
||||
log = log.With(
|
||||
@@ -807,11 +818,37 @@ func (h adminHandler) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// common mitigations in browser contexts
|
||||
if strings.Contains(r.Header.Get("Upgrade"), "websocket") {
|
||||
// I've never been able demonstrate a vulnerability myself, but apparently
|
||||
// WebSocket connections originating from browsers aren't subject to CORS
|
||||
// restrictions, so we'll just be on the safe side
|
||||
h.handleError(w, r, fmt.Errorf("websocket connections aren't allowed"))
|
||||
h.handleError(w, r, APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: errors.New("websocket connections aren't allowed"),
|
||||
Message: "WebSocket connections aren't allowed.",
|
||||
})
|
||||
return
|
||||
}
|
||||
if strings.Contains(r.Header.Get("Sec-Fetch-Mode"), "no-cors") {
|
||||
// turns out web pages can just disable the same-origin policy (!???!?)
|
||||
// but at least browsers let us know that's the case, holy heck
|
||||
h.handleError(w, r, APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: errors.New("client attempted to make request by disabling same-origin policy using no-cors mode"),
|
||||
Message: "Disabling same-origin restrictions is not allowed.",
|
||||
})
|
||||
return
|
||||
}
|
||||
if r.Header.Get("Origin") == "null" {
|
||||
// bug in Firefox in certain cross-origin situations (yikes?)
|
||||
// (not strictly a security vuln on its own, but it's red flaggy,
|
||||
// since it seems to manifest in cross-origin contexts)
|
||||
h.handleError(w, r, APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: errors.New("invalid origin 'null'"),
|
||||
Message: "Buggy browser is sending null Origin header.",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -824,7 +861,9 @@ func (h adminHandler) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if h.enforceOrigin {
|
||||
_, hasOriginHeader := r.Header["Origin"]
|
||||
_, hasSecHeader := r.Header["Sec-Fetch-Mode"]
|
||||
if h.enforceOrigin || hasOriginHeader || hasSecHeader {
|
||||
// cross-site mitigation
|
||||
origin, err := h.checkOrigin(r)
|
||||
if err != nil {
|
||||
@@ -1012,6 +1051,9 @@ func handleConfig(w http.ResponseWriter, r *http.Request) error {
|
||||
buf.Reset()
|
||||
defer bufPool.Put(buf)
|
||||
|
||||
const maxConfigSize = 100 * 1024 * 1024 // 100 MB
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxConfigSize)
|
||||
|
||||
_, err := io.Copy(buf, r.Body)
|
||||
if err != nil {
|
||||
return APIError{
|
||||
@@ -1094,6 +1136,20 @@ func handleStop(w http.ResponseWriter, r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseCanonicalArrayIndex(idx string) (int, error) {
|
||||
if idx == "" {
|
||||
return 0, fmt.Errorf("empty index")
|
||||
}
|
||||
i, err := strconv.Atoi(idx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if strconv.Itoa(i) != idx {
|
||||
return 0, fmt.Errorf("non-canonical array index")
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// unsyncedConfigAccess traverses into the current config and performs
|
||||
// the operation at path according to method, using body and out as
|
||||
// needed. This is a low-level, unsynchronized function; most callers
|
||||
@@ -1155,11 +1211,12 @@ traverseLoop:
|
||||
var idx int
|
||||
if method != http.MethodPost {
|
||||
idxStr := parts[len(parts)-1]
|
||||
idx, err = strconv.Atoi(idxStr)
|
||||
idx, err = parseCanonicalArrayIndex(idxStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[%s] invalid array index '%s': %v",
|
||||
path, idxStr, err)
|
||||
}
|
||||
|
||||
if idx < 0 || (method != http.MethodPut && idx >= len(arr)) || idx > len(arr) {
|
||||
return fmt.Errorf("[%s] array index out of bounds: %s", path, idxStr)
|
||||
}
|
||||
@@ -1259,7 +1316,7 @@ traverseLoop:
|
||||
}
|
||||
|
||||
case []any:
|
||||
partInt, err := strconv.Atoi(part)
|
||||
partInt, err := parseCanonicalArrayIndex(part)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[/%s] invalid array index '%s': %v",
|
||||
strings.Join(parts[:i+1], "/"), part, err)
|
||||
|
||||
+243
-23
@@ -15,20 +15,28 @@
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zaptest/observer"
|
||||
)
|
||||
|
||||
var testCfg = []byte(`{
|
||||
@@ -49,6 +57,13 @@ var testCfg = []byte(`{
|
||||
}
|
||||
`)
|
||||
|
||||
type testAdminPublicKey string
|
||||
|
||||
func (k testAdminPublicKey) Equal(x crypto.PublicKey) bool {
|
||||
other, ok := x.(testAdminPublicKey)
|
||||
return ok && k == other
|
||||
}
|
||||
|
||||
func TestUnsyncedConfigAccess(t *testing.T) {
|
||||
// each test is performed in sequence, so
|
||||
// each change builds on the previous ones;
|
||||
@@ -240,6 +255,51 @@ func TestAdminHandlerErrorHandling(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminHandlerServeHTTPRedactsSensitiveHeadersInLogs(t *testing.T) {
|
||||
core, logs := observer.New(zap.InfoLevel)
|
||||
|
||||
defaultLoggerMu.Lock()
|
||||
origLogger := defaultLogger.logger
|
||||
defaultLogger.logger = zap.New(core)
|
||||
defaultLoggerMu.Unlock()
|
||||
t.Cleanup(func() {
|
||||
defaultLoggerMu.Lock()
|
||||
defaultLogger.logger = origLogger
|
||||
defaultLoggerMu.Unlock()
|
||||
})
|
||||
|
||||
handler := adminHandler{
|
||||
mux: http.NewServeMux(),
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.Header.Set("Authorization", "Bearer secret")
|
||||
req.Header.Set("Cookie", "session=secret")
|
||||
req.Header.Set("X-Test", "ok")
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
|
||||
if logs.Len() == 0 {
|
||||
t.Fatal("expected request log entry")
|
||||
}
|
||||
|
||||
ctx := logs.All()[0].ContextMap()
|
||||
headers, ok := ctx["headers"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected headers field in log context, got %T", ctx["headers"])
|
||||
}
|
||||
|
||||
if got := headers["Authorization"]; !reflect.DeepEqual(got, []any{"REDACTED"}) {
|
||||
t.Fatalf("expected redacted Authorization header, got %#v", got)
|
||||
}
|
||||
if got := headers["Cookie"]; !reflect.DeepEqual(got, []any{"REDACTED"}) {
|
||||
t.Fatalf("expected redacted Cookie header, got %#v", got)
|
||||
}
|
||||
if got := headers["X-Test"]; !reflect.DeepEqual(got, []any{"ok"}) {
|
||||
t.Fatalf("expected X-Test header to remain visible, got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func initAdminMetrics() {
|
||||
if adminMetrics.requestErrors != nil {
|
||||
prometheus.Unregister(adminMetrics.requestErrors)
|
||||
@@ -275,13 +335,15 @@ func TestAdminHandlerBuiltinRouteErrors(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := replaceLocalAdminServer(cfg, Context{})
|
||||
// Build the admin handler directly (no listener active)
|
||||
addr, err := ParseNetworkAddress("localhost:2019")
|
||||
if err != nil {
|
||||
t.Fatalf("setting up admin server: %v", err)
|
||||
t.Fatalf("Failed to parse address: %v", err)
|
||||
}
|
||||
handler, err := cfg.Admin.newAdminHandler(addr, false, Context{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create admin handler: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
stopAdminServer(localAdminServer)
|
||||
}()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -314,7 +376,7 @@ func TestAdminHandlerBuiltinRouteErrors(t *testing.T) {
|
||||
req := httptest.NewRequest(test.method, fmt.Sprintf("http://localhost:2019%s", test.path), nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
localAdminServer.Handler.ServeHTTP(rr, req)
|
||||
handler.ServeHTTP(rr, req)
|
||||
|
||||
if rr.Code != test.expectedStatus {
|
||||
t.Errorf("expected status %d but got %d", test.expectedStatus, rr.Code)
|
||||
@@ -402,7 +464,10 @@ func TestNewAdminHandlerRouterRegistration(t *testing.T) {
|
||||
admin := &AdminConfig{
|
||||
EnforceOrigin: false,
|
||||
}
|
||||
handler := admin.newAdminHandler(addr, false, Context{})
|
||||
handler, err := admin.newAdminHandler(addr, false, Context{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create admin handler: %v", err)
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("GET", "/mock", nil)
|
||||
req.Host = "localhost:2019"
|
||||
@@ -414,10 +479,6 @@ func TestNewAdminHandlerRouterRegistration(t *testing.T) {
|
||||
t.Errorf("Expected status code %d but got %d", http.StatusOK, rr.Code)
|
||||
t.Logf("Response body: %s", rr.Body.String())
|
||||
}
|
||||
|
||||
if len(admin.routers) != 1 {
|
||||
t.Errorf("Expected 1 router to be stored, got %d", len(admin.routers))
|
||||
}
|
||||
}
|
||||
|
||||
type mockProvisionableRouter struct {
|
||||
@@ -455,19 +516,16 @@ func TestAdminRouterProvisioning(t *testing.T) {
|
||||
name string
|
||||
provisionErr error
|
||||
wantErr bool
|
||||
routersAfter int // expected number of routers after provisioning
|
||||
}{
|
||||
{
|
||||
name: "successful provisioning",
|
||||
provisionErr: nil,
|
||||
wantErr: false,
|
||||
routersAfter: 0,
|
||||
},
|
||||
{
|
||||
name: "provisioning error",
|
||||
provisionErr: fmt.Errorf("provision failed"),
|
||||
wantErr: true,
|
||||
routersAfter: 1,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -503,8 +561,7 @@ func TestAdminRouterProvisioning(t *testing.T) {
|
||||
t.Fatalf("Failed to parse address: %v", err)
|
||||
}
|
||||
|
||||
_ = admin.newAdminHandler(addr, false, Context{})
|
||||
err = admin.provisionAdminRouters(Context{})
|
||||
_, err = admin.newAdminHandler(addr, false, Context{})
|
||||
|
||||
if test.wantErr {
|
||||
if err == nil {
|
||||
@@ -515,10 +572,6 @@ func TestAdminRouterProvisioning(t *testing.T) {
|
||||
t.Errorf("Expected no error but got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(admin.routers) != test.routersAfter {
|
||||
t.Errorf("Expected %d routers after provisioning, got %d", test.routersAfter, len(admin.routers))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -603,6 +656,99 @@ func TestAllowedOriginsUnixSocket(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteAdminAccessControlPathSegmentMatching(t *testing.T) {
|
||||
const authorizedKey testAdminPublicKey = "authorized"
|
||||
peerCert := &x509.Certificate{PublicKey: authorizedKey}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
allowedPath string
|
||||
requestPath string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "exact path",
|
||||
allowedPath: "/pki/ca/prod",
|
||||
requestPath: "/pki/ca/prod",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "subpath",
|
||||
allowedPath: "/pki/ca/prod",
|
||||
requestPath: "/pki/ca/prod/certificates",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "trailing slash subpath",
|
||||
allowedPath: "/pki/ca/prod/",
|
||||
requestPath: "/pki/ca/prod/certificates",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "sibling with shared prefix",
|
||||
allowedPath: "/pki/ca/prod",
|
||||
requestPath: "/pki/ca/prod-backup",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "same segment plus digit",
|
||||
allowedPath: "/pki/ca/prod",
|
||||
requestPath: "/pki/ca/prod1",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "root path",
|
||||
allowedPath: "/",
|
||||
requestPath: "/pki/ca/prod",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
remote := RemoteAdmin{
|
||||
AccessControl: []*AdminAccess{
|
||||
{
|
||||
Permissions: []AdminPermissions{
|
||||
{
|
||||
Methods: []string{http.MethodGet},
|
||||
Paths: []string{test.allowedPath},
|
||||
},
|
||||
},
|
||||
publicKeys: []crypto.PublicKey{authorizedKey},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "https://localhost:2021"+test.requestPath, nil)
|
||||
req.TLS = &tls.ConnectionState{
|
||||
VerifiedChains: [][]*x509.Certificate{{peerCert}},
|
||||
}
|
||||
|
||||
err := remote.enforceAccessControls(req)
|
||||
if test.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("test %d (%s): allowed path %q, request path %q: expected forbidden error, got nil", i, test.name, test.allowedPath, test.requestPath)
|
||||
return
|
||||
}
|
||||
var apiErr APIError
|
||||
if !errors.As(err, &apiErr) {
|
||||
t.Errorf("test %d (%s): allowed path %q, request path %q: expected APIError with HTTP status %d, got %T: %v", i, test.name, test.allowedPath, test.requestPath, http.StatusForbidden, err, err)
|
||||
return
|
||||
}
|
||||
if apiErr.HTTPStatus != http.StatusForbidden {
|
||||
t.Errorf("test %d (%s): allowed path %q, request path %q: expected HTTP status %d, got %d", i, test.name, test.allowedPath, test.requestPath, http.StatusForbidden, apiErr.HTTPStatus)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("test %d (%s): allowed path %q, request path %q: expected no error, got %v", i, test.name, test.allowedPath, test.requestPath, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceRemoteAdminServer(t *testing.T) {
|
||||
const testCert = `MIIDCTCCAfGgAwIBAgIUXsqJ1mY8pKlHQtI3HJ23x2eZPqwwDQYJKoZIhvcNAQEL
|
||||
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIzMDEwMTAwMDAwMFoXDTI0MDEw
|
||||
@@ -799,8 +945,24 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP
|
||||
...
|
||||
-----END PRIVATE KEY-----`)
|
||||
|
||||
testStorage := certmagic.FileStorage{Path: t.TempDir()}
|
||||
err := testStorage.Store(context.Background(), "localhost/localhost.crt", certPEM)
|
||||
tmpDir, err := os.MkdirTemp("", "TestManageIdentity-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testStorage := certmagic.FileStorage{Path: tmpDir}
|
||||
// Clean up the temp dir after the test finishes. Ensure any background
|
||||
// certificate maintenance is stopped first to avoid RemoveAll races.
|
||||
t.Cleanup(func() {
|
||||
if identityCertCache != nil {
|
||||
identityCertCache.Stop()
|
||||
identityCertCache = nil
|
||||
}
|
||||
// Give goroutines a moment to exit and release file handles.
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
_ = os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
err = testStorage.Store(context.Background(), "localhost/localhost.crt", certPEM)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -862,7 +1024,7 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP
|
||||
},
|
||||
},
|
||||
},
|
||||
storage: &certmagic.FileStorage{Path: "testdata"},
|
||||
storage: &testStorage,
|
||||
},
|
||||
checkState: func(t *testing.T, cfg *Config) {
|
||||
if len(cfg.Admin.Identity.issuers) != 1 {
|
||||
@@ -900,6 +1062,13 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP
|
||||
identityCertCache.Stop()
|
||||
identityCertCache = nil
|
||||
}
|
||||
// Ensure any cache started by manageIdentity is stopped at the end
|
||||
defer func() {
|
||||
if identityCertCache != nil {
|
||||
identityCertCache.Stop()
|
||||
identityCertCache = nil
|
||||
}
|
||||
}()
|
||||
|
||||
ctx := Context{
|
||||
Context: context.Background(),
|
||||
@@ -907,6 +1076,13 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP
|
||||
moduleInstances: make(map[string][]Module),
|
||||
}
|
||||
|
||||
// If this test provided a FileStorage, set the package-level
|
||||
// testCertMagicStorageOverride so certmagicConfig will use it.
|
||||
if test.cfg != nil && test.cfg.storage != nil {
|
||||
testCertMagicStorageOverride = test.cfg.storage
|
||||
defer func() { testCertMagicStorageOverride = nil }()
|
||||
}
|
||||
|
||||
err := manageIdentity(ctx, test.cfg)
|
||||
|
||||
if test.wantErr {
|
||||
@@ -925,3 +1101,47 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsyncedConfigAccessCanonicalArrayIndices(t *testing.T) {
|
||||
rawCfg = map[string]any{
|
||||
rawConfigKey: map[string]any{
|
||||
"list": []any{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"},
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
wantOutput string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "allow zero", path: "/" + rawConfigKey + "/list/0", wantOutput: "\"zero\"\n"},
|
||||
{name: "allow one", path: "/" + rawConfigKey + "/list/1", wantOutput: "\"one\"\n"},
|
||||
{name: "allow ten", path: "/" + rawConfigKey + "/list/10", wantOutput: "\"ten\"\n"},
|
||||
{name: "reject leading zero", path: "/" + rawConfigKey + "/list/01", wantErr: true},
|
||||
{name: "reject multiple leading zeros", path: "/" + rawConfigKey + "/list/002", wantErr: true},
|
||||
{name: "reject plus sign", path: "/" + rawConfigKey + "/list/+1", wantErr: true},
|
||||
{name: "reject negative zero", path: "/" + rawConfigKey + "/list/-0", wantErr: true},
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var gotOutput bytes.Buffer
|
||||
err := unsyncedConfigAccess(http.MethodGet, tc.path, nil, &gotOutput)
|
||||
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("test %d (%s): input path %q: expected error, got nil with output %q", i, tc.name, tc.path, gotOutput.String())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("test %d (%s): input path %q: expected no error with output %q, got error %v with output %q", i, tc.name, tc.path, tc.wantOutput, err, gotOutput.String())
|
||||
}
|
||||
if gotOutput.String() != tc.wantOutput {
|
||||
t.Errorf("test %d (%s): input path %q: expected output %q, got %q", i, tc.name, tc.path, tc.wantOutput, gotOutput.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,377 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAPIError_Error_WithErr(t *testing.T) {
|
||||
underlyingErr := errors.New("underlying error")
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: underlyingErr,
|
||||
Message: "API error message",
|
||||
}
|
||||
|
||||
result := apiErr.Error()
|
||||
expected := "underlying error"
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected '%s', got '%s'", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_Error_WithoutErr(t *testing.T) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: nil,
|
||||
Message: "API error message",
|
||||
}
|
||||
|
||||
result := apiErr.Error()
|
||||
expected := "API error message"
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected '%s', got '%s'", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_Error_BothNil(t *testing.T) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: nil,
|
||||
Message: "",
|
||||
}
|
||||
|
||||
result := apiErr.Error()
|
||||
expected := ""
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected empty string, got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_JSON_Serialization(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
apiErr APIError
|
||||
}{
|
||||
{
|
||||
name: "with message only",
|
||||
apiErr: APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Message: "validation failed",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with underlying error only",
|
||||
apiErr: APIError{
|
||||
HTTPStatus: http.StatusInternalServerError,
|
||||
Err: errors.New("internal error"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with both message and error",
|
||||
apiErr: APIError{
|
||||
HTTPStatus: http.StatusConflict,
|
||||
Err: errors.New("underlying"),
|
||||
Message: "conflict detected",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "minimal error",
|
||||
apiErr: APIError{
|
||||
HTTPStatus: http.StatusNotFound,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// Marshal to JSON
|
||||
jsonData, err := json.Marshal(test.apiErr)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal APIError: %v", err)
|
||||
}
|
||||
|
||||
// Unmarshal back
|
||||
var unmarshaled APIError
|
||||
err = json.Unmarshal(jsonData, &unmarshaled)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to unmarshal APIError: %v", err)
|
||||
}
|
||||
|
||||
// Only Message field should survive JSON round-trip
|
||||
// HTTPStatus and Err are marked with json:"-"
|
||||
if unmarshaled.Message != test.apiErr.Message {
|
||||
t.Errorf("Message mismatch: expected '%s', got '%s'",
|
||||
test.apiErr.Message, unmarshaled.Message)
|
||||
}
|
||||
|
||||
// HTTPStatus and Err should be zero values after unmarshal
|
||||
if unmarshaled.HTTPStatus != 0 {
|
||||
t.Errorf("HTTPStatus should be 0 after unmarshal, got %d", unmarshaled.HTTPStatus)
|
||||
}
|
||||
if unmarshaled.Err != nil {
|
||||
t.Errorf("Err should be nil after unmarshal, got %v", unmarshaled.Err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_HTTPStatus_Values(t *testing.T) {
|
||||
// Test common HTTP status codes
|
||||
statusCodes := []int{
|
||||
http.StatusBadRequest,
|
||||
http.StatusUnauthorized,
|
||||
http.StatusForbidden,
|
||||
http.StatusNotFound,
|
||||
http.StatusMethodNotAllowed,
|
||||
http.StatusConflict,
|
||||
http.StatusPreconditionFailed,
|
||||
http.StatusInternalServerError,
|
||||
http.StatusNotImplemented,
|
||||
http.StatusServiceUnavailable,
|
||||
}
|
||||
|
||||
for _, status := range statusCodes {
|
||||
t.Run(fmt.Sprintf("status_%d", status), func(t *testing.T) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: status,
|
||||
Message: http.StatusText(status),
|
||||
}
|
||||
|
||||
if apiErr.HTTPStatus != status {
|
||||
t.Errorf("Expected status %d, got %d", status, apiErr.HTTPStatus)
|
||||
}
|
||||
|
||||
// Test that error message is reasonable
|
||||
if apiErr.Message == "" && status >= 400 {
|
||||
t.Errorf("Status %d should have a message", status)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_ErrorInterface_Compliance(t *testing.T) {
|
||||
// Verify APIError properly implements error interface
|
||||
var err error = APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Message: "test error",
|
||||
}
|
||||
|
||||
errorMsg := err.Error()
|
||||
if errorMsg != "test error" {
|
||||
t.Errorf("Expected 'test error', got '%s'", errorMsg)
|
||||
}
|
||||
|
||||
// Test with underlying error
|
||||
underlyingErr := errors.New("underlying")
|
||||
err2 := APIError{
|
||||
HTTPStatus: http.StatusInternalServerError,
|
||||
Err: underlyingErr,
|
||||
Message: "wrapper",
|
||||
}
|
||||
|
||||
if err2.Error() != "underlying" {
|
||||
t.Errorf("Expected 'underlying', got '%s'", err2.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_JSON_EdgeCases(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
message string
|
||||
}{
|
||||
{
|
||||
name: "empty message",
|
||||
message: "",
|
||||
},
|
||||
{
|
||||
name: "unicode message",
|
||||
message: "Error: 🚨 Something went wrong! 你好",
|
||||
},
|
||||
{
|
||||
name: "json characters in message",
|
||||
message: `Error with "quotes" and {brackets}`,
|
||||
},
|
||||
{
|
||||
name: "newlines in message",
|
||||
message: "Line 1\nLine 2\r\nLine 3",
|
||||
},
|
||||
{
|
||||
name: "very long message",
|
||||
message: string(make([]byte, 10000)), // 10KB message
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Message: test.message,
|
||||
}
|
||||
|
||||
// Should be JSON serializable
|
||||
jsonData, err := json.Marshal(apiErr)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal APIError: %v", err)
|
||||
}
|
||||
|
||||
// Should be deserializable
|
||||
var unmarshaled APIError
|
||||
err = json.Unmarshal(jsonData, &unmarshaled)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to unmarshal APIError: %v", err)
|
||||
}
|
||||
|
||||
if unmarshaled.Message != test.message {
|
||||
t.Errorf("Message corrupted during JSON round-trip")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_Chaining(t *testing.T) {
|
||||
// Test error chaining scenarios
|
||||
rootErr := errors.New("root cause")
|
||||
wrappedErr := fmt.Errorf("wrapped: %w", rootErr)
|
||||
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusInternalServerError,
|
||||
Err: wrappedErr,
|
||||
Message: "API wrapper",
|
||||
}
|
||||
|
||||
// Error() should return the underlying error message
|
||||
if apiErr.Error() != wrappedErr.Error() {
|
||||
t.Errorf("Expected underlying error message, got '%s'", apiErr.Error())
|
||||
}
|
||||
|
||||
// Should be able to unwrap
|
||||
if !errors.Is(apiErr.Err, rootErr) {
|
||||
t.Error("Should be able to unwrap to root cause")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError_StatusCode_Boundaries(t *testing.T) {
|
||||
// Test edge cases for HTTP status codes
|
||||
tests := []struct {
|
||||
name string
|
||||
status int
|
||||
valid bool
|
||||
}{
|
||||
{
|
||||
name: "negative status",
|
||||
status: -1,
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "zero status",
|
||||
status: 0,
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "valid 1xx",
|
||||
status: http.StatusContinue,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "valid 2xx",
|
||||
status: http.StatusOK,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "valid 4xx",
|
||||
status: http.StatusBadRequest,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "valid 5xx",
|
||||
status: http.StatusInternalServerError,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "too large status",
|
||||
status: 9999,
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := APIError{
|
||||
HTTPStatus: test.status,
|
||||
Message: "test",
|
||||
}
|
||||
|
||||
// The struct allows any int value, but we can test
|
||||
// if it's a valid HTTP status
|
||||
statusText := http.StatusText(test.status)
|
||||
isValidStatus := statusText != ""
|
||||
|
||||
if isValidStatus != test.valid {
|
||||
t.Errorf("Status %d validity: expected %v, got %v",
|
||||
test.status, test.valid, isValidStatus)
|
||||
}
|
||||
|
||||
// Verify the struct holds the status
|
||||
if err.HTTPStatus != test.status {
|
||||
t.Errorf("Status not preserved: expected %d, got %d", test.status, err.HTTPStatus)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAPIError_Error(b *testing.B) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: errors.New("benchmark error"),
|
||||
Message: "benchmark message",
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
apiErr.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAPIError_JSON_Marshal(b *testing.B) {
|
||||
apiErr := APIError{
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: errors.New("benchmark error"),
|
||||
Message: "benchmark message",
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
json.Marshal(apiErr)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAPIError_JSON_Unmarshal(b *testing.B) {
|
||||
jsonData := []byte(`{"error": "benchmark message"}`)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
var result APIError
|
||||
_ = json.Unmarshal(jsonData, &result)
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ type Config struct {
|
||||
storage certmagic.Storage
|
||||
eventEmitter eventEmitter
|
||||
|
||||
cancelFunc context.CancelFunc
|
||||
cancelFunc context.CancelCauseFunc
|
||||
|
||||
// fileSystems is a dict of fileSystems that will later be loaded from and added to.
|
||||
fileSystems FileSystems
|
||||
@@ -127,10 +127,9 @@ func Load(cfgJSON []byte, forceReload bool) error {
|
||||
zap.Error(notifyErr),
|
||||
zap.String("reload_err", err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := notify.Ready(); err != nil {
|
||||
Log().Error("unable to notify to service manager of ready state", zap.Error(err))
|
||||
if notifyErr := notify.Ready(); notifyErr != nil {
|
||||
Log().Error("unable to notify to service manager of ready state", zap.Error(notifyErr))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -147,8 +146,8 @@ func Load(cfgJSON []byte, forceReload bool) error {
|
||||
// the new value (if applicable; i.e. "DELETE" doesn't have an input).
|
||||
// If the resulting config is the same as the previous, no reload will
|
||||
// occur unless forceReload is true. If the config is unchanged and not
|
||||
// forcefully reloaded, then errConfigUnchanged This function is safe for
|
||||
// concurrent use.
|
||||
// forcefully reloaded, then errConfigUnchanged is returned. This function
|
||||
// is safe for concurrent use.
|
||||
// The ifMatchHeader can optionally be given a string of the format:
|
||||
//
|
||||
// "<path> <hash>"
|
||||
@@ -227,8 +226,18 @@ func changeConfig(method, path string, input []byte, ifMatchHeader string, force
|
||||
idx := make(map[string]string)
|
||||
err = indexConfigObjects(rawCfg[rawConfigKey], "/"+rawConfigKey, idx)
|
||||
if err != nil {
|
||||
if len(rawCfgJSON) > 0 {
|
||||
var oldCfg any
|
||||
err2 := json.Unmarshal(rawCfgJSON, &oldCfg)
|
||||
if err2 != nil {
|
||||
err = fmt.Errorf("%v; additionally, restoring old config: %v", err, err2)
|
||||
}
|
||||
rawCfg[rawConfigKey] = oldCfg
|
||||
} else {
|
||||
rawCfg[rawConfigKey] = nil
|
||||
}
|
||||
return APIError{
|
||||
HTTPStatus: http.StatusInternalServerError,
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Err: fmt.Errorf("indexing config: %v", err),
|
||||
}
|
||||
}
|
||||
@@ -248,6 +257,8 @@ func changeConfig(method, path string, input []byte, ifMatchHeader string, force
|
||||
err = fmt.Errorf("%v; additionally, restoring old config: %v", err, err2)
|
||||
}
|
||||
rawCfg[rawConfigKey] = oldCfg
|
||||
} else {
|
||||
rawCfg[rawConfigKey] = nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("loading new config: %v", err)
|
||||
@@ -281,14 +292,19 @@ func indexConfigObjects(ptr any, configPath string, index map[string]string) err
|
||||
case map[string]any:
|
||||
for k, v := range val {
|
||||
if k == idKey {
|
||||
var idStr string
|
||||
switch idVal := v.(type) {
|
||||
case string:
|
||||
index[idVal] = configPath
|
||||
idStr = idVal
|
||||
case float64: // all JSON numbers decode as float64
|
||||
index[fmt.Sprintf("%v", idVal)] = configPath
|
||||
idStr = fmt.Sprintf("%v", idVal)
|
||||
default:
|
||||
return fmt.Errorf("%s: %s field must be a string or number", configPath, idKey)
|
||||
}
|
||||
if existingPath, ok := index[idStr]; ok {
|
||||
return fmt.Errorf("duplicate ID '%s' found at %s and %s", idStr, existingPath, configPath)
|
||||
}
|
||||
index[idStr] = configPath
|
||||
continue
|
||||
}
|
||||
// traverse this object property recursively
|
||||
@@ -416,7 +432,7 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
// partially copied from provisionContext
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
ctx.cfg.cancelFunc()
|
||||
ctx.cfg.cancelFunc(fmt.Errorf("configuration start error: %w", err))
|
||||
|
||||
if currentCtx.cfg != nil {
|
||||
certmagic.Default.Storage = currentCtx.cfg.storage
|
||||
@@ -424,13 +440,6 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
// Provision any admin routers which may need to access
|
||||
// some of the other apps at runtime
|
||||
err = ctx.cfg.Admin.provisionAdminRouters(ctx)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// Start
|
||||
err = func() error {
|
||||
started := make([]string, 0, len(ctx.cfg.apps))
|
||||
@@ -492,7 +501,7 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
|
||||
// cleanup occurs when we return if there
|
||||
// was an error; if no error, it will get
|
||||
// cleaned up on next config cycle
|
||||
ctx, cancel := NewContext(Context{Context: context.Background(), cfg: newCfg})
|
||||
ctx, cancelCause := NewContextWithCause(Context{Context: context.Background(), cfg: newCfg})
|
||||
defer func() {
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
@@ -501,7 +510,7 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
|
||||
// since the associated config won't be used;
|
||||
// this will cause all modules that were newly
|
||||
// provisioned to clean themselves up
|
||||
cancel()
|
||||
cancelCause(fmt.Errorf("configuration error: %w", err))
|
||||
|
||||
// also undo any other state changes we made
|
||||
if currentCtx.cfg != nil {
|
||||
@@ -509,7 +518,7 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
|
||||
}
|
||||
}
|
||||
}()
|
||||
newCfg.cancelFunc = cancel // clean up later
|
||||
newCfg.cancelFunc = cancelCause // clean up later
|
||||
|
||||
// set up logging before anything bad happens
|
||||
if newCfg.Logging == nil {
|
||||
@@ -729,7 +738,7 @@ func unsyncedStop(ctx Context) {
|
||||
}
|
||||
|
||||
// clean up all modules
|
||||
ctx.cfg.cancelFunc()
|
||||
ctx.cfg.cancelFunc(fmt.Errorf("stopping apps"))
|
||||
}
|
||||
|
||||
// Validate loads, provisions, and validates
|
||||
@@ -737,7 +746,7 @@ func unsyncedStop(ctx Context) {
|
||||
func Validate(cfg *Config) error {
|
||||
_, err := run(cfg, false)
|
||||
if err == nil {
|
||||
cfg.cancelFunc() // call Cleanup on all modules
|
||||
cfg.cancelFunc(fmt.Errorf("validation complete")) // call Cleanup on all modules
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -750,7 +759,7 @@ func Validate(cfg *Config) error {
|
||||
// code is emitted.
|
||||
func exitProcess(ctx context.Context, logger *zap.Logger) {
|
||||
// let the rest of the program know we're quitting; only do it once
|
||||
if !atomic.CompareAndSwapInt32(exiting, 0, 1) {
|
||||
if !exiting.CompareAndSwap(false, true) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -829,11 +838,11 @@ func exitProcess(ctx context.Context, logger *zap.Logger) {
|
||||
}()
|
||||
}
|
||||
|
||||
var exiting = new(int32) // accessed atomically
|
||||
var exiting atomic.Bool
|
||||
|
||||
// Exiting returns true if the process is exiting.
|
||||
// EXPERIMENTAL API: subject to change or removal.
|
||||
func Exiting() bool { return atomic.LoadInt32(exiting) == 1 }
|
||||
func Exiting() bool { return exiting.Load() }
|
||||
|
||||
// OnExit registers a callback to invoke during process exit.
|
||||
// This registration is PROCESS-GLOBAL, meaning that each
|
||||
@@ -945,6 +954,34 @@ func InstanceID() (uuid.UUID, error) {
|
||||
// for example.
|
||||
var CustomVersion string
|
||||
|
||||
// CustomBinaryName is an optional string that overrides the root
|
||||
// command name from the default of "caddy". This is useful for
|
||||
// downstream projects that embed Caddy but use a different binary
|
||||
// name. Shell completions and help text will use this name instead
|
||||
// of "caddy".
|
||||
//
|
||||
// Set this variable during `go build` with `-ldflags`:
|
||||
//
|
||||
// -ldflags '-X github.com/caddyserver/caddy/v2.CustomBinaryName=my_custom_caddy'
|
||||
//
|
||||
// for example.
|
||||
var CustomBinaryName string
|
||||
|
||||
// CustomLongDescription is an optional string that overrides the
|
||||
// long description of the root Cobra command. This is useful for
|
||||
// downstream projects that embed Caddy but want different help
|
||||
// output.
|
||||
//
|
||||
// Set this variable in an init() function of a package that is
|
||||
// imported by your main:
|
||||
//
|
||||
// func init() {
|
||||
// caddy.CustomLongDescription = "My custom server based on Caddy..."
|
||||
// }
|
||||
//
|
||||
// for example.
|
||||
var CustomLongDescription string
|
||||
|
||||
// Version returns the Caddy version in a simple/short form, and
|
||||
// a full version string. The short form will not have spaces and
|
||||
// is intended for User-Agent strings and similar, but may be
|
||||
@@ -1092,7 +1129,7 @@ type Event struct {
|
||||
}
|
||||
|
||||
// NewEvent creates a new event, but does not emit the event. To emit an
|
||||
// event, call Emit() on the current instance of the caddyevents app insteaad.
|
||||
// event, call Emit() on the current instance of the caddyevents app instead.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change.
|
||||
func NewEvent(ctx Context, name string, data map[string]any) (Event, error) {
|
||||
@@ -1250,10 +1287,10 @@ func getLastConfig() (file, adapter string, fn reloadFromSourceFunc) {
|
||||
|
||||
// lastConfigMatches returns true if the provided source file and/or adapter
|
||||
// matches the recorded last-config. Matching rules (in priority order):
|
||||
// 1. If srcAdapter is provided and differs from the recorded adapter, no match.
|
||||
// 2. If srcFile exactly equals the recorded file, match.
|
||||
// 3. If both sides can be made absolute and equal, match.
|
||||
// 4. If basenames are equal, match.
|
||||
// 1. If srcAdapter is provided and differs from the recorded adapter, no match.
|
||||
// 2. If srcFile exactly equals the recorded file, match.
|
||||
// 3. If both sides can be made absolute and equal, match.
|
||||
// 4. If basenames are equal, match.
|
||||
func lastConfigMatches(srcFile, srcAdapter string) bool {
|
||||
lf, la, _ := getLastConfig()
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ func (d *Dispenser) File() string {
|
||||
// targets are left unchanged. If all the targets are filled,
|
||||
// then true is returned.
|
||||
func (d *Dispenser) Args(targets ...*string) bool {
|
||||
for i := 0; i < len(targets); i++ {
|
||||
for i := range targets {
|
||||
if !d.NextArg() {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -63,8 +63,33 @@ func Format(input []byte) []byte {
|
||||
heredocClosingMarker []rune
|
||||
|
||||
nesting int // indentation level
|
||||
|
||||
currentToken strings.Builder
|
||||
currentLineFirstToken string
|
||||
previousLineWasTopLevelImport bool
|
||||
openBraceOwnLine bool
|
||||
)
|
||||
|
||||
finishToken := func() {
|
||||
if currentToken.Len() == 0 {
|
||||
return
|
||||
}
|
||||
if currentLineFirstToken == "" {
|
||||
currentLineFirstToken = currentToken.String()
|
||||
}
|
||||
currentToken.Reset()
|
||||
}
|
||||
|
||||
finishLine := func() {
|
||||
finishToken()
|
||||
if currentLineFirstToken != "" {
|
||||
previousLineWasTopLevelImport = nesting == 0 && currentLineFirstToken == "import"
|
||||
} else if !openBrace || !openBraceOwnLine || openBraceWritten {
|
||||
previousLineWasTopLevelImport = false
|
||||
}
|
||||
currentLineFirstToken = ""
|
||||
}
|
||||
|
||||
write := func(ch rune) {
|
||||
out.WriteRune(ch)
|
||||
last = ch
|
||||
@@ -220,9 +245,11 @@ func Format(input []byte) []byte {
|
||||
}
|
||||
|
||||
if unicode.IsSpace(ch) {
|
||||
finishToken()
|
||||
space = true
|
||||
heredocEscaped = false
|
||||
if ch == '\n' {
|
||||
finishLine()
|
||||
newLines++
|
||||
}
|
||||
continue
|
||||
@@ -249,13 +276,19 @@ func Format(input []byte) []byte {
|
||||
}
|
||||
|
||||
openBrace = false
|
||||
if beginningOfLine {
|
||||
if openBraceOwnLine && previousLineWasTopLevelImport {
|
||||
if last != '\n' {
|
||||
nextLine()
|
||||
}
|
||||
indent()
|
||||
} else if beginningOfLine {
|
||||
indent()
|
||||
} else if !openBraceSpace || !unicode.IsSpace(last) {
|
||||
write(' ')
|
||||
}
|
||||
write('{')
|
||||
openBraceWritten = true
|
||||
openBraceOwnLine = false
|
||||
nextLine()
|
||||
newLines = 0
|
||||
// prevent infinite nesting from ridiculous inputs (issue #4169)
|
||||
@@ -266,8 +299,10 @@ func Format(input []byte) []byte {
|
||||
|
||||
switch {
|
||||
case ch == '{':
|
||||
finishToken()
|
||||
openBrace = true
|
||||
openBraceSpace = spacePrior && !beginningOfLine
|
||||
openBraceOwnLine = newLines > 0
|
||||
if openBraceSpace && newLines == 0 {
|
||||
write(' ')
|
||||
}
|
||||
@@ -275,11 +310,13 @@ func Format(input []byte) []byte {
|
||||
if quotes == "`" {
|
||||
write('{')
|
||||
openBraceWritten = true
|
||||
openBraceOwnLine = false
|
||||
continue
|
||||
}
|
||||
continue
|
||||
|
||||
case ch == '}' && (spacePrior || !openBrace):
|
||||
finishToken()
|
||||
if quotes == "`" {
|
||||
write('}')
|
||||
continue
|
||||
@@ -324,6 +361,7 @@ func Format(input []byte) []byte {
|
||||
space = true
|
||||
}
|
||||
|
||||
currentToken.WriteRune(ch)
|
||||
write(ch)
|
||||
|
||||
beginningOfLine = false
|
||||
|
||||
@@ -475,6 +475,21 @@ Hope this helps.` + "`" + `
|
||||
}`,
|
||||
expect: "https://localhost:8953 {\n\trespond `Here are some random numbers:\n\n{{randNumeric 16}}\n\nHope this helps.`\n}",
|
||||
},
|
||||
{
|
||||
description: "imports before global options block keep standalone brace",
|
||||
input: `import ./conf.d/matcher_my_subnet.caddy
|
||||
import ./conf.d/matcher_not_my_subnet.caddy
|
||||
{
|
||||
order crowdsec first
|
||||
order appsec after crowdsec
|
||||
}`,
|
||||
expect: `import ./conf.d/matcher_my_subnet.caddy
|
||||
import ./conf.d/matcher_not_my_subnet.caddy
|
||||
{
|
||||
order crowdsec first
|
||||
order appsec after crowdsec
|
||||
}`,
|
||||
},
|
||||
} {
|
||||
// the formatter should output a trailing newline,
|
||||
// even if the tests aren't written to expect that
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
package caddyfile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestImportGraphAddNode(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
|
||||
g.addNode("a")
|
||||
if !g.exists("a") {
|
||||
t.Error("expected node 'a' to exist after addNode")
|
||||
}
|
||||
|
||||
// Adding again should not error
|
||||
g.addNode("a")
|
||||
if !g.exists("a") {
|
||||
t.Error("expected node 'a' to still exist after duplicate addNode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddNodes(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
|
||||
g.addNodes([]string{"a", "b", "c"})
|
||||
for _, name := range []string{"a", "b", "c"} {
|
||||
if !g.exists(name) {
|
||||
t.Errorf("expected node %q to exist", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphRemoveNode(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
|
||||
g.addNode("a")
|
||||
g.addNode("b")
|
||||
g.removeNode("a")
|
||||
|
||||
if g.exists("a") {
|
||||
t.Error("expected node 'a' to not exist after removeNode")
|
||||
}
|
||||
if !g.exists("b") {
|
||||
t.Error("expected node 'b' to still exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphRemoveNodes(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
|
||||
g.addNodes([]string{"a", "b", "c", "d"})
|
||||
g.removeNodes([]string{"a", "c"})
|
||||
|
||||
if g.exists("a") {
|
||||
t.Error("expected node 'a' to be removed")
|
||||
}
|
||||
if g.exists("c") {
|
||||
t.Error("expected node 'c' to be removed")
|
||||
}
|
||||
if !g.exists("b") {
|
||||
t.Error("expected node 'b' to still exist")
|
||||
}
|
||||
if !g.exists("d") {
|
||||
t.Error("expected node 'd' to still exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddEdge(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b"})
|
||||
|
||||
err := g.addEdge("a", "b")
|
||||
if err != nil {
|
||||
t.Fatalf("addEdge() error = %v", err)
|
||||
}
|
||||
|
||||
if !g.areConnected("a", "b") {
|
||||
t.Error("expected 'a' -> 'b' edge to exist")
|
||||
}
|
||||
if g.areConnected("b", "a") {
|
||||
t.Error("expected no 'b' -> 'a' edge (directed)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddEdgeNonExistentNode(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNode("a")
|
||||
|
||||
err := g.addEdge("a", "nonexistent")
|
||||
if err == nil {
|
||||
t.Error("expected error when adding edge to nonexistent node")
|
||||
}
|
||||
|
||||
err = g.addEdge("nonexistent", "a")
|
||||
if err == nil {
|
||||
t.Error("expected error when adding edge from nonexistent node")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddEdgeDuplicate(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b"})
|
||||
|
||||
_ = g.addEdge("a", "b")
|
||||
err := g.addEdge("a", "b")
|
||||
if err != nil {
|
||||
t.Errorf("duplicate addEdge() should not error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphCycleDetectionDirect(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b"})
|
||||
|
||||
_ = g.addEdge("a", "b")
|
||||
|
||||
// Adding b -> a should create a cycle
|
||||
err := g.addEdge("b", "a")
|
||||
if err == nil {
|
||||
t.Error("expected error for cycle: a -> b -> a")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphCycleDetectionIndirect(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b", "c"})
|
||||
|
||||
_ = g.addEdge("a", "b")
|
||||
_ = g.addEdge("b", "c")
|
||||
|
||||
// Adding c -> a should create a cycle: a -> b -> c -> a
|
||||
err := g.addEdge("c", "a")
|
||||
if err == nil {
|
||||
t.Error("expected error for indirect cycle: a -> b -> c -> a")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphCycleDetectionLongChain(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
nodes := []string{"a", "b", "c", "d", "e"}
|
||||
g.addNodes(nodes)
|
||||
|
||||
_ = g.addEdge("a", "b")
|
||||
_ = g.addEdge("b", "c")
|
||||
_ = g.addEdge("c", "d")
|
||||
_ = g.addEdge("d", "e")
|
||||
|
||||
// Adding e -> a should create a cycle
|
||||
err := g.addEdge("e", "a")
|
||||
if err == nil {
|
||||
t.Error("expected error for long cycle: a -> b -> c -> d -> e -> a")
|
||||
}
|
||||
|
||||
// Adding e -> c should also create a cycle
|
||||
err = g.addEdge("e", "c")
|
||||
if err == nil {
|
||||
t.Error("expected error for cycle: c -> d -> e -> c")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphNoCycleDAG(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b", "c", "d"})
|
||||
|
||||
// Create a diamond DAG: a -> b, a -> c, b -> d, c -> d
|
||||
_ = g.addEdge("a", "b")
|
||||
_ = g.addEdge("a", "c")
|
||||
_ = g.addEdge("b", "d")
|
||||
|
||||
err := g.addEdge("c", "d")
|
||||
if err != nil {
|
||||
t.Errorf("expected no cycle in DAG, got error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphSelfLoop(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNode("a")
|
||||
|
||||
// BUG: Self-loops are not detected by willCycle(). The function checks if
|
||||
// adding edge from→to would create a cycle by traversing edges from "to"
|
||||
// to see if "from" is reachable. But for a self-loop (from==to), the edge
|
||||
// doesn't exist yet, so the DFS finds nothing and returns false.
|
||||
// A self-importing file would NOT be caught by this cycle detection.
|
||||
err := g.addEdge("a", "a")
|
||||
if err != nil {
|
||||
t.Log("Self-loop was correctly detected (bug may have been fixed)")
|
||||
} else {
|
||||
t.Log("BUG CONFIRMED: addEdge('a', 'a') did not detect self-loop cycle")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphExistsNonExistent(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
if g.exists("nonexistent") {
|
||||
t.Error("expected false for nonexistent node on empty graph")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAreConnectedEmpty(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
if g.areConnected("a", "b") {
|
||||
t.Error("expected false for areConnected on empty graph")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddEdges(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b", "c", "d"})
|
||||
|
||||
err := g.addEdges("a", []string{"b", "c", "d"})
|
||||
if err != nil {
|
||||
t.Fatalf("addEdges() error = %v", err)
|
||||
}
|
||||
|
||||
if !g.areConnected("a", "b") || !g.areConnected("a", "c") || !g.areConnected("a", "d") {
|
||||
t.Error("expected all edges from 'a' to exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphAddEdgesWithCycle(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b", "c"})
|
||||
|
||||
_ = g.addEdge("b", "c")
|
||||
_ = g.addEdge("c", "a")
|
||||
|
||||
// This should fail because a -> b -> c -> a creates a cycle
|
||||
err := g.addEdges("a", []string{"b"})
|
||||
if err == nil {
|
||||
t.Error("expected error when addEdges creates a cycle")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphRemoveNodeEdgeLeakBug(t *testing.T) {
|
||||
// This test documents a known bug: removeNode doesn't clean up edges.
|
||||
// Edges FROM the removed node remain in the adjacency list.
|
||||
g := &importGraph{}
|
||||
g.addNodes([]string{"a", "b", "c"})
|
||||
_ = g.addEdge("a", "b")
|
||||
_ = g.addEdge("b", "c")
|
||||
|
||||
g.removeNode("b")
|
||||
|
||||
// Bug: "b" is removed from nodes, but edges from "b" are still in the adjacency list.
|
||||
// This means the graph is now inconsistent.
|
||||
// The node doesn't exist...
|
||||
if g.exists("b") {
|
||||
t.Error("node 'b' should not exist after removeNode")
|
||||
}
|
||||
|
||||
// ...but edges from "b" may still be present in the edges map (this is a bug).
|
||||
// We test this to document the behavior.
|
||||
if g.edges != nil {
|
||||
if targets, ok := g.edges["b"]; ok && len(targets) > 0 {
|
||||
t.Log("BUG CONFIRMED: removeNode does not clean up outgoing edges. " +
|
||||
"Edges from removed node 'b' still exist in adjacency list.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportGraphWillCycleEmptyGraph(t *testing.T) {
|
||||
g := &importGraph{}
|
||||
// willCycle on empty graph should return false
|
||||
if g.willCycle("a", "b") {
|
||||
t.Error("expected no cycle on empty graph")
|
||||
}
|
||||
}
|
||||
@@ -507,7 +507,7 @@ func (p *parser) doImport(nesting int) error {
|
||||
// format, won't check for nesting correctness or any other error, that's what parser does.
|
||||
if !maybeSnippet && nesting == 0 {
|
||||
// first of the line
|
||||
if i == 0 || isNextOnNewLine(tokensCopy[i-1], token) {
|
||||
if i == 0 || isNextOnNewLine(tokensCopy[len(tokensCopy)-1], token) {
|
||||
index = 0
|
||||
} else {
|
||||
index++
|
||||
@@ -550,7 +550,11 @@ func (p *parser) doImport(nesting int) error {
|
||||
}
|
||||
|
||||
if foundBlockDirective {
|
||||
tokensCopy = append(tokensCopy, tokensToAdd...)
|
||||
if maybeSnippet {
|
||||
tokensCopy = append(tokensCopy, token)
|
||||
} else {
|
||||
tokensCopy = append(tokensCopy, tokensToAdd...)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -616,7 +620,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
|
||||
if err != nil {
|
||||
return nil, p.Errf("Failed to get absolute path of file: %s: %v", importFile, err)
|
||||
}
|
||||
for i := 0; i < len(importedTokens); i++ {
|
||||
for i := range importedTokens {
|
||||
importedTokens[i].File = filename
|
||||
}
|
||||
|
||||
@@ -682,11 +686,28 @@ func (p *parser) directive() error {
|
||||
// a opening curly brace. It does NOT advance the token.
|
||||
func (p *parser) openCurlyBrace() error {
|
||||
if p.Val() != "{" {
|
||||
if p.valLooksLikeGlobalOptionsAfterImportedSnippets() {
|
||||
return p.Err("global options block must appear before import directives; move the global options block to the top of the Caddyfile")
|
||||
}
|
||||
return p.SyntaxErr("{")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parser) valLooksLikeGlobalOptionsAfterImportedSnippets() bool {
|
||||
if p.Val() != "import" || len(p.block.Keys) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, key := range p.block.Keys {
|
||||
if !strings.HasPrefix(key.Text, "(") || !strings.HasSuffix(key.Text, ")") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// closeCurlyBrace expects the current token to be
|
||||
// a closing curly brace. This acts like an assertion
|
||||
// because it returns an error if the token is not
|
||||
|
||||
@@ -930,6 +930,107 @@ func TestAcceptSiteImportWithBraces(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalOptionsAfterImportedSnippetsGivesHelpfulError(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
importFile1 := filepath.Join(tempDir, "matcher_snippet_1.caddy")
|
||||
importFile2 := filepath.Join(tempDir, "matcher_snippet_2.caddy")
|
||||
|
||||
err := os.WriteFile(importFile1, []byte(`(matcher1)`), 0o644)
|
||||
if err != nil {
|
||||
t.Fatalf("writing first import file: %v", err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(importFile2, []byte(`(matcher2)`), 0o644)
|
||||
if err != nil {
|
||||
t.Fatalf("writing second import file: %v", err)
|
||||
}
|
||||
|
||||
_, err = Parse("Testfile", []byte(`import `+importFile1+`
|
||||
import `+importFile2+`
|
||||
{
|
||||
debug
|
||||
}`))
|
||||
if err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
}
|
||||
|
||||
expected := "global options block must appear before import directives; move the global options block to the top of the Caddyfile"
|
||||
if !strings.HasPrefix(err.Error(), expected) {
|
||||
t.Errorf("Expected error to start with '%s' but got '%v'", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportedSnippetDefinitionRetainsBlockPlaceholder(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
importFile := filepath.Join(tempDir, "snippets.caddy")
|
||||
|
||||
err := os.WriteFile(importFile, []byte(`
|
||||
(site) {
|
||||
http://{args[0]} {
|
||||
respond "before"
|
||||
{block}
|
||||
respond "after"
|
||||
}
|
||||
}
|
||||
`), 0o644)
|
||||
if err != nil {
|
||||
t.Fatalf("writing imported snippet file: %v", err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input string
|
||||
expectedDirectives []string
|
||||
}{
|
||||
{
|
||||
name: "with nested block",
|
||||
input: `
|
||||
import ` + importFile + `
|
||||
|
||||
import site example.com {
|
||||
redir https://example.net
|
||||
}
|
||||
`,
|
||||
expectedDirectives: []string{"respond", "redir", "respond"},
|
||||
},
|
||||
{
|
||||
name: "without nested block",
|
||||
input: `
|
||||
import ` + importFile + `
|
||||
|
||||
import site example.com
|
||||
`,
|
||||
expectedDirectives: []string{"respond", "respond"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
p := testParser(tc.input)
|
||||
blocks, err := p.parseAll()
|
||||
if err != nil {
|
||||
t.Fatalf("parseAll: %v", err)
|
||||
}
|
||||
|
||||
if len(blocks) != 1 {
|
||||
t.Fatalf("expected exactly one server block, got %d", len(blocks))
|
||||
}
|
||||
|
||||
if actual := blocks[0].GetKeysText(); len(actual) != 1 || actual[0] != "http://example.com" {
|
||||
t.Fatalf("expected server block key http://example.com, got %v", actual)
|
||||
}
|
||||
|
||||
if len(blocks[0].Segments) != len(tc.expectedDirectives) {
|
||||
t.Fatalf("expected %d segments, got %d", len(tc.expectedDirectives), len(blocks[0].Segments))
|
||||
}
|
||||
|
||||
for i, directive := range tc.expectedDirectives {
|
||||
if actual := blocks[0].Segments[i].Directive(); actual != directive {
|
||||
t.Fatalf("segment %d: expected directive %q, got %q", i, directive, actual)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testParser(input string) parser {
|
||||
return parser{Dispenser: NewTestDispenser(input)}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package caddyconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSON(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
val any
|
||||
wantNil bool
|
||||
wantWarnings int
|
||||
nilWarnings bool // pass nil warnings pointer
|
||||
}{
|
||||
{
|
||||
name: "simple string",
|
||||
val: "hello",
|
||||
wantNil: false,
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "struct",
|
||||
val: struct{ Name string }{"test"},
|
||||
wantNil: false,
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "nil value",
|
||||
val: nil,
|
||||
wantNil: false, // json.Marshal(nil) returns "null"
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "map",
|
||||
val: map[string]string{"key": "val"},
|
||||
wantNil: false,
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "unmarshalable value produces warning",
|
||||
val: make(chan int),
|
||||
wantNil: true,
|
||||
wantWarnings: 1,
|
||||
},
|
||||
{
|
||||
name: "unmarshalable value with nil warnings pointer",
|
||||
val: make(chan int),
|
||||
wantNil: true,
|
||||
nilWarnings: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var warnings *[]Warning
|
||||
if !tt.nilWarnings {
|
||||
w := []Warning{}
|
||||
warnings = &w
|
||||
}
|
||||
|
||||
result := JSON(tt.val, warnings)
|
||||
|
||||
if tt.wantNil && result != nil {
|
||||
t.Errorf("JSON() = %v, want nil", string(result))
|
||||
}
|
||||
if !tt.wantNil && result == nil {
|
||||
t.Error("JSON() = nil, want non-nil")
|
||||
}
|
||||
if warnings != nil && len(*warnings) != tt.wantWarnings {
|
||||
t.Errorf("JSON() produced %d warnings, want %d", len(*warnings), tt.wantWarnings)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONModuleObject(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
val any
|
||||
fieldName string
|
||||
fieldVal string
|
||||
wantNil bool
|
||||
wantField bool
|
||||
wantWarnings int
|
||||
}{
|
||||
{
|
||||
name: "simple struct",
|
||||
val: struct{ Name string }{"test"},
|
||||
fieldName: "handler",
|
||||
fieldVal: "file_server",
|
||||
wantNil: false,
|
||||
wantField: true,
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "map value",
|
||||
val: map[string]any{"key": "val"},
|
||||
fieldName: "module",
|
||||
fieldVal: "my_module",
|
||||
wantNil: false,
|
||||
wantField: true,
|
||||
wantWarnings: 0,
|
||||
},
|
||||
{
|
||||
name: "non-object type (string) produces warning",
|
||||
val: "not-an-object",
|
||||
fieldName: "handler",
|
||||
fieldVal: "test",
|
||||
wantNil: true,
|
||||
wantField: false,
|
||||
wantWarnings: 1,
|
||||
},
|
||||
{
|
||||
name: "unmarshalable value produces warning",
|
||||
val: make(chan int),
|
||||
fieldName: "handler",
|
||||
fieldVal: "test",
|
||||
wantNil: true,
|
||||
wantField: false,
|
||||
wantWarnings: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
warnings := []Warning{}
|
||||
result := JSONModuleObject(tt.val, tt.fieldName, tt.fieldVal, &warnings)
|
||||
|
||||
if tt.wantNil && result != nil {
|
||||
t.Errorf("JSONModuleObject() = %v, want nil", string(result))
|
||||
}
|
||||
if !tt.wantNil && result == nil {
|
||||
t.Error("JSONModuleObject() = nil, want non-nil")
|
||||
}
|
||||
if len(warnings) != tt.wantWarnings {
|
||||
t.Errorf("JSONModuleObject() produced %d warnings, want %d", len(warnings), tt.wantWarnings)
|
||||
}
|
||||
if tt.wantField && result != nil {
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(result, &m); err != nil {
|
||||
t.Fatalf("failed to unmarshal result: %v", err)
|
||||
}
|
||||
if v, ok := m[tt.fieldName]; !ok {
|
||||
t.Errorf("expected field %q in result", tt.fieldName)
|
||||
} else if v != tt.fieldVal {
|
||||
t.Errorf("field %q = %v, want %v", tt.fieldName, v, tt.fieldVal)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONModuleObjectPreservesExistingFields(t *testing.T) {
|
||||
val := struct {
|
||||
Name string `json:"name"`
|
||||
Port int `json:"port"`
|
||||
}{"example", 8080}
|
||||
|
||||
warnings := []Warning{}
|
||||
result := JSONModuleObject(val, "handler", "static", &warnings)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("expected non-nil result")
|
||||
}
|
||||
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(result, &m); err != nil {
|
||||
t.Fatalf("failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if m["name"] != "example" {
|
||||
t.Errorf("name = %v, want 'example'", m["name"])
|
||||
}
|
||||
if m["port"] != float64(8080) {
|
||||
t.Errorf("port = %v, want 8080", m["port"])
|
||||
}
|
||||
if m["handler"] != "static" {
|
||||
t.Errorf("handler = %v, want 'static'", m["handler"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAdapterNil(t *testing.T) {
|
||||
adapter := GetAdapter("nonexistent_adapter_xyz")
|
||||
if adapter != nil {
|
||||
t.Error("expected nil for unregistered adapter")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWarningString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
warning Warning
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "all fields",
|
||||
warning: Warning{File: "Caddyfile", Line: 10, Directive: "reverse_proxy", Message: "upstream not found"},
|
||||
want: "Caddyfile:10 (reverse_proxy): upstream not found",
|
||||
},
|
||||
{
|
||||
name: "no directive",
|
||||
warning: Warning{File: "Caddyfile", Line: 5, Message: "something off"},
|
||||
want: "Caddyfile:5: something off",
|
||||
},
|
||||
{
|
||||
name: "zero line",
|
||||
warning: Warning{File: "config.json", Line: 0, Message: "invalid"},
|
||||
want: "config.json:0: invalid",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := tt.warning.String()
|
||||
if got != tt.want {
|
||||
t.Errorf("Warning.String() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@ func parseBind(h Helper) ([]ConfigValue, error) {
|
||||
// issuer <module_name> [...]
|
||||
// get_certificate <module_name> [...]
|
||||
// insecure_secrets_log <log_file>
|
||||
// renewal_window_ratio <ratio>
|
||||
// }
|
||||
func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
h.Next() // consume directive name
|
||||
@@ -129,6 +130,7 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
var onDemand bool
|
||||
var reusePrivateKeys bool
|
||||
var forceAutomate bool
|
||||
var renewalWindowRatio float64
|
||||
|
||||
// Track which DNS challenge options are set
|
||||
var dnsOptionsSet []string
|
||||
@@ -473,6 +475,20 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
}
|
||||
cp.InsecureSecretsLog = h.Val()
|
||||
|
||||
case "renewal_window_ratio":
|
||||
arg := h.RemainingArgs()
|
||||
if len(arg) != 1 {
|
||||
return nil, h.ArgErr()
|
||||
}
|
||||
ratio, err := strconv.ParseFloat(arg[0], 64)
|
||||
if err != nil {
|
||||
return nil, h.Errf("parsing renewal_window_ratio: %v", err)
|
||||
}
|
||||
if ratio <= 0 || ratio >= 1 {
|
||||
return nil, h.Errf("renewal_window_ratio must be between 0 and 1 (exclusive)")
|
||||
}
|
||||
renewalWindowRatio = ratio
|
||||
|
||||
default:
|
||||
return nil, h.Errf("unknown subdirective: %s", h.Val())
|
||||
}
|
||||
@@ -534,26 +550,11 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
}
|
||||
|
||||
case acmeIssuer != nil:
|
||||
// implicit ACME issuers (from various subdirectives) - use defaults; there might be more than one
|
||||
defaultIssuers := caddytls.DefaultIssuers(acmeIssuer.Email)
|
||||
|
||||
// if an ACME CA endpoint was set, the user expects to use that specific one,
|
||||
// not any others that may be defaults, so replace all defaults with that ACME CA
|
||||
if acmeIssuer.CA != "" {
|
||||
defaultIssuers = []certmagic.Issuer{acmeIssuer}
|
||||
}
|
||||
|
||||
// implicit ACME issuers (from various subdirectives) should inherit from
|
||||
// any globally-configured ACME issuer templates, then apply the local
|
||||
// shortcut settings as overrides.
|
||||
defaultIssuers := implicitACMEIssuers(h, acmeIssuer)
|
||||
for _, issuer := range defaultIssuers {
|
||||
// apply settings from the implicitly-configured ACMEIssuer to any
|
||||
// default ACMEIssuers, but preserve each default issuer's CA endpoint,
|
||||
// because, for example, if you configure the DNS challenge, it should
|
||||
// apply to any of the default ACMEIssuers, but you don't want to trample
|
||||
// out their unique CA endpoints
|
||||
if iss, ok := issuer.(*caddytls.ACMEIssuer); ok && iss != nil {
|
||||
acmeCopy := *acmeIssuer
|
||||
acmeCopy.CA = iss.CA
|
||||
issuer = &acmeCopy
|
||||
}
|
||||
configVals = append(configVals, ConfigValue{
|
||||
Class: "tls.cert_issuer",
|
||||
Value: issuer,
|
||||
@@ -597,6 +598,14 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// renewal window ratio
|
||||
if renewalWindowRatio > 0 {
|
||||
configVals = append(configVals, ConfigValue{
|
||||
Class: "tls.renewal_window_ratio",
|
||||
Value: renewalWindowRatio,
|
||||
})
|
||||
}
|
||||
|
||||
// if enabled, the names in the site addresses will be
|
||||
// added to the automation policies
|
||||
if forceAutomate {
|
||||
@@ -644,6 +653,8 @@ func parseRoot(h Helper) ([]ConfigValue, error) {
|
||||
if !h.NextArg() {
|
||||
return nil, h.ArgErr()
|
||||
}
|
||||
// store the unmatched root in block state so sibling directives can access it
|
||||
h.BlockState["root"] = h.Val()
|
||||
return h.NewRoute(nil, caddyhttp.VarsMiddleware{"root": h.Val()}), nil
|
||||
}
|
||||
|
||||
@@ -658,6 +669,10 @@ func parseRoot(h Helper) ([]ConfigValue, error) {
|
||||
if !h.NextArg() {
|
||||
return nil, h.ArgErr()
|
||||
}
|
||||
// store the unmatched root in state so sibling/child directives can access it
|
||||
if userMatcherSet == nil {
|
||||
h.BlockState["root"] = h.Val()
|
||||
}
|
||||
// make the route with the matcher
|
||||
return h.NewRoute(userMatcherSet, caddyhttp.VarsMiddleware{"root": h.Val()}), nil
|
||||
}
|
||||
@@ -1038,7 +1053,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
interval, err := time.ParseDuration(d.Val() + "ns")
|
||||
interval, err := caddy.ParseDuration(d.Val())
|
||||
if err != nil {
|
||||
return nil, d.Errf("failed to parse interval: %v", err)
|
||||
}
|
||||
|
||||
@@ -66,14 +66,14 @@ func TestLogDirectiveSyntax(t *testing.T) {
|
||||
input: `:8080 {
|
||||
log {
|
||||
sampling {
|
||||
interval 2
|
||||
interval 2s
|
||||
first 3
|
||||
thereafter 4
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
|
||||
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2000000000,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
|
||||
expectError: false,
|
||||
},
|
||||
} {
|
||||
|
||||
@@ -202,7 +202,10 @@ func RegisterGlobalOption(opt string, setupFunc UnmarshalGlobalFunc) {
|
||||
type Helper struct {
|
||||
*caddyfile.Dispenser
|
||||
// State stores intermediate variables during caddyfile adaptation.
|
||||
State map[string]any
|
||||
State map[string]any
|
||||
// BlockState stores intermediate variables scoped to the current block.
|
||||
// It propagates down, but unlike state not back up from child to parent.
|
||||
BlockState map[string]any
|
||||
options map[string]any
|
||||
warnings *[]caddyconfig.Warning
|
||||
matcherDefs map[string]caddy.ModuleMap
|
||||
@@ -385,6 +388,11 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// clone BlockState once for the entire block so sibling directives
|
||||
// can share state, but changes don't leak to the parent scope
|
||||
subBlockState := make(map[string]any, len(h.BlockState))
|
||||
maps.Copy(subBlockState, h.BlockState)
|
||||
|
||||
// with matchers ready to go, evaluate each directive's segment
|
||||
for _, seg := range segments {
|
||||
dir := seg.Directive()
|
||||
@@ -396,6 +404,7 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
|
||||
subHelper := h
|
||||
subHelper.Dispenser = caddyfile.NewDispenser(seg)
|
||||
subHelper.matcherDefs = matcherDefs
|
||||
subHelper.BlockState = subBlockState
|
||||
|
||||
results, err := dirFunc(subHelper)
|
||||
if err != nil {
|
||||
|
||||
@@ -143,6 +143,7 @@ func (st ServerType) Setup(
|
||||
parentBlock: sb.block,
|
||||
groupCounter: gc,
|
||||
State: state,
|
||||
BlockState: state,
|
||||
}
|
||||
|
||||
results, err := dirFunc(h)
|
||||
@@ -504,6 +505,7 @@ func (ServerType) extractNamedRoutes(
|
||||
parentBlock: sb.block,
|
||||
groupCounter: gc,
|
||||
State: state,
|
||||
BlockState: state,
|
||||
}
|
||||
|
||||
handler, err := ParseSegmentAsSubroute(h)
|
||||
@@ -822,7 +824,7 @@ func (st *ServerType) serversFromPairings(
|
||||
// https://caddy.community/t/making-sense-of-auto-https-and-why-disabling-it-still-serves-https-instead-of-http/9761
|
||||
createdTLSConnPolicies, ok := sblock.pile["tls.connection_policy"]
|
||||
hasTLSEnabled := (ok && len(createdTLSConnPolicies) > 0) ||
|
||||
(addr.Host != "" && srv.AutoHTTPS != nil && !slices.Contains(srv.AutoHTTPS.Skip, addr.Host))
|
||||
(addr.Host != "" && (srv.AutoHTTPS == nil || !slices.Contains(srv.AutoHTTPS.Skip, addr.Host)))
|
||||
|
||||
// we'll need to remember if the address qualifies for auto-HTTPS, so we
|
||||
// can add a TLS conn policy if necessary
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package httpcaddyfile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||
)
|
||||
|
||||
func TestMatcherSyntax(t *testing.T) {
|
||||
@@ -209,3 +211,53 @@ func TestGlobalOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultSNIWithoutHTTPS(t *testing.T) {
|
||||
caddyfileStr := `{
|
||||
default_sni my-sni.com
|
||||
}
|
||||
example.com {
|
||||
}`
|
||||
|
||||
adapter := caddyfile.Adapter{
|
||||
ServerType: ServerType{},
|
||||
}
|
||||
|
||||
result, _, err := adapter.Adapt([]byte(caddyfileStr), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to adapt Caddyfile: %v", err)
|
||||
}
|
||||
|
||||
var config struct {
|
||||
Apps struct {
|
||||
HTTP struct {
|
||||
Servers map[string]*caddyhttp.Server `json:"servers"`
|
||||
} `json:"http"`
|
||||
} `json:"apps"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(result, &config); err != nil {
|
||||
t.Fatalf("Failed to unmarshal JSON config: %v", err)
|
||||
}
|
||||
|
||||
server, ok := config.Apps.HTTP.Servers["srv0"]
|
||||
if !ok {
|
||||
t.Fatalf("Expected server 'srv0' to be created")
|
||||
}
|
||||
|
||||
if len(server.TLSConnPolicies) == 0 {
|
||||
t.Fatalf("Expected TLS connection policies to be generated, got none")
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, policy := range server.TLSConnPolicies {
|
||||
if policy.DefaultSNI == "my-sni.com" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Errorf("Expected default_sni 'my-sni.com' in TLS connection policies, but it was missing. Generated JSON: %s", string(result))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ func init() {
|
||||
RegisterGlobalOption("preferred_chains", parseOptPreferredChains)
|
||||
RegisterGlobalOption("persist_config", parseOptPersistConfig)
|
||||
RegisterGlobalOption("dns", parseOptDNS)
|
||||
RegisterGlobalOption("tls_resolvers", parseOptTLSResolvers)
|
||||
RegisterGlobalOption("ech", parseOptECH)
|
||||
RegisterGlobalOption("renewal_window_ratio", parseOptRenewalWindowRatio)
|
||||
}
|
||||
|
||||
func parseOptTrue(d *caddyfile.Dispenser, _ any) (any, error) { return true, nil }
|
||||
@@ -305,6 +307,15 @@ func parseOptSingleString(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func parseOptTLSResolvers(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
d.Next() // consume option name
|
||||
resolvers := d.RemainingArgs()
|
||||
if len(resolvers) == 0 {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func parseOptDefaultBind(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
d.Next() // consume option name
|
||||
|
||||
@@ -457,9 +468,8 @@ func parseOptAutoHTTPS(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
case "disable_redirects":
|
||||
case "disable_certs":
|
||||
case "ignore_loaded_certs":
|
||||
case "prefer_wildcard":
|
||||
default:
|
||||
return "", d.Errf("auto_https must be one of 'off', 'disable_redirects', 'disable_certs', 'ignore_loaded_certs', or 'prefer_wildcard'")
|
||||
return "", d.Errf("auto_https must be one of 'off', 'disable_redirects', 'disable_certs', or 'ignore_loaded_certs'")
|
||||
}
|
||||
}
|
||||
return val, nil
|
||||
@@ -474,6 +484,8 @@ func unmarshalCaddyfileMetricsOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
metrics.PerHost = true
|
||||
case "observe_catchall_hosts":
|
||||
metrics.ObserveCatchallHosts = true
|
||||
case "otlp":
|
||||
metrics.OTLP = true
|
||||
default:
|
||||
return nil, d.Errf("unrecognized servers option '%s'", d.Val())
|
||||
}
|
||||
@@ -625,3 +637,22 @@ func parseOptECH(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
|
||||
return ech, nil
|
||||
}
|
||||
|
||||
func parseOptRenewalWindowRatio(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
d.Next() // consume option name
|
||||
if !d.Next() {
|
||||
return 0, d.ArgErr()
|
||||
}
|
||||
val := d.Val()
|
||||
ratio, err := strconv.ParseFloat(val, 64)
|
||||
if err != nil {
|
||||
return 0, d.Errf("parsing renewal_window_ratio: %v", err)
|
||||
}
|
||||
if ratio <= 0 || ratio >= 1 {
|
||||
return 0, d.Errf("renewal_window_ratio must be between 0 and 1 (exclusive)")
|
||||
}
|
||||
if d.Next() {
|
||||
return 0, d.ArgErr()
|
||||
}
|
||||
return ratio, nil
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package httpcaddyfile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
||||
_ "github.com/caddyserver/caddy/v2/modules/logging"
|
||||
)
|
||||
|
||||
@@ -62,3 +66,228 @@ func TestGlobalLogOptionSyntax(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalResolversOption(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectResolvers []string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "single resolver",
|
||||
input: `{
|
||||
tls_resolvers 1.1.1.1
|
||||
}
|
||||
example.com {
|
||||
}`,
|
||||
expectResolvers: []string{"1.1.1.1"},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "two resolvers",
|
||||
input: `{
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
}
|
||||
example.com {
|
||||
}`,
|
||||
expectResolvers: []string{"1.1.1.1", "8.8.8.8"},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "multiple resolvers",
|
||||
input: `{
|
||||
tls_resolvers 1.1.1.1 8.8.8.8 9.9.9.9
|
||||
}
|
||||
example.com {
|
||||
}`,
|
||||
expectResolvers: []string{"1.1.1.1", "8.8.8.8", "9.9.9.9"},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "no resolvers specified",
|
||||
input: `{
|
||||
}
|
||||
example.com {
|
||||
}`,
|
||||
expectResolvers: nil,
|
||||
expectError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
adapter := caddyfile.Adapter{
|
||||
ServerType: ServerType{},
|
||||
}
|
||||
|
||||
out, _, err := adapter.Adapt([]byte(tc.input), nil)
|
||||
|
||||
if (err != nil) != tc.expectError {
|
||||
t.Errorf("error expectation failed. Expected error: %v, got: %v", tc.expectError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if tc.expectError {
|
||||
return
|
||||
}
|
||||
|
||||
// Parse the output JSON to check resolvers
|
||||
var config struct {
|
||||
Apps struct {
|
||||
TLS *caddytls.TLS `json:"tls"`
|
||||
} `json:"apps"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(out, &config); err != nil {
|
||||
t.Errorf("failed to unmarshal output: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if resolvers match expected
|
||||
if config.Apps.TLS == nil {
|
||||
if tc.expectResolvers != nil {
|
||||
t.Errorf("Expected TLS config with resolvers %v, but TLS config is nil", tc.expectResolvers)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
actualResolvers := config.Apps.TLS.Resolvers
|
||||
if len(tc.expectResolvers) == 0 && len(actualResolvers) == 0 {
|
||||
return // Both empty, ok
|
||||
}
|
||||
if len(actualResolvers) != len(tc.expectResolvers) {
|
||||
t.Errorf("Expected %d resolvers, got %d. Expected: %v, got: %v", len(tc.expectResolvers), len(actualResolvers), tc.expectResolvers, actualResolvers)
|
||||
return
|
||||
}
|
||||
for j, expected := range tc.expectResolvers {
|
||||
if actualResolvers[j] != expected {
|
||||
t.Errorf("Resolver %d mismatch. Expected: %s, got: %s", j, expected, actualResolvers[j])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalCertIssuerAppliesToImplicitACMEIssuer(t *testing.T) {
|
||||
adapter := caddyfile.Adapter{
|
||||
ServerType: ServerType{},
|
||||
}
|
||||
|
||||
input := `{
|
||||
cert_issuer acme {
|
||||
disable_tlsalpn_challenge
|
||||
}
|
||||
}
|
||||
report.company.intern {
|
||||
tls {
|
||||
ca https://deglacme01.company.intern/acme/acme/directory
|
||||
ca_root /etc/certs/company_root2.crt
|
||||
}
|
||||
respond "ok"
|
||||
}`
|
||||
|
||||
out, _, err := adapter.Adapt([]byte(input), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("adapting caddyfile: %v", err)
|
||||
}
|
||||
|
||||
var config struct {
|
||||
Apps struct {
|
||||
TLS *caddytls.TLS `json:"tls"`
|
||||
} `json:"apps"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &config); err != nil {
|
||||
t.Fatalf("unmarshaling adapted config: %v", err)
|
||||
}
|
||||
if config.Apps.TLS == nil || config.Apps.TLS.Automation == nil {
|
||||
t.Fatal("expected tls automation config")
|
||||
}
|
||||
|
||||
var subjectPolicy *caddytls.AutomationPolicy
|
||||
for _, ap := range config.Apps.TLS.Automation.Policies {
|
||||
if len(ap.SubjectsRaw) == 1 && ap.SubjectsRaw[0] == "report.company.intern" {
|
||||
subjectPolicy = ap
|
||||
break
|
||||
}
|
||||
}
|
||||
if subjectPolicy == nil {
|
||||
t.Fatal("expected subject-specific automation policy")
|
||||
}
|
||||
if len(subjectPolicy.IssuersRaw) != 1 {
|
||||
t.Fatalf("expected one issuer for subject-specific policy, got %d", len(subjectPolicy.IssuersRaw))
|
||||
}
|
||||
|
||||
var issuer caddytls.ACMEIssuer
|
||||
if err := json.Unmarshal(subjectPolicy.IssuersRaw[0], &issuer); err != nil {
|
||||
t.Fatalf("unmarshaling issuer: %v", err)
|
||||
}
|
||||
if issuer.CA != "https://deglacme01.company.intern/acme/acme/directory" {
|
||||
t.Fatalf("expected custom ACME CA, got %q", issuer.CA)
|
||||
}
|
||||
if len(issuer.TrustedRootsPEMFiles) != 1 || issuer.TrustedRootsPEMFiles[0] != "/etc/certs/company_root2.crt" {
|
||||
t.Fatalf("expected trusted roots to include site CA root, got %v", issuer.TrustedRootsPEMFiles)
|
||||
}
|
||||
if issuer.Challenges == nil || issuer.Challenges.TLSALPN == nil || !issuer.Challenges.TLSALPN.Disabled {
|
||||
t.Fatalf("expected tls-alpn challenge to be disabled, got %#v", issuer.Challenges)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeACMEIssuers(t *testing.T) {
|
||||
base := &caddytls.ACMEIssuer{
|
||||
Email: "ops@example.com",
|
||||
Challenges: &caddytls.ChallengesConfig{
|
||||
HTTP: &caddytls.HTTPChallengeConfig{
|
||||
AlternatePort: 8080,
|
||||
},
|
||||
TLSALPN: &caddytls.TLSALPNChallengeConfig{
|
||||
Disabled: true,
|
||||
AlternatePort: 8443,
|
||||
},
|
||||
DNS: &caddytls.DNSChallengeConfig{
|
||||
Resolvers: []string{"1.1.1.1"},
|
||||
OverrideDomain: "_acme-challenge.example.net",
|
||||
},
|
||||
},
|
||||
TrustedRootsPEMFiles: []string{"global.pem"},
|
||||
}
|
||||
overrides := &caddytls.ACMEIssuer{
|
||||
CA: "https://deglacme01.company.intern/acme/acme/directory",
|
||||
Challenges: &caddytls.ChallengesConfig{
|
||||
HTTP: &caddytls.HTTPChallengeConfig{
|
||||
Disabled: true,
|
||||
},
|
||||
DNS: &caddytls.DNSChallengeConfig{
|
||||
PropagationTimeout: caddy.Duration(time.Minute),
|
||||
},
|
||||
},
|
||||
TrustedRootsPEMFiles: []string{"site.pem"},
|
||||
}
|
||||
|
||||
merged := mergeACMEIssuers(base, overrides)
|
||||
if merged.CA != overrides.CA {
|
||||
t.Fatalf("expected merged CA %q, got %q", overrides.CA, merged.CA)
|
||||
}
|
||||
if merged.Email != base.Email {
|
||||
t.Fatalf("expected merged email %q, got %q", base.Email, merged.Email)
|
||||
}
|
||||
if len(merged.TrustedRootsPEMFiles) != 2 || merged.TrustedRootsPEMFiles[0] != "global.pem" || merged.TrustedRootsPEMFiles[1] != "site.pem" {
|
||||
t.Fatalf("expected merged roots [global.pem site.pem], got %v", merged.TrustedRootsPEMFiles)
|
||||
}
|
||||
if merged.Challenges == nil || merged.Challenges.HTTP == nil || !merged.Challenges.HTTP.Disabled || merged.Challenges.HTTP.AlternatePort != 8080 {
|
||||
t.Fatalf("expected merged HTTP challenge config to preserve alternate port and apply disable flag, got %#v", merged.Challenges)
|
||||
}
|
||||
if merged.Challenges.TLSALPN == nil || !merged.Challenges.TLSALPN.Disabled || merged.Challenges.TLSALPN.AlternatePort != 8443 {
|
||||
t.Fatalf("expected merged TLS-ALPN challenge config to preserve global settings, got %#v", merged.Challenges)
|
||||
}
|
||||
if merged.Challenges.DNS == nil || merged.Challenges.DNS.PropagationTimeout != caddy.Duration(time.Minute) || len(merged.Challenges.DNS.Resolvers) != 1 || merged.Challenges.DNS.Resolvers[0] != "1.1.1.1" || merged.Challenges.DNS.OverrideDomain != "_acme-challenge.example.net" {
|
||||
t.Fatalf("expected merged DNS challenge config to preserve global values and apply overrides, got %#v", merged.Challenges)
|
||||
}
|
||||
|
||||
if base.CA != "" {
|
||||
t.Fatalf("expected base issuer to remain unchanged, got CA %q", base.CA)
|
||||
}
|
||||
if len(base.TrustedRootsPEMFiles) != 1 || base.TrustedRootsPEMFiles[0] != "global.pem" {
|
||||
t.Fatalf("expected base roots to remain unchanged, got %v", base.TrustedRootsPEMFiles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package httpcaddyfile
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
@@ -27,14 +28,16 @@ func init() {
|
||||
RegisterGlobalOption("pki", parsePKIApp)
|
||||
}
|
||||
|
||||
// parsePKIApp parses the global log option. Syntax:
|
||||
// parsePKIApp parses the global pki option. Syntax:
|
||||
//
|
||||
// pki {
|
||||
// ca [<id>] {
|
||||
// name <name>
|
||||
// root_cn <name>
|
||||
// intermediate_cn <name>
|
||||
// intermediate_lifetime <duration>
|
||||
// name <name>
|
||||
// root_cn <name>
|
||||
// intermediate_cn <name>
|
||||
// intermediate_lifetime <duration>
|
||||
// maintenance_interval <duration>
|
||||
// renewal_window_ratio <ratio>
|
||||
// root {
|
||||
// cert <path>
|
||||
// key <path>
|
||||
@@ -99,6 +102,26 @@ func parsePKIApp(d *caddyfile.Dispenser, existingVal any) (any, error) {
|
||||
}
|
||||
pkiCa.IntermediateLifetime = caddy.Duration(dur)
|
||||
|
||||
case "maintenance_interval":
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
dur, err := caddy.ParseDuration(d.Val())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkiCa.MaintenanceInterval = caddy.Duration(dur)
|
||||
|
||||
case "renewal_window_ratio":
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
ratio, err := strconv.ParseFloat(d.Val(), 64)
|
||||
if err != nil || ratio <= 0 || ratio > 1 {
|
||||
return nil, d.Errf("renewal_window_ratio must be a number in (0, 1], got %s", d.Val())
|
||||
}
|
||||
pkiCa.RenewalWindowRatio = ratio
|
||||
|
||||
case "root":
|
||||
if pkiCa.Root == nil {
|
||||
pkiCa.Root = new(caddypki.KeyPair)
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package httpcaddyfile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
)
|
||||
|
||||
func TestParsePKIApp_maintenanceIntervalAndRenewalWindowRatio(t *testing.T) {
|
||||
input := `{
|
||||
pki {
|
||||
ca local {
|
||||
maintenance_interval 5m
|
||||
renewal_window_ratio 0.15
|
||||
}
|
||||
}
|
||||
}
|
||||
:8080 {
|
||||
}
|
||||
`
|
||||
adapter := caddyfile.Adapter{ServerType: ServerType{}}
|
||||
out, _, err := adapter.Adapt([]byte(input), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Adapt failed: %v", err)
|
||||
}
|
||||
|
||||
var cfg struct {
|
||||
Apps struct {
|
||||
PKI struct {
|
||||
CertificateAuthorities map[string]struct {
|
||||
MaintenanceInterval int64 `json:"maintenance_interval,omitempty"`
|
||||
RenewalWindowRatio float64 `json:"renewal_window_ratio,omitempty"`
|
||||
} `json:"certificate_authorities,omitempty"`
|
||||
} `json:"pki,omitempty"`
|
||||
} `json:"apps"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &cfg); err != nil {
|
||||
t.Fatalf("unmarshal config: %v", err)
|
||||
}
|
||||
|
||||
ca, ok := cfg.Apps.PKI.CertificateAuthorities["local"]
|
||||
if !ok {
|
||||
t.Fatal("expected certificate_authorities.local to exist")
|
||||
}
|
||||
wantInterval := 5 * time.Minute.Nanoseconds()
|
||||
if ca.MaintenanceInterval != wantInterval {
|
||||
t.Errorf("maintenance_interval = %d, want %d (5m)", ca.MaintenanceInterval, wantInterval)
|
||||
}
|
||||
if ca.RenewalWindowRatio != 0.15 {
|
||||
t.Errorf("renewal_window_ratio = %v, want 0.15", ca.RenewalWindowRatio)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePKIApp_renewalWindowRatioInvalid(t *testing.T) {
|
||||
input := `{
|
||||
pki {
|
||||
ca local {
|
||||
renewal_window_ratio 1.5
|
||||
}
|
||||
}
|
||||
}
|
||||
:8080 {
|
||||
}
|
||||
`
|
||||
adapter := caddyfile.Adapter{ServerType: ServerType{}}
|
||||
_, _, err := adapter.Adapt([]byte(input), nil)
|
||||
if err == nil {
|
||||
t.Error("expected error for renewal_window_ratio > 1")
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,9 @@ type serverOptions struct {
|
||||
ShouldLogCredentials bool
|
||||
Metrics *caddyhttp.Metrics
|
||||
Trace bool // TODO: EXPERIMENTAL
|
||||
// If set, overrides whether QUIC listeners allow 0-RTT (early data).
|
||||
// If nil, the default behavior is used (currently allowed).
|
||||
Allow0RTT *bool
|
||||
}
|
||||
|
||||
func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
@@ -309,6 +312,17 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
}
|
||||
serverOpts.Trace = true
|
||||
|
||||
case "0rtt":
|
||||
// only supports "off" for now
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
if d.Val() != "off" {
|
||||
return nil, d.Errf("unsupported 0rtt argument '%s' (only 'off' is supported)", d.Val())
|
||||
}
|
||||
boolVal := false
|
||||
serverOpts.Allow0RTT = &boolVal
|
||||
|
||||
default:
|
||||
return nil, d.Errf("unrecognized servers option '%s'", d.Val())
|
||||
}
|
||||
@@ -373,6 +387,7 @@ func applyServerOptions(
|
||||
server.TrustedProxiesStrict = opts.TrustedProxiesStrict
|
||||
server.TrustedProxiesUnix = opts.TrustedProxiesUnix
|
||||
server.Metrics = opts.Metrics
|
||||
server.Allow0RTT = opts.Allow0RTT
|
||||
if opts.ShouldLogCredentials {
|
||||
if server.Logs == nil {
|
||||
server.Logs = new(caddyhttp.ServerLogConfig)
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
package httpcaddyfile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
)
|
||||
|
||||
func TestShorthandReplacerSimpleReplacements(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "host",
|
||||
input: "{host}",
|
||||
want: "{http.request.host}",
|
||||
},
|
||||
{
|
||||
name: "hostport",
|
||||
input: "{hostport}",
|
||||
want: "{http.request.hostport}",
|
||||
},
|
||||
{
|
||||
name: "port",
|
||||
input: "{port}",
|
||||
want: "{http.request.port}",
|
||||
},
|
||||
{
|
||||
name: "method",
|
||||
input: "{method}",
|
||||
want: "{http.request.method}",
|
||||
},
|
||||
{
|
||||
name: "uri",
|
||||
input: "{uri}",
|
||||
want: "{http.request.uri}",
|
||||
},
|
||||
{
|
||||
name: "path",
|
||||
input: "{path}",
|
||||
want: "{http.request.uri.path}",
|
||||
},
|
||||
{
|
||||
name: "query",
|
||||
input: "{query}",
|
||||
want: "{http.request.uri.query}",
|
||||
},
|
||||
{
|
||||
name: "scheme",
|
||||
input: "{scheme}",
|
||||
want: "{http.request.scheme}",
|
||||
},
|
||||
{
|
||||
name: "remote_host",
|
||||
input: "{remote_host}",
|
||||
want: "{http.request.remote.host}",
|
||||
},
|
||||
{
|
||||
name: "remote_port",
|
||||
input: "{remote_port}",
|
||||
want: "{http.request.remote.port}",
|
||||
},
|
||||
{
|
||||
name: "uuid",
|
||||
input: "{uuid}",
|
||||
want: "{http.request.uuid}",
|
||||
},
|
||||
{
|
||||
name: "tls_cipher",
|
||||
input: "{tls_cipher}",
|
||||
want: "{http.request.tls.cipher_suite}",
|
||||
},
|
||||
{
|
||||
name: "tls_version",
|
||||
input: "{tls_version}",
|
||||
want: "{http.request.tls.version}",
|
||||
},
|
||||
{
|
||||
name: "client_ip",
|
||||
input: "{client_ip}",
|
||||
want: "{http.vars.client_ip}",
|
||||
},
|
||||
{
|
||||
name: "upstream_hostport",
|
||||
input: "{upstream_hostport}",
|
||||
want: "{http.reverse_proxy.upstream.hostport}",
|
||||
},
|
||||
{
|
||||
name: "dir",
|
||||
input: "{dir}",
|
||||
want: "{http.request.uri.path.dir}",
|
||||
},
|
||||
{
|
||||
name: "file",
|
||||
input: "{file}",
|
||||
want: "{http.request.uri.path.file}",
|
||||
},
|
||||
{
|
||||
name: "orig_method",
|
||||
input: "{orig_method}",
|
||||
want: "{http.request.orig_method}",
|
||||
},
|
||||
{
|
||||
name: "orig_uri",
|
||||
input: "{orig_uri}",
|
||||
want: "{http.request.orig_uri}",
|
||||
},
|
||||
{
|
||||
name: "orig_path",
|
||||
input: "{orig_path}",
|
||||
want: "{http.request.orig_uri.path}",
|
||||
},
|
||||
{
|
||||
name: "no matching placeholder",
|
||||
input: "{unknown}",
|
||||
want: "{unknown}",
|
||||
},
|
||||
{
|
||||
name: "not a placeholder",
|
||||
input: "plain text",
|
||||
want: "plain text",
|
||||
},
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "multiple placeholders in one string",
|
||||
input: "{host}:{port}",
|
||||
want: "{http.request.host}:{http.request.port}",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
segment := caddyfile.Segment{{Text: tt.input}}
|
||||
sr.ApplyToSegment(&segment)
|
||||
got := segment[0].Text
|
||||
if got != tt.want {
|
||||
t.Errorf("ApplyToSegment(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorthandReplacerComplexReplacements(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "header placeholder",
|
||||
input: "{header.X-Forwarded-For}",
|
||||
want: "{http.request.header.X-Forwarded-For}",
|
||||
},
|
||||
{
|
||||
name: "cookie placeholder",
|
||||
input: "{cookie.session_id}",
|
||||
want: "{http.request.cookie.session_id}",
|
||||
},
|
||||
{
|
||||
name: "labels placeholder",
|
||||
input: "{labels.0}",
|
||||
want: "{http.request.host.labels.0}",
|
||||
},
|
||||
{
|
||||
name: "path segment placeholder",
|
||||
input: "{path.0}",
|
||||
want: "{http.request.uri.path.0}",
|
||||
},
|
||||
{
|
||||
name: "query placeholder",
|
||||
input: "{query.page}",
|
||||
want: "{http.request.uri.query.page}",
|
||||
},
|
||||
{
|
||||
name: "re placeholder with dots",
|
||||
input: "{re.name.group}",
|
||||
want: "{http.regexp.name.group}",
|
||||
},
|
||||
{
|
||||
name: "vars placeholder",
|
||||
input: "{vars.my_var}",
|
||||
want: "{http.vars.my_var}",
|
||||
},
|
||||
{
|
||||
name: "rp placeholder",
|
||||
input: "{rp.upstream.address}",
|
||||
want: "{http.reverse_proxy.upstream.address}",
|
||||
},
|
||||
{
|
||||
name: "resp placeholder",
|
||||
input: "{resp.status_code}",
|
||||
want: "{http.intercept.status_code}",
|
||||
},
|
||||
{
|
||||
name: "err placeholder",
|
||||
input: "{err.status_code}",
|
||||
want: "{http.error.status_code}",
|
||||
},
|
||||
{
|
||||
name: "file_match placeholder",
|
||||
input: "{file_match.relative}",
|
||||
want: "{http.matchers.file.relative}",
|
||||
},
|
||||
{
|
||||
name: "header with hyphen",
|
||||
input: "{header.Content-Type}",
|
||||
want: "{http.request.header.Content-Type}",
|
||||
},
|
||||
{
|
||||
name: "header with underscore",
|
||||
input: "{header.X_Custom_Header}",
|
||||
want: "{http.request.header.X_Custom_Header}",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
segment := caddyfile.Segment{{Text: tt.input}}
|
||||
sr.ApplyToSegment(&segment)
|
||||
got := segment[0].Text
|
||||
if got != tt.want {
|
||||
t.Errorf("ApplyToSegment(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorthandReplacerApplyToNilSegment(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
// Should not panic
|
||||
sr.ApplyToSegment(nil)
|
||||
}
|
||||
|
||||
func TestShorthandReplacerMultipleTokens(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
|
||||
segment := caddyfile.Segment{
|
||||
{Text: "{host}"},
|
||||
{Text: "{path}"},
|
||||
{Text: "{header.X-Test}"},
|
||||
{Text: "plain"},
|
||||
}
|
||||
|
||||
sr.ApplyToSegment(&segment)
|
||||
|
||||
expected := []string{
|
||||
"{http.request.host}",
|
||||
"{http.request.uri.path}",
|
||||
"{http.request.header.X-Test}",
|
||||
"plain",
|
||||
}
|
||||
|
||||
for i, want := range expected {
|
||||
if segment[i].Text != want {
|
||||
t.Errorf("token %d: got %q, want %q", i, segment[i].Text, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorthandReplacerEmptySegment(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
segment := caddyfile.Segment{}
|
||||
sr.ApplyToSegment(&segment) // should not panic
|
||||
}
|
||||
|
||||
func TestShorthandReplacerEscapedPlaceholders(t *testing.T) {
|
||||
sr := NewShorthandReplacer()
|
||||
|
||||
// Percent-escaped path placeholder
|
||||
segment := caddyfile.Segment{{Text: "{%path}"}}
|
||||
sr.ApplyToSegment(&segment)
|
||||
if segment[0].Text != "{http.request.uri.path_escaped}" {
|
||||
t.Errorf("got %q, want {http.request.uri.path_escaped}", segment[0].Text)
|
||||
}
|
||||
|
||||
// Percent-escaped query placeholder
|
||||
segment = caddyfile.Segment{{Text: "{%query}"}}
|
||||
sr.ApplyToSegment(&segment)
|
||||
if segment[0].Text != "{http.request.uri.query_escaped}" {
|
||||
t.Errorf("got %q, want {http.request.uri.query_escaped}", segment[0].Text)
|
||||
}
|
||||
|
||||
// Prefixed query
|
||||
segment = caddyfile.Segment{{Text: "{?query}"}}
|
||||
sr.ApplyToSegment(&segment)
|
||||
if segment[0].Text != "{http.request.uri.prefixed_query}" {
|
||||
t.Errorf("got %q, want {http.request.uri.prefixed_query}", segment[0].Text)
|
||||
}
|
||||
}
|
||||
@@ -92,26 +92,8 @@ func (st ServerType) buildTLSApp(
|
||||
tlsApp.Automation.Policies = append(tlsApp.Automation.Policies, catchAllAP)
|
||||
}
|
||||
|
||||
var wildcardHosts []string // collect all hosts that have a wildcard in them, and aren't HTTP
|
||||
forcedAutomatedNames := make(map[string]struct{}) // explicitly configured to be automated, even if covered by a wildcard
|
||||
|
||||
for _, p := range pairings {
|
||||
var addresses []string
|
||||
for _, addressWithProtocols := range p.addressesWithProtocols {
|
||||
addresses = append(addresses, addressWithProtocols.address)
|
||||
}
|
||||
if !listenersUseAnyPortOtherThan(addresses, httpPort) {
|
||||
continue
|
||||
}
|
||||
for _, sblock := range p.serverBlocks {
|
||||
for _, addr := range sblock.parsedKeys {
|
||||
if strings.HasPrefix(addr.Host, "*.") {
|
||||
wildcardHosts = append(wildcardHosts, addr.Host[2:])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range pairings {
|
||||
// avoid setting up TLS automation policies for a server that is HTTP-only
|
||||
var addresses []string
|
||||
@@ -135,12 +117,6 @@ func (st ServerType) buildTLSApp(
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
// make a plain copy so we can compare whether we made any changes
|
||||
apCopy, err := newBaseAutomationPolicy(options, warnings, true)
|
||||
if err != nil {
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
sblockHosts := sblock.hostsFromKeys(false)
|
||||
if len(sblockHosts) == 0 && catchAllAP != nil {
|
||||
ap = catchAllAP
|
||||
@@ -167,6 +143,12 @@ func (st ServerType) buildTLSApp(
|
||||
ap.KeyType = keyTypeVals[0].Value.(string)
|
||||
}
|
||||
|
||||
if renewalWindowRatioVals, ok := sblock.pile["tls.renewal_window_ratio"]; ok {
|
||||
ap.RenewalWindowRatio = renewalWindowRatioVals[0].Value.(float64)
|
||||
} else if globalRenewalWindowRatio, ok := options["renewal_window_ratio"]; ok {
|
||||
ap.RenewalWindowRatio = globalRenewalWindowRatio.(float64)
|
||||
}
|
||||
|
||||
// certificate issuers
|
||||
if issuerVals, ok := sblock.pile["tls.cert_issuer"]; ok {
|
||||
var issuers []certmagic.Issuer
|
||||
@@ -253,16 +235,6 @@ func (st ServerType) buildTLSApp(
|
||||
hostsNotHTTP := sblock.hostsFromKeysNotHTTP(httpPort)
|
||||
sort.Strings(hostsNotHTTP) // solely for deterministic test results
|
||||
|
||||
// if the we prefer wildcards and the AP is unchanged,
|
||||
// then we can skip this AP because it should be covered
|
||||
// by an AP with a wildcard
|
||||
if slices.Contains(autoHTTPS, "prefer_wildcard") {
|
||||
if hostsCoveredByWildcard(hostsNotHTTP, wildcardHosts) &&
|
||||
reflect.DeepEqual(ap, apCopy) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// associate our new automation policy with this server block's hosts
|
||||
ap.SubjectsRaw = hostsNotHTTP
|
||||
|
||||
@@ -362,6 +334,11 @@ func (st ServerType) buildTLSApp(
|
||||
tlsApp.DNSRaw = caddyconfig.JSONModuleObject(globalDNS, "name", globalDNS.(caddy.Module).CaddyModule().ID.Name(), nil)
|
||||
}
|
||||
|
||||
// set up "global" (to the TLS app) DNS resolvers config
|
||||
if globalResolvers, ok := options["tls_resolvers"]; ok && globalResolvers != nil {
|
||||
tlsApp.Resolvers = globalResolvers.([]string)
|
||||
}
|
||||
|
||||
// set up ECH from Caddyfile options
|
||||
if ech, ok := options["ech"].(*caddytls.ECH); ok {
|
||||
tlsApp.EncryptedClientHello = ech
|
||||
@@ -576,9 +553,8 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
|
||||
if acmeIssuer.Challenges.DNS == nil {
|
||||
acmeIssuer.Challenges.DNS = new(caddytls.DNSChallengeConfig)
|
||||
}
|
||||
// If global `dns` is set, do NOT set provider in issuer, just set empty dns config
|
||||
if globalDNS == nil && acmeIssuer.Challenges.DNS.ProviderRaw == nil {
|
||||
// Set a global DNS provider if `acme_dns` is set and `dns` is NOT set
|
||||
if globalACMEDNS != nil && acmeIssuer.Challenges.DNS.ProviderRaw == nil {
|
||||
// Set a global DNS provider if `acme_dns` is set
|
||||
acmeIssuer.Challenges.DNS.ProviderRaw = caddyconfig.JSONModuleObject(globalACMEDNS, "name", globalACMEDNS.(caddy.Module).CaddyModule().ID.Name(), nil)
|
||||
}
|
||||
}
|
||||
@@ -624,9 +600,301 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
|
||||
if globalCertLifetime != nil && acmeIssuer.CertificateLifetime == 0 {
|
||||
acmeIssuer.CertificateLifetime = globalCertLifetime.(caddy.Duration)
|
||||
}
|
||||
// apply global resolvers if DNS challenge is configured and resolvers are not already set
|
||||
globalResolvers := options["tls_resolvers"]
|
||||
if globalResolvers != nil && acmeIssuer.Challenges != nil && acmeIssuer.Challenges.DNS != nil {
|
||||
// Check if DNS challenge is actually configured
|
||||
hasDNSChallenge := globalACMEDNSok || acmeIssuer.Challenges.DNS.ProviderRaw != nil
|
||||
if hasDNSChallenge && len(acmeIssuer.Challenges.DNS.Resolvers) == 0 {
|
||||
acmeIssuer.Challenges.DNS.Resolvers = globalResolvers.([]string)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// implicitACMEIssuers returns the issuers to use for ACME-related tls
|
||||
// shortcuts such as ca, ca_root, and dns. If any global cert_issuer options
|
||||
// configure ACME issuers, those become the templates for the local shortcut
|
||||
// configuration; otherwise, default ACME issuers are used.
|
||||
func implicitACMEIssuers(h Helper, acmeIssuer *caddytls.ACMEIssuer) []certmagic.Issuer {
|
||||
globalIssuers, _ := h.Option("cert_issuer").([]certmagic.Issuer)
|
||||
|
||||
var implicitIssuers []certmagic.Issuer
|
||||
for _, issuer := range globalIssuers {
|
||||
acmeWrapper, ok := issuer.(acmeCapable)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
baseIssuer := acmeWrapper.GetACMEIssuer()
|
||||
if baseIssuer == nil {
|
||||
continue
|
||||
}
|
||||
implicitIssuers = append(implicitIssuers, mergeACMEIssuers(baseIssuer, acmeIssuer))
|
||||
}
|
||||
if len(implicitIssuers) > 0 {
|
||||
return implicitIssuers
|
||||
}
|
||||
|
||||
// If an ACME CA endpoint was set locally, the user expects to use only that
|
||||
// CA rather than the usual default fallback issuers.
|
||||
defaultIssuers := caddytls.DefaultIssuers(acmeIssuer.Email)
|
||||
if acmeIssuer.CA != "" {
|
||||
defaultIssuers = []certmagic.Issuer{new(caddytls.ACMEIssuer)}
|
||||
}
|
||||
|
||||
implicitIssuers = make([]certmagic.Issuer, 0, len(defaultIssuers))
|
||||
for _, issuer := range defaultIssuers {
|
||||
acmeWrapper, ok := issuer.(acmeCapable)
|
||||
if !ok {
|
||||
implicitIssuers = append(implicitIssuers, issuer)
|
||||
continue
|
||||
}
|
||||
baseIssuer := acmeWrapper.GetACMEIssuer()
|
||||
if baseIssuer == nil {
|
||||
implicitIssuers = append(implicitIssuers, issuer)
|
||||
continue
|
||||
}
|
||||
implicitIssuers = append(implicitIssuers, mergeACMEIssuers(baseIssuer, acmeIssuer))
|
||||
}
|
||||
return implicitIssuers
|
||||
}
|
||||
|
||||
func mergeACMEIssuers(base, overrides *caddytls.ACMEIssuer) *caddytls.ACMEIssuer {
|
||||
if base == nil {
|
||||
return cloneACMEIssuer(overrides)
|
||||
}
|
||||
|
||||
merged := cloneACMEIssuer(base)
|
||||
if overrides == nil {
|
||||
return merged
|
||||
}
|
||||
|
||||
if overrides.CA != "" {
|
||||
merged.CA = overrides.CA
|
||||
}
|
||||
if overrides.TestCA != "" {
|
||||
merged.TestCA = overrides.TestCA
|
||||
}
|
||||
if overrides.Email != "" {
|
||||
merged.Email = overrides.Email
|
||||
}
|
||||
if overrides.Profile != "" {
|
||||
merged.Profile = overrides.Profile
|
||||
}
|
||||
if overrides.AccountKey != "" {
|
||||
merged.AccountKey = overrides.AccountKey
|
||||
}
|
||||
if overrides.ExternalAccount != nil {
|
||||
merged.ExternalAccount = cloneACMEEAB(overrides.ExternalAccount)
|
||||
}
|
||||
if overrides.ACMETimeout != 0 {
|
||||
merged.ACMETimeout = overrides.ACMETimeout
|
||||
}
|
||||
if len(overrides.TrustedRootsPEMFiles) > 0 {
|
||||
merged.TrustedRootsPEMFiles = appendUniqueStrings(merged.TrustedRootsPEMFiles, overrides.TrustedRootsPEMFiles...)
|
||||
}
|
||||
if overrides.PreferredChains != nil {
|
||||
merged.PreferredChains = cloneChainPreference(overrides.PreferredChains)
|
||||
}
|
||||
if overrides.CertificateLifetime != 0 {
|
||||
merged.CertificateLifetime = overrides.CertificateLifetime
|
||||
}
|
||||
if len(overrides.NetworkProxyRaw) > 0 {
|
||||
merged.NetworkProxyRaw = slices.Clone(overrides.NetworkProxyRaw)
|
||||
}
|
||||
merged.Challenges = mergeChallengesConfig(merged.Challenges, overrides.Challenges)
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
func mergeChallengesConfig(base, overrides *caddytls.ChallengesConfig) *caddytls.ChallengesConfig {
|
||||
if base == nil {
|
||||
return cloneChallengesConfig(overrides)
|
||||
}
|
||||
merged := cloneChallengesConfig(base)
|
||||
if overrides == nil {
|
||||
return merged
|
||||
}
|
||||
|
||||
merged.HTTP = mergeHTTPChallengeConfig(merged.HTTP, overrides.HTTP)
|
||||
merged.TLSALPN = mergeTLSALPNChallengeConfig(merged.TLSALPN, overrides.TLSALPN)
|
||||
merged.DNS = mergeDNSChallengeConfig(merged.DNS, overrides.DNS)
|
||||
if overrides.BindHost != "" {
|
||||
merged.BindHost = overrides.BindHost
|
||||
}
|
||||
if overrides.Distributed != nil {
|
||||
value := *overrides.Distributed
|
||||
merged.Distributed = &value
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
func mergeHTTPChallengeConfig(base, overrides *caddytls.HTTPChallengeConfig) *caddytls.HTTPChallengeConfig {
|
||||
if base == nil {
|
||||
return cloneHTTPChallengeConfig(overrides)
|
||||
}
|
||||
merged := cloneHTTPChallengeConfig(base)
|
||||
if overrides == nil {
|
||||
return merged
|
||||
}
|
||||
|
||||
if overrides.Disabled {
|
||||
merged.Disabled = true
|
||||
}
|
||||
if overrides.AlternatePort != 0 {
|
||||
merged.AlternatePort = overrides.AlternatePort
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
func mergeTLSALPNChallengeConfig(base, overrides *caddytls.TLSALPNChallengeConfig) *caddytls.TLSALPNChallengeConfig {
|
||||
if base == nil {
|
||||
return cloneTLSALPNChallengeConfig(overrides)
|
||||
}
|
||||
merged := cloneTLSALPNChallengeConfig(base)
|
||||
if overrides == nil {
|
||||
return merged
|
||||
}
|
||||
|
||||
if overrides.Disabled {
|
||||
merged.Disabled = true
|
||||
}
|
||||
if overrides.AlternatePort != 0 {
|
||||
merged.AlternatePort = overrides.AlternatePort
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
func mergeDNSChallengeConfig(base, overrides *caddytls.DNSChallengeConfig) *caddytls.DNSChallengeConfig {
|
||||
if base == nil {
|
||||
return cloneDNSChallengeConfig(overrides)
|
||||
}
|
||||
merged := cloneDNSChallengeConfig(base)
|
||||
if overrides == nil {
|
||||
return merged
|
||||
}
|
||||
|
||||
if len(overrides.ProviderRaw) > 0 {
|
||||
merged.ProviderRaw = slices.Clone(overrides.ProviderRaw)
|
||||
}
|
||||
if overrides.PropagationDelay != 0 {
|
||||
merged.PropagationDelay = overrides.PropagationDelay
|
||||
}
|
||||
if overrides.PropagationTimeout != 0 {
|
||||
merged.PropagationTimeout = overrides.PropagationTimeout
|
||||
}
|
||||
if overrides.Resolvers != nil {
|
||||
merged.Resolvers = slices.Clone(overrides.Resolvers)
|
||||
}
|
||||
if overrides.OverrideDomain != "" {
|
||||
merged.OverrideDomain = overrides.OverrideDomain
|
||||
}
|
||||
if overrides.TTL != 0 {
|
||||
merged.TTL = overrides.TTL
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
func cloneACMEIssuer(iss *caddytls.ACMEIssuer) *caddytls.ACMEIssuer {
|
||||
if iss == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *iss
|
||||
cloned.Challenges = cloneChallengesConfig(iss.Challenges)
|
||||
cloned.ExternalAccount = cloneACMEEAB(iss.ExternalAccount)
|
||||
cloned.TrustedRootsPEMFiles = slices.Clone(iss.TrustedRootsPEMFiles)
|
||||
cloned.PreferredChains = cloneChainPreference(iss.PreferredChains)
|
||||
cloned.NetworkProxyRaw = slices.Clone(iss.NetworkProxyRaw)
|
||||
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneChallengesConfig(cfg *caddytls.ChallengesConfig) *caddytls.ChallengesConfig {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *cfg
|
||||
cloned.HTTP = cloneHTTPChallengeConfig(cfg.HTTP)
|
||||
cloned.TLSALPN = cloneTLSALPNChallengeConfig(cfg.TLSALPN)
|
||||
cloned.DNS = cloneDNSChallengeConfig(cfg.DNS)
|
||||
if cfg.Distributed != nil {
|
||||
value := *cfg.Distributed
|
||||
cloned.Distributed = &value
|
||||
}
|
||||
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneHTTPChallengeConfig(cfg *caddytls.HTTPChallengeConfig) *caddytls.HTTPChallengeConfig {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *cfg
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneTLSALPNChallengeConfig(cfg *caddytls.TLSALPNChallengeConfig) *caddytls.TLSALPNChallengeConfig {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *cfg
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneDNSChallengeConfig(cfg *caddytls.DNSChallengeConfig) *caddytls.DNSChallengeConfig {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *cfg
|
||||
cloned.ProviderRaw = slices.Clone(cfg.ProviderRaw)
|
||||
cloned.Resolvers = slices.Clone(cfg.Resolvers)
|
||||
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneACMEEAB(eab *acme.EAB) *acme.EAB {
|
||||
if eab == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *eab
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneChainPreference(pref *caddytls.ChainPreference) *caddytls.ChainPreference {
|
||||
if pref == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cloned := *pref
|
||||
cloned.RootCommonName = slices.Clone(pref.RootCommonName)
|
||||
cloned.AnyCommonName = slices.Clone(pref.AnyCommonName)
|
||||
if pref.Smallest != nil {
|
||||
value := *pref.Smallest
|
||||
cloned.Smallest = &value
|
||||
}
|
||||
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func appendUniqueStrings(existing []string, additions ...string) []string {
|
||||
for _, value := range additions {
|
||||
if !slices.Contains(existing, value) {
|
||||
existing = append(existing, value)
|
||||
}
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
||||
// newBaseAutomationPolicy returns a new TLS automation policy that gets
|
||||
// its values from the global options map. It should be used as the base
|
||||
// for any other automation policies. A nil policy (and no error) will be
|
||||
@@ -641,7 +909,8 @@ func newBaseAutomationPolicy(
|
||||
_, hasLocalCerts := options["local_certs"]
|
||||
keyType, hasKeyType := options["key_type"]
|
||||
ocspStapling, hasOCSPStapling := options["ocsp_stapling"]
|
||||
hasGlobalAutomationOpts := hasIssuers || hasLocalCerts || hasKeyType || hasOCSPStapling
|
||||
renewalWindowRatio, hasRenewalWindowRatio := options["renewal_window_ratio"]
|
||||
hasGlobalAutomationOpts := hasIssuers || hasLocalCerts || hasKeyType || hasOCSPStapling || hasRenewalWindowRatio
|
||||
|
||||
globalACMECA := options["acme_ca"]
|
||||
globalACMECARoot := options["acme_ca_root"]
|
||||
@@ -688,6 +957,10 @@ func newBaseAutomationPolicy(
|
||||
ap.OCSPOverrides = ocspConfig.ResponderOverrides
|
||||
}
|
||||
|
||||
if hasRenewalWindowRatio {
|
||||
ap.RenewalWindowRatio = renewalWindowRatio.(float64)
|
||||
}
|
||||
|
||||
return ap, nil
|
||||
}
|
||||
|
||||
@@ -708,14 +981,31 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
|
||||
emptyAPCount := 0
|
||||
origLenAPs := len(aps)
|
||||
// compute the number of empty policies (disregarding subjects) - see #4128
|
||||
// while we're at it,
|
||||
emptyAP := new(caddytls.AutomationPolicy)
|
||||
for i := 0; i < len(aps); i++ {
|
||||
emptyAP.SubjectsRaw = aps[i].SubjectsRaw
|
||||
emptyAP.ManagersRaw = nil
|
||||
if reflect.DeepEqual(aps[i], emptyAP) {
|
||||
// AP is empty
|
||||
emptyAPCount++
|
||||
if !automationPolicyHasAllPublicNames(aps[i]) {
|
||||
// if this automation policy has internal names, we might as well remove it
|
||||
// so auto-https can implicitly use the internal issuer
|
||||
|
||||
// see if this AP shadows something later
|
||||
shadowIdx := automationPolicyShadows(i, aps)
|
||||
emptyAP.SubjectsRaw = nil
|
||||
if shadowIdx >= 0 {
|
||||
emptyAP.SubjectsRaw = aps[shadowIdx].SubjectsRaw
|
||||
// allow the later policy, which is likely for a wildcard, to have cert
|
||||
// managers ("get_certificate"), since wildcards now cover specific
|
||||
// subdomains by default, when configured (see discussion in #7559)
|
||||
emptyAP.ManagersRaw = aps[shadowIdx].ManagersRaw
|
||||
}
|
||||
|
||||
// if this is the last AP, we can delete it, since auto-https should
|
||||
// pick it up; if it shadows something later that is also empty, we
|
||||
// can similarly delete this; but if it shadows something that is NOT
|
||||
// empty, we must not delete it since the shadowing has a purpose
|
||||
if i == len(aps)-1 || (shadowIdx >= 0 && reflect.DeepEqual(aps[shadowIdx], emptyAP)) {
|
||||
aps = slices.Delete(aps, i, i+1)
|
||||
i--
|
||||
}
|
||||
@@ -849,20 +1139,3 @@ func automationPolicyHasAllPublicNames(ap *caddytls.AutomationPolicy) bool {
|
||||
func isTailscaleDomain(name string) bool {
|
||||
return strings.HasSuffix(strings.ToLower(name), ".ts.net")
|
||||
}
|
||||
|
||||
func hostsCoveredByWildcard(hosts []string, wildcards []string) bool {
|
||||
if len(hosts) == 0 || len(wildcards) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, host := range hosts {
|
||||
for _, wildcard := range wildcards {
|
||||
if strings.HasPrefix(host, "*.") {
|
||||
continue
|
||||
}
|
||||
if certmagic.MatchWildcard(host, "*."+wildcard) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
func attemptHttpCall(client *http.Client, request *http.Request) (*http.Response, error) {
|
||||
resp, err := client.Do(request)
|
||||
resp, err := client.Do(request) //nolint:gosec // no SSRF; comes from trusted config
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("problem calling http loader url: %v", err)
|
||||
} else if resp.StatusCode < 200 || resp.StatusCode > 499 {
|
||||
@@ -151,7 +151,7 @@ func doHttpCallWithRetries(ctx caddy.Context, client *http.Client, request *http
|
||||
var err error
|
||||
const maxAttempts = 10
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
for i := range maxAttempts {
|
||||
resp, err = attemptHttpCall(client, request)
|
||||
if err != nil && i < maxAttempts-1 {
|
||||
select {
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ func (adminLoad) handleLoad(w http.ResponseWriter, r *http.Request) error {
|
||||
if err != nil {
|
||||
caddy.Log().Named("admin.api.load").Error(err.Error())
|
||||
}
|
||||
_, _ = w.Write(respBody)
|
||||
_, _ = w.Write(respBody) //nolint:gosec // false positive: no XSS here
|
||||
}
|
||||
body = result
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||
req.Header.Add("Content-Type", "text/"+configType)
|
||||
}
|
||||
|
||||
res, err := client.Do(req)
|
||||
res, err := client.Do(req) //nolint:gosec // no SSRF because URL is hard-coded to localhost, and port comes from config
|
||||
if err != nil {
|
||||
tc.t.Errorf("unable to contact caddy server. %s", err)
|
||||
return err
|
||||
@@ -279,7 +279,7 @@ func validateTestPrerequisites(tc *Tester) error {
|
||||
return err
|
||||
}
|
||||
tc.t.Cleanup(func() {
|
||||
os.Remove(f.Name())
|
||||
os.Remove(f.Name()) //nolint:gosec // false positive, filename comes from std lib, no path traversal
|
||||
})
|
||||
if _, err := fmt.Fprintf(f, initConfig, tc.config.AdminPort); err != nil {
|
||||
return err
|
||||
@@ -506,7 +506,7 @@ func applyHeaders(t testing.TB, req *http.Request, requestHeaders []string) {
|
||||
func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response {
|
||||
tc.t.Helper()
|
||||
|
||||
resp, err := tc.Client.Do(req)
|
||||
resp, err := tc.Client.Do(req) //nolint:gosec // no SSRFs demonstrated
|
||||
if err != nil {
|
||||
tc.t.Fatalf("failed to call server %s", err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package caddytest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -126,3 +127,118 @@ func TestLoadUnorderedJSON(t *testing.T) {
|
||||
}
|
||||
tester.AssertResponseCode(req, 200)
|
||||
}
|
||||
|
||||
func TestCheckID(t *testing.T) {
|
||||
tester := NewTester(t)
|
||||
tester.InitServer(`{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"servers": {
|
||||
"s_server": {
|
||||
"@id": "s_server",
|
||||
"listen": [
|
||||
":9080"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "static_response",
|
||||
"body": "Hello"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "json")
|
||||
headers := []string{"Content-Type:application/json"}
|
||||
sServer1 := []byte(`{"@id":"s_server","listen":[":9080"],"routes":[{"@id":"route1","handle":[{"handler":"static_response","body":"Hello 2"}]}]}`)
|
||||
|
||||
// PUT to an existing ID should fail with a 409 conflict
|
||||
tester.AssertPutResponseBody(
|
||||
"http://localhost:2999/id/s_server",
|
||||
headers,
|
||||
bytes.NewBuffer(sServer1),
|
||||
409,
|
||||
`{"error":"[/config/apps/http/servers/s_server] key already exists: s_server"}`+"\n")
|
||||
|
||||
// POST replaces the object fully
|
||||
tester.AssertPostResponseBody(
|
||||
"http://localhost:2999/id/s_server",
|
||||
headers,
|
||||
bytes.NewBuffer(sServer1),
|
||||
200,
|
||||
"")
|
||||
|
||||
// Verify the server is running the new route
|
||||
tester.AssertGetResponse(
|
||||
"http://localhost:9080/",
|
||||
200,
|
||||
"Hello 2")
|
||||
|
||||
// Update the existing route to ensure IDs are handled correctly when replaced
|
||||
tester.AssertPostResponseBody(
|
||||
"http://localhost:2999/id/s_server",
|
||||
headers,
|
||||
bytes.NewBuffer([]byte(`{"@id":"s_server","listen":[":9080"],"routes":[{"@id":"route1","handle":[{"handler":"static_response","body":"Hello2"}],"match":[{"path":["/route_1/*"]}]}]}`)),
|
||||
200,
|
||||
"")
|
||||
|
||||
sServer2 := []byte(`{"@id":"s_server","listen":[":9080"],"routes":[{"@id":"route1","handle":[{"handler":"static_response","body":"Hello2"}],"match":[{"path":["/route_1/*"]}]}]}`)
|
||||
|
||||
// Identical patch should succeed and return 200 (config is unchanged branch)
|
||||
tester.AssertPatchResponseBody(
|
||||
"http://localhost:2999/id/s_server",
|
||||
headers,
|
||||
bytes.NewBuffer(sServer2),
|
||||
200,
|
||||
"")
|
||||
|
||||
route2 := []byte(`{"@id":"route2","handle": [{"handler": "static_response","body": "route2"}],"match":[{"path":["/route_2/*"]}]}`)
|
||||
|
||||
// Put a new route2 object before the route1 object due to the path of /id/route1
|
||||
// Being translated to: /config/apps/http/servers/s_server/routes/0
|
||||
tester.AssertPutResponseBody(
|
||||
"http://localhost:2999/id/route1",
|
||||
headers,
|
||||
bytes.NewBuffer(route2),
|
||||
200,
|
||||
"")
|
||||
|
||||
// Verify that the whole config looks correct, now containing both route1 and route2
|
||||
tester.AssertGetResponse(
|
||||
"http://localhost:2999/config/",
|
||||
200,
|
||||
`{"admin":{"listen":"localhost:2999"},"apps":{"http":{"http_port":9080,"servers":{"s_server":{"@id":"s_server","listen":[":9080"],"routes":[{"@id":"route2","handle":[{"body":"route2","handler":"static_response"}],"match":[{"path":["/route_2/*"]}]},{"@id":"route1","handle":[{"body":"Hello2","handler":"static_response"}],"match":[{"path":["/route_1/*"]}]}]}}}}}`+"\n")
|
||||
|
||||
// Try to add another copy of route2 using POST to test duplicate ID handling
|
||||
// Since the first route2 ended up at array index 0, and we are appending to the array, the index for the new element would be 2
|
||||
tester.AssertPostResponseBody(
|
||||
"http://localhost:2999/id/route2",
|
||||
headers,
|
||||
bytes.NewBuffer(route2),
|
||||
400,
|
||||
`{"error":"indexing config: duplicate ID 'route2' found at /config/apps/http/servers/s_server/routes/0 and /config/apps/http/servers/s_server/routes/2"}`+"\n")
|
||||
|
||||
// Use PATCH to modify an existing object successfully
|
||||
tester.AssertPatchResponseBody(
|
||||
"http://localhost:2999/id/route1",
|
||||
headers,
|
||||
bytes.NewBuffer([]byte(`{"@id":"route1","handle":[{"handler":"static_response","body":"route1"}],"match":[{"path":["/route_1/*"]}]}`)),
|
||||
200,
|
||||
"")
|
||||
|
||||
// Verify the PATCH updated the server state
|
||||
tester.AssertGetResponse(
|
||||
"http://localhost:9080/route_1/",
|
||||
200,
|
||||
"route1")
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestACMEServerWithDefaults(t *testing.T) {
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Logger: slog.New(zapslog.NewHandler(logger.Core())),
|
||||
Logger: slog.New(zapslog.NewHandler(logger.Core(), zapslog.WithName("acmez"))),
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
acme.ChallengeTypeHTTP01: &naiveHTTPSolver{logger: logger},
|
||||
@@ -120,7 +120,7 @@ func TestACMEServerWithMismatchedChallenges(t *testing.T) {
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Logger: slog.New(zapslog.NewHandler(logger.Core())),
|
||||
Logger: slog.New(zapslog.NewHandler(logger.Core(), zapslog.WithName("acmez"))),
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
acme.ChallengeTypeHTTP01: &naiveHTTPSolver{logger: logger},
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
_, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"not-matching.localhost"})
|
||||
if err == nil {
|
||||
t.Errorf("obtaining certificate for 'not-matching.localhost' domain")
|
||||
} else if err != nil && !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
|
||||
} else if !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
|
||||
t.Logf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ func TestACMEServerDenyPolicy(t *testing.T) {
|
||||
_, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"deny.localhost"})
|
||||
if err == nil {
|
||||
t.Errorf("obtaining certificate for 'deny.localhost' domain")
|
||||
} else if err != nil && !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
|
||||
} else if !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
|
||||
t.Logf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,28 @@ func TestAutoHTTPtoHTTPSRedirectsExplicitPortDifferentFromHTTPSPort(t *testing.T
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost:1234/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPtoHTTPSRedirectsPreferHTTPSPortOverAlternatePort(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
local_certs
|
||||
}
|
||||
localhost {
|
||||
respond "Canonical"
|
||||
}
|
||||
|
||||
localhost:10443 {
|
||||
respond "Alternate"
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
@@ -143,3 +165,26 @@ func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAllWithNoExplicitHTTPSit
|
||||
tester.AssertGetResponse("http://foo.localhost:9080/", 200, "Foo")
|
||||
tester.AssertGetResponse("http://baz.localhost:9080/", 200, "Foo")
|
||||
}
|
||||
|
||||
func TestAutoHTTPSRedirectSortingExactMatchOverWildcard(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
local_certs
|
||||
}
|
||||
*.localhost:10443 {
|
||||
respond "Wildcard"
|
||||
}
|
||||
dev.localhost {
|
||||
respond "Exact"
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
tester.AssertRedirect("http://dev.localhost:9080/", "https://dev.localhost/", http.StatusPermanentRedirect)
|
||||
|
||||
tester.AssertRedirect("http://foo.localhost:9080/", "https://foo.localhost:10443/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ encode gzip zstd {
|
||||
|
||||
# Long way with a block for each encoding
|
||||
encode {
|
||||
zstd
|
||||
zstd {
|
||||
disable_checksum
|
||||
}
|
||||
gzip 5
|
||||
}
|
||||
|
||||
@@ -71,7 +73,9 @@ encode
|
||||
"gzip": {
|
||||
"level": 5
|
||||
},
|
||||
"zstd": {}
|
||||
"zstd": {
|
||||
"checksum": false
|
||||
}
|
||||
},
|
||||
"handler": "encode",
|
||||
"prefer": [
|
||||
|
||||
@@ -46,6 +46,18 @@ app.example.com {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"Remote-Email"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -73,6 +85,18 @@ app.example.com {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"Remote-Groups"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -100,6 +124,18 @@ app.example.com {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"Remote-Name"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -127,6 +163,18 @@ app.example.com {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"Remote-User"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -200,4 +248,4 @@ app.example.com {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
:8080
|
||||
|
||||
forward_auth 127.0.0.1:9091 {
|
||||
uri /
|
||||
copy_headers X-User-Id X-User-Role
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8080"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handle_response": [
|
||||
{
|
||||
"match": {
|
||||
"status_code": [
|
||||
2
|
||||
]
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "vars"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"X-User-Id"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"set": {
|
||||
"X-User-Id": [
|
||||
"{http.reverse_proxy.header.X-User-Id}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"not": [
|
||||
{
|
||||
"vars": {
|
||||
"{http.reverse_proxy.header.X-User-Id}": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"X-User-Role"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"set": {
|
||||
"X-User-Role": [
|
||||
"{http.reverse_proxy.header.X-User-Role}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"not": [
|
||||
{
|
||||
"vars": {
|
||||
"{http.reverse_proxy.header.X-User-Role}": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"handler": "reverse_proxy",
|
||||
"headers": {
|
||||
"request": {
|
||||
"set": {
|
||||
"X-Forwarded-Method": [
|
||||
"{http.request.method}"
|
||||
],
|
||||
"X-Forwarded-Uri": [
|
||||
"{http.request.uri}"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"rewrite": {
|
||||
"method": "GET",
|
||||
"uri": "/"
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:9091"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,18 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"1"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -62,6 +74,18 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"B"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -89,6 +113,18 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"3"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -116,6 +152,18 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"D"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -143,6 +191,18 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"request": {
|
||||
"delete": [
|
||||
"5"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
@@ -203,4 +263,4 @@ forward_auth localhost:9000 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
log {
|
||||
sampling {
|
||||
interval 300
|
||||
interval 5m
|
||||
first 50
|
||||
thereafter 40
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
"logs": {
|
||||
"default": {
|
||||
"sampling": {
|
||||
"interval": 300,
|
||||
"interval": 300000000000,
|
||||
"first": 50,
|
||||
"thereafter": 40
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
{
|
||||
email test@example.com
|
||||
dns mock
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
acme_dns
|
||||
}
|
||||
|
||||
example.com {
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": {
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
{
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
}
|
||||
|
||||
example.com {
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
{
|
||||
email test@example.com
|
||||
dns mock
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
}
|
||||
|
||||
example.com {
|
||||
tls {
|
||||
dns mock
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"example.com"
|
||||
],
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"provider": {
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": {
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
{
|
||||
email test@example.com
|
||||
dns mock
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
acme_dns
|
||||
}
|
||||
|
||||
example.com {
|
||||
tls {
|
||||
resolvers 9.9.9.9
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"example.com"
|
||||
],
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"9.9.9.9"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": {
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
{
|
||||
email test@example.com
|
||||
dns mock
|
||||
tls_resolvers 1.1.1.1 8.8.8.8
|
||||
acme_dns
|
||||
}
|
||||
|
||||
site1.example.com {
|
||||
}
|
||||
|
||||
site2.example.com {
|
||||
tls {
|
||||
resolvers 9.9.9.9 8.8.4.4
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"site1.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"site2.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"site2.example.com"
|
||||
],
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"9.9.9.9",
|
||||
"8.8.4.4"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": {
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"1.1.1.1",
|
||||
"8.8.8.8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
keepalive_interval 20s
|
||||
keepalive_idle 20s
|
||||
keepalive_count 10
|
||||
0rtt off
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +91,8 @@ foo.com {
|
||||
"h2",
|
||||
"h2c",
|
||||
"h3"
|
||||
]
|
||||
],
|
||||
"allow_0rtt": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
admin off
|
||||
auto_https off
|
||||
}
|
||||
|
||||
import testdata/issue_7557_invalid_subdirective_snippet.conf
|
||||
|
||||
:8080 {
|
||||
import test {
|
||||
this_is_nonsense
|
||||
}
|
||||
}
|
||||
|
||||
----------
|
||||
parsing caddyfile tokens for 'reverse_proxy': unrecognized subdirective this_is_nonsense
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import testdata/issue_7518_unused_block_panic_snippets.conf
|
||||
|
||||
example.com {
|
||||
import snippet
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Reverse_proxy": [
|
||||
"localhost:3000"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
log {
|
||||
format journald {
|
||||
wrap console
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:80 {
|
||||
respond "Hello, World!"
|
||||
}
|
||||
----------
|
||||
{
|
||||
"logging": {
|
||||
"logs": {
|
||||
"default": {
|
||||
"encoder": {
|
||||
"format": "journald",
|
||||
"wrap": {
|
||||
"format": "console"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":80"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Hello, World!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,47 @@
|
||||
:80
|
||||
|
||||
log {
|
||||
log one {
|
||||
output file /var/log/access.log {
|
||||
mode 0644
|
||||
dir_mode 0755
|
||||
roll_size 1gb
|
||||
roll_uncompressed
|
||||
roll_compression none
|
||||
roll_local_time
|
||||
roll_keep 5
|
||||
roll_keep_for 90d
|
||||
}
|
||||
}
|
||||
log two {
|
||||
output file /var/log/access-2.log {
|
||||
mode 0777
|
||||
dir_mode from_file
|
||||
roll_size 1gib
|
||||
roll_compression zstd
|
||||
roll_interval 12h
|
||||
roll_at 00:00 06:00 12:00,18:00
|
||||
roll_minutes 10 40 45,46
|
||||
roll_keep 10
|
||||
roll_keep_for 90d
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"logging": {
|
||||
"logs": {
|
||||
"default": {
|
||||
"exclude": [
|
||||
"http.log.access.log0"
|
||||
"http.log.access.one",
|
||||
"http.log.access.two"
|
||||
]
|
||||
},
|
||||
"log0": {
|
||||
"one": {
|
||||
"writer": {
|
||||
"dir_mode": "0755",
|
||||
"filename": "/var/log/access.log",
|
||||
"mode": "0644",
|
||||
"output": "file",
|
||||
"roll_compression": "none",
|
||||
"roll_gzip": false,
|
||||
"roll_keep": 5,
|
||||
"roll_keep_days": 90,
|
||||
@@ -29,7 +49,35 @@ log {
|
||||
"roll_size_mb": 954
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.log0"
|
||||
"http.log.access.one"
|
||||
]
|
||||
},
|
||||
"two": {
|
||||
"writer": {
|
||||
"dir_mode": "from_file",
|
||||
"filename": "/var/log/access-2.log",
|
||||
"mode": "0777",
|
||||
"output": "file",
|
||||
"roll_at": [
|
||||
"00:00",
|
||||
"06:00",
|
||||
"12:00",
|
||||
"18:00"
|
||||
],
|
||||
"roll_compression": "zstd",
|
||||
"roll_interval": 43200000000000,
|
||||
"roll_keep": 10,
|
||||
"roll_keep_days": 90,
|
||||
"roll_minutes": [
|
||||
10,
|
||||
40,
|
||||
45,
|
||||
46
|
||||
],
|
||||
"roll_size_mb": 1024
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.two"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -42,7 +90,7 @@ log {
|
||||
":80"
|
||||
],
|
||||
"logs": {
|
||||
"default_logger_name": "log0"
|
||||
"default_logger_name": "two"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
:80 {
|
||||
log {
|
||||
sampling {
|
||||
interval 300
|
||||
interval 5m
|
||||
first 50
|
||||
thereafter 40
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"log0": {
|
||||
"sampling": {
|
||||
"interval": 300,
|
||||
"interval": 300000000000,
|
||||
"first": 50,
|
||||
"thereafter": 40
|
||||
},
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
metrics {
|
||||
otlp
|
||||
}
|
||||
}
|
||||
:80 {
|
||||
respond "Hello"
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":80"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Hello",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"metrics": {
|
||||
"otlp": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
renewal_window_ratio 0.1666
|
||||
}
|
||||
|
||||
example.com {
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"renewal_window_ratio": 0.1666
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
{
|
||||
renewal_window_ratio 0.1666
|
||||
}
|
||||
|
||||
a.example.com {
|
||||
tls {
|
||||
renewal_window_ratio 0.25
|
||||
}
|
||||
}
|
||||
|
||||
b.example.com {
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"a.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"b.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"a.example.com"
|
||||
],
|
||||
"renewal_window_ratio": 0.25
|
||||
},
|
||||
{
|
||||
"renewal_window_ratio": 0.1666
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
:8884
|
||||
|
||||
reverse_proxy 127.0.0.1:65535 {
|
||||
lb_retries 3
|
||||
lb_retry_match expression `{rp.status_code} in [502, 503]`
|
||||
lb_retry_match expression `{rp.is_transport_error} || {rp.status_code} == 502`
|
||||
lb_retry_match expression `method('POST') && {rp.status_code} == 503`
|
||||
lb_retry_match `{rp.status_code} == 504`
|
||||
lb_retry_match `{rp.is_transport_error} && method('PUT')`
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"load_balancing": {
|
||||
"retries": 3,
|
||||
"retry_match": [
|
||||
{
|
||||
"expression": "{http.reverse_proxy.status_code} in [502, 503]"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.is_transport_error} || {http.reverse_proxy.status_code} == 502"
|
||||
},
|
||||
{
|
||||
"expression": "method('POST') \u0026\u0026 {http.reverse_proxy.status_code} == 503"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.status_code} == 504"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.is_transport_error} \u0026\u0026 method('PUT')"
|
||||
}
|
||||
]
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:65535"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
:8884
|
||||
|
||||
reverse_proxy 127.0.0.1:65535 {
|
||||
lb_retries 5
|
||||
|
||||
# request matchers (backward-compatible, non-expression)
|
||||
lb_retry_match {
|
||||
method POST PUT
|
||||
}
|
||||
lb_retry_match {
|
||||
path /foo*
|
||||
}
|
||||
lb_retry_match {
|
||||
header X-Idempotency-Key *
|
||||
}
|
||||
|
||||
# response status code via expression
|
||||
lb_retry_match {
|
||||
expression `{rp.status_code} in [502, 503, 504]`
|
||||
}
|
||||
|
||||
# response header via expression
|
||||
lb_retry_match {
|
||||
expression `{rp.header.X-Retry} == "true"`
|
||||
}
|
||||
|
||||
# CEL request functions combined with response placeholders
|
||||
lb_retry_match {
|
||||
expression `method('POST') && {rp.status_code} >= 500`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `path('/api*') && {rp.status_code} in [502, 503]`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `host('example.com') && {rp.status_code} == 503`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `query({'retry': 'true'}) && {rp.status_code} >= 500`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `header({'X-Idempotency-Key': '*'}) && {rp.status_code} in [502, 503]`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `protocol('https') && {rp.status_code} == 502`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `path_regexp('^/api/v[0-9]+/') && {rp.status_code} >= 500`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `header_regexp('Content-Type', '^application/json') && {rp.status_code} == 502`
|
||||
}
|
||||
|
||||
# transport error handling via placeholder
|
||||
lb_retry_match {
|
||||
expression `{rp.is_transport_error} || {rp.status_code} in [502, 503]`
|
||||
}
|
||||
lb_retry_match {
|
||||
expression `{rp.is_transport_error} && method('POST')`
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"load_balancing": {
|
||||
"retries": 5,
|
||||
"retry_match": [
|
||||
{
|
||||
"method": [
|
||||
"POST",
|
||||
"PUT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": [
|
||||
"/foo*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"X-Idempotency-Key": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.status_code} in [502, 503, 504]"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.header.X-Retry} == \"true\""
|
||||
},
|
||||
{
|
||||
"expression": "method('POST') \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500"
|
||||
},
|
||||
{
|
||||
"expression": "path('/api*') \u0026\u0026 {http.reverse_proxy.status_code} in [502, 503]"
|
||||
},
|
||||
{
|
||||
"expression": "host('example.com') \u0026\u0026 {http.reverse_proxy.status_code} == 503"
|
||||
},
|
||||
{
|
||||
"expression": "query({'retry': 'true'}) \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500"
|
||||
},
|
||||
{
|
||||
"expression": "header({'X-Idempotency-Key': '*'}) \u0026\u0026 {http.reverse_proxy.status_code} in [502, 503]"
|
||||
},
|
||||
{
|
||||
"expression": "protocol('https') \u0026\u0026 {http.reverse_proxy.status_code} == 502"
|
||||
},
|
||||
{
|
||||
"expression": "path_regexp('^/api/v[0-9]+/') \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500"
|
||||
},
|
||||
{
|
||||
"expression": "header_regexp('Content-Type', '^application/json') \u0026\u0026 {http.reverse_proxy.status_code} == 502"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.is_transport_error} || {http.reverse_proxy.status_code} in [502, 503]"
|
||||
},
|
||||
{
|
||||
"expression": "{http.reverse_proxy.is_transport_error} \u0026\u0026 method('POST')"
|
||||
}
|
||||
]
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:65535"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
https://example.com {
|
||||
reverse_proxy https://localhost:54321 {
|
||||
stream_buffer_size 8KB
|
||||
}
|
||||
}
|
||||
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"stream_buffer_size": 8000,
|
||||
"transport": {
|
||||
"protocol": "http",
|
||||
"tls": {}
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "localhost:54321"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
dns mock foo
|
||||
acme_dns mock bar
|
||||
}
|
||||
|
||||
localhost {
|
||||
tls {
|
||||
resolvers 8.8.8.8 8.8.4.4
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"localhost"
|
||||
],
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"provider": {
|
||||
"argument": "bar",
|
||||
"name": "mock"
|
||||
},
|
||||
"resolvers": [
|
||||
"8.8.8.8",
|
||||
"8.8.4.4"
|
||||
]
|
||||
}
|
||||
},
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"issuers": [
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"provider": {
|
||||
"argument": "bar",
|
||||
"name": "mock"
|
||||
}
|
||||
}
|
||||
},
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dns": {
|
||||
"argument": "foo",
|
||||
"name": "mock"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,6 @@ b.com {
|
||||
"via": "http"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"subjects": [
|
||||
"b.com"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
# example from https://github.com/caddyserver/caddy/issues/7559
|
||||
*.test.local {
|
||||
tls {
|
||||
get_certificate http http://cert-server:9000/certs
|
||||
}
|
||||
respond "wildcard"
|
||||
}
|
||||
|
||||
# certificate for this subdomain is covered by wildcard above
|
||||
subdomain.test.local {
|
||||
respond "subdomain"
|
||||
}
|
||||
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"subdomain.test.local"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "subdomain",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"*.test.local"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "wildcard",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"*.test.local"
|
||||
],
|
||||
"get_certificate": [
|
||||
{
|
||||
"url": "http://cert-server:9000/certs",
|
||||
"via": "http"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
localhost
|
||||
|
||||
respond "hello from localhost"
|
||||
tls {
|
||||
client_auth {
|
||||
mode request
|
||||
trust_pool combined {
|
||||
source inline {
|
||||
trust_der MIIDSzCCAjOgAwIBAgIUfIRObjWNUA4jxQ/0x8BOCvE2Vw4wDQYJKoZIhvcNAQELBQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMTkwODI4MTYyNTU5WhcNMjkwODI1MTYyNTU5WjAWMRQwEgYDVQQDDAtFYXN5LVJTQSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK5m5elxhQfMp/3aVJ4JnpN9PUSz6LlP6LePAPFU7gqohVVFVtDkChJAG3FNkNQNlieVTja/bgH9IcC6oKbROwdY1h0MvNV8AHHigvl03WuJD8g2ReVFXXwsnrPmKXCFzQyMI6TYk3m2gYrXsZOU1GLnfMRC3KAMRgE2F45twOs9hqG169YJ6mM2eQjzjCHWI6S2/iUYvYxRkCOlYUbLsMD/AhgAf1plzg6LPqNxtdlwxZnA0ytgkmhK67HtzJu0+ovUCsMv0RwcMhsEo9T8nyFAGt9XLZ63X5WpBCTUApaAUhnG0XnerjmUWb6eUWw4zev54sEfY5F3x002iQaW6cECAwEAAaOBkDCBjTAdBgNVHQ4EFgQU4CBUbZsS2GaNIkGRz/cBsD5ivjswUQYDVR0jBEowSIAU4CBUbZsS2GaNIkGRz/cBsD5ivjuhGqQYMBYxFDASBgNVBAMMC0Vhc3ktUlNBIENBghR8hE5uNY1QDiPFD/THwE4K8TZXDjAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAKB3V4HIzoiO/Ch6WMj9bLJ2FGbpkMrcb/Eq01hT5zcfKD66lVS1MlK+cRL446Z2b2KDP1oFyVs+qmrmtdwrWgD+nfe2sBmmIHo9m9KygMkEOfG3MghGTEcS+0cTKEcoHYWYyOqQh6jnedXY8Cdm4GM1hAc9MiL3/sqV8YCVSLNnkoNysmr06/rZ0MCUZPGUtRmfd0heWhrfzAKw2HLgX+RAmpOE2MZqWcjvqKGyaRiaZks4nJkP6521aC2Lgp0HhCz1j8/uQ5ldoDszCnu/iro0NAsNtudTMD+YoLQxLqdleIh6CW+illc2VdXwj7mn6J04yns9jfE2jRjW/yTLFuQ==
|
||||
}
|
||||
source file {
|
||||
pem_file ../caddy.ca.cer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "hello from localhost",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
],
|
||||
"tls_connection_policies": [
|
||||
{
|
||||
"match": {
|
||||
"sni": [
|
||||
"localhost"
|
||||
]
|
||||
},
|
||||
"client_authentication": {
|
||||
"ca": {
|
||||
"provider": "combined",
|
||||
"sources": [
|
||||
{
|
||||
"provider": "inline",
|
||||
"trusted_ca_certs": [
|
||||
"MIIDSzCCAjOgAwIBAgIUfIRObjWNUA4jxQ/0x8BOCvE2Vw4wDQYJKoZIhvcNAQELBQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMTkwODI4MTYyNTU5WhcNMjkwODI1MTYyNTU5WjAWMRQwEgYDVQQDDAtFYXN5LVJTQSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK5m5elxhQfMp/3aVJ4JnpN9PUSz6LlP6LePAPFU7gqohVVFVtDkChJAG3FNkNQNlieVTja/bgH9IcC6oKbROwdY1h0MvNV8AHHigvl03WuJD8g2ReVFXXwsnrPmKXCFzQyMI6TYk3m2gYrXsZOU1GLnfMRC3KAMRgE2F45twOs9hqG169YJ6mM2eQjzjCHWI6S2/iUYvYxRkCOlYUbLsMD/AhgAf1plzg6LPqNxtdlwxZnA0ytgkmhK67HtzJu0+ovUCsMv0RwcMhsEo9T8nyFAGt9XLZ63X5WpBCTUApaAUhnG0XnerjmUWb6eUWw4zev54sEfY5F3x002iQaW6cECAwEAAaOBkDCBjTAdBgNVHQ4EFgQU4CBUbZsS2GaNIkGRz/cBsD5ivjswUQYDVR0jBEowSIAU4CBUbZsS2GaNIkGRz/cBsD5ivjuhGqQYMBYxFDASBgNVBAMMC0Vhc3ktUlNBIENBghR8hE5uNY1QDiPFD/THwE4K8TZXDjAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAKB3V4HIzoiO/Ch6WMj9bLJ2FGbpkMrcb/Eq01hT5zcfKD66lVS1MlK+cRL446Z2b2KDP1oFyVs+qmrmtdwrWgD+nfe2sBmmIHo9m9KygMkEOfG3MghGTEcS+0cTKEcoHYWYyOqQh6jnedXY8Cdm4GM1hAc9MiL3/sqV8YCVSLNnkoNysmr06/rZ0MCUZPGUtRmfd0heWhrfzAKw2HLgX+RAmpOE2MZqWcjvqKGyaRiaZks4nJkP6521aC2Lgp0HhCz1j8/uQ5ldoDszCnu/iro0NAsNtudTMD+YoLQxLqdleIh6CW+illc2VdXwj7mn6J04yns9jfE2jRjW/yTLFuQ=="
|
||||
]
|
||||
},
|
||||
{
|
||||
"pem_files": [
|
||||
"../caddy.ca.cer"
|
||||
],
|
||||
"provider": "file"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mode": "request"
|
||||
}
|
||||
},
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
localhost
|
||||
|
||||
respond "hello from localhost"
|
||||
tls {
|
||||
client_auth {
|
||||
mode require_and_verify
|
||||
trust_pool combined {
|
||||
source inline {
|
||||
trust_der MIIDSzCCAjOgAwIBAgIUfIRObjWNUA4jxQ/0x8BOCvE2Vw4wDQYJKoZIhvcNAQELBQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMTkwODI4MTYyNTU5WhcNMjkwODI1MTYyNTU5WjAWMRQwEgYDVQQDDAtFYXN5LVJTQSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK5m5elxhQfMp/3aVJ4JnpN9PUSz6LlP6LePAPFU7gqohVVFVtDkChJAG3FNkNQNlieVTja/bgH9IcC6oKbROwdY1h0MvNV8AHHigvl03WuJD8g2ReVFXXwsnrPmKXCFzQyMI6TYk3m2gYrXsZOU1GLnfMRC3KAMRgE2F45twOs9hqG169YJ6mM2eQjzjCHWI6S2/iUYvYxRkCOlYUbLsMD/AhgAf1plzg6LPqNxtdlwxZnA0ytgkmhK67HtzJu0+ovUCsMv0RwcMhsEo9T8nyFAGt9XLZ63X5WpBCTUApaAUhnG0XnerjmUWb6eUWw4zev54sEfY5F3x002iQaW6cECAwEAAaOBkDCBjTAdBgNVHQ4EFgQU4CBUbZsS2GaNIkGRz/cBsD5ivjswUQYDVR0jBEowSIAU4CBUbZsS2GaNIkGRz/cBsD5ivjuhGqQYMBYxFDASBgNVBAMMC0Vhc3ktUlNBIENBghR8hE5uNY1QDiPFD/THwE4K8TZXDjAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAKB3V4HIzoiO/Ch6WMj9bLJ2FGbpkMrcb/Eq01hT5zcfKD66lVS1MlK+cRL446Z2b2KDP1oFyVs+qmrmtdwrWgD+nfe2sBmmIHo9m9KygMkEOfG3MghGTEcS+0cTKEcoHYWYyOqQh6jnedXY8Cdm4GM1hAc9MiL3/sqV8YCVSLNnkoNysmr06/rZ0MCUZPGUtRmfd0heWhrfzAKw2HLgX+RAmpOE2MZqWcjvqKGyaRiaZks4nJkP6521aC2Lgp0HhCz1j8/uQ5ldoDszCnu/iro0NAsNtudTMD+YoLQxLqdleIh6CW+illc2VdXwj7mn6J04yns9jfE2jRjW/yTLFuQ==
|
||||
}
|
||||
source pki_root {
|
||||
authority local
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "hello from localhost",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
],
|
||||
"tls_connection_policies": [
|
||||
{
|
||||
"match": {
|
||||
"sni": [
|
||||
"localhost"
|
||||
]
|
||||
},
|
||||
"client_authentication": {
|
||||
"ca": {
|
||||
"provider": "combined",
|
||||
"sources": [
|
||||
{
|
||||
"provider": "inline",
|
||||
"trusted_ca_certs": [
|
||||
"MIIDSzCCAjOgAwIBAgIUfIRObjWNUA4jxQ/0x8BOCvE2Vw4wDQYJKoZIhvcNAQELBQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMTkwODI4MTYyNTU5WhcNMjkwODI1MTYyNTU5WjAWMRQwEgYDVQQDDAtFYXN5LVJTQSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK5m5elxhQfMp/3aVJ4JnpN9PUSz6LlP6LePAPFU7gqohVVFVtDkChJAG3FNkNQNlieVTja/bgH9IcC6oKbROwdY1h0MvNV8AHHigvl03WuJD8g2ReVFXXwsnrPmKXCFzQyMI6TYk3m2gYrXsZOU1GLnfMRC3KAMRgE2F45twOs9hqG169YJ6mM2eQjzjCHWI6S2/iUYvYxRkCOlYUbLsMD/AhgAf1plzg6LPqNxtdlwxZnA0ytgkmhK67HtzJu0+ovUCsMv0RwcMhsEo9T8nyFAGt9XLZ63X5WpBCTUApaAUhnG0XnerjmUWb6eUWw4zev54sEfY5F3x002iQaW6cECAwEAAaOBkDCBjTAdBgNVHQ4EFgQU4CBUbZsS2GaNIkGRz/cBsD5ivjswUQYDVR0jBEowSIAU4CBUbZsS2GaNIkGRz/cBsD5ivjuhGqQYMBYxFDASBgNVBAMMC0Vhc3ktUlNBIENBghR8hE5uNY1QDiPFD/THwE4K8TZXDjAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAKB3V4HIzoiO/Ch6WMj9bLJ2FGbpkMrcb/Eq01hT5zcfKD66lVS1MlK+cRL446Z2b2KDP1oFyVs+qmrmtdwrWgD+nfe2sBmmIHo9m9KygMkEOfG3MghGTEcS+0cTKEcoHYWYyOqQh6jnedXY8Cdm4GM1hAc9MiL3/sqV8YCVSLNnkoNysmr06/rZ0MCUZPGUtRmfd0heWhrfzAKw2HLgX+RAmpOE2MZqWcjvqKGyaRiaZks4nJkP6521aC2Lgp0HhCz1j8/uQ5ldoDszCnu/iro0NAsNtudTMD+YoLQxLqdleIh6CW+illc2VdXwj7mn6J04yns9jfE2jRjW/yTLFuQ=="
|
||||
]
|
||||
},
|
||||
{
|
||||
"authority": [
|
||||
"local"
|
||||
],
|
||||
"provider": "pki_root"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mode": "require_and_verify"
|
||||
}
|
||||
},
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
localhost
|
||||
|
||||
respond "hello from localhost"
|
||||
tls {
|
||||
client_auth {
|
||||
mode request
|
||||
trust_pool system
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "hello from localhost",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
],
|
||||
"tls_connection_policies": [
|
||||
{
|
||||
"match": {
|
||||
"sni": [
|
||||
"localhost"
|
||||
]
|
||||
},
|
||||
"client_authentication": {
|
||||
"ca": {
|
||||
"provider": "system"
|
||||
},
|
||||
"mode": "request"
|
||||
}
|
||||
},
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
)
|
||||
|
||||
// TestForwardAuthCopyHeadersStripsClientHeaders is a regression test for the
|
||||
// header injection vulnerability in forward_auth copy_headers.
|
||||
//
|
||||
// When the auth service returns 200 OK without one of the copy_headers headers,
|
||||
// the MatchNot guard skips the Set operation. Before this fix, the original
|
||||
// client-supplied header survived unchanged into the backend request, allowing
|
||||
// privilege escalation with only a valid (non-privileged) bearer token. After
|
||||
// the fix, an unconditional delete route runs first, so the backend always
|
||||
// sees an absent header rather than the attacker-supplied value.
|
||||
func TestForwardAuthCopyHeadersStripsClientHeaders(t *testing.T) {
|
||||
// Mock auth service: accepts any Bearer token, returns 200 OK with NO
|
||||
// identity headers. This is the stateless JWT validator pattern that
|
||||
// triggers the vulnerability.
|
||||
authSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.Header.Get("Authorization"), "Bearer ") {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}))
|
||||
defer authSrv.Close()
|
||||
|
||||
// Mock backend: records the identity headers it receives. A real application
|
||||
// would use X-User-Id / X-User-Role to make authorization decisions.
|
||||
type received struct{ userID, userRole string }
|
||||
var (
|
||||
mu sync.Mutex
|
||||
last received
|
||||
)
|
||||
backendSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
last = received{
|
||||
userID: r.Header.Get("X-User-Id"),
|
||||
userRole: r.Header.Get("X-User-Role"),
|
||||
}
|
||||
mu.Unlock()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "ok")
|
||||
}))
|
||||
defer backendSrv.Close()
|
||||
|
||||
authAddr := strings.TrimPrefix(authSrv.URL, "http://")
|
||||
backendAddr := strings.TrimPrefix(backendSrv.URL, "http://")
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
forward_auth %s {
|
||||
uri /
|
||||
copy_headers X-User-Id X-User-Role
|
||||
}
|
||||
reverse_proxy %s
|
||||
}
|
||||
`, authAddr, backendAddr), "caddyfile")
|
||||
|
||||
// Case 1: no token. Auth must still reject the request even when the client
|
||||
// includes identity headers. This confirms the auth check is not bypassed.
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req.Header.Set("X-User-Id", "injected")
|
||||
req.Header.Set("X-User-Role", "injected")
|
||||
resp := tester.AssertResponseCode(req, http.StatusUnauthorized)
|
||||
resp.Body.Close()
|
||||
|
||||
// Case 2: valid token, no injected headers. The backend should see absent
|
||||
// identity headers (the auth service never returns them).
|
||||
req, _ = http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req.Header.Set("Authorization", "Bearer token123")
|
||||
tester.AssertResponse(req, http.StatusOK, "ok")
|
||||
mu.Lock()
|
||||
gotID, gotRole := last.userID, last.userRole
|
||||
mu.Unlock()
|
||||
if gotID != "" {
|
||||
t.Errorf("baseline: X-User-Id should be absent, got %q", gotID)
|
||||
}
|
||||
if gotRole != "" {
|
||||
t.Errorf("baseline: X-User-Role should be absent, got %q", gotRole)
|
||||
}
|
||||
|
||||
// Case 3 (the security regression): valid token plus forged identity headers.
|
||||
// The fix must strip those values so the backend never sees them.
|
||||
req, _ = http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req.Header.Set("Authorization", "Bearer token123")
|
||||
req.Header.Set("X-User-Id", "admin") // forged
|
||||
req.Header.Set("X-User-Role", "superadmin") // forged
|
||||
tester.AssertResponse(req, http.StatusOK, "ok")
|
||||
mu.Lock()
|
||||
gotID, gotRole = last.userID, last.userRole
|
||||
mu.Unlock()
|
||||
if gotID != "" {
|
||||
t.Errorf("injection: X-User-Id must be stripped, got %q", gotID)
|
||||
}
|
||||
if gotRole != "" {
|
||||
t.Errorf("injection: X-User-Role must be stripped, got %q", gotRole)
|
||||
}
|
||||
}
|
||||
|
||||
// TestForwardAuthCopyHeadersAuthResponseWins verifies that when the auth
|
||||
// service does include a copy_headers header in its response, that value
|
||||
// is forwarded to the backend and takes precedence over any client-supplied
|
||||
// value for the same header.
|
||||
func TestForwardAuthCopyHeadersAuthResponseWins(t *testing.T) {
|
||||
const wantUserID = "service-user-42"
|
||||
const wantUserRole = "editor"
|
||||
|
||||
// Auth service: accepts bearer token and sets identity headers.
|
||||
authSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.Header.Get("Authorization"), "Bearer ") {
|
||||
w.Header().Set("X-User-Id", wantUserID)
|
||||
w.Header().Set("X-User-Role", wantUserRole)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}))
|
||||
defer authSrv.Close()
|
||||
|
||||
type received struct{ userID, userRole string }
|
||||
var (
|
||||
mu sync.Mutex
|
||||
last received
|
||||
)
|
||||
backendSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
last = received{
|
||||
userID: r.Header.Get("X-User-Id"),
|
||||
userRole: r.Header.Get("X-User-Role"),
|
||||
}
|
||||
mu.Unlock()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "ok")
|
||||
}))
|
||||
defer backendSrv.Close()
|
||||
|
||||
authAddr := strings.TrimPrefix(authSrv.URL, "http://")
|
||||
backendAddr := strings.TrimPrefix(backendSrv.URL, "http://")
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
forward_auth %s {
|
||||
uri /
|
||||
copy_headers X-User-Id X-User-Role
|
||||
}
|
||||
reverse_proxy %s
|
||||
}
|
||||
`, authAddr, backendAddr), "caddyfile")
|
||||
|
||||
// The client sends forged headers; the auth service overrides them with
|
||||
// its own values. The backend must receive the auth service values.
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req.Header.Set("Authorization", "Bearer token123")
|
||||
req.Header.Set("X-User-Id", "forged-id") // must be overwritten
|
||||
req.Header.Set("X-User-Role", "forged-role") // must be overwritten
|
||||
tester.AssertResponse(req, http.StatusOK, "ok")
|
||||
|
||||
mu.Lock()
|
||||
gotID, gotRole := last.userID, last.userRole
|
||||
mu.Unlock()
|
||||
if gotID != wantUserID {
|
||||
t.Errorf("X-User-Id: want %q, got %q", wantUserID, gotID)
|
||||
}
|
||||
if gotRole != wantUserRole {
|
||||
t.Errorf("X-User-Role: want %q, got %q", wantUserRole, gotRole)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -54,7 +54,7 @@ func TestHTTPRedirectWrapperWithLargeUpload(t *testing.T) {
|
||||
const uploadSize = (1024 * 1024) + 1 // 1 MB + 1 byte
|
||||
// 1 more than an MB
|
||||
body := make([]byte, uploadSize)
|
||||
rand.New(rand.NewSource(0)).Read(body)
|
||||
rand.NewChaCha8([32]byte{}).Read(body)
|
||||
|
||||
tester := setupListenerWrapperTest(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestLeafCertLifetimeLessThanIntermediate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "json", "certificate lifetime (168h0m0s) should be less than intermediate certificate lifetime (168h0m0s)")
|
||||
`, "json", "should be less than intermediate certificate lifetime")
|
||||
}
|
||||
|
||||
func TestIntermediateLifetimeLessThanRoot(t *testing.T) {
|
||||
@@ -103,5 +103,5 @@ func TestIntermediateLifetimeLessThanRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "json", "intermediate certificate lifetime must be less than root certificate lifetime (86400h0m0s)")
|
||||
`, "json", "intermediate certificate lifetime must be less than actual root certificate lifetime")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,595 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Integration tests for Caddy's PROXY protocol support, covering two distinct
|
||||
// roles that Caddy can play:
|
||||
//
|
||||
// 1. As a PROXY protocol *sender* (reverse proxy outbound transport):
|
||||
// Caddy receives an inbound request from a test client and the
|
||||
// reverse_proxy handler forwards it to an upstream with a PROXY protocol
|
||||
// header (v1 or v2) prepended to the connection. A lightweight backend
|
||||
// built with go-proxyproto validates that the header was received and
|
||||
// carries the correct client address.
|
||||
//
|
||||
// Transport versions tested:
|
||||
// - "1.1" -> plain HTTP/1.1 to the upstream
|
||||
// - "h2c" -> HTTP/2 cleartext (h2c) to the upstream (regression for #7529)
|
||||
// - "2" -> HTTP/2 over TLS (h2) to the upstream
|
||||
//
|
||||
// For each transport version both PROXY protocol v1 and v2 are exercised.
|
||||
//
|
||||
// HTTP/3 (h3) is not included because it uses QUIC/UDP and therefore
|
||||
// bypasses the TCP-level dialContext that injects PROXY protocol headers;
|
||||
// there is no meaningful h3 + proxy protocol sender combination to test.
|
||||
//
|
||||
// 2. As a PROXY protocol *receiver* (server-side listener wrapper):
|
||||
// A raw TCP client dials Caddy directly, injects a PROXY v2 header
|
||||
// spoofing a source address, and sends a normal HTTP/1.1 request. The
|
||||
// Caddy server is configured with the proxy_protocol listener wrapper and
|
||||
// is expected to surface the spoofed address via the
|
||||
// {http.request.remote.host} placeholder.
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
goproxy "github.com/pires/go-proxyproto"
|
||||
"golang.org/x/net/http2"
|
||||
"golang.org/x/net/http2/h2c"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
)
|
||||
|
||||
// proxyProtoBackend is a minimal HTTP server that sits behind a
|
||||
// go-proxyproto listener and records the source address that was
|
||||
// delivered in the PROXY header for each request.
|
||||
type proxyProtoBackend struct {
|
||||
mu sync.Mutex
|
||||
headerAddrs []string // host:port strings extracted from each PROXY header
|
||||
|
||||
ln net.Listener
|
||||
srv *http.Server
|
||||
}
|
||||
|
||||
// newProxyProtoBackend starts a TCP listener wrapped with go-proxyproto on a
|
||||
// random local port and serves requests with a simple "OK" body. The PROXY
|
||||
// header source addresses are accumulated in headerAddrs so tests can
|
||||
// inspect them.
|
||||
func newProxyProtoBackend(t *testing.T) *proxyProtoBackend {
|
||||
t.Helper()
|
||||
|
||||
b := &proxyProtoBackend{}
|
||||
|
||||
rawLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("backend: listen: %v", err)
|
||||
}
|
||||
|
||||
// Wrap with go-proxyproto so the PROXY header is stripped and parsed
|
||||
// before the HTTP server sees the connection. We use REQUIRE so that a
|
||||
// missing header returns an error instead of silently passing through.
|
||||
pLn := &goproxy.Listener{
|
||||
Listener: rawLn,
|
||||
Policy: func(_ net.Addr) (goproxy.Policy, error) {
|
||||
return goproxy.REQUIRE, nil
|
||||
},
|
||||
}
|
||||
b.ln = pLn
|
||||
|
||||
// Wrap the handler with h2c support so the backend can speak HTTP/2
|
||||
// cleartext (h2c) as well as plain HTTP/1.1. Without this, Caddy's
|
||||
// reverse proxy would receive a 'frame too large' error when the
|
||||
// upstream transport is configured to use h2c.
|
||||
h2Server := &http2.Server{}
|
||||
handlerFn := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// go-proxyproto has already updated the net.Conn's remote
|
||||
// address to the value from the PROXY header; the HTTP server
|
||||
// surfaces it in r.RemoteAddr.
|
||||
b.mu.Lock()
|
||||
b.headerAddrs = append(b.headerAddrs, r.RemoteAddr)
|
||||
b.mu.Unlock()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprint(w, "OK")
|
||||
})
|
||||
|
||||
b.srv = &http.Server{
|
||||
Handler: h2c.NewHandler(handlerFn, h2Server),
|
||||
}
|
||||
|
||||
go b.srv.Serve(pLn) //nolint:errcheck
|
||||
t.Cleanup(func() {
|
||||
_ = b.srv.Close()
|
||||
_ = rawLn.Close()
|
||||
})
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// addr returns the listening address (host:port) of the backend.
|
||||
func (b *proxyProtoBackend) addr() string {
|
||||
return b.ln.Addr().String()
|
||||
}
|
||||
|
||||
// recordedAddrs returns a snapshot of all PROXY-header source addresses seen
|
||||
// so far.
|
||||
func (b *proxyProtoBackend) recordedAddrs() []string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
cp := make([]string, len(b.headerAddrs))
|
||||
copy(cp, b.headerAddrs)
|
||||
return cp
|
||||
}
|
||||
|
||||
// tlsProxyProtoBackend is a TLS-enabled backend that sits behind a
|
||||
// go-proxyproto listener. The PROXY header is stripped before the TLS
|
||||
// handshake so the layer order on a connection is:
|
||||
//
|
||||
// raw TCP → go-proxyproto (strips PROXY header) → TLS handshake → HTTP/2
|
||||
type tlsProxyProtoBackend struct {
|
||||
mu sync.Mutex
|
||||
headerAddrs []string
|
||||
|
||||
srv *httptest.Server
|
||||
}
|
||||
|
||||
// newTLSProxyProtoBackend starts a TLS listener that first reads and strips
|
||||
// PROXY protocol headers (go-proxyproto, REQUIRE policy) and then performs a
|
||||
// TLS handshake. The backend speaks HTTP/2 over TLS (h2).
|
||||
//
|
||||
// The certificate is the standard self-signed certificate generated by
|
||||
// httptest.Server; the Caddy transport must be configured with
|
||||
// insecure_skip_verify: true to trust it.
|
||||
func newTLSProxyProtoBackend(t *testing.T) *tlsProxyProtoBackend {
|
||||
t.Helper()
|
||||
|
||||
b := &tlsProxyProtoBackend{}
|
||||
|
||||
handlerFn := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
b.mu.Lock()
|
||||
b.headerAddrs = append(b.headerAddrs, r.RemoteAddr)
|
||||
b.mu.Unlock()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprint(w, "OK")
|
||||
})
|
||||
|
||||
rawLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("tlsBackend: listen: %v", err)
|
||||
}
|
||||
|
||||
// Wrap with go-proxyproto so the PROXY header is consumed before TLS.
|
||||
pLn := &goproxy.Listener{
|
||||
Listener: rawLn,
|
||||
Policy: func(_ net.Addr) (goproxy.Policy, error) {
|
||||
return goproxy.REQUIRE, nil
|
||||
},
|
||||
}
|
||||
|
||||
// httptest.NewUnstartedServer lets us replace the listener before
|
||||
// calling StartTLS(), which wraps our proxyproto listener with
|
||||
// tls.NewListener. This gives us the right layer order.
|
||||
b.srv = httptest.NewUnstartedServer(handlerFn)
|
||||
b.srv.Listener = pLn
|
||||
|
||||
// StartTLS enables HTTP/2 on the server automatically.
|
||||
b.srv.StartTLS()
|
||||
|
||||
t.Cleanup(func() {
|
||||
b.srv.Close()
|
||||
})
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// addr returns the listening address (host:port) of the TLS backend.
|
||||
func (b *tlsProxyProtoBackend) addr() string {
|
||||
return b.srv.Listener.Addr().String()
|
||||
}
|
||||
|
||||
// tlsConfig returns the *tls.Config used by the backend server.
|
||||
// Tests can use it to verify cert details if needed.
|
||||
func (b *tlsProxyProtoBackend) tlsConfig() *tls.Config {
|
||||
return b.srv.TLS
|
||||
}
|
||||
|
||||
// recordedAddrs returns a snapshot of all PROXY-header source addresses.
|
||||
func (b *tlsProxyProtoBackend) recordedAddrs() []string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
cp := make([]string, len(b.headerAddrs))
|
||||
copy(cp, b.headerAddrs)
|
||||
return cp
|
||||
}
|
||||
|
||||
// proxyProtoTLSConfig builds a Caddy JSON configuration that proxies to a TLS
|
||||
// upstream with PROXY protocol. The transport uses insecure_skip_verify so
|
||||
// the self-signed certificate generated by httptest.Server is accepted.
|
||||
func proxyProtoTLSConfig(listenPort int, backendAddr, ppVersion string, transportVersions []string) string {
|
||||
versionsJSON, _ := json.Marshal(transportVersions)
|
||||
return fmt.Sprintf(`{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
"certificate_authorities": {
|
||||
"local": {
|
||||
"install_trust": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"proxy": {
|
||||
"listen": [":%d"],
|
||||
"automatic_https": {
|
||||
"disable": true
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [{"dial": "%s"}],
|
||||
"transport": {
|
||||
"protocol": "http",
|
||||
"proxy_protocol": "%s",
|
||||
"versions": %s,
|
||||
"tls": {
|
||||
"insecure_skip_verify": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, listenPort, backendAddr, ppVersion, string(versionsJSON))
|
||||
}
|
||||
|
||||
// testTLSProxyProtocolMatrix is the shared implementation for TLS-based proxy
|
||||
// protocol tests. It mirrors testProxyProtocolMatrix but uses a TLS backend.
|
||||
func testTLSProxyProtocolMatrix(t *testing.T, ppVersion string, transportVersions []string, numRequests int) {
|
||||
t.Helper()
|
||||
|
||||
backend := newTLSProxyProtoBackend(t)
|
||||
listenPort := freePort(t)
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.WithDefaultOverrides(caddytest.Config{
|
||||
AdminPort: 2999,
|
||||
})
|
||||
cfg := proxyProtoTLSConfig(listenPort, backend.addr(), ppVersion, transportVersions)
|
||||
tester.InitServer(cfg, "json")
|
||||
|
||||
proxyURL := fmt.Sprintf("http://127.0.0.1:%d/", listenPort)
|
||||
|
||||
for i := 0; i < numRequests; i++ {
|
||||
resp, err := tester.Client.Get(proxyURL)
|
||||
if err != nil {
|
||||
t.Fatalf("request %d/%d: GET %s: %v", i+1, numRequests, proxyURL, err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("request %d/%d: expected status 200, got %d", i+1, numRequests, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
addrs := backend.recordedAddrs()
|
||||
if len(addrs) == 0 {
|
||||
t.Fatalf("backend recorded no PROXY protocol addresses (expected at least 1)")
|
||||
}
|
||||
|
||||
for i, addr := range addrs {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
t.Errorf("addr[%d] %q: SplitHostPort: %v", i, addr, err)
|
||||
continue
|
||||
}
|
||||
if host != "127.0.0.1" {
|
||||
t.Errorf("addr[%d]: expected source 127.0.0.1, got %q", i, host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// proxyProtoConfig builds a Caddy JSON configuration that:
|
||||
// - listens on listenPort for inbound HTTP requests
|
||||
// - proxies them to backendAddr with PROXY protocol ppVersion ("v1"/"v2")
|
||||
// - uses the given transport versions (e.g. ["1.1"] or ["h2c"])
|
||||
func proxyProtoConfig(listenPort int, backendAddr, ppVersion string, transportVersions []string) string {
|
||||
versionsJSON, _ := json.Marshal(transportVersions)
|
||||
return fmt.Sprintf(`{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
"certificate_authorities": {
|
||||
"local": {
|
||||
"install_trust": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"proxy": {
|
||||
"listen": [":%d"],
|
||||
"automatic_https": {
|
||||
"disable": true
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [{"dial": "%s"}],
|
||||
"transport": {
|
||||
"protocol": "http",
|
||||
"proxy_protocol": "%s",
|
||||
"versions": %s
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, listenPort, backendAddr, ppVersion, string(versionsJSON))
|
||||
}
|
||||
|
||||
// freePort returns a free local TCP port by binding briefly and releasing it.
|
||||
func freePort(t *testing.T) int {
|
||||
t.Helper()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("freePort: %v", err)
|
||||
}
|
||||
port := ln.Addr().(*net.TCPAddr).Port
|
||||
_ = ln.Close()
|
||||
return port
|
||||
}
|
||||
|
||||
// TestProxyProtocolV1WithH1 verifies that PROXY protocol v1 headers are sent
|
||||
// correctly when the transport uses HTTP/1.1 to the upstream.
|
||||
func TestProxyProtocolV1WithH1(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, "v1", []string{"1.1"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV2WithH1 verifies that PROXY protocol v2 headers are sent
|
||||
// correctly when the transport uses HTTP/1.1 to the upstream.
|
||||
func TestProxyProtocolV2WithH1(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, "v2", []string{"1.1"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV1WithH2C verifies that PROXY protocol v1 headers are sent
|
||||
// correctly when the transport uses h2c (HTTP/2 cleartext) to the upstream.
|
||||
func TestProxyProtocolV1WithH2C(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, "v1", []string{"h2c"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV2WithH2C verifies that PROXY protocol v2 headers are sent
|
||||
// correctly when the transport uses h2c (HTTP/2 cleartext) to the upstream.
|
||||
// This is the primary regression test for github.com/caddyserver/caddy/issues/7529:
|
||||
// before the fix, the h2 transport opened a new TCP connection per request
|
||||
// (because req.URL.Host was mangled differently for each request due to the
|
||||
// varying client port), which caused file-descriptor exhaustion under load.
|
||||
func TestProxyProtocolV2WithH2C(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, "v2", []string{"h2c"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV2WithH2CMultipleRequests sends several sequential requests
|
||||
// through the h2c + PROXY-protocol path and confirms that:
|
||||
// 1. Every request receives a 200 response (no connection exhaustion).
|
||||
// 2. The backend received at least one PROXY header (connection was reused).
|
||||
//
|
||||
// This is the core regression guard for issue #7529: without the fix, a new
|
||||
// TCP connection was opened per request, quickly exhausting file descriptors.
|
||||
func TestProxyProtocolV2WithH2CMultipleRequests(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, "v2", []string{"h2c"}, 5)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV1WithH2 verifies that PROXY protocol v1 headers are sent
|
||||
// correctly when the transport uses HTTP/2 over TLS (h2) to the upstream.
|
||||
func TestProxyProtocolV1WithH2(t *testing.T) {
|
||||
testTLSProxyProtocolMatrix(t, "v1", []string{"2"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolV2WithH2 verifies that PROXY protocol v2 headers are sent
|
||||
// correctly when the transport uses HTTP/2 over TLS (h2) to the upstream.
|
||||
func TestProxyProtocolV2WithH2(t *testing.T) {
|
||||
testTLSProxyProtocolMatrix(t, "v2", []string{"2"}, 1)
|
||||
}
|
||||
|
||||
// TestProxyProtocolServerAndProxy is an end-to-end matrix test that exercises
|
||||
// all combinations of PROXY protocol version x transport version.
|
||||
func TestProxyProtocolServerAndProxy(t *testing.T) {
|
||||
plainTests := []struct {
|
||||
name string
|
||||
ppVersion string
|
||||
transportVersions []string
|
||||
numRequests int
|
||||
}{
|
||||
{"h1-v1", "v1", []string{"1.1"}, 3},
|
||||
{"h1-v2", "v2", []string{"1.1"}, 3},
|
||||
{"h2c-v1", "v1", []string{"h2c"}, 3},
|
||||
{"h2c-v2", "v2", []string{"h2c"}, 3},
|
||||
}
|
||||
for _, tc := range plainTests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
testProxyProtocolMatrix(t, tc.ppVersion, tc.transportVersions, tc.numRequests)
|
||||
})
|
||||
}
|
||||
|
||||
tlsTests := []struct {
|
||||
name string
|
||||
ppVersion string
|
||||
transportVersions []string
|
||||
numRequests int
|
||||
}{
|
||||
{"h2-v1", "v1", []string{"2"}, 3},
|
||||
{"h2-v2", "v2", []string{"2"}, 3},
|
||||
}
|
||||
for _, tc := range tlsTests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
testTLSProxyProtocolMatrix(t, tc.ppVersion, tc.transportVersions, tc.numRequests)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// testProxyProtocolMatrix is the shared implementation for the proxy protocol
|
||||
// tests. It:
|
||||
// 1. Starts a go-proxyproto-wrapped backend.
|
||||
// 2. Configures Caddy as a reverse proxy with the given PROXY protocol
|
||||
// version and transport versions.
|
||||
// 3. Sends numRequests GET requests through Caddy and asserts 200 OK each time.
|
||||
// 4. Asserts the backend recorded at least one PROXY header whose source host
|
||||
// is 127.0.0.1 (the loopback address used by the test client).
|
||||
func testProxyProtocolMatrix(t *testing.T, ppVersion string, transportVersions []string, numRequests int) {
|
||||
t.Helper()
|
||||
|
||||
backend := newProxyProtoBackend(t)
|
||||
listenPort := freePort(t)
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.WithDefaultOverrides(caddytest.Config{
|
||||
AdminPort: 2999,
|
||||
})
|
||||
cfg := proxyProtoConfig(listenPort, backend.addr(), ppVersion, transportVersions)
|
||||
tester.InitServer(cfg, "json")
|
||||
|
||||
// If the test is h2c-only (no "1.1" in versions), reconfigure the test
|
||||
// client transport to use unencrypted HTTP/2 so we actually exercise the
|
||||
// h2c code path through Caddy.
|
||||
if slices.Contains(transportVersions, "h2c") && !slices.Contains(transportVersions, "1.1") {
|
||||
tr, ok := tester.Client.Transport.(*http.Transport)
|
||||
if ok {
|
||||
tr.Protocols = new(http.Protocols)
|
||||
tr.Protocols.SetHTTP1(false)
|
||||
tr.Protocols.SetUnencryptedHTTP2(true)
|
||||
}
|
||||
}
|
||||
|
||||
proxyURL := fmt.Sprintf("http://127.0.0.1:%d/", listenPort)
|
||||
|
||||
for i := 0; i < numRequests; i++ {
|
||||
resp, err := tester.Client.Get(proxyURL)
|
||||
if err != nil {
|
||||
t.Fatalf("request %d/%d: GET %s: %v", i+1, numRequests, proxyURL, err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("request %d/%d: expected status 200, got %d", i+1, numRequests, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// The backend must have seen at least one PROXY header. For h1, there is
|
||||
// one per request; for h2c, requests share the same connection so only one
|
||||
// header is written at connection establishment.
|
||||
addrs := backend.recordedAddrs()
|
||||
if len(addrs) == 0 {
|
||||
t.Fatalf("backend recorded no PROXY protocol addresses (expected at least 1)")
|
||||
}
|
||||
|
||||
// Every PROXY-decoded source address must be the loopback address since
|
||||
// the test client always connects from 127.0.0.1.
|
||||
for i, addr := range addrs {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
t.Errorf("addr[%d] %q: SplitHostPort: %v", i, addr, err)
|
||||
continue
|
||||
}
|
||||
if host != "127.0.0.1" {
|
||||
t.Errorf("addr[%d]: expected source 127.0.0.1, got %q", i, host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyProtocolListenerWrapper verifies that Caddy's
|
||||
// caddy.listeners.proxy_protocol listener wrapper can successfully parse
|
||||
// incoming PROXY protocol headers.
|
||||
//
|
||||
// The test dials Caddy's listening port directly, injects a raw PROXY v2
|
||||
// header spoofing source address 10.0.0.1:1234, then sends a normal
|
||||
// HTTP/1.1 GET request. The Caddy server is configured to echo back the
|
||||
// remote address ({http.request.remote.host}). The test asserts that the
|
||||
// echoed address is the spoofed 10.0.0.1.
|
||||
func TestProxyProtocolListenerWrapper(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
servers :9080 {
|
||||
listener_wrappers {
|
||||
proxy_protocol {
|
||||
timeout 5s
|
||||
allow 127.0.0.0/8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
http://localhost:9080 {
|
||||
respond "{http.request.remote.host}"
|
||||
}`, "caddyfile")
|
||||
|
||||
// Dial the Caddy listener directly and inject a PROXY v2 header that
|
||||
// claims the connection originates from 10.0.0.1:1234.
|
||||
conn, err := net.Dial("tcp", "127.0.0.1:9080")
|
||||
if err != nil {
|
||||
t.Fatalf("dial: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
spoofedSrc := &net.TCPAddr{IP: net.ParseIP("10.0.0.1"), Port: 1234}
|
||||
spoofedDst := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 9080}
|
||||
hdr := goproxy.HeaderProxyFromAddrs(2, spoofedSrc, spoofedDst)
|
||||
if _, err := hdr.WriteTo(conn); err != nil {
|
||||
t.Fatalf("write proxy header: %v", err)
|
||||
}
|
||||
|
||||
// Write a minimal HTTP/1.1 GET request.
|
||||
_, err = fmt.Fprintf(conn,
|
||||
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")
|
||||
if err != nil {
|
||||
t.Fatalf("write HTTP request: %v", err)
|
||||
}
|
||||
|
||||
// Read the raw response and look for the spoofed address in the body.
|
||||
buf := make([]byte, 4096)
|
||||
n, _ := conn.Read(buf)
|
||||
raw := string(buf[:n])
|
||||
|
||||
if !strings.Contains(raw, "10.0.0.1") {
|
||||
t.Errorf("expected spoofed address 10.0.0.1 in response body; full response:\n%s", raw)
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
)
|
||||
@@ -327,6 +327,41 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
// Start lightweight backend servers so they're ready before Caddy's
|
||||
// active health checker runs; this avoids a startup race where the
|
||||
// health checker probes backends that haven't yet begun accepting
|
||||
// connections and marks them unhealthy.
|
||||
//
|
||||
// This mirrors how health checks are typically used in practice (to a separate
|
||||
// backend service) and avoids probing the same Caddy instance while it's still
|
||||
// provisioning and not ready to accept connections.
|
||||
|
||||
// backend server that responds to proxied requests
|
||||
helloSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
_, _ = w.Write([]byte("Hello, World!"))
|
||||
}),
|
||||
}
|
||||
ln0, err := net.Listen("tcp", "127.0.0.1:2020")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen on 127.0.0.1:2020: %v", err)
|
||||
}
|
||||
go helloSrv.Serve(ln0)
|
||||
t.Cleanup(func() { helloSrv.Close(); ln0.Close() })
|
||||
|
||||
// backend server that serves health checks
|
||||
healthSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}),
|
||||
}
|
||||
ln1, err := net.Listen("tcp", "127.0.0.1:2021")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen on 127.0.0.1:2021: %v", err)
|
||||
}
|
||||
go healthSrv.Serve(ln1)
|
||||
t.Cleanup(func() { healthSrv.Close(); ln1.Close() })
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
{
|
||||
@@ -336,12 +371,6 @@ func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:2020 {
|
||||
respond "Hello, World!"
|
||||
}
|
||||
http://localhost:2021 {
|
||||
respond "ok"
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy {
|
||||
to localhost:2020
|
||||
@@ -355,8 +384,68 @@ func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // TODO: for some reason this test seems particularly flaky, getting 503 when it should be 200, unless we wait
|
||||
// TestReverseProxyHealthCheckPortUsed verifies that health_port is actually
|
||||
// used for active health checks and not the upstream's main port. This is a
|
||||
// regression test for https://github.com/caddyserver/caddy/issues/7524.
|
||||
func TestReverseProxyHealthCheckPortUsed(t *testing.T) {
|
||||
// upstream server: serves proxied requests normally, but returns 503 for
|
||||
// /health so that if health checks mistakenly hit this port the upstream
|
||||
// gets marked unhealthy and the proxy returns 503.
|
||||
upstreamSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.Path == "/health" {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte("Hello, World!"))
|
||||
}),
|
||||
}
|
||||
ln0, err := net.Listen("tcp", "127.0.0.1:2022")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen on 127.0.0.1:2022: %v", err)
|
||||
}
|
||||
go upstreamSrv.Serve(ln0)
|
||||
t.Cleanup(func() { upstreamSrv.Close(); ln0.Close() })
|
||||
|
||||
// separate health check server on the configured health_port: returns 200
|
||||
// so the upstream is marked healthy only if health checks go to this port.
|
||||
healthSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}),
|
||||
}
|
||||
ln1, err := net.Listen("tcp", "127.0.0.1:2023")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen on 127.0.0.1:2023: %v", err)
|
||||
}
|
||||
go healthSrv.Serve(ln1)
|
||||
t.Cleanup(func() { healthSrv.Close(); ln1.Close() })
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy {
|
||||
to localhost:2022
|
||||
|
||||
health_uri /health
|
||||
health_port 2023
|
||||
health_interval 10ms
|
||||
health_timeout 100ms
|
||||
health_passes 1
|
||||
health_fails 1
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
}
|
||||
|
||||
@@ -474,3 +563,233 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
}
|
||||
|
||||
// TestReverseProxyRetryMatchStatusCode verifies that lb_retry_match with a
|
||||
// CEL expression matching on {rp.status_code} causes the request to be
|
||||
// retried on the next upstream when the first upstream returns a matching
|
||||
// status code
|
||||
func TestReverseProxyRetryMatchStatusCode(t *testing.T) {
|
||||
// Bad upstream: returns 502
|
||||
badSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
}),
|
||||
}
|
||||
badLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go badSrv.Serve(badLn)
|
||||
t.Cleanup(func() { badSrv.Close(); badLn.Close() })
|
||||
|
||||
// Good upstream: returns 200
|
||||
goodSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("ok"))
|
||||
}),
|
||||
}
|
||||
goodLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go goodSrv.Serve(goodLn)
|
||||
t.Cleanup(func() { goodSrv.Close(); goodLn.Close() })
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy %s %s {
|
||||
lb_policy round_robin
|
||||
lb_retries 1
|
||||
lb_retry_match {
|
||||
expression `+"`{rp.status_code} in [502, 503]`"+`
|
||||
}
|
||||
}
|
||||
}
|
||||
`, goodLn.Addr().String(), badLn.Addr().String()), "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "ok")
|
||||
}
|
||||
|
||||
// TestReverseProxyRetryMatchHeader verifies that lb_retry_match with a CEL
|
||||
// expression matching on {rp.header.*} causes the request to be retried when
|
||||
// the upstream sets a matching response header
|
||||
func TestReverseProxyRetryMatchHeader(t *testing.T) {
|
||||
var badHits atomic.Int32
|
||||
|
||||
// Bad upstream: returns 200 but signals retry via header
|
||||
badSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
badHits.Add(1)
|
||||
w.Header().Set("X-Upstream-Retry", "true")
|
||||
w.Write([]byte("bad"))
|
||||
}),
|
||||
}
|
||||
badLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go badSrv.Serve(badLn)
|
||||
t.Cleanup(func() { badSrv.Close(); badLn.Close() })
|
||||
|
||||
// Good upstream: returns 200 without retry header
|
||||
goodSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("good"))
|
||||
}),
|
||||
}
|
||||
goodLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go goodSrv.Serve(goodLn)
|
||||
t.Cleanup(func() { goodSrv.Close(); goodLn.Close() })
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy %s %s {
|
||||
lb_policy round_robin
|
||||
lb_retries 1
|
||||
lb_retry_match {
|
||||
expression `+"`{rp.header.X-Upstream-Retry} == \"true\"`"+`
|
||||
}
|
||||
}
|
||||
}
|
||||
`, goodLn.Addr().String(), badLn.Addr().String()), "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "good")
|
||||
|
||||
if badHits.Load() != 1 {
|
||||
t.Errorf("bad upstream hits: got %d, want 1", badHits.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// TestReverseProxyRetryMatchCombined verifies that a CEL expression combining
|
||||
// request path matching with response status code matching works correctly -
|
||||
// only retrying when both conditions are met
|
||||
func TestReverseProxyRetryMatchCombined(t *testing.T) {
|
||||
// Upstream: returns 502 for all requests
|
||||
srv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
}),
|
||||
}
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go srv.Serve(ln)
|
||||
t.Cleanup(func() { srv.Close(); ln.Close() })
|
||||
|
||||
// Good upstream
|
||||
goodSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("ok"))
|
||||
}),
|
||||
}
|
||||
goodLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go goodSrv.Serve(goodLn)
|
||||
t.Cleanup(func() { goodSrv.Close(); goodLn.Close() })
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy %s %s {
|
||||
lb_policy round_robin
|
||||
lb_retries 1
|
||||
lb_retry_match {
|
||||
expression `+"`path('/retry*') && {rp.status_code} in [502, 503]`"+`
|
||||
}
|
||||
}
|
||||
}
|
||||
`, goodLn.Addr().String(), ln.Addr().String()), "caddyfile")
|
||||
|
||||
// /retry path matches the expression - should retry to good upstream
|
||||
tester.AssertGetResponse("http://localhost:9080/retry", 200, "ok")
|
||||
|
||||
// /other path does NOT match - should return the 502
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/other", nil)
|
||||
tester.AssertResponse(req, 502, "")
|
||||
}
|
||||
|
||||
// TestReverseProxyRetryMatchIsTransportError verifies that the
|
||||
// {rp.is_transport_error} == true CEL function correctly identifies transport errors
|
||||
// and allows retrying them alongside response-based matching
|
||||
func TestReverseProxyRetryMatchIsTransportError(t *testing.T) {
|
||||
// Good upstream: returns 200
|
||||
goodSrv := &http.Server{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("ok"))
|
||||
}),
|
||||
}
|
||||
goodLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
go goodSrv.Serve(goodLn)
|
||||
t.Cleanup(func() { goodSrv.Close(); goodLn.Close() })
|
||||
|
||||
// Broken upstream: accepts connections but closes immediately
|
||||
brokenLn, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { brokenLn.Close() })
|
||||
go func() {
|
||||
for {
|
||||
conn, err := brokenLn.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
conn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
reverse_proxy %s %s {
|
||||
lb_policy round_robin
|
||||
lb_retries 1
|
||||
lb_retry_match {
|
||||
expression `+"`{rp.is_transport_error} || {rp.status_code} in [502, 503]`"+`
|
||||
}
|
||||
}
|
||||
}
|
||||
`, goodLn.Addr().String(), brokenLn.Addr().String()), "caddyfile")
|
||||
|
||||
// Transport error on broken upstream should be retried to good upstream
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "ok")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# Used by import_block_snippet_non_replaced_block_from_separate_file.caddyfiletest
|
||||
|
||||
(snippet) {
|
||||
header {
|
||||
reverse_proxy localhost:3000
|
||||
{block}
|
||||
}
|
||||
}
|
||||
|
||||
# This snippet being unused by the test Caddyfile is intentional.
|
||||
# This is to test that a panic runtime error triggered by an out-of-range slice index access
|
||||
# will not happen again, please see issue #7518 and pull request #7543 for more information
|
||||
(unused_snippet) {
|
||||
header SomeHeader SomeValue
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Used by import_block_snippet_invalid_subdirective.caddyfiletest
|
||||
|
||||
(test) {
|
||||
reverse_proxy {
|
||||
{block}
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -9,9 +9,14 @@ import (
|
||||
)
|
||||
|
||||
var defaultFactory = newRootCommandFactory(func() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "caddy",
|
||||
Long: `Caddy is an extensible server platform written in Go.
|
||||
bin := caddy.CustomBinaryName
|
||||
if bin == "" {
|
||||
bin = "caddy"
|
||||
}
|
||||
|
||||
long := caddy.CustomLongDescription
|
||||
if long == "" {
|
||||
long = `Caddy is an extensible server platform written in Go.
|
||||
|
||||
At its core, Caddy merely manages configuration. Modules are plugged
|
||||
in statically at compile-time to provide useful functionality. Caddy's
|
||||
@@ -91,7 +96,12 @@ package installers: https://caddyserver.com/docs/install
|
||||
|
||||
Instructions for running Caddy in production are also available:
|
||||
https://caddyserver.com/docs/running
|
||||
`,
|
||||
`
|
||||
}
|
||||
|
||||
return &cobra.Command{
|
||||
Use: bin,
|
||||
Long: long,
|
||||
Example: ` $ caddy run
|
||||
$ caddy run --config caddy.json
|
||||
$ caddy reload --config caddy.json
|
||||
|
||||
+4
-4
@@ -74,7 +74,7 @@ func cmdStart(fl Flags) (int, error) {
|
||||
// ensure it's the process we're expecting - we can be
|
||||
// sure by giving it some random bytes and having it echo
|
||||
// them back to us)
|
||||
cmd := exec.Command(os.Args[0], "run", "--pingback", ln.Addr().String())
|
||||
cmd := exec.Command(os.Args[0], "run", "--pingback", ln.Addr().String()) //nolint:gosec // no command injection that I can determine...
|
||||
// we should be able to run caddy in relative paths
|
||||
if errors.Is(cmd.Err, exec.ErrDot) {
|
||||
cmd.Err = nil
|
||||
@@ -372,7 +372,7 @@ func cmdReload(fl Flags) (int, error) {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("no config file to load")
|
||||
}
|
||||
|
||||
adminAddr, err := DetermineAdminAPIAddress(addressFlag, config, configFlag, configAdapterFlag)
|
||||
adminAddr, err := DetermineAdminAPIAddress(addressFlag, config, configFile, configAdapterFlag)
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("couldn't determine admin API address: %v", err)
|
||||
}
|
||||
@@ -697,7 +697,7 @@ func cmdFmt(fl Flags) (int, error) {
|
||||
output := caddyfile.Format(input)
|
||||
|
||||
if fl.Bool("overwrite") {
|
||||
if err := os.WriteFile(configFile, output, 0o600); err != nil {
|
||||
if err := os.WriteFile(configFile, output, 0o600); err != nil { //nolint:gosec // path traversal is not really a thing here, this is either "Caddyfile" or admin-controlled
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("overwriting formatted file: %v", err)
|
||||
}
|
||||
return caddy.ExitCodeSuccess, nil
|
||||
@@ -820,7 +820,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := client.Do(req) //nolint:gosec // the only SSRF here would be self-sabatoge I think
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("performing request: %v", err)
|
||||
}
|
||||
|
||||
+7
-1
@@ -484,7 +484,13 @@ func setResourceLimits(logger *zap.Logger) func() {
|
||||
// See https://pkg.go.dev/runtime/debug#SetMemoryLimit
|
||||
_, _ = memlimit.SetGoMemLimitWithOpts(
|
||||
memlimit.WithLogger(
|
||||
slog.New(zapslog.NewHandler(logger.Core())),
|
||||
slog.New(zapslog.NewHandler(
|
||||
logger.Core(),
|
||||
zapslog.WithName("memlimit"),
|
||||
// the default enables traces at ERROR level, this disables
|
||||
// them by setting it to a level higher than any other level
|
||||
zapslog.AddStacktraceAt(slog.Level(127)),
|
||||
)),
|
||||
),
|
||||
memlimit.WithProvider(
|
||||
memlimit.ApplyFallback(
|
||||
|
||||
@@ -234,7 +234,7 @@ func getModules() (standard, nonstandard, unknown []moduleInfo, err error) {
|
||||
// not sure why), and since New() should return a pointer
|
||||
// value, we need to dereference it first
|
||||
iface := any(modInfo.New())
|
||||
if rv := reflect.ValueOf(iface); rv.Kind() == reflect.Ptr {
|
||||
if rv := reflect.ValueOf(iface); rv.Kind() == reflect.Pointer {
|
||||
iface = reflect.New(reflect.TypeOf(iface).Elem()).Elem().Interface()
|
||||
}
|
||||
modPkgPath := reflect.TypeOf(iface).PkgPath()
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddycmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSplitModule(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectedModule string
|
||||
expectedVersion string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "simple module without version",
|
||||
input: "github.com/caddyserver/caddy",
|
||||
expectedModule: "github.com/caddyserver/caddy",
|
||||
expectedVersion: "",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with version",
|
||||
input: "github.com/caddyserver/caddy@v2.0.0",
|
||||
expectedModule: "github.com/caddyserver/caddy",
|
||||
expectedVersion: "v2.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with semantic version",
|
||||
input: "github.com/user/module@v1.2.3",
|
||||
expectedModule: "github.com/user/module",
|
||||
expectedVersion: "v1.2.3",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with prerelease version",
|
||||
input: "github.com/user/module@v1.0.0-beta.1",
|
||||
expectedModule: "github.com/user/module",
|
||||
expectedVersion: "v1.0.0-beta.1",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with commit hash",
|
||||
input: "github.com/user/module@abc123def",
|
||||
expectedModule: "github.com/user/module",
|
||||
expectedVersion: "abc123def",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with @ in path and version",
|
||||
input: "github.com/@user/module@v1.0.0",
|
||||
expectedModule: "github.com/@user/module",
|
||||
expectedVersion: "v1.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with multiple @ in path",
|
||||
input: "github.com/@org/@user/module@v2.3.4",
|
||||
expectedModule: "github.com/@org/@user/module",
|
||||
expectedVersion: "v2.3.4",
|
||||
expectError: false,
|
||||
},
|
||||
// TODO: decide on the behavior for this case; it fails currently
|
||||
// {
|
||||
// name: "module with @ in path but no version",
|
||||
// input: "github.com/@user/module",
|
||||
// expectedModule: "github.com/@user/module",
|
||||
// expectedVersion: "",
|
||||
// expectError: false,
|
||||
// },
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
expectedModule: "",
|
||||
expectedVersion: "",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "only @ symbol",
|
||||
input: "@",
|
||||
expectedModule: "",
|
||||
expectedVersion: "",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "@ at start",
|
||||
input: "@v1.0.0",
|
||||
expectedModule: "",
|
||||
expectedVersion: "v1.0.0",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "@ at end",
|
||||
input: "github.com/user/module@",
|
||||
expectedModule: "github.com/user/module",
|
||||
expectedVersion: "",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "multiple consecutive @",
|
||||
input: "github.com/user/module@@v1.0.0",
|
||||
expectedModule: "github.com/user/module@",
|
||||
expectedVersion: "v1.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "version with latest tag",
|
||||
input: "github.com/user/module@latest",
|
||||
expectedModule: "github.com/user/module",
|
||||
expectedVersion: "latest",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "long module path",
|
||||
input: "github.com/organization/team/project/subproject/module@v3.14.159",
|
||||
expectedModule: "github.com/organization/team/project/subproject/module",
|
||||
expectedVersion: "v3.14.159",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with dots in name",
|
||||
input: "github.com/user/my.module.name@v1.0",
|
||||
expectedModule: "github.com/user/my.module.name",
|
||||
expectedVersion: "v1.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "module with hyphens",
|
||||
input: "github.com/user/my-module-name@v1.0.0",
|
||||
expectedModule: "github.com/user/my-module-name",
|
||||
expectedVersion: "v1.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "gitlab module",
|
||||
input: "gitlab.com/user/module@v2.0.0",
|
||||
expectedModule: "gitlab.com/user/module",
|
||||
expectedVersion: "v2.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "bitbucket module",
|
||||
input: "bitbucket.org/user/module@v1.5.0",
|
||||
expectedModule: "bitbucket.org/user/module",
|
||||
expectedVersion: "v1.5.0",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "custom domain",
|
||||
input: "example.com/custom/module@v1.0.0",
|
||||
expectedModule: "example.com/custom/module",
|
||||
expectedVersion: "v1.0.0",
|
||||
expectError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
module, version, err := splitModule(tt.input)
|
||||
|
||||
// Check error expectation
|
||||
if tt.expectError {
|
||||
if err == nil {
|
||||
t.Errorf("expected error but got none")
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Check module
|
||||
if module != tt.expectedModule {
|
||||
t.Errorf("module: got %q, want %q", module, tt.expectedModule)
|
||||
}
|
||||
|
||||
// Check version
|
||||
if version != tt.expectedVersion {
|
||||
t.Errorf("version: got %q, want %q", version, tt.expectedVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitModule_ErrorCases(t *testing.T) {
|
||||
errorCases := []string{
|
||||
"",
|
||||
"@",
|
||||
"@version",
|
||||
"@v1.0.0",
|
||||
}
|
||||
|
||||
for _, tc := range errorCases {
|
||||
t.Run("error_"+tc, func(t *testing.T) {
|
||||
_, _, err := splitModule(tc)
|
||||
if err == nil {
|
||||
t.Errorf("splitModule(%q) should return error", tc)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkSplitModule benchmarks the splitModule function
|
||||
func BenchmarkSplitModule(b *testing.B) {
|
||||
testCases := []string{
|
||||
"github.com/user/module",
|
||||
"github.com/user/module@v1.0.0",
|
||||
"github.com/@org/@user/module@v2.3.4",
|
||||
"github.com/organization/team/project/subproject/module@v3.14.159",
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
b.Run(tc, func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
splitModule(tc)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+720
@@ -0,0 +1,720 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestConfig_Start_Stop_Basic(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Admin: &AdminConfig{Disabled: true}, // Disable admin to avoid port conflicts
|
||||
}
|
||||
|
||||
ctx, err := run(cfg, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to run config: %v", err)
|
||||
}
|
||||
|
||||
// Verify context is valid
|
||||
if ctx.cfg == nil {
|
||||
t.Error("Expected non-nil config in context")
|
||||
}
|
||||
|
||||
// Stop the config
|
||||
unsyncedStop(ctx)
|
||||
|
||||
// Verify cleanup was called
|
||||
if ctx.cfg.cancelFunc == nil {
|
||||
t.Error("Expected cancel function to be set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_Validate_InvalidConfig(t *testing.T) {
|
||||
// Create a config with an invalid app module
|
||||
cfg := &Config{
|
||||
AppsRaw: ModuleMap{
|
||||
"non-existent-app": json.RawMessage(`{}`),
|
||||
},
|
||||
}
|
||||
|
||||
err := Validate(cfg)
|
||||
if err == nil {
|
||||
t.Error("Expected validation error for invalid app module")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_Validate_ValidConfig(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Admin: &AdminConfig{Disabled: true},
|
||||
}
|
||||
|
||||
err := Validate(cfg)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected validation error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeConfig_ConcurrentAccess(t *testing.T) {
|
||||
// Save original config state
|
||||
originalRawCfg := rawCfg[rawConfigKey]
|
||||
originalRawCfgJSON := rawCfgJSON
|
||||
defer func() {
|
||||
rawCfg[rawConfigKey] = originalRawCfg
|
||||
rawCfgJSON = originalRawCfgJSON
|
||||
}()
|
||||
|
||||
// Initialize with a basic config
|
||||
initialCfg := map[string]any{
|
||||
"test": "value",
|
||||
}
|
||||
rawCfg[rawConfigKey] = initialCfg
|
||||
|
||||
const numGoroutines = 10 // Reduced for more controlled testing
|
||||
var wg sync.WaitGroup
|
||||
errors := make([]error, numGoroutines)
|
||||
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
|
||||
// Only test read operations to avoid complex state changes
|
||||
// that could cause nil pointer issues in concurrent scenarios
|
||||
var buf bytes.Buffer
|
||||
errors[index] = readConfig("/"+rawConfigKey+"/test", &buf)
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// Check that read operations succeeded
|
||||
for i, err := range errors {
|
||||
if err != nil {
|
||||
t.Errorf("Goroutine %d: Unexpected read error: %v", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeConfig_MethodValidation(t *testing.T) {
|
||||
// Save original config state
|
||||
originalRawCfg := rawCfg[rawConfigKey]
|
||||
defer func() {
|
||||
rawCfg[rawConfigKey] = originalRawCfg
|
||||
}()
|
||||
|
||||
// Set up a simple valid config for testing
|
||||
rawCfg[rawConfigKey] = map[string]any{}
|
||||
|
||||
tests := []struct {
|
||||
method string
|
||||
expectErr bool
|
||||
}{
|
||||
{http.MethodPost, false},
|
||||
{http.MethodPut, true}, // because key 'admin' already exists
|
||||
{http.MethodPatch, false},
|
||||
{http.MethodDelete, false},
|
||||
{http.MethodGet, true},
|
||||
{http.MethodHead, true},
|
||||
{http.MethodOptions, true},
|
||||
{http.MethodConnect, true},
|
||||
{http.MethodTrace, true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.method, func(t *testing.T) {
|
||||
// Use a simple admin config path that won't cause complex validation
|
||||
err := changeConfig(test.method, "/"+rawConfigKey+"/admin", []byte(`{"disabled": true}`), "", false)
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error for invalid method")
|
||||
}
|
||||
if !test.expectErr && err != nil && (err != errSameConfig) {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeConfig_IfMatchHeader_Validation(t *testing.T) {
|
||||
// Set up initial config
|
||||
initialCfg := map[string]any{"test": "value"}
|
||||
rawCfg[rawConfigKey] = initialCfg
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ifMatch string
|
||||
expectErr bool
|
||||
expectStatusCode int
|
||||
}{
|
||||
{
|
||||
name: "malformed - no quotes",
|
||||
ifMatch: "path hash",
|
||||
expectErr: true,
|
||||
expectStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
{
|
||||
name: "malformed - single quote",
|
||||
ifMatch: `"path hash`,
|
||||
expectErr: true,
|
||||
expectStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
{
|
||||
name: "malformed - wrong number of parts",
|
||||
ifMatch: `"path"`,
|
||||
expectErr: true,
|
||||
expectStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
{
|
||||
name: "malformed - too many parts",
|
||||
ifMatch: `"path hash extra"`,
|
||||
expectErr: true,
|
||||
expectStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
{
|
||||
name: "wrong hash",
|
||||
ifMatch: `"/config/test wronghash"`,
|
||||
expectErr: true,
|
||||
expectStatusCode: http.StatusPreconditionFailed,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := changeConfig(http.MethodPost, "/"+rawConfigKey+"/test", []byte(`"newvalue"`), test.ifMatch, false)
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if test.expectErr && err != nil {
|
||||
if apiErr, ok := err.(APIError); ok {
|
||||
if apiErr.HTTPStatus != test.expectStatusCode {
|
||||
t.Errorf("Expected status %d, got %d", test.expectStatusCode, apiErr.HTTPStatus)
|
||||
}
|
||||
} else {
|
||||
t.Error("Expected APIError type")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexConfigObjects_Basic(t *testing.T) {
|
||||
config := map[string]any{
|
||||
"app1": map[string]any{
|
||||
"@id": "my-app",
|
||||
"config": "value",
|
||||
},
|
||||
"nested": map[string]any{
|
||||
"array": []any{
|
||||
map[string]any{
|
||||
"@id": "nested-item",
|
||||
"data": "test",
|
||||
},
|
||||
map[string]any{
|
||||
"@id": 123.0, // JSON numbers are float64
|
||||
"more": "data",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
index := make(map[string]string)
|
||||
err := indexConfigObjects(config, "/config", index)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
expected := map[string]string{
|
||||
"my-app": "/config/app1",
|
||||
"nested-item": "/config/nested/array/0",
|
||||
"123": "/config/nested/array/1",
|
||||
}
|
||||
|
||||
if len(index) != len(expected) {
|
||||
t.Errorf("Expected %d indexed items, got %d", len(expected), len(index))
|
||||
}
|
||||
|
||||
for id, expectedPath := range expected {
|
||||
if actualPath, exists := index[id]; !exists || actualPath != expectedPath {
|
||||
t.Errorf("ID %s: expected path '%s', got '%s'", id, expectedPath, actualPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexConfigObjects_InvalidID(t *testing.T) {
|
||||
config := map[string]any{
|
||||
"app": map[string]any{
|
||||
"@id": map[string]any{"invalid": "id"}, // Invalid ID type
|
||||
},
|
||||
}
|
||||
|
||||
index := make(map[string]string)
|
||||
err := indexConfigObjects(config, "/config", index)
|
||||
if err == nil {
|
||||
t.Error("Expected error for invalid ID type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_AppStartFailure(t *testing.T) {
|
||||
// Register a mock app that fails to start
|
||||
RegisterModule(&failingApp{})
|
||||
defer func() {
|
||||
// Clean up module registry
|
||||
delete(modules, "failing-app")
|
||||
}()
|
||||
|
||||
cfg := &Config{
|
||||
Admin: &AdminConfig{Disabled: true},
|
||||
AppsRaw: ModuleMap{
|
||||
"failing-app": json.RawMessage(`{}`),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := run(cfg, true)
|
||||
if err == nil {
|
||||
t.Error("Expected error when app fails to start")
|
||||
}
|
||||
|
||||
// Should contain the app name in the error
|
||||
if err.Error() == "" {
|
||||
t.Error("Expected descriptive error message")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_AppStopFailure_During_Cleanup(t *testing.T) {
|
||||
// Register apps where one fails to start and another fails to stop
|
||||
RegisterModule(&workingApp{})
|
||||
RegisterModule(&failingStopApp{})
|
||||
defer func() {
|
||||
delete(modules, "working-app")
|
||||
delete(modules, "failing-stop-app")
|
||||
}()
|
||||
|
||||
cfg := &Config{
|
||||
Admin: &AdminConfig{Disabled: true},
|
||||
AppsRaw: ModuleMap{
|
||||
"working-app": json.RawMessage(`{}`),
|
||||
"failing-stop-app": json.RawMessage(`{}`),
|
||||
},
|
||||
}
|
||||
|
||||
// Start both apps
|
||||
ctx, err := run(cfg, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error starting apps: %v", err)
|
||||
}
|
||||
|
||||
// Stop context - this should handle stop failures gracefully
|
||||
unsyncedStop(ctx)
|
||||
|
||||
// Test passed if we reach here without panic
|
||||
}
|
||||
|
||||
func TestProvisionContext_NilConfig(t *testing.T) {
|
||||
ctx, err := provisionContext(nil, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ctx.cfg == nil {
|
||||
t.Error("Expected non-nil config even when input is nil")
|
||||
}
|
||||
|
||||
// Clean up
|
||||
// TODO: Investigate
|
||||
ctx.cfg.cancelFunc(nil)
|
||||
}
|
||||
|
||||
func TestDuration_UnmarshalJSON_EdgeCases(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectErr bool
|
||||
expected time.Duration
|
||||
}{
|
||||
{
|
||||
name: "empty input",
|
||||
input: "",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "integer nanoseconds",
|
||||
input: "1000000000",
|
||||
expected: time.Second,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "string duration",
|
||||
input: `"5m30s"`,
|
||||
expected: 5*time.Minute + 30*time.Second,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "days conversion",
|
||||
input: `"2d"`,
|
||||
expected: 48 * time.Hour,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "mixed days and hours",
|
||||
input: `"1d12h"`,
|
||||
expected: 36 * time.Hour,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid duration",
|
||||
input: `"invalid"`,
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var d Duration
|
||||
err := d.UnmarshalJSON([]byte(test.input))
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if !test.expectErr && time.Duration(d) != test.expected {
|
||||
t.Errorf("Expected %v, got %v", test.expected, time.Duration(d))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDuration_LongInput(t *testing.T) {
|
||||
// Test input length limit
|
||||
longInput := string(make([]byte, 1025)) // Exceeds 1024 limit
|
||||
for i := range longInput {
|
||||
longInput = longInput[:i] + "1"
|
||||
}
|
||||
longInput += "d"
|
||||
|
||||
_, err := ParseDuration(longInput)
|
||||
if err == nil {
|
||||
t.Error("Expected error for input longer than 1024 characters")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersion_Deterministic(t *testing.T) {
|
||||
// Test that Version() returns consistent results
|
||||
simple1, full1 := Version()
|
||||
simple2, full2 := Version()
|
||||
|
||||
if simple1 != simple2 {
|
||||
t.Errorf("Version() simple form not deterministic: '%s' != '%s'", simple1, simple2)
|
||||
}
|
||||
if full1 != full2 {
|
||||
t.Errorf("Version() full form not deterministic: '%s' != '%s'", full1, full2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstanceID_Consistency(t *testing.T) {
|
||||
// Test that InstanceID returns the same ID on subsequent calls
|
||||
id1, err := InstanceID()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get instance ID: %v", err)
|
||||
}
|
||||
|
||||
id2, err := InstanceID()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get instance ID on second call: %v", err)
|
||||
}
|
||||
|
||||
if id1 != id2 {
|
||||
t.Errorf("InstanceID not consistent: %v != %v", id1, id2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveMetaFields_EdgeCases(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "no meta fields",
|
||||
input: `{"normal": "field"}`,
|
||||
expected: `{"normal": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "single @id field",
|
||||
input: `{"@id": "test", "other": "field"}`,
|
||||
expected: `{"other": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "@id at beginning",
|
||||
input: `{"@id": "test", "other": "field"}`,
|
||||
expected: `{"other": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "@id at end",
|
||||
input: `{"other": "field", "@id": "test"}`,
|
||||
expected: `{"other": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "@id in middle",
|
||||
input: `{"first": "value", "@id": "test", "last": "value"}`,
|
||||
expected: `{"first": "value", "last": "value"}`,
|
||||
},
|
||||
{
|
||||
name: "multiple @id fields",
|
||||
input: `{"@id": "test1", "other": "field", "@id": "test2"}`,
|
||||
expected: `{"other": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "numeric @id",
|
||||
input: `{"@id": 123, "other": "field"}`,
|
||||
expected: `{"other": "field"}`,
|
||||
},
|
||||
{
|
||||
name: "nested objects with @id",
|
||||
input: `{"outer": {"@id": "nested", "data": "value"}}`,
|
||||
expected: `{"outer": {"data": "value"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := RemoveMetaFields([]byte(test.input))
|
||||
// resultStr := string(result)
|
||||
|
||||
// Parse both to ensure valid JSON and compare structures
|
||||
var expectedObj, resultObj any
|
||||
if err := json.Unmarshal([]byte(test.expected), &expectedObj); err != nil {
|
||||
t.Fatalf("Expected result is not valid JSON: %v", err)
|
||||
}
|
||||
if err := json.Unmarshal(result, &resultObj); err != nil {
|
||||
t.Fatalf("Result is not valid JSON: %v", err)
|
||||
}
|
||||
|
||||
// Note: We can't do exact string comparison due to potential field ordering
|
||||
// Instead, verify the structure matches
|
||||
expectedJSON, _ := json.Marshal(expectedObj)
|
||||
resultJSON, _ := json.Marshal(resultObj)
|
||||
|
||||
if string(expectedJSON) != string(resultJSON) {
|
||||
t.Errorf("Expected %s, got %s", string(expectedJSON), string(resultJSON))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsyncedConfigAccess_ArrayOperations_EdgeCases(t *testing.T) {
|
||||
// Test array boundary conditions and edge cases
|
||||
tests := []struct {
|
||||
name string
|
||||
initialState map[string]any
|
||||
method string
|
||||
path string
|
||||
payload string
|
||||
expectErr bool
|
||||
expectState map[string]any
|
||||
}{
|
||||
{
|
||||
name: "delete from empty array",
|
||||
initialState: map[string]any{"arr": []any{}},
|
||||
method: http.MethodDelete,
|
||||
path: "/config/arr/0",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "access negative index",
|
||||
initialState: map[string]any{"arr": []any{"a", "b"}},
|
||||
method: http.MethodGet,
|
||||
path: "/config/arr/-1",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "put at index beyond end",
|
||||
initialState: map[string]any{"arr": []any{"a"}},
|
||||
method: http.MethodPut,
|
||||
path: "/config/arr/5",
|
||||
payload: `"new"`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "patch non-existent index",
|
||||
initialState: map[string]any{"arr": []any{"a"}},
|
||||
method: http.MethodPatch,
|
||||
path: "/config/arr/5",
|
||||
payload: `"new"`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "put at exact end of array",
|
||||
initialState: map[string]any{"arr": []any{"a", "b"}},
|
||||
method: http.MethodPut,
|
||||
path: "/config/arr/2",
|
||||
payload: `"c"`,
|
||||
expectState: map[string]any{"arr": []any{"a", "b", "c"}},
|
||||
},
|
||||
{
|
||||
name: "ellipses with non-array payload",
|
||||
initialState: map[string]any{"arr": []any{"a"}},
|
||||
method: http.MethodPost,
|
||||
path: "/config/arr/...",
|
||||
payload: `"not-array"`,
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// Set up initial state
|
||||
rawCfg[rawConfigKey] = test.initialState
|
||||
|
||||
err := unsyncedConfigAccess(test.method, test.path, []byte(test.payload), nil)
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if test.expectState != nil {
|
||||
// Compare resulting state
|
||||
expectedJSON, _ := json.Marshal(test.expectState)
|
||||
actualJSON, _ := json.Marshal(rawCfg[rawConfigKey])
|
||||
|
||||
if string(expectedJSON) != string(actualJSON) {
|
||||
t.Errorf("Expected state %s, got %s", string(expectedJSON), string(actualJSON))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExitProcess_ConcurrentCalls(t *testing.T) {
|
||||
// Test that multiple concurrent calls to exitProcess are safe
|
||||
// We can't test the actual exit, but we can test the atomic flag
|
||||
|
||||
// Reset the exiting flag
|
||||
oldExiting := exiting
|
||||
exiting = new(int32)
|
||||
defer func() { exiting = oldExiting }()
|
||||
|
||||
const numGoroutines = 10
|
||||
var wg sync.WaitGroup
|
||||
results := make([]bool, numGoroutines)
|
||||
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
// Check the Exiting() function which reads the atomic flag
|
||||
wasExitingBefore := Exiting()
|
||||
|
||||
// This would call exitProcess, but we don't want to actually exit
|
||||
// So we just test the atomic operation directly
|
||||
results[index] = atomic.CompareAndSwapInt32(exiting, 0, 1)
|
||||
|
||||
wasExitingAfter := Exiting()
|
||||
|
||||
// At least one should succeed in setting the flag
|
||||
if !wasExitingBefore && wasExitingAfter && !results[index] {
|
||||
t.Errorf("Goroutine %d: Flag was set but CAS failed", index)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// Exactly one goroutine should have successfully set the flag
|
||||
successCount := 0
|
||||
for _, success := range results {
|
||||
if success {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
|
||||
if successCount != 1 {
|
||||
t.Errorf("Expected exactly 1 successful flag set, got %d", successCount)
|
||||
}
|
||||
|
||||
// Flag should be set
|
||||
if !Exiting() {
|
||||
t.Error("Exiting flag should be set")
|
||||
}
|
||||
}
|
||||
|
||||
// Mock apps for testing
|
||||
type failingApp struct{}
|
||||
|
||||
func (fa *failingApp) CaddyModule() ModuleInfo {
|
||||
return ModuleInfo{
|
||||
ID: "failing-app",
|
||||
New: func() Module { return new(failingApp) },
|
||||
}
|
||||
}
|
||||
|
||||
func (fa *failingApp) Start() error {
|
||||
return fmt.Errorf("simulated start failure")
|
||||
}
|
||||
|
||||
func (fa *failingApp) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type workingApp struct{}
|
||||
|
||||
func (wa *workingApp) CaddyModule() ModuleInfo {
|
||||
return ModuleInfo{
|
||||
ID: "working-app",
|
||||
New: func() Module { return new(workingApp) },
|
||||
}
|
||||
}
|
||||
|
||||
func (wa *workingApp) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wa *workingApp) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type failingStopApp struct{}
|
||||
|
||||
func (fsa *failingStopApp) CaddyModule() ModuleInfo {
|
||||
return ModuleInfo{
|
||||
ID: "failing-stop-app",
|
||||
New: func() Module { return new(failingStopApp) },
|
||||
}
|
||||
}
|
||||
|
||||
func (fsa *failingStopApp) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fsa *failingStopApp) Stop() error {
|
||||
return fmt.Errorf("simulated stop failure")
|
||||
}
|
||||
+19
-7
@@ -63,10 +63,17 @@ type Context struct {
|
||||
// modules which are loaded will be properly unloaded.
|
||||
// See standard library context package's documentation.
|
||||
func NewContext(ctx Context) (Context, context.CancelFunc) {
|
||||
newCtx, cancelCause := NewContextWithCause(ctx)
|
||||
return newCtx, func() { cancelCause(nil) }
|
||||
}
|
||||
|
||||
// NewContextWithCause is like NewContext but returns a context.CancelCauseFunc.
|
||||
// EXPERIMENTAL: This API is subject to change.
|
||||
func NewContextWithCause(ctx Context) (Context, context.CancelCauseFunc) {
|
||||
newCtx := Context{moduleInstances: make(map[string][]Module), cfg: ctx.cfg, metricsRegistry: prometheus.NewPedanticRegistry()}
|
||||
c, cancel := context.WithCancel(ctx.Context)
|
||||
wrappedCancel := func() {
|
||||
cancel()
|
||||
c, cancel := context.WithCancelCause(ctx.Context)
|
||||
wrappedCancel := func(cause error) {
|
||||
cancel(cause)
|
||||
|
||||
for _, f := range ctx.cleanupFuncs {
|
||||
f()
|
||||
@@ -371,7 +378,7 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
|
||||
// value must be a pointer for unmarshaling into concrete type, even if
|
||||
// the module's concrete type is a slice or map; New() *should* return
|
||||
// a pointer, otherwise unmarshaling errors or panics will occur
|
||||
if rv := reflect.ValueOf(val); rv.Kind() != reflect.Ptr {
|
||||
if rv := reflect.ValueOf(val); rv.Kind() != reflect.Pointer {
|
||||
log.Printf("[WARNING] ModuleInfo.New() for module '%s' did not return a pointer,"+
|
||||
" so we are using reflection to make a pointer instead; please fix this by"+
|
||||
" using new(Type) or &Type notation in your module's New() function.", id)
|
||||
@@ -608,6 +615,11 @@ func (ctx Context) Slogger() *slog.Logger {
|
||||
core zapcore.Core
|
||||
moduleID string
|
||||
)
|
||||
|
||||
// the default enables traces at ERROR level, this disables
|
||||
// them by setting it to a level higher than any other level
|
||||
tracesOpt := zapslog.AddStacktraceAt(slog.Level(127))
|
||||
|
||||
if ctx.cfg == nil {
|
||||
// often the case in tests; just use a dev logger
|
||||
l, err := zap.NewDevelopment()
|
||||
@@ -616,16 +628,16 @@ func (ctx Context) Slogger() *slog.Logger {
|
||||
}
|
||||
|
||||
core = l.Core()
|
||||
handler = zapslog.NewHandler(core)
|
||||
handler = zapslog.NewHandler(core, tracesOpt)
|
||||
} else {
|
||||
mod := ctx.Module()
|
||||
if mod == nil {
|
||||
core = Log().Core()
|
||||
handler = zapslog.NewHandler(core)
|
||||
handler = zapslog.NewHandler(core, tracesOpt)
|
||||
} else {
|
||||
moduleID = string(mod.CaddyModule().ID)
|
||||
core = ctx.cfg.Logging.Logger(mod).Core()
|
||||
handler = zapslog.NewHandler(core, zapslog.WithName(moduleID))
|
||||
handler = zapslog.NewHandler(core, zapslog.WithName(moduleID), tracesOpt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,407 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseDuration_EdgeCases(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectErr bool
|
||||
expected time.Duration
|
||||
}{
|
||||
{
|
||||
name: "zero duration",
|
||||
input: "0",
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
name: "invalid format",
|
||||
input: "abc",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "negative days",
|
||||
input: "-2d",
|
||||
expected: -48 * time.Hour,
|
||||
},
|
||||
{
|
||||
name: "decimal days",
|
||||
input: "0.5d",
|
||||
expected: 12 * time.Hour,
|
||||
},
|
||||
{
|
||||
name: "large decimal days",
|
||||
input: "365.25d",
|
||||
expected: time.Duration(365.25*24) * time.Hour,
|
||||
},
|
||||
{
|
||||
name: "multiple days in same string",
|
||||
input: "1d2d3d",
|
||||
expected: (24 * 6) * time.Hour, // 6 days total
|
||||
},
|
||||
{
|
||||
name: "days with other units",
|
||||
input: "1d30m15s",
|
||||
expected: 24*time.Hour + 30*time.Minute + 15*time.Second,
|
||||
},
|
||||
{
|
||||
name: "malformed days",
|
||||
input: "d",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid day value",
|
||||
input: "abcd",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "overflow protection",
|
||||
input: "9999999999999999999999999d",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "zero days",
|
||||
input: "0d",
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
name: "input at limit",
|
||||
input: strings.Repeat("1", 1024) + "ns",
|
||||
expectErr: true, // Likely to cause parsing error due to size
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result, err := ParseDuration(test.input)
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error but got none")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if !test.expectErr && result != test.expected {
|
||||
t.Errorf("Expected %v, got %v", test.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDuration_InputLengthLimit(t *testing.T) {
|
||||
// Test the 1024 character limit
|
||||
longInput := strings.Repeat("1", 1025) + "s"
|
||||
|
||||
_, err := ParseDuration(longInput)
|
||||
if err == nil {
|
||||
t.Error("Expected error for input longer than 1024 characters")
|
||||
}
|
||||
|
||||
expectedErrMsg := "parsing duration: input string too long"
|
||||
if err.Error() != expectedErrMsg {
|
||||
t.Errorf("Expected error message '%s', got '%s'", expectedErrMsg, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDuration_ComplexNumberFormats(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected time.Duration
|
||||
}{
|
||||
{
|
||||
input: "+1d",
|
||||
expected: 24 * time.Hour,
|
||||
},
|
||||
{
|
||||
input: "-1.5d",
|
||||
expected: -36 * time.Hour,
|
||||
},
|
||||
{
|
||||
input: "1.0d",
|
||||
expected: 24 * time.Hour,
|
||||
},
|
||||
{
|
||||
input: "0.25d",
|
||||
expected: 6 * time.Hour,
|
||||
},
|
||||
{
|
||||
input: "1.5d30m",
|
||||
expected: 36*time.Hour + 30*time.Minute,
|
||||
},
|
||||
{
|
||||
input: "2.5d1h30m45s",
|
||||
expected: 60*time.Hour + time.Hour + 30*time.Minute + 45*time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.input, func(t *testing.T) {
|
||||
result, err := ParseDuration(test.input)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
if result != test.expected {
|
||||
t.Errorf("Expected %v, got %v", test.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuration_UnmarshalJSON_TypeValidation(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectErr bool
|
||||
expected time.Duration
|
||||
}{
|
||||
{
|
||||
name: "null value",
|
||||
input: "null",
|
||||
expectErr: false,
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
name: "boolean value",
|
||||
input: "true",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "array value",
|
||||
input: `[1,2,3]`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "object value",
|
||||
input: `{"duration": "5m"}`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "negative integer",
|
||||
input: "-1000000000",
|
||||
expected: -time.Second,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "zero integer",
|
||||
input: "0",
|
||||
expected: 0,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "large integer",
|
||||
input: "9223372036854775807", // Max int64
|
||||
expected: time.Duration(math.MaxInt64),
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "float as integer (invalid JSON for int)",
|
||||
input: "1.5",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "string with special characters",
|
||||
input: `"5m\"30s"`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "string with unicode",
|
||||
input: `"5m🚀"`,
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var d Duration
|
||||
err := d.UnmarshalJSON([]byte(test.input))
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error but got none")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if !test.expectErr && time.Duration(d) != test.expected {
|
||||
t.Errorf("Expected %v, got %v", test.expected, time.Duration(d))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuration_JSON_RoundTrip(t *testing.T) {
|
||||
tests := []struct {
|
||||
duration time.Duration
|
||||
asString bool
|
||||
}{
|
||||
{duration: 5 * time.Minute, asString: true},
|
||||
{duration: 24 * time.Hour, asString: false}, // Will be stored as nanoseconds
|
||||
{duration: 0, asString: false},
|
||||
{duration: -time.Hour, asString: true},
|
||||
{duration: time.Nanosecond, asString: false},
|
||||
{duration: time.Second, asString: false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.duration.String(), func(t *testing.T) {
|
||||
d := Duration(test.duration)
|
||||
|
||||
// Marshal to JSON
|
||||
jsonData, err := json.Marshal(d)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal: %v", err)
|
||||
}
|
||||
|
||||
// Unmarshal back
|
||||
var unmarshaled Duration
|
||||
err = unmarshaled.UnmarshalJSON(jsonData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
// Should be equal
|
||||
if time.Duration(unmarshaled) != test.duration {
|
||||
t.Errorf("Round trip failed: expected %v, got %v", test.duration, time.Duration(unmarshaled))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDuration_Precision(t *testing.T) {
|
||||
// Test floating point precision with days
|
||||
tests := []struct {
|
||||
input string
|
||||
expected time.Duration
|
||||
}{
|
||||
{
|
||||
input: "0.1d",
|
||||
expected: time.Duration(0.1 * 24 * float64(time.Hour)),
|
||||
},
|
||||
{
|
||||
input: "0.01d",
|
||||
expected: time.Duration(0.01 * 24 * float64(time.Hour)),
|
||||
},
|
||||
{
|
||||
input: "0.001d",
|
||||
expected: time.Duration(0.001 * 24 * float64(time.Hour)),
|
||||
},
|
||||
{
|
||||
input: "1.23456789d",
|
||||
expected: time.Duration(1.23456789 * 24 * float64(time.Hour)),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.input, func(t *testing.T) {
|
||||
result, err := ParseDuration(test.input)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
// Allow for small floating point differences
|
||||
diff := result - test.expected
|
||||
if diff < 0 {
|
||||
diff = -diff
|
||||
}
|
||||
if diff > time.Nanosecond {
|
||||
t.Errorf("Expected %v, got %v (diff: %v)", test.expected, result, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDuration_Boundary_Values(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "minimum day value",
|
||||
input: "0.000000001d", // Very small but valid
|
||||
},
|
||||
{
|
||||
name: "very large day value",
|
||||
input: "999999999999999999999d",
|
||||
expectErr: true, // Should overflow
|
||||
},
|
||||
{
|
||||
name: "negative zero",
|
||||
input: "-0d",
|
||||
},
|
||||
{
|
||||
name: "positive zero",
|
||||
input: "+0d",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, err := ParseDuration(test.input)
|
||||
|
||||
if test.expectErr && err == nil {
|
||||
t.Error("Expected error but got none")
|
||||
}
|
||||
if !test.expectErr && err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseDuration_SimpleDay(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
ParseDuration("1d")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseDuration_ComplexDay(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
ParseDuration("1.5d30m15.5s")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseDuration_MultipleDays(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
ParseDuration("1d2d3d4d5d")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDuration_UnmarshalJSON_String(b *testing.B) {
|
||||
input := []byte(`"5m30s"`)
|
||||
var d Duration
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
d.UnmarshalJSON(input)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDuration_UnmarshalJSON_Integer(b *testing.B) {
|
||||
input := []byte("300000000000") // 5 minutes in nanoseconds
|
||||
var d Duration
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
d.UnmarshalJSON(input)
|
||||
}
|
||||
}
|
||||
+642
@@ -0,0 +1,642 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNewEvent_Basic(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
eventName := "test.event"
|
||||
eventData := map[string]any{
|
||||
"key1": "value1",
|
||||
"key2": 42,
|
||||
}
|
||||
|
||||
event, err := NewEvent(ctx, eventName, eventData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
// Verify event properties
|
||||
if event.Name() != eventName {
|
||||
t.Errorf("Expected name '%s', got '%s'", eventName, event.Name())
|
||||
}
|
||||
|
||||
if event.Data == nil {
|
||||
t.Error("Expected non-nil data")
|
||||
}
|
||||
|
||||
if len(event.Data) != len(eventData) {
|
||||
t.Errorf("Expected %d data items, got %d", len(eventData), len(event.Data))
|
||||
}
|
||||
|
||||
for key, expectedValue := range eventData {
|
||||
if actualValue, exists := event.Data[key]; !exists || actualValue != expectedValue {
|
||||
t.Errorf("Data key '%s': expected %v, got %v", key, expectedValue, actualValue)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify ID is generated
|
||||
if event.ID().String() == "" {
|
||||
t.Error("Event ID should not be empty")
|
||||
}
|
||||
|
||||
// Verify timestamp is recent
|
||||
if time.Since(event.Timestamp()) > time.Second {
|
||||
t.Error("Event timestamp should be recent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewEvent_NameNormalization(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"UPPERCASE", "uppercase"},
|
||||
{"MixedCase", "mixedcase"},
|
||||
{"already.lower", "already.lower"},
|
||||
{"With-Dashes", "with-dashes"},
|
||||
{"With_Underscores", "with_underscores"},
|
||||
{"", ""},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.input, func(t *testing.T) {
|
||||
event, err := NewEvent(ctx, test.input, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
if event.Name() != test.expected {
|
||||
t.Errorf("Expected normalized name '%s', got '%s'", test.expected, event.Name())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_CloudEvent_NilData(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, err := NewEvent(ctx, "test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
// Should not panic with nil data
|
||||
if cloudEvent.Data == nil {
|
||||
t.Error("CloudEvent data should not be nil even with nil input")
|
||||
}
|
||||
|
||||
// Should be valid JSON
|
||||
var parsed any
|
||||
if err := json.Unmarshal(cloudEvent.Data, &parsed); err != nil {
|
||||
t.Errorf("CloudEvent data should be valid JSON: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_CloudEvent_WithModule(t *testing.T) {
|
||||
// Create a context with a mock module
|
||||
mockMod := &mockModule{}
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Simulate module ancestry
|
||||
ctx.ancestry = []Module{mockMod}
|
||||
|
||||
event, err := NewEvent(ctx, "test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
// Source should be the module ID
|
||||
expectedSource := string(mockMod.CaddyModule().ID)
|
||||
if cloudEvent.Source != expectedSource {
|
||||
t.Errorf("Expected source '%s', got '%s'", expectedSource, cloudEvent.Source)
|
||||
}
|
||||
|
||||
// Origin should be the module
|
||||
if event.Origin() != mockMod {
|
||||
t.Error("Expected event origin to be the mock module")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_CloudEvent_Fields(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
eventName := "test.event"
|
||||
eventData := map[string]any{"test": "data"}
|
||||
|
||||
event, err := NewEvent(ctx, eventName, eventData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
// Verify CloudEvent fields
|
||||
if cloudEvent.ID == "" {
|
||||
t.Error("CloudEvent ID should not be empty")
|
||||
}
|
||||
|
||||
if cloudEvent.Source != "caddy" {
|
||||
t.Errorf("Expected source 'caddy' for nil module, got '%s'", cloudEvent.Source)
|
||||
}
|
||||
|
||||
if cloudEvent.SpecVersion != "1.0" {
|
||||
t.Errorf("Expected spec version '1.0', got '%s'", cloudEvent.SpecVersion)
|
||||
}
|
||||
|
||||
if cloudEvent.Type != eventName {
|
||||
t.Errorf("Expected type '%s', got '%s'", eventName, cloudEvent.Type)
|
||||
}
|
||||
|
||||
if cloudEvent.DataContentType != "application/json" {
|
||||
t.Errorf("Expected content type 'application/json', got '%s'", cloudEvent.DataContentType)
|
||||
}
|
||||
|
||||
// Verify data is valid JSON
|
||||
var parsedData map[string]any
|
||||
if err := json.Unmarshal(cloudEvent.Data, &parsedData); err != nil {
|
||||
t.Errorf("CloudEvent data is not valid JSON: %v", err)
|
||||
}
|
||||
|
||||
if parsedData["test"] != "data" {
|
||||
t.Errorf("Expected data to contain test='data', got %v", parsedData)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_ConcurrentAccess(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, err := NewEvent(ctx, "concurrent.test", map[string]any{
|
||||
"counter": 0,
|
||||
"data": "shared",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
const numGoroutines = 50
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Test concurrent read access to event properties
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
|
||||
// These should be safe for concurrent access
|
||||
_ = event.ID()
|
||||
_ = event.Name()
|
||||
_ = event.Timestamp()
|
||||
_ = event.Origin()
|
||||
_ = event.CloudEvent()
|
||||
|
||||
// Data map is not synchronized, so read-only access should be safe
|
||||
if data, exists := event.Data["data"]; !exists || data != "shared" {
|
||||
t.Errorf("Goroutine %d: Expected shared data", id)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestEvent_DataModification_Warning(t *testing.T) {
|
||||
// This test documents the non-thread-safe nature of event data
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, err := NewEvent(ctx, "data.test", map[string]any{
|
||||
"mutable": "original",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
// Modifying data after creation (this is allowed but not thread-safe)
|
||||
event.Data["mutable"] = "modified"
|
||||
event.Data["new_key"] = "new_value"
|
||||
|
||||
// Verify modifications are visible
|
||||
if event.Data["mutable"] != "modified" {
|
||||
t.Error("Data modification should be visible")
|
||||
}
|
||||
if event.Data["new_key"] != "new_value" {
|
||||
t.Error("New data should be visible")
|
||||
}
|
||||
|
||||
// CloudEvent should reflect the current state
|
||||
cloudEvent := event.CloudEvent()
|
||||
var parsedData map[string]any
|
||||
json.Unmarshal(cloudEvent.Data, &parsedData)
|
||||
|
||||
if parsedData["mutable"] != "modified" {
|
||||
t.Error("CloudEvent should reflect modified data")
|
||||
}
|
||||
if parsedData["new_key"] != "new_value" {
|
||||
t.Error("CloudEvent should reflect new data")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_Aborted_State(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, err := NewEvent(ctx, "abort.test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
// Initially not aborted
|
||||
if event.Aborted != nil {
|
||||
t.Error("Event should not be aborted initially")
|
||||
}
|
||||
|
||||
// Simulate aborting the event
|
||||
event.Aborted = ErrEventAborted
|
||||
|
||||
if event.Aborted != ErrEventAborted {
|
||||
t.Error("Event should be marked as aborted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrEventAborted_Value(t *testing.T) {
|
||||
if ErrEventAborted == nil {
|
||||
t.Error("ErrEventAborted should not be nil")
|
||||
}
|
||||
|
||||
if ErrEventAborted.Error() != "event aborted" {
|
||||
t.Errorf("Expected 'event aborted', got '%s'", ErrEventAborted.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_UniqueIDs(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
const numEvents = 1000
|
||||
ids := make(map[string]bool)
|
||||
|
||||
for i := 0; i < numEvents; i++ {
|
||||
event, err := NewEvent(ctx, "unique.test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event %d: %v", i, err)
|
||||
}
|
||||
|
||||
idStr := event.ID().String()
|
||||
if ids[idStr] {
|
||||
t.Errorf("Duplicate event ID: %s", idStr)
|
||||
}
|
||||
ids[idStr] = true
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_TimestampProgression(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Create events with small delays
|
||||
events := make([]Event, 5)
|
||||
for i := range events {
|
||||
var err error
|
||||
events[i], err = NewEvent(ctx, "time.test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event %d: %v", i, err)
|
||||
}
|
||||
|
||||
if i < len(events)-1 {
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify timestamps are in ascending order
|
||||
for i := 1; i < len(events); i++ {
|
||||
if !events[i].Timestamp().After(events[i-1].Timestamp()) {
|
||||
t.Errorf("Event %d timestamp (%v) should be after event %d timestamp (%v)",
|
||||
i, events[i].Timestamp(), i-1, events[i-1].Timestamp())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_JSON_Serialization(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
eventData := map[string]any{
|
||||
"string": "value",
|
||||
"number": 42,
|
||||
"boolean": true,
|
||||
"array": []any{1, 2, 3},
|
||||
"object": map[string]any{"nested": "value"},
|
||||
}
|
||||
|
||||
event, err := NewEvent(ctx, "json.test", eventData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
// CloudEvent should be JSON serializable
|
||||
cloudEventJSON, err := json.Marshal(cloudEvent)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal CloudEvent: %v", err)
|
||||
}
|
||||
|
||||
// Should be able to unmarshal back
|
||||
var parsed CloudEvent
|
||||
err = json.Unmarshal(cloudEventJSON, &parsed)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to unmarshal CloudEvent: %v", err)
|
||||
}
|
||||
|
||||
// Verify key fields survived round-trip
|
||||
if parsed.ID != cloudEvent.ID {
|
||||
t.Errorf("ID mismatch after round-trip")
|
||||
}
|
||||
if parsed.Source != cloudEvent.Source {
|
||||
t.Errorf("Source mismatch after round-trip")
|
||||
}
|
||||
if parsed.Type != cloudEvent.Type {
|
||||
t.Errorf("Type mismatch after round-trip")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_EmptyData(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Test with empty map
|
||||
event1, err := NewEvent(ctx, "empty.map", map[string]any{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event with empty map: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent1 := event1.CloudEvent()
|
||||
var parsed1 map[string]any
|
||||
json.Unmarshal(cloudEvent1.Data, &parsed1)
|
||||
if len(parsed1) != 0 {
|
||||
t.Error("Expected empty data map")
|
||||
}
|
||||
|
||||
// Test with nil data
|
||||
event2, err := NewEvent(ctx, "nil.data", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event with nil data: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent2 := event2.CloudEvent()
|
||||
if cloudEvent2.Data == nil {
|
||||
t.Error("CloudEvent data should not be nil even with nil input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_Origin_WithModule(t *testing.T) {
|
||||
mockMod := &mockEventModule{}
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Set module in ancestry
|
||||
ctx.ancestry = []Module{mockMod}
|
||||
|
||||
event, err := NewEvent(ctx, "module.test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
if event.Origin() != mockMod {
|
||||
t.Error("Expected event origin to be the mock module")
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
expectedSource := string(mockMod.CaddyModule().ID)
|
||||
if cloudEvent.Source != expectedSource {
|
||||
t.Errorf("Expected source '%s', got '%s'", expectedSource, cloudEvent.Source)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_LargeData(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Create event with large data
|
||||
largeData := make(map[string]any)
|
||||
for i := 0; i < 1000; i++ {
|
||||
largeData[fmt.Sprintf("key%d", i)] = fmt.Sprintf("value%d", i)
|
||||
}
|
||||
|
||||
event, err := NewEvent(ctx, "large.data", largeData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event with large data: %v", err)
|
||||
}
|
||||
|
||||
// CloudEvent should handle large data
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
var parsedData map[string]any
|
||||
err = json.Unmarshal(cloudEvent.Data, &parsedData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse large data in CloudEvent: %v", err)
|
||||
}
|
||||
|
||||
if len(parsedData) != len(largeData) {
|
||||
t.Errorf("Expected %d data items, got %d", len(largeData), len(parsedData))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_SpecialCharacters_InData(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
specialData := map[string]any{
|
||||
"unicode": "🚀✨",
|
||||
"newlines": "line1\nline2\r\nline3",
|
||||
"quotes": `"double" and 'single' quotes`,
|
||||
"backslashes": "\\path\\to\\file",
|
||||
"json_chars": `{"key": "value"}`,
|
||||
"empty": "",
|
||||
"null_value": nil,
|
||||
}
|
||||
|
||||
event, err := NewEvent(ctx, "special.chars", specialData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
cloudEvent := event.CloudEvent()
|
||||
|
||||
// Should produce valid JSON
|
||||
var parsedData map[string]any
|
||||
err = json.Unmarshal(cloudEvent.Data, &parsedData)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse data with special characters: %v", err)
|
||||
}
|
||||
|
||||
// Verify some special cases survived JSON round-trip
|
||||
if parsedData["unicode"] != "🚀✨" {
|
||||
t.Error("Unicode characters should survive JSON encoding")
|
||||
}
|
||||
|
||||
if parsedData["quotes"] != `"double" and 'single' quotes` {
|
||||
t.Error("Quotes should be properly escaped in JSON")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_ConcurrentCreation(t *testing.T) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
const numGoroutines = 100
|
||||
var wg sync.WaitGroup
|
||||
events := make([]Event, numGoroutines)
|
||||
errors := make([]error, numGoroutines)
|
||||
|
||||
// Create events concurrently
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
|
||||
eventData := map[string]any{
|
||||
"goroutine": index,
|
||||
"timestamp": time.Now().UnixNano(),
|
||||
}
|
||||
|
||||
events[index], errors[index] = NewEvent(ctx, "concurrent.test", eventData)
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// Verify all events were created successfully
|
||||
ids := make(map[string]bool)
|
||||
for i, event := range events {
|
||||
if errors[i] != nil {
|
||||
t.Errorf("Goroutine %d: Failed to create event: %v", i, errors[i])
|
||||
continue
|
||||
}
|
||||
|
||||
// Verify unique IDs
|
||||
idStr := event.ID().String()
|
||||
if ids[idStr] {
|
||||
t.Errorf("Duplicate event ID: %s", idStr)
|
||||
}
|
||||
ids[idStr] = true
|
||||
|
||||
// Verify data integrity
|
||||
if goroutineID, exists := event.Data["goroutine"]; !exists || goroutineID != i {
|
||||
t.Errorf("Event %d: Data corruption detected", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mock module for event testing
|
||||
type mockEventModule struct{}
|
||||
|
||||
func (m *mockEventModule) CaddyModule() ModuleInfo {
|
||||
return ModuleInfo{
|
||||
ID: "test.event.module",
|
||||
New: func() Module { return new(mockEventModule) },
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_TimeAccuracy(t *testing.T) {
|
||||
before := time.Now()
|
||||
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, err := NewEvent(ctx, "time.accuracy", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create event: %v", err)
|
||||
}
|
||||
|
||||
after := time.Now()
|
||||
eventTime := event.Timestamp()
|
||||
|
||||
// Event timestamp should be between before and after
|
||||
if eventTime.Before(before) || eventTime.After(after) {
|
||||
t.Errorf("Event timestamp %v should be between %v and %v", eventTime, before, after)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewEvent(b *testing.B) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
eventData := map[string]any{
|
||||
"key1": "value1",
|
||||
"key2": 42,
|
||||
"key3": true,
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewEvent(ctx, "benchmark.test", eventData)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEvent_CloudEvent(b *testing.B) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
event, _ := NewEvent(ctx, "benchmark.cloud", map[string]any{
|
||||
"data": "test",
|
||||
"num": 123,
|
||||
})
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
event.CloudEvent()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEvent_CloudEvent_LargeData(b *testing.B) {
|
||||
ctx, cancel := NewContext(Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
|
||||
// Create event with substantial data
|
||||
largeData := make(map[string]any)
|
||||
for i := 0; i < 100; i++ {
|
||||
largeData[fmt.Sprintf("key%d", i)] = fmt.Sprintf("value%d", i)
|
||||
}
|
||||
|
||||
event, _ := NewEvent(ctx, "benchmark.large", largeData)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
event.CloudEvent()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !windows
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFastAbs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
checkFunc func(result string, err error) error
|
||||
}{
|
||||
{
|
||||
name: "absolute path",
|
||||
input: "/usr/local/bin",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if result != "/usr/local/bin" {
|
||||
t.Errorf("expected /usr/local/bin, got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "absolute path with dots",
|
||||
input: "/usr/local/../bin",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if result != "/usr/bin" {
|
||||
t.Errorf("expected /usr/bin, got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "relative path",
|
||||
input: "relative/path",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if !filepath.IsAbs(result) {
|
||||
t.Errorf("expected absolute path, got %s", result)
|
||||
}
|
||||
if !strings.HasSuffix(result, "relative/path") {
|
||||
t.Errorf("expected path to end with 'relative/path', got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dot",
|
||||
input: ".",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if !filepath.IsAbs(result) {
|
||||
t.Errorf("expected absolute path, got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dot dot",
|
||||
input: "..",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if !filepath.IsAbs(result) {
|
||||
t.Errorf("expected absolute path, got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
// Empty string should resolve to current directory
|
||||
if !filepath.IsAbs(result) {
|
||||
t.Errorf("expected absolute path, got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "complex relative path",
|
||||
input: "./foo/../bar/./baz",
|
||||
checkFunc: func(result string, err error) error {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if !filepath.IsAbs(result) {
|
||||
t.Errorf("expected absolute path, got %s", result)
|
||||
}
|
||||
if !strings.HasSuffix(result, "bar/baz") {
|
||||
t.Errorf("expected path to end with 'bar/baz', got %s", result)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := FastAbs(tt.input)
|
||||
tt.checkFunc(result, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestFastAbsVsFilepathAbs compares FastAbs with filepath.Abs to ensure consistent behavior
|
||||
func TestFastAbsVsFilepathAbs(t *testing.T) {
|
||||
// Skip if working directory cannot be determined
|
||||
if wderr != nil {
|
||||
t.Skip("working directory error, skipping comparison test")
|
||||
}
|
||||
|
||||
testPaths := []string{
|
||||
".",
|
||||
"..",
|
||||
"foo",
|
||||
"foo/bar",
|
||||
"./foo",
|
||||
"../foo",
|
||||
"/absolute/path",
|
||||
"/usr/local/bin",
|
||||
}
|
||||
|
||||
for _, path := range testPaths {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
fast, fastErr := FastAbs(path)
|
||||
std, stdErr := filepath.Abs(path)
|
||||
|
||||
// Both should succeed or fail together
|
||||
if (fastErr != nil) != (stdErr != nil) {
|
||||
t.Errorf("error mismatch: FastAbs=%v, filepath.Abs=%v", fastErr, stdErr)
|
||||
}
|
||||
|
||||
// If both succeed, results should be the same
|
||||
if fastErr == nil && stdErr == nil && fast != std {
|
||||
t.Errorf("result mismatch for %q: FastAbs=%s, filepath.Abs=%s", path, fast, std)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestFastAbsErrorHandling tests error handling when working directory is unavailable
|
||||
func TestFastAbsErrorHandling(t *testing.T) {
|
||||
// This tests the cached wderr behavior
|
||||
if wderr != nil {
|
||||
// Test that FastAbs properly returns the cached error for relative paths
|
||||
_, err := FastAbs("relative/path")
|
||||
if err == nil {
|
||||
t.Error("expected error for relative path when working directory is unavailable")
|
||||
}
|
||||
if err != wderr {
|
||||
t.Errorf("expected cached wderr, got different error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkFastAbs benchmarks FastAbs
|
||||
func BenchmarkFastAbs(b *testing.B) {
|
||||
paths := []string{
|
||||
"relative/path",
|
||||
"/absolute/path",
|
||||
".",
|
||||
"..",
|
||||
"./foo/bar",
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
FastAbs(paths[i%len(paths)])
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkFastAbsVsStdLib compares performance of FastAbs vs filepath.Abs
|
||||
func BenchmarkFastAbsVsStdLib(b *testing.B) {
|
||||
path := "relative/path/to/file"
|
||||
|
||||
b.Run("FastAbs", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FastAbs(path)
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("filepath.Abs", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
filepath.Abs(path)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Mock filesystem implementation for testing
|
||||
type mockFileSystem struct {
|
||||
name string
|
||||
files map[string]string
|
||||
}
|
||||
|
||||
func (m *mockFileSystem) Open(name string) (fs.File, error) {
|
||||
if content, exists := m.files[name]; exists {
|
||||
return &mockFile{name: name, content: content}, nil
|
||||
}
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
|
||||
type mockFile struct {
|
||||
name string
|
||||
content string
|
||||
pos int
|
||||
}
|
||||
|
||||
func (m *mockFile) Stat() (fs.FileInfo, error) {
|
||||
return &mockFileInfo{name: m.name, size: int64(len(m.content))}, nil
|
||||
}
|
||||
|
||||
func (m *mockFile) Read(b []byte) (int, error) {
|
||||
if m.pos >= len(m.content) {
|
||||
return 0, fs.ErrClosed
|
||||
}
|
||||
n := copy(b, m.content[m.pos:])
|
||||
m.pos += n
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (m *mockFile) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
}
|
||||
|
||||
func (m *mockFileInfo) Name() string { return m.name }
|
||||
func (m *mockFileInfo) Size() int64 { return m.size }
|
||||
func (m *mockFileInfo) Mode() fs.FileMode { return 0o644 }
|
||||
func (m *mockFileInfo) ModTime() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
func (m *mockFileInfo) IsDir() bool { return false }
|
||||
func (m *mockFileInfo) Sys() any { return nil }
|
||||
|
||||
// Mock FileSystems implementation for testing
|
||||
type mockFileSystems struct {
|
||||
mu sync.RWMutex
|
||||
filesystems map[string]fs.FS
|
||||
defaultFS fs.FS
|
||||
}
|
||||
|
||||
func newMockFileSystems() *mockFileSystems {
|
||||
return &mockFileSystems{
|
||||
filesystems: make(map[string]fs.FS),
|
||||
defaultFS: &mockFileSystem{name: "default", files: map[string]string{"default.txt": "default content"}},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockFileSystems) Register(k string, v fs.FS) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.filesystems[k] = v
|
||||
}
|
||||
|
||||
func (m *mockFileSystems) Unregister(k string) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
delete(m.filesystems, k)
|
||||
}
|
||||
|
||||
func (m *mockFileSystems) Get(k string) (fs.FS, bool) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
v, ok := m.filesystems[k]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func (m *mockFileSystems) Default() fs.FS {
|
||||
return m.defaultFS
|
||||
}
|
||||
|
||||
func TestFileSystems_Register_Get(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
mockFS := &mockFileSystem{
|
||||
name: "test",
|
||||
files: map[string]string{"test.txt": "test content"},
|
||||
}
|
||||
|
||||
// Register filesystem
|
||||
fsys.Register("test", mockFS)
|
||||
|
||||
// Retrieve filesystem
|
||||
retrieved, exists := fsys.Get("test")
|
||||
if !exists {
|
||||
t.Error("Expected filesystem to exist after registration")
|
||||
}
|
||||
if retrieved != mockFS {
|
||||
t.Error("Retrieved filesystem is not the same as registered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystems_Unregister(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
mockFS := &mockFileSystem{name: "test"}
|
||||
|
||||
// Register then unregister
|
||||
fsys.Register("test", mockFS)
|
||||
fsys.Unregister("test")
|
||||
|
||||
// Should not exist after unregistration
|
||||
_, exists := fsys.Get("test")
|
||||
if exists {
|
||||
t.Error("Filesystem should not exist after unregistration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystems_Default(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
|
||||
defaultFS := fsys.Default()
|
||||
if defaultFS == nil {
|
||||
t.Error("Default filesystem should not be nil")
|
||||
}
|
||||
|
||||
// Test that default filesystem works
|
||||
file, err := defaultFS.Open("default.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to open default file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
data := make([]byte, 100)
|
||||
n, err := file.Read(data)
|
||||
if err != nil && err != fs.ErrClosed {
|
||||
t.Fatalf("Failed to read default file: %v", err)
|
||||
}
|
||||
|
||||
content := string(data[:n])
|
||||
if content != "default content" {
|
||||
t.Errorf("Expected 'default content', got '%s'", content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystems_Concurrent_Access(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
|
||||
const numGoroutines = 50
|
||||
const numOperations = 10
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Concurrent register/unregister/get operations
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
|
||||
key := fmt.Sprintf("fs-%d", id)
|
||||
mockFS := &mockFileSystem{
|
||||
name: key,
|
||||
files: map[string]string{key + ".txt": "content"},
|
||||
}
|
||||
|
||||
for j := 0; j < numOperations; j++ {
|
||||
// Register
|
||||
fsys.Register(key, mockFS)
|
||||
|
||||
// Get
|
||||
retrieved, exists := fsys.Get(key)
|
||||
if !exists {
|
||||
t.Errorf("Filesystem %s should exist", key)
|
||||
continue
|
||||
}
|
||||
if retrieved != mockFS {
|
||||
t.Errorf("Retrieved filesystem for %s is not correct", key)
|
||||
}
|
||||
|
||||
// Test file access
|
||||
file, err := retrieved.Open(key + ".txt")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to open file in %s: %v", key, err)
|
||||
continue
|
||||
}
|
||||
file.Close()
|
||||
|
||||
// Unregister
|
||||
fsys.Unregister(key)
|
||||
|
||||
// Should not exist after unregister
|
||||
_, stillExists := fsys.Get(key)
|
||||
if stillExists {
|
||||
t.Errorf("Filesystem %s should not exist after unregister", key)
|
||||
}
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestFileSystems_Get_NonExistent(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
|
||||
_, exists := fsys.Get("non-existent")
|
||||
if exists {
|
||||
t.Error("Non-existent filesystem should not exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystems_Register_Overwrite(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
key := "overwrite-test"
|
||||
|
||||
// Register first filesystem
|
||||
fs1 := &mockFileSystem{name: "fs1"}
|
||||
fsys.Register(key, fs1)
|
||||
|
||||
// Register second filesystem with same key (should overwrite)
|
||||
fs2 := &mockFileSystem{name: "fs2"}
|
||||
fsys.Register(key, fs2)
|
||||
|
||||
// Should get the second filesystem
|
||||
retrieved, exists := fsys.Get(key)
|
||||
if !exists {
|
||||
t.Error("Filesystem should exist")
|
||||
}
|
||||
if retrieved != fs2 {
|
||||
t.Error("Should get the overwritten filesystem")
|
||||
}
|
||||
if retrieved == fs1 {
|
||||
t.Error("Should not get the original filesystem")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystems_Concurrent_RegisterUnregister_SameKey(t *testing.T) {
|
||||
fsys := newMockFileSystems()
|
||||
key := "concurrent-key"
|
||||
|
||||
const numGoroutines = 20
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Half the goroutines register, half unregister
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
if i%2 == 0 {
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
mockFS := &mockFileSystem{name: fmt.Sprintf("fs-%d", id)}
|
||||
fsys.Register(key, mockFS)
|
||||
}(i)
|
||||
} else {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
fsys.Unregister(key)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// The final state is unpredictable due to race conditions,
|
||||
// but the operations should not panic or cause corruption
|
||||
// Test passes if we reach here without issues
|
||||
}
|
||||
|
||||
func TestFileSystems_StressTest(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping stress test in short mode")
|
||||
}
|
||||
|
||||
fsys := newMockFileSystems()
|
||||
|
||||
const numGoroutines = 100
|
||||
const duration = 100 * time.Millisecond
|
||||
|
||||
var wg sync.WaitGroup
|
||||
stopChan := make(chan struct{})
|
||||
|
||||
// Start timer
|
||||
go func() {
|
||||
time.Sleep(duration)
|
||||
close(stopChan)
|
||||
}()
|
||||
|
||||
// Stress test with continuous operations
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
|
||||
key := fmt.Sprintf("stress-fs-%d", id%10) // Use limited set of keys
|
||||
mockFS := &mockFileSystem{
|
||||
name: key,
|
||||
files: map[string]string{key + ".txt": "stress content"},
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stopChan:
|
||||
return
|
||||
default:
|
||||
// Rapid register/get/unregister cycles
|
||||
fsys.Register(key, mockFS)
|
||||
|
||||
if retrieved, exists := fsys.Get(key); exists {
|
||||
// Try to use the filesystem
|
||||
if file, err := retrieved.Open(key + ".txt"); err == nil {
|
||||
file.Close()
|
||||
}
|
||||
}
|
||||
|
||||
fsys.Unregister(key)
|
||||
}
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// Test passes if we reach here without panics or deadlocks
|
||||
}
|
||||
@@ -1,76 +1,79 @@
|
||||
module github.com/caddyserver/caddy/v2
|
||||
|
||||
go 1.25
|
||||
go 1.25.1
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.6.0
|
||||
github.com/DeRuina/timberjack v1.3.9
|
||||
github.com/DeRuina/timberjack v1.4.2
|
||||
github.com/KimMachineGun/automemlimit v0.7.5
|
||||
github.com/Masterminds/sprig/v3 v3.3.0
|
||||
github.com/alecthomas/chroma/v2 v2.21.1
|
||||
github.com/alecthomas/chroma/v2 v2.23.1
|
||||
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b
|
||||
github.com/caddyserver/certmagic v0.25.1
|
||||
github.com/caddyserver/zerossl v0.1.4
|
||||
github.com/cloudflare/circl v1.6.2
|
||||
github.com/caddyserver/certmagic v0.25.3
|
||||
github.com/caddyserver/zerossl v0.1.5
|
||||
github.com/cloudflare/circl v1.6.3
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/go-chi/chi/v5 v5.2.3
|
||||
github.com/google/cel-go v0.26.1
|
||||
github.com/go-chi/chi/v5 v5.2.5
|
||||
github.com/google/cel-go v0.28.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/klauspost/compress v1.18.2
|
||||
github.com/klauspost/compress v1.18.5
|
||||
github.com/klauspost/cpuid/v2 v2.3.0
|
||||
github.com/mholt/acmez/v3 v3.1.4
|
||||
github.com/mholt/acmez/v3 v3.1.6
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/quic-go/quic-go v0.59.0
|
||||
github.com/smallstep/certificates v0.29.0
|
||||
github.com/smallstep/nosql v0.7.0
|
||||
github.com/quic-go/quic-go v0.59.1
|
||||
github.com/smallstep/certificates v0.30.2
|
||||
github.com/smallstep/nosql v0.8.0
|
||||
github.com/smallstep/truststore v0.13.0
|
||||
github.com/spf13/cobra v1.10.2
|
||||
github.com/spf13/pflag v1.0.10
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/tailscale/tscert v0.0.0-20251216020129-aea342f6d747
|
||||
github.com/yuin/goldmark v1.7.15
|
||||
github.com/yuin/goldmark v1.8.2
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.64.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.64.0
|
||||
go.opentelemetry.io/otel v1.39.0
|
||||
go.opentelemetry.io/otel/sdk v1.39.0
|
||||
go.step.sm/crypto v0.75.0
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.68.0
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.65.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.65.0
|
||||
go.opentelemetry.io/otel v1.43.0
|
||||
go.opentelemetry.io/otel/sdk v1.43.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0
|
||||
go.step.sm/crypto v0.81.0
|
||||
go.uber.org/automaxprocs v1.6.0
|
||||
go.uber.org/zap v1.27.1
|
||||
go.uber.org/zap/exp v0.3.0
|
||||
golang.org/x/crypto v0.46.0
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20250927194341-2beaa59a3c99
|
||||
golang.org/x/net v0.48.0
|
||||
golang.org/x/sync v0.19.0
|
||||
golang.org/x/term v0.38.0
|
||||
golang.org/x/time v0.14.0
|
||||
golang.org/x/crypto v0.51.0
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20260213171211-a408498e5541
|
||||
golang.org/x/net v0.53.0
|
||||
golang.org/x/sync v0.20.0
|
||||
golang.org/x/term v0.43.0
|
||||
golang.org/x/time v0.15.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
cel.dev/expr v0.24.0 // indirect
|
||||
cloud.google.com/go/auth v0.17.0 // indirect
|
||||
cel.dev/expr v0.25.1 // indirect
|
||||
cloud.google.com/go/auth v0.20.0 // indirect
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.9.0 // indirect
|
||||
dario.cat/mergo v1.0.1 // indirect
|
||||
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
|
||||
dario.cat/mergo v1.0.2 // indirect
|
||||
filippo.io/bigmod v0.1.0 // indirect
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
|
||||
github.com/ccoveille/go-safecast/v2 v2.0.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/coreos/go-oidc/v3 v3.17.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
|
||||
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
||||
github.com/google/certificate-transparency-go v1.1.8-0.20240110162603-74a5dd331745 // indirect
|
||||
github.com/google/go-tpm v0.9.7 // indirect
|
||||
github.com/google/go-tpm v0.9.8 // indirect
|
||||
github.com/google/go-tspi v0.3.0 // indirect
|
||||
github.com/google/s2a-go v0.1.9 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.7 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.15 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.22.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
|
||||
github.com/jackc/pgx/v5 v5.9.2 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
|
||||
@@ -86,39 +89,37 @@ require (
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
github.com/zeebo/blake3 v0.2.4 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.64.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.39.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.39.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.39.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.15.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.15.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.61.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.15.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.15.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/log v0.15.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.43.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.43.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.43.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.65.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/log v0.19.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.4 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 // indirect
|
||||
golang.org/x/oauth2 v0.33.0 // indirect
|
||||
google.golang.org/api v0.256.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
||||
golang.org/x/oauth2 v0.36.0 // indirect
|
||||
google.golang.org/api v0.277.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 // indirect
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
filippo.io/edwards25519 v1.2.0 // indirect
|
||||
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.3.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.4.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0
|
||||
@@ -132,47 +133,46 @@ require (
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.9.3 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/huandu/xstrings v1.5.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/libdns/libdns v1.1.1
|
||||
github.com/manifoldco/promptui v0.9.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/miekg/dns v1.1.69 // indirect
|
||||
github.com/miekg/dns v1.1.72 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/go-ps v1.0.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/pires/go-proxyproto v0.8.1
|
||||
github.com/pires/go-proxyproto v0.11.0
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/client_model v0.6.2
|
||||
github.com/prometheus/common v0.67.4 // indirect
|
||||
github.com/prometheus/procfs v0.19.2 // indirect
|
||||
github.com/prometheus/common v0.67.5 // indirect
|
||||
github.com/prometheus/procfs v0.20.1 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/slackhq/nebula v1.9.7 // indirect
|
||||
github.com/sirupsen/logrus v1.9.4 // indirect
|
||||
github.com/slackhq/nebula v1.10.3 // indirect
|
||||
github.com/spf13/cast v1.7.0 // indirect
|
||||
github.com/stoewer/go-strcase v1.2.0 // indirect
|
||||
github.com/urfave/cli v1.22.17 // indirect
|
||||
go.etcd.io/bbolt v1.3.10 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.39.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.39.0
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
||||
go.etcd.io/bbolt v1.4.3 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.43.0
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/mod v0.30.0 // indirect
|
||||
golang.org/x/sys v0.39.0
|
||||
golang.org/x/text v0.32.0 // indirect
|
||||
golang.org/x/tools v0.39.0 // indirect
|
||||
google.golang.org/grpc v1.77.0 // indirect
|
||||
google.golang.org/protobuf v1.36.10 // indirect
|
||||
golang.org/x/mod v0.35.0 // indirect
|
||||
golang.org/x/sys v0.44.0
|
||||
golang.org/x/text v0.37.0 // indirect
|
||||
golang.org/x/tools v0.44.0 // indirect
|
||||
google.golang.org/grpc v1.81.0 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
howett.net/plist v1.0.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,37 +1,41 @@
|
||||
cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
|
||||
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
|
||||
cloud.google.com/go v0.121.6 h1:waZiuajrI28iAf40cWgycWNgaXPO06dupuS+sgibK6c=
|
||||
cloud.google.com/go v0.121.6/go.mod h1:coChdst4Ea5vUpiALcYKXEpR1S9ZgXbhEzzMcMR66vI=
|
||||
cloud.google.com/go/auth v0.17.0 h1:74yCm7hCj2rUyyAocqnFzsAYXgJhrG26XCFimrc/Kz4=
|
||||
cloud.google.com/go/auth v0.17.0/go.mod h1:6wv/t5/6rOPAX4fJiRjKkJCvswLwdet7G8+UGXt7nCQ=
|
||||
cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4=
|
||||
cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
|
||||
cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE=
|
||||
cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU=
|
||||
cloud.google.com/go/auth v0.20.0 h1:kXTssoVb4azsVDoUiF8KvxAqrsQcQtB53DcSgta74CA=
|
||||
cloud.google.com/go/auth v0.20.0/go.mod h1:942/yi/itH1SsmpyrbnTMDgGfdy2BUqIKyd0cyYLc5Q=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
|
||||
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
|
||||
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
|
||||
cloud.google.com/go/iam v1.5.2 h1:qgFRAGEmd8z6dJ/qyEchAuL9jpswyODjA2lS+w234g8=
|
||||
cloud.google.com/go/iam v1.5.2/go.mod h1:SE1vg0N81zQqLzQEwxL2WI6yhetBdbNQuTvIKCSkUHE=
|
||||
cloud.google.com/go/kms v1.23.2 h1:4IYDQL5hG4L+HzJBhzejUySoUOheh3Lk5YT4PCyyW6k=
|
||||
cloud.google.com/go/kms v1.23.2/go.mod h1:rZ5kK0I7Kn9W4erhYVoIRPtpizjunlrfU4fUkumUp8g=
|
||||
cloud.google.com/go/longrunning v0.7.0 h1:FV0+SYF1RIj59gyoWDRi45GiYUMM3K1qO51qoboQT1E=
|
||||
cloud.google.com/go/longrunning v0.7.0/go.mod h1:ySn2yXmjbK9Ba0zsQqunhDkYi0+9rlXIwnoAf+h+TPY=
|
||||
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
|
||||
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
cloud.google.com/go/iam v1.7.0 h1:JD3zh0C6LHl16aCn5Akff0+GELdp1+4hmh6ndoFLl8U=
|
||||
cloud.google.com/go/iam v1.7.0/go.mod h1:tetWZW1PD/m6vcuY2Zj/aU0eCHNPuxedbnbRTyKXvdY=
|
||||
cloud.google.com/go/kms v1.31.0 h1:LS8N92OxFDgOLg5NCo3OmbvjtQAIVT5gUHVLKIDHaFE=
|
||||
cloud.google.com/go/kms v1.31.0/go.mod h1:YIyXZym11R5uovJJt4oN5eUL3oPmirF3yKeIh6QAf4U=
|
||||
cloud.google.com/go/longrunning v0.9.0 h1:0EzbDEGsAvOZNbqXopgniY0w0a1phvu5IdUFq8grmqY=
|
||||
cloud.google.com/go/longrunning v0.9.0/go.mod h1:pkTz846W7bF4o2SzdWJ40Hu0Re+UoNT6Q5t+igIcb8E=
|
||||
code.pfad.fr/check v1.1.0 h1:GWvjdzhSEgHvEHe2uJujDcpmZoySKuHQNrZMfzfO0bE=
|
||||
code.pfad.fr/check v1.1.0/go.mod h1:NiUH13DtYsb7xp5wll0U4SXx7KhXQVCtRgdC96IPfoM=
|
||||
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
|
||||
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
|
||||
filippo.io/bigmod v0.1.0 h1:UNzDk7y9ADKST+axd9skUpBQeW7fG2KrTZyOE4uGQy8=
|
||||
filippo.io/bigmod v0.1.0/go.mod h1:OjOXDNlClLblvXdwgFFOQFJEocLhhtai8vGLy0JCZlI=
|
||||
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
||||
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
||||
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M=
|
||||
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
|
||||
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/DeRuina/timberjack v1.3.9 h1:6UXZ1I7ExPGTX/1UNYawR58LlOJUHKBPiYC7WQ91eBo=
|
||||
github.com/DeRuina/timberjack v1.3.9/go.mod h1:RLoeQrwrCGIEF8gO5nV5b/gMD0QIy7bzQhBUgpp1EqE=
|
||||
github.com/DeRuina/timberjack v1.4.2 h1:4bKlzhKdsR+2oNkgef9mqb4n11ICow8VK88RfzJPzN8=
|
||||
github.com/DeRuina/timberjack v1.4.2/go.mod h1:RLoeQrwrCGIEF8gO5nV5b/gMD0QIy7bzQhBUgpp1EqE=
|
||||
github.com/KimMachineGun/automemlimit v0.7.5 h1:RkbaC0MwhjL1ZuBKunGDjE/ggwAX43DwZrJqVwyveTk=
|
||||
github.com/KimMachineGun/automemlimit v0.7.5/go.mod h1:QZxpHaGOQoYvFhv/r4u3U0JTC2ZcOwbSr11UZF46UBM=
|
||||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
|
||||
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
||||
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
|
||||
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
||||
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
|
||||
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
|
||||
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
|
||||
@@ -39,52 +43,52 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
|
||||
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
|
||||
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
|
||||
github.com/alecthomas/chroma/v2 v2.21.1 h1:FaSDrp6N+3pphkNKU6HPCiYLgm8dbe5UXIXcoBhZSWA=
|
||||
github.com/alecthomas/chroma/v2 v2.21.1/go.mod h1:NqVhfBR0lte5Ouh3DcthuUCTUpDC9cxBOfyMbMQPs3o=
|
||||
github.com/alecthomas/chroma/v2 v2.23.1 h1:nv2AVZdTyClGbVQkIzlDm/rnhk1E9bU9nXwmZ/Vk/iY=
|
||||
github.com/alecthomas/chroma/v2 v2.23.1/go.mod h1:NqVhfBR0lte5Ouh3DcthuUCTUpDC9cxBOfyMbMQPs3o=
|
||||
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
||||
github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
|
||||
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
|
||||
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b h1:uUXgbcPDK3KpW29o4iy7GtuappbWT0l5NaMo9H9pJDw=
|
||||
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/aws/aws-sdk-go-v2 v1.40.0 h1:/WMUA0kjhZExjOQN2z3oLALDREea1A7TobfuiBrKlwc=
|
||||
github.com/aws/aws-sdk-go-v2 v1.40.0/go.mod h1:c9pm7VwuW0UPxAEYGyTmyurVcNrbF6Rt/wixFqDhcjE=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.1 h1:iODUDLgk3q8/flEC7ymhmxjfoAnBDwEEYEVyKZ9mzjU=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.1/go.mod h1:xoAgo17AGrPpJBSLg81W+ikM0cpOZG8ad04T2r+d5P0=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.1 h1:JeW+EwmtTE0yXFK8SmklrFh/cGTTXsQJumgMZNlbxfM=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.1/go.mod h1:BOoXiStwTF+fT2XufhO0Efssbi1CNIO/ZXpZu87N0pw=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 h1:WZVR5DbDgxzA0BJeudId89Kmgy6DIU4ORpxwsVHz0qA=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14/go.mod h1:Dadl9QO0kHgbrH1GRqGiZdYtW5w+IXXaBNCHTIaheM4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 h1:PZHqQACxYb8mYgms4RZbhZG0a7dPW06xOjmaH0EJC/I=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14/go.mod h1:VymhrMJUWs69D8u0/lZ7jSB6WgaG/NqHi3gX0aYf6U0=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 h1:bOS19y6zlJwagBfHxs0ESzr1XCOU2KXJCWcq3E2vfjY=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14/go.mod h1:1ipeGBMAxZ0xcTm6y6paC2C/J6f6OO7LBODV9afuAyM=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 h1:x2Ibm/Af8Fi+BH+Hsn9TXGdT+hKbDd5XOTZxTMxDk7o=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3/go.mod h1:IW1jwyrQgMdhisceG8fQLmQIydcT/jWY21rFhzgaKwo=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 h1:FIouAnCE46kyYqyhs0XEBDFFSREtdnr8HQuLPQPLCrY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14/go.mod h1:UTwDc5COa5+guonQU8qBikJo1ZJ4ln2r1MkF7Dqag1E=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.48.0 h1:pQgVxqqNOacqb19+xaoih/wNLil4d8tgi+FxtBi/qQY=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.48.0/go.mod h1:VJcNH6BLr+3VJwinRKdotLOMglHO8mIKlD3ea5c7hbw=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.1 h1:BDgIUYGEo5TkayOWv/oBLPphWwNm/A91AebUjAu5L5g=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.1/go.mod h1:iS6EPmNeqCsGo+xQmXv0jIMjyYtQfnwg36zl2FwEouk=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.4 h1:U//SlnkE1wOQiIImxzdY5PXat4Wq+8rlfVEw4Y7J8as=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.4/go.mod h1:av+ArJpoYf3pgyrj6tcehSFW+y9/QvAY8kMooR9bZCw=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.9 h1:LU8S9W/mPDAU9q0FjCLi0TrCheLMGwzbRpvUMwYspcA=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.9/go.mod h1:/j67Z5XBVDx8nZVp9EuFM9/BS5dvBznbqILGuu73hug=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.1 h1:GdGmKtG+/Krag7VfyOXV17xjTCz0i9NT+JnqLTOI5nA=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.1/go.mod h1:6TxbXoDSgBQ225Qd8Q+MbxUxUh6TtNKwbRt/EPS9xso=
|
||||
github.com/aws/smithy-go v1.23.2 h1:Crv0eatJUQhaManss33hS5r40CG3ZFH+21XSkqMrIUM=
|
||||
github.com/aws/smithy-go v1.23.2/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8=
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.17 h1:FpL4/758/diKwqbytU0prpuiu60fgXKUWCpDJtApclU=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.17/go.mod h1:OXqUMzgXytfoF9JaKkhrOYsyh72t9G+MJH8mMRaexOE=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.16 h1:r3RJBuU7X9ibt8RHbMjWE6y60QbKBiII6wSrXnapxSU=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.16/go.mod h1:6cx7zqDENJDbBIIWX6P8s0h6hqHC8Avbjh9Dseo27ug=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23 h1:UuSfcORqNSz/ey3VPRS8TcVH2Ikf0/sC+Hdj400QI6U=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23/go.mod h1:+G/OSGiOFnSOkYloKj/9M35s74LgVAdJBSD5lsFfqKg=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.23 h1:GpT/TrnBYuE5gan2cZbTtvP+JlHsutdmlV2YfEyNde0=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.23/go.mod h1:xYWD6BS9ywC5bS3sz9Xh04whO/hzK2plt2Zkyrp4JuA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23 h1:bpd8vxhlQi2r1hiueOw02f/duEPTMK59Q4QMAoTTtTo=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23/go.mod h1:15DfR2nw+CRHIk0tqNyifu3G1YdAOy68RftkhMDDwYk=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24 h1:OQqn11BtaYv1WLUowvcA30MpzIu8Ti4pcLPIIyoKZrA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24/go.mod h1:X5ZJyfwVrWA96GzPmUCWFQaEARPR7gCrpq2E92PJwAE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9 h1:FLudkZLt5ci0ozzgkVo8BJGwvqNaZbTWb3UcucAateA=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9/go.mod h1:w7wZ/s9qK7c8g4al+UyoF1Sp/Z45UwMGcqIzLWVQHWk=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.23 h1:pbrxO/kuIwgEsOPLkaHu0O+m4fNgLU8B3vxQ+72jTPw=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.23/go.mod h1:/CMNUqoj46HpS3MNRDEDIwcgEnrtZlKRaHNaHxIFpNA=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.51.1 h1:zuSf4olLKZW8cF/W9Y5wvGT+/0raY/3kVp49KsGs0QY=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.51.1/go.mod h1:Y0+uxvxz6ib4KktRdK0V4X45Vcs/JyYoz8H71pO8xeI=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.11 h1:TdJ+HdzOBhU8+iVAOGUTU63VXopcumCOF1paFulHWZc=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.11/go.mod h1:R82ZRExE/nheo0N+T8zHPcLRTcH8MGsnR3BiVGX0TwI=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.17 h1:7byT8HUWrgoRp6sXjxtZwgOKfhss5fW6SkLBtqzgRoE=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.17/go.mod h1:xNWknVi4Ezm1vg1QsB/5EWpAJURq22uqd38U8qKvOJc=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.21 h1:+1Kl1zx6bWi4X7cKi3VYh29h8BvsCoHQEQ6ST9X8w7w=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.21/go.mod h1:4vIRDq+CJB2xFAXZ+YgGUTiEft7oAQlhIs71xcSeuVg=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.42.1 h1:F/M5Y9I3nwr2IEpshZgh1GeHpOItExNM9L1euNuh/fk=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.42.1/go.mod h1:mTNxImtovCOEEuD65mKW7DCsL+2gjEH+RPEAexAzAio=
|
||||
github.com/aws/smithy-go v1.25.1 h1:J8ERsGSU7d+aCmdQur5Txg6bVoYelvQJgtZehD12GkI=
|
||||
github.com/aws/smithy-go v1.25.1/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/caddyserver/certmagic v0.25.1 h1:4sIKKbOt5pg6+sL7tEwymE1x2bj6CHr80da1CRRIPbY=
|
||||
github.com/caddyserver/certmagic v0.25.1/go.mod h1:VhyvndxtVton/Fo/wKhRoC46Rbw1fmjvQ3GjHYSQTEY=
|
||||
github.com/caddyserver/zerossl v0.1.4 h1:CVJOE3MZeFisCERZjkxIcsqIH4fnFdlYWnPYeFtBHRw=
|
||||
github.com/caddyserver/zerossl v0.1.4/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/caddyserver/certmagic v0.25.3 h1:mGf5ba8F7xA4c5jfDZZbK2buY1VEkbnwpMDixaju94A=
|
||||
github.com/caddyserver/certmagic v0.25.3/go.mod h1:YVs43D5+H/Dckt4bTga1KSO/xYfFBfVZainGDywYPAA=
|
||||
github.com/caddyserver/zerossl v0.1.5 h1:dkvOjBAEEtY6LIGAHei7sw2UgqSD6TrWweXpV7lvEvE=
|
||||
github.com/caddyserver/zerossl v0.1.5/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/ccoveille/go-safecast/v2 v2.0.0 h1:+5eyITXAUj3wMjad6cRVJKGnC7vDS55zk0INzJagub0=
|
||||
github.com/ccoveille/go-safecast/v2 v2.0.0/go.mod h1:JIYA4CAR33blIDuE6fSwCp2sz1oOBahXnvmdBhOAABs=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
@@ -102,8 +106,8 @@ github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObk
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
|
||||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
||||
github.com/cloudflare/circl v1.6.2 h1:hL7VBpHHKzrV5WTfHCaBsgx/HGbBYlgrwvNXEVDYYsQ=
|
||||
github.com/cloudflare/circl v1.6.2/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
|
||||
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||
github.com/coreos/go-oidc/v3 v3.17.0 h1:hWBGaQfbi0iVviX4ibC7bk8OKT5qNr4klBaCHVNvehc=
|
||||
@@ -143,19 +147,19 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
|
||||
github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
|
||||
github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
|
||||
github.com/go-jose/go-jose/v3 v3.0.4 h1:Wp5HA7bLQcKnf6YYao/4kpRpVMp/yf6+pJKV8WFSaNY=
|
||||
github.com/go-jose/go-jose/v3 v3.0.4/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 h1:CVLmWDhDVRa6Mi/IgCgaopNosCaHz7zrMeF9MlZRkrs=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
|
||||
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
|
||||
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
||||
github.com/go-jose/go-jose/v3 v3.0.5 h1:BLLJWbC4nMZOfuPVxoZIxeYsn6Nl2r1fITaJ78UQlVQ=
|
||||
github.com/go-jose/go-jose/v3 v3.0.5/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
|
||||
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
@@ -164,8 +168,8 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
|
||||
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
|
||||
github.com/google/cel-go v0.26.1 h1:iPbVVEdkhTX++hpe3lzSk7D3G3QSYqLGoHOcEio+UXQ=
|
||||
github.com/google/cel-go v0.26.1/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM=
|
||||
github.com/google/cel-go v0.28.0 h1:KjSWstCpz/MN5t4a8gnGJNIYUsJRpdi/r97xWDphIQc=
|
||||
github.com/google/cel-go v0.28.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8=
|
||||
github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
|
||||
github.com/google/certificate-transparency-go v1.1.8-0.20240110162603-74a5dd331745 h1:heyoXNxkRT155x4jTAiSv5BVSVkueifPUm+Q8LUXMRo=
|
||||
github.com/google/certificate-transparency-go v1.1.8-0.20240110162603-74a5dd331745/go.mod h1:zN0wUQgV9LjwLZeFHnrAbQi8hzMVvEWePyk+MhPOk7k=
|
||||
@@ -173,22 +177,22 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/go-tpm v0.9.7 h1:u89J4tUUeDTlH8xxC3CTW7OHZjbjKoHdQ9W7gCUhtxA=
|
||||
github.com/google/go-tpm v0.9.7/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm-tools v0.4.7 h1:J3ycC8umYxM9A4eF73EofRZu4BxY0jjQnUnkhIBbvws=
|
||||
github.com/google/go-tpm-tools v0.4.7/go.mod h1:gSyXTZHe3fgbzb6WEGd90QucmsnT1SRdlye82gH8QjQ=
|
||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm-tools v0.4.8 h1:V4oIYyAD3BykOycwYQzO29WefDouQMTsYZqmG3HxOfM=
|
||||
github.com/google/go-tpm-tools v0.4.8/go.mod h1:4DfiOtiS1KppJjwf1+tqtW4K3PrCJjAAqFKj/TYTJKg=
|
||||
github.com/google/go-tspi v0.3.0 h1:ADtq8RKfP+jrTyIWIZDIYcKOMecRqNJFOew2IT0Inus=
|
||||
github.com/google/go-tspi v0.3.0/go.mod h1:xfMGI3G0PhxCdNVcYr1C4C+EizojDg/TXuX5by8CiHI=
|
||||
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
|
||||
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
|
||||
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/googleapis/enterprise-certificate-proxy v0.3.7 h1:zrn2Ee/nWmHulBx5sAVrGgAa0f2/R35S4DJwfFaUPFQ=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.7/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
|
||||
github.com/googleapis/gax-go/v2 v2.15.0 h1:SyjDc1mGgZU5LncH8gimWo9lW1DtIfPibOG81vgd/bo=
|
||||
github.com/googleapis/gax-go/v2 v2.15.0/go.mod h1:zVVkkxAQHa1RQpg9z2AUCMnKhi0Qld9rcmyfL1OZhoc=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.15 h1:xolVQTEXusUcAA5UgtyRLjelpFFHWlPQ4XfWGc7MBas=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.15/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg=
|
||||
github.com/googleapis/gax-go/v2 v2.22.0 h1:PjIWBpgGIVKGoCXuiCoP64altEJCj3/Ei+kSU5vlZD4=
|
||||
github.com/googleapis/gax-go/v2 v2.22.0/go.mod h1:irWBbALSr0Sk3qlqb9SyJ1h68WjgeFuiOzI4Rqw5+aY=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||
@@ -199,16 +203,16 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.9.2 h1:3ZhOzMWnR4yJ+RW1XImIPsD1aNSz4T4fyP7zlQb56hw=
|
||||
github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
|
||||
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
|
||||
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
@@ -221,6 +225,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2 h1:0ON3ldMhZyWlfVNYYpFuWRTmZNnyfiL9Hh5YzC3JVwU=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2/go.mod h1:GhqMqcSoeGpYd5zX5TgwA6er/1MbWzx/o7yuuVya+Wk=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0 h1:Wq6gYXlsY6ubqI3hhxsTzdyotvfdjFBxuwYqCLCnj/U=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0/go.mod h1:Sk8cmUIPcIdv2nINo+9PB4L+ZBhzY+F9A1a/h/xmWiQ=
|
||||
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
|
||||
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
@@ -232,10 +240,10 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mholt/acmez/v3 v3.1.4 h1:DyzZe/RnAzT3rpZj/2Ii5xZpiEvvYk3cQEN/RmqxwFQ=
|
||||
github.com/mholt/acmez/v3 v3.1.4/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ=
|
||||
github.com/miekg/dns v1.1.69 h1:Kb7Y/1Jo+SG+a2GtfoFUfDkG//csdRPwRLkCsxDG9Sc=
|
||||
github.com/miekg/dns v1.1.69/go.mod h1:7OyjD9nEba5OkqQ/hB4fy3PIoxafSZJtducccIelz3g=
|
||||
github.com/mholt/acmez/v3 v3.1.6 h1:eGVQNObP0pBN4sxqrXeg7MYqTOWyoiYpQqITVWlrevk=
|
||||
github.com/mholt/acmez/v3 v3.1.6/go.mod h1:5nTPosTGosLxF3+LU4ygbgMRFDhbAVpqMI4+a4aHLBY=
|
||||
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
|
||||
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
@@ -251,8 +259,8 @@ github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhM
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/peterbourgon/diskv/v3 v3.0.1 h1:x06SQA46+PKIUftmEujdwSEpIx8kR+M9eLYsUxeYveU=
|
||||
github.com/peterbourgon/diskv/v3 v3.0.1/go.mod h1:kJ5Ny7vLdARGU3WUuy6uzO6T0nb/2gWcT1JiBvRmb5o=
|
||||
github.com/pires/go-proxyproto v0.8.1 h1:9KEixbdJfhrbtjpz/ZwCdWDD2Xem0NZ38qMYaASJgp0=
|
||||
github.com/pires/go-proxyproto v0.8.1/go.mod h1:ZKAAyp3cgy5Y5Mo4n9AlScrkCZwUy0g3Jf+slqQVcuU=
|
||||
github.com/pires/go-proxyproto v0.11.0 h1:gUQpS85X/VJMdUsYyEgyn59uLJvGqPhJV5YvG68wXH4=
|
||||
github.com/pires/go-proxyproto v0.11.0/go.mod h1:ZKAAyp3cgy5Y5Mo4n9AlScrkCZwUy0g3Jf+slqQVcuU=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
@@ -264,16 +272,16 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
|
||||
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
|
||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||
github.com/prometheus/common v0.67.4 h1:yR3NqWO1/UyO1w2PhUvXlGQs/PtFmoveVO0KZ4+Lvsc=
|
||||
github.com/prometheus/common v0.67.4/go.mod h1:gP0fq6YjjNCLssJCQp0yk4M8W6ikLURwkdd/YKtTbyI=
|
||||
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
|
||||
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
|
||||
github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEoIwkU+A6qos=
|
||||
github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM=
|
||||
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
|
||||
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
|
||||
github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc=
|
||||
github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
|
||||
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||
github.com/quic-go/quic-go v0.59.1 h1:0Gmua0HW1Tv7ANR7hUYwRyD0MG5OJfgvYSZasGZzBic=
|
||||
github.com/quic-go/quic-go v0.59.1/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
@@ -287,22 +295,22 @@ github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp
|
||||
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/slackhq/nebula v1.9.7 h1:v5u46efIyYHGdfjFnozQbRRhMdaB9Ma1SSTcUcE2lfE=
|
||||
github.com/slackhq/nebula v1.9.7/go.mod h1:1+4q4wd3dDAjO8rKCttSb9JIVbklQhuJiBp5I0lbIsQ=
|
||||
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
|
||||
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
|
||||
github.com/slackhq/nebula v1.10.3 h1:EstYj8ODEcv6T0R9X5BVq1zgWZnyU5gtPzk99QF1PMU=
|
||||
github.com/slackhq/nebula v1.10.3/go.mod h1:IL5TUQm4x9IFx2kCKPYm1gP47pwd5b8QGnnBH2RHnvs=
|
||||
github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262 h1:unQFBIznI+VYD1/1fApl1A+9VcBk+9dcqGfnePY87LY=
|
||||
github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262/go.mod h1:MyOHs9Po2fbM1LHej6sBUT8ozbxmMOFG+E+rx/GSGuc=
|
||||
github.com/smallstep/certificates v0.29.0 h1:f90szTKYTW62bmCc+qE5doGqIGPVxTQb8Ba37e/K8Zs=
|
||||
github.com/smallstep/certificates v0.29.0/go.mod h1:27WI0od6gu84mvE4mYQ/QZGyYwHXvhsiSRNC+y3t+mo=
|
||||
github.com/smallstep/certificates v0.30.2 h1:1G3xBi8sJ740iA1mMPW2Svv7EIZKJ4Zf/iQtA5QlN0Y=
|
||||
github.com/smallstep/certificates v0.30.2/go.mod h1:oyaE/aEYUGDr+YiCZLAxxP22bOQqcSHTeDgp8Vv2rlY=
|
||||
github.com/smallstep/cli-utils v0.12.2 h1:lGzM9PJrH/qawbzMC/s2SvgLdJPKDWKwKzx9doCVO+k=
|
||||
github.com/smallstep/cli-utils v0.12.2/go.mod h1:uCPqefO29goHLGqFnwk0i8W7XJu18X3WHQFRtOm/00Y=
|
||||
github.com/smallstep/go-attestation v0.4.4-0.20241119153605-2306d5b464ca h1:VX8L0r8vybH0bPeaIxh4NQzafKQiqvlOn8pmOXbFLO4=
|
||||
github.com/smallstep/go-attestation v0.4.4-0.20241119153605-2306d5b464ca/go.mod h1:vNAduivU014fubg6ewygkAvQC0IQVXqdc8vaGl/0er4=
|
||||
github.com/smallstep/linkedca v0.25.0 h1:txT9QHGbCsJq0MhAghBq7qhurGY727tQuqUi+n4BVBo=
|
||||
github.com/smallstep/linkedca v0.25.0/go.mod h1:Q3jVAauFKNlF86W5/RFtgQeyDKz98GL/KN3KG4mJOvc=
|
||||
github.com/smallstep/nosql v0.7.0 h1:YiWC9ZAHcrLCrayfaF+QJUv16I2bZ7KdLC3RpJcnAnE=
|
||||
github.com/smallstep/nosql v0.7.0/go.mod h1:H5VnKMCbeq9QA6SRY5iqPylfxLfYcLwvUff3onQ8+HU=
|
||||
github.com/smallstep/nosql v0.8.0 h1:FBTCUfKPmWYbrozW+RBKu+fnvbn+zr5rVli/XB4Jp4A=
|
||||
github.com/smallstep/nosql v0.8.0/go.mod h1:5dUpNotHLHhOUapP0PLBVVfp3tG1DFC31VRccg+Cqwo=
|
||||
github.com/smallstep/pkcs7 v0.2.1 h1:6Kfzr/QizdIuB6LSv8y1LJdZ3aPSfTNhTLqAx9CTLfA=
|
||||
github.com/smallstep/pkcs7 v0.2.1/go.mod h1:RcXHsMfL+BzH8tRhmrF1NkkpebKpq3JEM66cOFxanf0=
|
||||
github.com/smallstep/scep v0.0.0-20250318231241-a25cabb69492 h1:k23+s51sgYix4Zgbvpmy+1ZgXLjr4ZTkBTqXmpnImwA=
|
||||
@@ -325,8 +333,6 @@ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
@@ -334,7 +340,6 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
@@ -354,8 +359,8 @@ github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcY
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/goldmark v1.7.15 h1:xYJWgq3Qd8qsaZpj5pHKoEI4mosqVZi/qRpq/MdKyyk=
|
||||
github.com/yuin/goldmark v1.7.15/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
github.com/yuin/goldmark v1.8.2 h1:kEGpgqJXdgbkhcOgBxkC0X0PmoPG1ZyoZ117rDVp4zE=
|
||||
github.com/yuin/goldmark v1.8.2/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
|
||||
github.com/zeebo/assert v1.1.0 h1:hU1L1vLTHsnO8x8c9KAR5GmM5QscxHg5RNU5z5qbUWY=
|
||||
@@ -364,70 +369,70 @@ github.com/zeebo/blake3 v0.2.4 h1:KYQPkhpRtcqh0ssGYcKLG1JYvddkEA8QwCM/yBqhaZI=
|
||||
github.com/zeebo/blake3 v0.2.4/go.mod h1:7eeQ6d2iXWRGF6npfaxl2CU+xy2Fjo2gxeyZGCRUjcE=
|
||||
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
|
||||
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
|
||||
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
|
||||
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
|
||||
go.etcd.io/bbolt v1.4.3 h1:dEadXpI6G79deX5prL3QRNP6JB8UxVkqo4UPnHaNXJo=
|
||||
go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.64.0 h1:7TYhBCu6Xz6vDJGNtEslWZLuuX2IJ/aH50hBY4MVeUg=
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.64.0/go.mod h1:tHQctZfAe7e4PBPGyt3kae6mQFXNpj+iiDJa3ithM50=
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.64.0 h1:9pzPj3RFyKOxBAMkM2w84LpT+rdHam1XoFA+QhARiRw=
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.64.0/go.mod h1:hlVZx1btWH0XTfXpuGX9dsquB50s+tc3fYFOO5elo2M=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 h1:ssfIgGNANqpVFCndZvcuyKbl0g+UAVcbBcqGkG28H0Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0/go.mod h1:GQ/474YrbE4Jx8gZ4q5I4hrhUzM6UPzyrqJYV2AqPoQ=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.64.0 h1:VVrb1ErDD0Tlh/0K0rUqjky1e8AekjspTFN9sU2ekaA=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.64.0/go.mod h1:QCsOQk+9Ep8Mkp4/aPtSzUT0dc8SaPYzBAE6o1jYuSE=
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.39.0 h1:IvNR8pAVGpkK1CHMjU/YE6B6TlnAPGFvogkMWRWU6wo=
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.39.0/go.mod h1:TUsFCERuGM4IGhJG9w+9l0nzmHUKHuaDYYNF6mtNgjY=
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.39.0 h1:PI7pt9pkSnimWcp5sQhUA9OzLbc3Ba4sL+VEUTNsxrk=
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.39.0/go.mod h1:5gV/EzPnfYIwjzj+6y8tbGW2PKWhcsz5e/7twptRVQY=
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.39.0 h1:Gz3yKzfMSEFzF0Vy5eIpu9ndpo4DhXMCxsLMF0OOApo=
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.39.0/go.mod h1:2D/cxxCqTlrday0rZrPujjg5aoAdqk1NaNyoXn8FJn8=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.39.0 h1:vKTve1W/WKPVp1fzJamhCDDECt+5upJJ65bPyWoddGg=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.39.0/go.mod h1:FH5VB2N19duNzh1Q8ks6CsZFyu3LFhNLiA9lPxyEkvU=
|
||||
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
|
||||
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.15.0 h1:W+m0g+/6v3pa5PgVf2xoFMi5YtNR06WtS7ve5pcvLtM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.15.0/go.mod h1:JM31r0GGZ/GU94mX8hN4D8v6e40aFlUECSQ48HaLgHM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.15.0 h1:EKpiGphOYq3CYnIe2eX9ftUkyU+Y8Dtte8OaWyHJ4+I=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.15.0/go.mod h1:nWFP7C+T8TygkTjJ7mAyEaFaE7wNfms3nV/vexZ6qt0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.39.0 h1:cEf8jF6WbuGQWUVcqgyWtTR0kOOAWY1DYZ+UhvdmQPw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.39.0/go.mod h1:k1lzV5n5U3HkGvTCJHraTAGJ7MqsgL1wrGwTj1Isfiw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.39.0 h1:nKP4Z2ejtHn3yShBb+2KawiXgpn8In5cT7aO2wXuOTE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.39.0/go.mod h1:NwjeBbNigsO4Aj9WgM0C+cKIrxsZUaRmZUO7A8I7u8o=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 h1:f0cb2XPmrqn4XMy9PNliTgRKJgS5WcL/u0/WRYGz4t0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0/go.mod h1:vnakAaFckOMiMtOIhFI2MNH4FYrZzXCYxmb1LlhoGz8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0 h1:in9O8ESIOlwJAEGTkkf34DesGRAc/Pn8qJ7k3r/42LM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0/go.mod h1:Rp0EXBm5tfnv0WL+ARyO/PHBEaEAT8UUHQ6AGJcSq6c=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0 h1:Ckwye2FpXkYgiHX7fyVrN1uA/UYd9ounqqTuSNAv0k4=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0/go.mod h1:teIFJh5pW2y+AN7riv6IBPX2DuesS3HgP39mwOspKwU=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.61.0 h1:cCyZS4dr67d30uDyh8etKM2QyDsQ4zC9ds3bdbrVoD0=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.61.0/go.mod h1:iivMuj3xpR2DkUrUya3TPS/Z9h3dz7h01GxU+fQBRNg=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.15.0 h1:0BSddrtQqLEylcErkeFrJBmwFzcqfQq9+/uxfTZq+HE=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.15.0/go.mod h1:87sjYuAPzaRCtdd09GU5gM1U9wQLrrcYrm77mh5EBoc=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.39.0 h1:5gn2urDL/FBnK8OkCfD1j3/ER79rUuTYmCvlXBKeYL8=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.39.0/go.mod h1:0fBG6ZJxhqByfFZDwSwpZGzJU671HkwpWaNe2t4VUPI=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.39.0 h1:8UPA4IbVZxpsD76ihGOQiFml99GPAEZLohDXvqHdi6U=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.39.0/go.mod h1:MZ1T/+51uIVKlRzGw1Fo46KEWThjlCBZKl2LzY5nv4g=
|
||||
go.opentelemetry.io/otel/log v0.15.0 h1:0VqVnc3MgyYd7QqNVIldC3dsLFKgazR6P3P3+ypkyDY=
|
||||
go.opentelemetry.io/otel/log v0.15.0/go.mod h1:9c/G1zbyZfgu1HmQD7Qj84QMmwTp2QCQsZH1aeoWDE4=
|
||||
go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
|
||||
go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE=
|
||||
go.opentelemetry.io/otel/sdk/log v0.15.0 h1:WgMEHOUt5gjJE93yqfqJOkRflApNif84kxoHWS9VVHE=
|
||||
go.opentelemetry.io/otel/sdk/log v0.15.0/go.mod h1:qDC/FlKQCXfH5hokGsNg9aUBGMJQsrUyeOiW5u+dKBQ=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0 h1:Ijbtz+JKXl8T2MngiwqBlPaHqc4YCaP/i13Qrow6gAM=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0/go.mod h1:dCU8aEL6q+L9cYTqcVOk8rM9Tp8WdnHOPLiBgp0SGOA=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew=
|
||||
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
|
||||
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
||||
go.step.sm/crypto v0.75.0 h1:UAHYD6q6ggYyzLlIKHv1MCUVjZIesXRZpGTlRC/HSHw=
|
||||
go.step.sm/crypto v0.75.0/go.mod h1:wwQ57+ajmDype9mrI/2hRyrvJd7yja5xVgWYqpUN3PE=
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.68.0 h1:w3zlHYETbDwXyWHZlyyR58ZC39XGi8rAhkBgUgJ9d5w=
|
||||
go.opentelemetry.io/contrib/bridges/prometheus v0.68.0/go.mod h1:GR/mClR2nn7vE8RLwxKjoBNg+QtgdDhRzxVa93koy5o=
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.65.0 h1:2gApdml7SznX9szEKFjKjM4qGcGSvAybYLBY319XG3g=
|
||||
go.opentelemetry.io/contrib/exporters/autoexport v0.65.0/go.mod h1:0QqAGlbHXhmPYACG3n5hNzO5DnEqqtg4VcK5pr22RI0=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 h1:yI1/OhfEPy7J9eoa6Sj051C7n5dvpj0QX8g4sRchg04=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0/go.mod h1:NoUCKYWK+3ecatC4HjkRktREheMeEtrXoQxrqYFeHSc=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 h1:OyrsyzuttWTSur2qN/Lm0m2a8yqyIjUVBZcxFPuXq2o=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0/go.mod h1:C2NGBr+kAB4bk3xtMXfZ94gqFDtg/GkI7e9zqGh5Beg=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.65.0 h1:kTaCycF9Xkm8VBBvH0rJ4wFeRjtIV55Erk3uuVsIs5s=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.65.0/go.mod h1:rooPzAbXfxMX9fsPJjmOBg2SN4RhFEV8D7cfGK+N3tE=
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.43.0 h1:EwnsB3cXRLAh7/Nr/9rMuGw73nfb3z6uAvVDjRrbeUg=
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.43.0/go.mod h1:CJjTym6F87tEdm61Qvnz5xrV8vKlH4C92djiqcn62k8=
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.43.0 h1:CETqV3QLLPTy5yNrqyMr41VnAOOD4lsRved7n4QG00A=
|
||||
go.opentelemetry.io/contrib/propagators/b3 v1.43.0/go.mod h1:Q4mCiCdziYzpNR0g+6UqVotAlCDZdzz6L8jwY4knOrw=
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.43.0 h1:peiLMz1+aqJE+3L4mOVtR9wlmv+yh/JVYXCBjqmzJJE=
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.43.0/go.mod h1:Agvif+4A8p/3UtZzJ0MCcDEuQwgtrzM71DueU41DCs8=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.43.0 h1:Hh1HahlGc81AOE7siqi1tVOlbanY/UxMMWedpb0d5oQ=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.43.0/go.mod h1:58MlyS7lghzYvAm5LN9gGmZpCMQEMB5vpZp9SRgOyE4=
|
||||
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
|
||||
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.19.0 h1:Dn8rkudDzY6KV9dr/D/bTUuWgqDf9xe0rr4G2elrn0Y=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.19.0/go.mod h1:gMk9F0xDgyN9M/3Ed5Y1wKcx/9mlU91NXY2SNq7RQuU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 h1:HIBTQ3VO5aupLKjC90JgMqpezVXwFuq6Ryjn0/izoag=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0/go.mod h1:ji9vId85hMxqfvICA0Jt8JqEdrXaAkcpkI9HPXya0ro=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.43.0 h1:8UQVDcZxOJLtX6gxtDt3vY2WTgvZqMQRzjsqiIHQdkc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.43.0/go.mod h1:2lmweYCiHYpEjQ/lSJBYhj9jP1zvCvQW4BqL9dnT7FQ=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 h1:w1K+pCJoPpQifuVpsKamUdn9U0zM3xUziVOqsGksUrY=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0/go.mod h1:HBy4BjzgVE8139ieRI75oXm3EcDN+6GhD88JT1Kjvxg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0 h1:RAE+JPfvEmvy+0LzyUA25/SGawPwIUbZ6u0Wug54sLc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0/go.mod h1:AGmbycVGEsRx9mXMZ75CsOyhSP6MFIcj/6dnG+vhVjk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.65.0 h1:jOveH/b4lU9HT7y+Gfamf18BqlOuz2PWEvs8yM7Q6XE=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.65.0/go.mod h1:i1P8pcumauPtUI4YNopea1dhzEMuEqWP1xoUZDylLHo=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0 h1:GJkybS+crDMdExT/BUNCEgfrmfboztcS6PhvSo88HKM=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0/go.mod h1:NuAyxRYIG2lKX3YQkB+83StTxM7s52PUUkRRiC0wnYI=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0 h1:TC+BewnDpeiAmcscXbGMfxkO+mwYUwE/VySwvw88PfA=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0/go.mod h1:J/ZyF4vfPwsSr9xJSPyQ4LqtcTPULFR64KwTikGLe+A=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 h1:mS47AX77OtFfKG4vtp+84kuGSFZHTyxtXIN269vChY0=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0/go.mod h1:PJnsC41lAGncJlPUniSwM81gc80GkgWJWr3cu2nKEtU=
|
||||
go.opentelemetry.io/otel/log v0.19.0 h1:KUZs/GOsw79TBBMfDWsXS+KZ4g2Ckzksd1ymzsIEbo4=
|
||||
go.opentelemetry.io/otel/log v0.19.0/go.mod h1:5DQYeGmxVIr4n0/BcJvF4upsraHjg6vudJJpnkL6Ipk=
|
||||
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
|
||||
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
|
||||
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
|
||||
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.19.0 h1:scYVLqT22D2gqXItnWiocLUKGH9yvkkeql5dBDiXyko=
|
||||
go.opentelemetry.io/otel/sdk/log v0.19.0/go.mod h1:vFBowwXGLlW9AvpuF7bMgnNI95LiW10szrOdvzBHlAg=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.19.0 h1:BEbF7ZBB6qQloV/Ub1+3NQoOUnVtcGkU3XX4Ws3GQfk=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.19.0/go.mod h1:Lua81/3yM0wOmoHTokLj9y9ADeA02v1naRrVrkAZuKk=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
|
||||
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
|
||||
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
|
||||
go.step.sm/crypto v0.81.0 h1:e+ouzpNt3Xm4dp7HGXhgYB5y4iFik3vh3phHKWmvugU=
|
||||
go.step.sm/crypto v0.81.0/go.mod h1:fsTizqQeASjTXnbv9O00XtRlIuXRkCdoRiJNyXGQujc=
|
||||
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
|
||||
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
@@ -440,8 +445,8 @@ go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
|
||||
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
|
||||
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
|
||||
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
|
||||
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
|
||||
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
|
||||
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
@@ -451,19 +456,19 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20250927194341-2beaa59a3c99 h1:CH0o4/bZX6KIUCjjgjmtNtfM/kXSkTYlzTOB9vZF45g=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20250927194341-2beaa59a3c99/go.mod h1:MEIPiCnxvQEjA4astfaKItNwEVZA5Ki+3+nyGbJ5N18=
|
||||
golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 h1:SbTAbRFnd5kjQXbczszQ0hdk3ctwYf3qBNH9jIsGclE=
|
||||
golang.org/x/exp v0.0.0-20250813145105-42675adae3e6/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4=
|
||||
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
|
||||
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20260213171211-a408498e5541 h1:FmKxj9ocLKn45jiR2jQMwCVhDvaK7fKQFzfuT9GvyK8=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20260213171211-a408498e5541/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs=
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
||||
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
||||
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
@@ -472,10 +477,10 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||
golang.org/x/oauth2 v0.33.0 h1:4Q+qn+E5z8gPRJfmRy7C2gGG3T4jIprK6aSYgTXGRpo=
|
||||
golang.org/x/oauth2 v0.33.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
|
||||
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
|
||||
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -483,8 +488,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -493,7 +498,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -502,8 +506,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
|
||||
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -513,8 +517,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
||||
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
|
||||
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
|
||||
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
|
||||
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
@@ -524,35 +528,35 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
||||
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
||||
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
||||
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
|
||||
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
|
||||
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
|
||||
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/api v0.256.0 h1:u6Khm8+F9sxbCTYNoBHg6/Hwv0N/i+V94MvkOSor6oI=
|
||||
google.golang.org/api v0.256.0/go.mod h1:KIgPhksXADEKJlnEoRa9qAII4rXcy40vfI8HRqcU964=
|
||||
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 h1:rHWScKit0gvAPuOnu87KpaYtjK5zBMLcULh7gxkCXu4=
|
||||
google.golang.org/genproto v0.0.0-20250603155806-513f23925822/go.mod h1:HubltRL7rMh0LfnQPkMH4NPDFEWp0jw3vixw7jEM53s=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
|
||||
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM=
|
||||
google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHhrNig=
|
||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||
google.golang.org/api v0.277.0 h1:HJfyJUiNeBBUMai7ez8u14wkp/gH/I4wpGbbO9o+cSk=
|
||||
google.golang.org/api v0.277.0/go.mod h1:B9TqLBwJqVjp1mtt7WeoQwWRwvu/400y5lETOql+giQ=
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 h1:XzmzkmB14QhVhgnawEVsOn6OFsnpyxNPRY9QV01dNB0=
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:L43LFes82YgSonw6iTXTxXUX1OlULt4AQtkik4ULL/I=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 h1:tEkOQcXgF6dH1G+MVKZrfpYvozGrzb91k6ha7jireSM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/grpc v1.81.0 h1:W3G9N3KQf3BU+YuCtGKJk0CmxQNbAISICD/9AORxLIw=
|
||||
google.golang.org/grpc v1.81.0/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A=
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
package filesystems
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
)
|
||||
|
||||
func TestFileSystemMapDefaultKey(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
|
||||
// Empty key should map to default
|
||||
if m.key("") != DefaultFileSystemKey {
|
||||
t.Errorf("empty key should map to %q, got %q", DefaultFileSystemKey, m.key(""))
|
||||
}
|
||||
|
||||
// Non-empty key should be returned as-is
|
||||
if m.key("custom") != "custom" {
|
||||
t.Errorf("non-empty key should be returned as-is, got %q", m.key("custom"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapRegisterAndGet(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
testFS := fstest.MapFS{
|
||||
"hello.txt": &fstest.MapFile{Data: []byte("hello")},
|
||||
}
|
||||
|
||||
m.Register("test", testFS)
|
||||
|
||||
got, ok := m.Get("test")
|
||||
if !ok {
|
||||
t.Fatal("expected to find registered filesystem")
|
||||
}
|
||||
if got == nil {
|
||||
t.Fatal("expected non-nil filesystem")
|
||||
}
|
||||
|
||||
// Verify the filesystem works
|
||||
f, err := got.Open("hello.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("Open() error = %v", err)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func TestFileSystemMapGetNonExistent(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
|
||||
_, ok := m.Get("nonexistent")
|
||||
if ok {
|
||||
t.Error("expected Get to return false for nonexistent key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapDefault(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
|
||||
d := m.Default()
|
||||
if d == nil {
|
||||
t.Fatal("Default() should never return nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapGetDefaultLazyInit(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
|
||||
// Getting the default key before any registration should
|
||||
// auto-initialize to DefaultFileSystem
|
||||
got, ok := m.Get(DefaultFileSystemKey)
|
||||
if !ok {
|
||||
t.Fatal("expected default filesystem to be auto-initialized")
|
||||
}
|
||||
if got == nil {
|
||||
t.Fatal("expected non-nil default filesystem")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapUnregister(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
testFS := fstest.MapFS{}
|
||||
|
||||
m.Register("test", testFS)
|
||||
m.Unregister("test")
|
||||
|
||||
_, ok := m.Get("test")
|
||||
if ok {
|
||||
t.Error("expected filesystem to be unregistered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapUnregisterDefault(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
customFS := fstest.MapFS{}
|
||||
|
||||
// Override default
|
||||
m.Register("", customFS)
|
||||
// Unregister default should reset to OsFS, not delete
|
||||
m.Unregister("")
|
||||
|
||||
d := m.Default()
|
||||
if d == nil {
|
||||
t.Fatal("unregistering default should reset it, not delete it")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapRegisterNil(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
testFS := fstest.MapFS{}
|
||||
|
||||
// Register then register nil (should unregister)
|
||||
m.Register("test", testFS)
|
||||
m.Register("test", nil)
|
||||
|
||||
_, ok := m.Get("test")
|
||||
if ok {
|
||||
t.Error("registering nil should unregister the filesystem")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapEmptyKeyIsDefault(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
testFS := fstest.MapFS{
|
||||
"test.txt": &fstest.MapFile{Data: []byte("test")},
|
||||
}
|
||||
|
||||
// Register with empty key should register as default
|
||||
m.Register("", testFS)
|
||||
|
||||
got, ok := m.Get("")
|
||||
if !ok {
|
||||
t.Fatal("expected to find filesystem registered with empty key")
|
||||
}
|
||||
|
||||
// Should also be accessible via default key
|
||||
got2, ok := m.Get(DefaultFileSystemKey)
|
||||
if !ok {
|
||||
t.Fatal("expected to find filesystem via default key")
|
||||
}
|
||||
|
||||
// Both should work
|
||||
if got == nil || got2 == nil {
|
||||
t.Fatal("expected non-nil filesystems")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystemMapGetTrimsWhitespace(t *testing.T) {
|
||||
m := &FileSystemMap{}
|
||||
testFS := fstest.MapFS{}
|
||||
|
||||
m.Register("test", testFS)
|
||||
|
||||
// Get with whitespace-padded key should match
|
||||
got, ok := m.Get("test ")
|
||||
if !ok {
|
||||
t.Fatal("expected Get to trim whitespace from key")
|
||||
}
|
||||
if got == nil {
|
||||
t.Fatal("expected non-nil filesystem")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOsFSInterfaces(t *testing.T) {
|
||||
var osFS OsFS
|
||||
|
||||
// Verify interface compliance at compile time (already done with var _ checks)
|
||||
// but test that the methods exist and are callable
|
||||
var _ fs.FS = osFS
|
||||
var _ fs.StatFS = osFS
|
||||
var _ fs.GlobFS = osFS
|
||||
var _ fs.ReadDirFS = osFS
|
||||
var _ fs.ReadFileFS = osFS
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"go.uber.org/zap/zaptest/observer"
|
||||
)
|
||||
|
||||
func TestLogBufferCoreEnabled(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
if !core.Enabled(zapcore.InfoLevel) {
|
||||
t.Error("expected InfoLevel to be enabled")
|
||||
}
|
||||
if !core.Enabled(zapcore.ErrorLevel) {
|
||||
t.Error("expected ErrorLevel to be enabled")
|
||||
}
|
||||
if core.Enabled(zapcore.DebugLevel) {
|
||||
t.Error("expected DebugLevel to be disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreWriteAndFlush(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
// Write entries
|
||||
entry1 := zapcore.Entry{Level: zapcore.InfoLevel, Message: "message1"}
|
||||
entry2 := zapcore.Entry{Level: zapcore.WarnLevel, Message: "message2"}
|
||||
|
||||
if err := core.Write(entry1, []zapcore.Field{zap.String("key1", "val1")}); err != nil {
|
||||
t.Fatalf("Write() error = %v", err)
|
||||
}
|
||||
if err := core.Write(entry2, []zapcore.Field{zap.String("key2", "val2")}); err != nil {
|
||||
t.Fatalf("Write() error = %v", err)
|
||||
}
|
||||
|
||||
// Verify entries are buffered
|
||||
if len(core.entries) != 2 {
|
||||
t.Errorf("expected 2 entries, got %d", len(core.entries))
|
||||
}
|
||||
if len(core.fields) != 2 {
|
||||
t.Errorf("expected 2 field sets, got %d", len(core.fields))
|
||||
}
|
||||
|
||||
// Set up an observed logger to capture flushed entries
|
||||
observedCore, logs := observer.New(zapcore.InfoLevel)
|
||||
logger := zap.New(observedCore)
|
||||
|
||||
core.FlushTo(logger)
|
||||
|
||||
// Verify entries were flushed
|
||||
if logs.Len() != 2 {
|
||||
t.Errorf("expected 2 flushed log entries, got %d", logs.Len())
|
||||
}
|
||||
|
||||
// Verify buffer is cleared after flush
|
||||
if len(core.entries) != 0 {
|
||||
t.Errorf("expected entries to be cleared after flush, got %d", len(core.entries))
|
||||
}
|
||||
if len(core.fields) != 0 {
|
||||
t.Errorf("expected fields to be cleared after flush, got %d", len(core.fields))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreSync(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
if err := core.Sync(); err != nil {
|
||||
t.Errorf("Sync() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreWith(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
// With() currently returns the same core (known limitation)
|
||||
result := core.With([]zapcore.Field{zap.String("test", "val")})
|
||||
if result != core {
|
||||
t.Error("With() should return the same core instance")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreCheck(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
// Check for enabled level should add core
|
||||
entry := zapcore.Entry{Level: zapcore.InfoLevel, Message: "test"}
|
||||
ce := &zapcore.CheckedEntry{}
|
||||
result := core.Check(entry, ce)
|
||||
if result == nil {
|
||||
t.Error("Check() should return non-nil for enabled level")
|
||||
}
|
||||
|
||||
// Check for disabled level should not add core
|
||||
debugEntry := zapcore.Entry{Level: zapcore.DebugLevel, Message: "test"}
|
||||
ce2 := &zapcore.CheckedEntry{}
|
||||
result2 := core.Check(debugEntry, ce2)
|
||||
// The ce2 should be returned unchanged (no core added)
|
||||
if result2 != ce2 {
|
||||
t.Error("Check() should return unchanged CheckedEntry for disabled level")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreEmptyFlush(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
// Flushing with no entries should not panic
|
||||
observedCore, logs := observer.New(zapcore.InfoLevel)
|
||||
logger := zap.New(observedCore)
|
||||
|
||||
core.FlushTo(logger)
|
||||
|
||||
if logs.Len() != 0 {
|
||||
t.Errorf("expected 0 flushed entries for empty buffer, got %d", logs.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogBufferCoreConcurrentWrites(t *testing.T) {
|
||||
core := NewLogBufferCore(zapcore.InfoLevel)
|
||||
|
||||
done := make(chan struct{})
|
||||
const numWriters = 10
|
||||
const numWrites = 100
|
||||
|
||||
for i := 0; i < numWriters; i++ {
|
||||
go func() {
|
||||
defer func() { done <- struct{}{} }()
|
||||
for j := 0; j < numWrites; j++ {
|
||||
entry := zapcore.Entry{Level: zapcore.InfoLevel, Message: "concurrent"}
|
||||
_ = core.Write(entry, nil)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < numWriters; i++ {
|
||||
<-done
|
||||
}
|
||||
|
||||
core.mu.Lock()
|
||||
count := len(core.entries)
|
||||
core.mu.Unlock()
|
||||
|
||||
if count != numWriters*numWrites {
|
||||
t.Errorf("expected %d entries, got %d", numWriters*numWrites, count)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// LoggableHTTPHeader makes an HTTP header loggable with zap.Object().
|
||||
// Headers with potentially sensitive information (Cookie, Set-Cookie,
|
||||
// Authorization, and Proxy-Authorization) are logged with empty values.
|
||||
type LoggableHTTPHeader struct {
|
||||
http.Header
|
||||
|
||||
ShouldLogCredentials bool
|
||||
}
|
||||
|
||||
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
|
||||
func (h LoggableHTTPHeader) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
||||
if h.Header == nil {
|
||||
return nil
|
||||
}
|
||||
for key, val := range h.Header {
|
||||
if !h.ShouldLogCredentials {
|
||||
switch strings.ToLower(key) {
|
||||
case "cookie", "set-cookie", "authorization", "proxy-authorization":
|
||||
val = []string{"REDACTED"} // see #5669. I still think ▒▒▒▒ would be cool.
|
||||
}
|
||||
}
|
||||
enc.AddArray(key, LoggableStringArray(val))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoggableStringArray makes a slice of strings marshalable for logging.
|
||||
type LoggableStringArray []string
|
||||
|
||||
// MarshalLogArray satisfies the zapcore.ArrayMarshaler interface.
|
||||
func (sa LoggableStringArray) MarshalLogArray(enc zapcore.ArrayEncoder) error {
|
||||
if sa == nil {
|
||||
return nil
|
||||
}
|
||||
for _, s := range sa {
|
||||
enc.AppendString(s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Interface guards
|
||||
var (
|
||||
_ zapcore.ObjectMarshaler = (*LoggableHTTPHeader)(nil)
|
||||
_ zapcore.ArrayMarshaler = (*LoggableStringArray)(nil)
|
||||
)
|
||||
@@ -17,6 +17,37 @@ func TestSanitizeMethod(t *testing.T) {
|
||||
{method: "trace", expected: "TRACE"},
|
||||
{method: "UNKNOWN", expected: "OTHER"},
|
||||
{method: strings.Repeat("ohno", 9999), expected: "OTHER"},
|
||||
|
||||
// Test all standard HTTP methods in uppercase
|
||||
{method: "GET", expected: "GET"},
|
||||
{method: "HEAD", expected: "HEAD"},
|
||||
{method: "POST", expected: "POST"},
|
||||
{method: "PUT", expected: "PUT"},
|
||||
{method: "DELETE", expected: "DELETE"},
|
||||
{method: "CONNECT", expected: "CONNECT"},
|
||||
{method: "OPTIONS", expected: "OPTIONS"},
|
||||
{method: "TRACE", expected: "TRACE"},
|
||||
{method: "PATCH", expected: "PATCH"},
|
||||
|
||||
// Test all standard HTTP methods in lowercase
|
||||
{method: "get", expected: "GET"},
|
||||
{method: "head", expected: "HEAD"},
|
||||
{method: "post", expected: "POST"},
|
||||
{method: "put", expected: "PUT"},
|
||||
{method: "delete", expected: "DELETE"},
|
||||
{method: "connect", expected: "CONNECT"},
|
||||
{method: "options", expected: "OPTIONS"},
|
||||
{method: "trace", expected: "TRACE"},
|
||||
{method: "patch", expected: "PATCH"},
|
||||
|
||||
// Test mixed case and non-standard methods
|
||||
{method: "Get", expected: "OTHER"},
|
||||
{method: "gEt", expected: "OTHER"},
|
||||
{method: "UNKNOWN", expected: "OTHER"},
|
||||
{method: "PROPFIND", expected: "OTHER"},
|
||||
{method: "MKCOL", expected: "OTHER"},
|
||||
{method: "", expected: "OTHER"},
|
||||
{method: " ", expected: "OTHER"},
|
||||
}
|
||||
|
||||
for _, d := range tests {
|
||||
@@ -26,3 +57,79 @@ func TestSanitizeMethod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeCode(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
code int
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "zero returns 200",
|
||||
code: 0,
|
||||
expected: "200",
|
||||
},
|
||||
{
|
||||
name: "200 returns 200",
|
||||
code: 200,
|
||||
expected: "200",
|
||||
},
|
||||
{
|
||||
name: "404 returns 404",
|
||||
code: 404,
|
||||
expected: "404",
|
||||
},
|
||||
{
|
||||
name: "500 returns 500",
|
||||
code: 500,
|
||||
expected: "500",
|
||||
},
|
||||
{
|
||||
name: "301 returns 301",
|
||||
code: 301,
|
||||
expected: "301",
|
||||
},
|
||||
{
|
||||
name: "418 teapot returns 418",
|
||||
code: 418,
|
||||
expected: "418",
|
||||
},
|
||||
{
|
||||
name: "999 custom code",
|
||||
code: 999,
|
||||
expected: "999",
|
||||
},
|
||||
{
|
||||
name: "negative code",
|
||||
code: -1,
|
||||
expected: "-1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := SanitizeCode(tt.code)
|
||||
if result != tt.expected {
|
||||
t.Errorf("SanitizeCode(%d) = %s; want %s", tt.code, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkSanitizeCode benchmarks the SanitizeCode function
|
||||
func BenchmarkSanitizeCode(b *testing.B) {
|
||||
codes := []int{0, 200, 404, 500, 301, 418}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
SanitizeCode(codes[i%len(codes)])
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkSanitizeMethod benchmarks the SanitizeMethod function
|
||||
func BenchmarkSanitizeMethod(b *testing.B) {
|
||||
methods := []string{"GET", "POST", "PUT", "DELETE", "UNKNOWN"}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
SanitizeMethod(methods[i%len(methods)])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrivateRangesCIDR(t *testing.T) {
|
||||
ranges := PrivateRangesCIDR()
|
||||
|
||||
// Should include standard private IP ranges
|
||||
expected := map[string]bool{
|
||||
"192.168.0.0/16": false,
|
||||
"172.16.0.0/12": false,
|
||||
"10.0.0.0/8": false,
|
||||
"127.0.0.1/8": false,
|
||||
"fd00::/8": false,
|
||||
"::1": false,
|
||||
}
|
||||
|
||||
for _, r := range ranges {
|
||||
if _, ok := expected[r]; ok {
|
||||
expected[r] = true
|
||||
}
|
||||
}
|
||||
|
||||
for cidr, found := range expected {
|
||||
if !found {
|
||||
t.Errorf("expected private range %q not found in PrivateRangesCIDR()", cidr)
|
||||
}
|
||||
}
|
||||
|
||||
if len(ranges) < 6 {
|
||||
t.Errorf("expected at least 6 private ranges, got %d", len(ranges))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxSizeSubjectsListForLog(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
subjects map[string]struct{}
|
||||
maxToDisplay int
|
||||
wantLen int
|
||||
wantSuffix bool // whether "(and N more...)" is expected
|
||||
}{
|
||||
{
|
||||
name: "empty map",
|
||||
subjects: map[string]struct{}{},
|
||||
maxToDisplay: 5,
|
||||
wantLen: 0,
|
||||
wantSuffix: false,
|
||||
},
|
||||
{
|
||||
name: "fewer than max",
|
||||
subjects: map[string]struct{}{
|
||||
"example.com": {},
|
||||
"example.org": {},
|
||||
},
|
||||
maxToDisplay: 5,
|
||||
wantLen: 2,
|
||||
wantSuffix: false,
|
||||
},
|
||||
{
|
||||
name: "equal to max",
|
||||
subjects: map[string]struct{}{
|
||||
"a.com": {},
|
||||
"b.com": {},
|
||||
"c.com": {},
|
||||
},
|
||||
maxToDisplay: 3,
|
||||
wantLen: 3,
|
||||
wantSuffix: false,
|
||||
},
|
||||
{
|
||||
name: "more than max",
|
||||
subjects: map[string]struct{}{
|
||||
"a.com": {},
|
||||
"b.com": {},
|
||||
"c.com": {},
|
||||
"d.com": {},
|
||||
"e.com": {},
|
||||
},
|
||||
maxToDisplay: 2,
|
||||
wantLen: 3, // 2 domains + suffix
|
||||
wantSuffix: true,
|
||||
},
|
||||
{
|
||||
name: "max is zero",
|
||||
subjects: map[string]struct{}{
|
||||
"a.com": {},
|
||||
"b.com": {},
|
||||
},
|
||||
maxToDisplay: 0,
|
||||
// BUG: When maxToDisplay is 0, code still appends one domain
|
||||
// because append happens before the break check in the loop.
|
||||
// Expected behavior: 1 item (just suffix). Actual: 2 items
|
||||
// (1 leaked domain + suffix).
|
||||
wantLen: 2,
|
||||
wantSuffix: true,
|
||||
},
|
||||
{
|
||||
name: "single subject with max 1",
|
||||
subjects: map[string]struct{}{
|
||||
"example.com": {},
|
||||
},
|
||||
maxToDisplay: 1,
|
||||
wantLen: 1,
|
||||
wantSuffix: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := MaxSizeSubjectsListForLog(tt.subjects, tt.maxToDisplay)
|
||||
if len(result) != tt.wantLen {
|
||||
t.Errorf("MaxSizeSubjectsListForLog() returned %d items, want %d; got: %v", len(result), tt.wantLen, result)
|
||||
}
|
||||
if tt.wantSuffix {
|
||||
last := result[len(result)-1]
|
||||
if len(last) < 4 || last[:4] != "(and" {
|
||||
t.Errorf("expected suffix '(and N more...)' but got %q", last)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSplitUnixSocketPermissionsBits(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
wantPath string
|
||||
wantFileMode fs.FileMode
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "no permission bits defaults to 0200",
|
||||
input: "/run/caddy.sock",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o200,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid permission 0222",
|
||||
input: "/run/caddy.sock|0222",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o222,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid permission 0200",
|
||||
input: "/run/caddy.sock|0200",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o200,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid permission 0777",
|
||||
input: "/run/caddy.sock|0777",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o777,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid permission 0755",
|
||||
input: "/run/caddy.sock|0755",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o755,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid permission 0666",
|
||||
input: "/tmp/test.sock|0666",
|
||||
wantPath: "/tmp/test.sock",
|
||||
wantFileMode: 0o666,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "missing owner write permission 0444",
|
||||
input: "/run/caddy.sock|0444",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing owner write permission 0044",
|
||||
input: "/run/caddy.sock|0044",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing owner write permission 0100",
|
||||
input: "/run/caddy.sock|0100",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing owner write permission 0500",
|
||||
input: "/run/caddy.sock|0500",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid octal digits",
|
||||
input: "/run/caddy.sock|09ab",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid non-numeric permission",
|
||||
input: "/run/caddy.sock|rwxrwxrwx",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty permission string",
|
||||
input: "/run/caddy.sock|",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "multiple pipes only splits on first",
|
||||
input: "/run/caddy|sock|0222",
|
||||
wantPath: "/run/caddy",
|
||||
wantFileMode: 0, // "sock|0222" is not valid octal
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty path with valid permission",
|
||||
input: "|0222",
|
||||
wantPath: "",
|
||||
wantFileMode: 0o222,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "path only with no pipe",
|
||||
input: "/var/run/my-app.sock",
|
||||
wantPath: "/var/run/my-app.sock",
|
||||
wantFileMode: 0o200,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "permission 0300 has write bit",
|
||||
input: "/run/caddy.sock|0300",
|
||||
wantPath: "/run/caddy.sock",
|
||||
wantFileMode: 0o300,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "permission 0422 missing owner write",
|
||||
input: "/run/caddy.sock|0422",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotPath, gotMode, err := SplitUnixSocketPermissionsBits(tt.input)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("SplitUnixSocketPermissionsBits(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if gotPath != tt.wantPath {
|
||||
t.Errorf("SplitUnixSocketPermissionsBits(%q) path = %q, want %q", tt.input, gotPath, tt.wantPath)
|
||||
}
|
||||
if gotMode != tt.wantFileMode {
|
||||
t.Errorf("SplitUnixSocketPermissionsBits(%q) mode = %04o, want %04o", tt.input, gotMode, tt.wantFileMode)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,6 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func reuseUnixSocket(_, _ string) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func listenReusable(ctx context.Context, lnKey string, network, address string, config net.ListenConfig) (any, error) {
|
||||
var socketFile *os.File
|
||||
|
||||
@@ -120,8 +116,8 @@ func listenReusable(ctx context.Context, lnKey string, network, address string,
|
||||
// re-wrapped in a new fakeCloseListener each time the listener
|
||||
// is reused. This type is atomic and values must not be copied.
|
||||
type fakeCloseListener struct {
|
||||
closed int32 // accessed atomically; belongs to this struct only
|
||||
*sharedListener // embedded, so we also become a net.Listener
|
||||
closed atomic.Bool
|
||||
*sharedListener // embedded, so we also become a net.Listener
|
||||
keepAliveConfig net.KeepAliveConfig
|
||||
}
|
||||
|
||||
@@ -131,7 +127,7 @@ type canSetKeepAliveConfig interface {
|
||||
|
||||
func (fcl *fakeCloseListener) Accept() (net.Conn, error) {
|
||||
// if the listener is already "closed", return error
|
||||
if atomic.LoadInt32(&fcl.closed) == 1 {
|
||||
if fcl.closed.Load() {
|
||||
return nil, fakeClosedErr(fcl)
|
||||
}
|
||||
|
||||
@@ -155,7 +151,7 @@ func (fcl *fakeCloseListener) Accept() (net.Conn, error) {
|
||||
// that we set when Close() was called, and return a non-temporary and
|
||||
// non-timeout error value to the caller, masking the "true" error, so
|
||||
// that server loops / goroutines won't retry, linger, and leak
|
||||
if atomic.LoadInt32(&fcl.closed) == 1 {
|
||||
if fcl.closed.Load() {
|
||||
// we dereference the sharedListener explicitly even though it's embedded
|
||||
// so that it's clear in the code that side-effects are shared with other
|
||||
// users of this listener, not just our own reference to it; we also don't
|
||||
@@ -175,7 +171,7 @@ func (fcl *fakeCloseListener) Accept() (net.Conn, error) {
|
||||
// underlying listener. The underlying listener is only closed
|
||||
// if the caller is the last known user of the socket.
|
||||
func (fcl *fakeCloseListener) Close() error {
|
||||
if atomic.CompareAndSwapInt32(&fcl.closed, 0, 1) {
|
||||
if fcl.closed.CompareAndSwap(false, true) {
|
||||
// There are two ways I know of to get an Accept()
|
||||
// function to return to the server loop that called
|
||||
// it: close the listener, or set a deadline in the
|
||||
@@ -238,13 +234,13 @@ func (sl *sharedListener) Destruct() error {
|
||||
// fakeClosePacketConn is like fakeCloseListener, but for PacketConns,
|
||||
// or more specifically, *net.UDPConn
|
||||
type fakeClosePacketConn struct {
|
||||
closed int32 // accessed atomically; belongs to this struct only
|
||||
*sharedPacketConn // embedded, so we also become a net.PacketConn; its key is used in Close
|
||||
closed atomic.Bool
|
||||
*sharedPacketConn // embedded, so we also become a net.PacketConn; its key is used in Close
|
||||
}
|
||||
|
||||
func (fcpc *fakeClosePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
// if the listener is already "closed", return error
|
||||
if atomic.LoadInt32(&fcpc.closed) == 1 {
|
||||
if fcpc.closed.Load() {
|
||||
return 0, nil, &net.OpError{
|
||||
Op: "readfrom",
|
||||
Net: fcpc.LocalAddr().Network(),
|
||||
@@ -258,7 +254,7 @@ func (fcpc *fakeClosePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err e
|
||||
if err != nil {
|
||||
// this server was stopped, so clear the deadline and let
|
||||
// any new server continue reading; but we will exit
|
||||
if atomic.LoadInt32(&fcpc.closed) == 1 {
|
||||
if fcpc.closed.Load() {
|
||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||
if err = fcpc.SetReadDeadline(time.Time{}); err != nil {
|
||||
return n, addr, err
|
||||
@@ -273,7 +269,7 @@ func (fcpc *fakeClosePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err e
|
||||
|
||||
// Close won't close the underlying socket unless there is no more reference, then listenerPool will close it.
|
||||
func (fcpc *fakeClosePacketConn) Close() error {
|
||||
if atomic.CompareAndSwapInt32(&fcpc.closed, 0, 1) {
|
||||
if fcpc.closed.CompareAndSwap(false, true) {
|
||||
_ = fcpc.SetReadDeadline(time.Now()) // unblock ReadFrom() calls to kick old servers out of their loops
|
||||
_, _ = listenerPool.Delete(fcpc.sharedPacketConn.key)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build (!unix || solaris) && !windows
|
||||
|
||||
package caddy
|
||||
|
||||
func reuseUnixSocket(_, _ string) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errUnixSocketAlreadyInUse = errors.New("unix socket is already in use by another process")
|
||||
|
||||
func reuseUnixSocket(network, addr string) (any, error) {
|
||||
if !IsUnixNetwork(network) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Note: This is here mainly for proper compatibility, because Unix sockets with abstract names are in an interesting limbo state on Windows:
|
||||
// Go already translates `@` characters to `\0` for Windows: https://github.com/golang/go/blob/65d5c5f6dd8aa7b221cff6ec3f5101ea2e5f3efa/src/syscall/syscall_windows.go#L910
|
||||
// ...but there still is an open issue about the fact that this is not properly supported: https://github.com/microsoft/WSL/issues/4240#issuecomment-620805115
|
||||
// The main issue is that the original announcement proclaimed support for this feature, but it was (apparently) never implemented: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
|
||||
isAbstractUnixSocket := strings.HasPrefix(addr, "@")
|
||||
|
||||
if isAbstractUnixSocket {
|
||||
// Abstract Unix sockets do not require us to remove stale socket files.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// On Windows, we're using the `fakeCloseListener` wrappers around a single, ever-living listener.
|
||||
// So, if there's an active listener entry in the pool, we're the current owner of the Unix socket file.
|
||||
_, socketBelongsToCurrentProcess := listenerPool.References(listenerKey(network, addr))
|
||||
|
||||
if socketBelongsToCurrentProcess {
|
||||
// Reuse/cleanup is entirely handled by the refcounting mechanism in `listenerPool`.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// If the socket file does not exist or has no backing server process, this will fail instantly.
|
||||
connection, err := net.DialTimeout("unix", addr, 10*time.Millisecond)
|
||||
|
||||
if err == nil {
|
||||
connection.Close()
|
||||
return nil, fmt.Errorf("cannot reuse socket %v: %w", addr, errUnixSocketAlreadyInUse)
|
||||
}
|
||||
|
||||
// Windows returns this error code both if the socket file does not exist and if it isn't backed by a server process anymore.
|
||||
// See: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2#wsaeconnrefused
|
||||
const WSAECONNREFUSED syscall.Errno = 10061
|
||||
|
||||
var errno syscall.Errno
|
||||
hasNoListeningServerProcess := errors.As(err, &errno) && errno == WSAECONNREFUSED
|
||||
|
||||
if !hasNoListeningServerProcess {
|
||||
return nil, fmt.Errorf("cannot reuse socket %v: %w", addr, errUnixSocketAlreadyInUse)
|
||||
}
|
||||
|
||||
// If the socket file exists, it hasn't been created by our process, and it seemingly
|
||||
// isn't backed by a server process anymore. Try to delete it so we can bind to it later.
|
||||
err = os.Remove(addr)
|
||||
|
||||
if err == nil {
|
||||
return nil, nil
|
||||
} else if errors.Is(err, fs.ErrNotExist) {
|
||||
// Either the file didn't exist in the first place, or it was deleted before we were able to.
|
||||
return nil, nil
|
||||
} else {
|
||||
// We failed to delete the file. Likely, it belongs to another (active) process.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user