mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-25 16:22:36 -04:00
Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f1ff118f8 | |||
| 4d40619aa4 | |||
| 3c591ecac9 | |||
| 73854014d9 | |||
| c0d9a2383e | |||
| 7bc7e1680e | |||
| edf4168c8e | |||
| 926fb82f6b | |||
| 841fe2544d | |||
| b19feec6dc | |||
| 41a4320fd3 | |||
| b491fc5d6c | |||
| 01cb878087 | |||
| b98c89fbb6 | |||
| 2619271a5c | |||
| 93a1853022 | |||
| 99dcdf7e42 | |||
| fab6375a8b | |||
| aca4002fd8 | |||
| 8e0d3e1ec5 | |||
| d85cc2ec10 | |||
| 04fb9fe87f | |||
| 0bc27e5fb1 | |||
| 9be4f194e0 | |||
| a10117f8bd | |||
| 101d3e7407 | |||
| 3f1add6c9f | |||
| 5db2f81695 | |||
| 243351b2b1 | |||
| 198f4385d2 | |||
| e7ecc7ede2 | |||
| 7088605cc1 | |||
| 15faeacb60 | |||
| f8a2c60297 | |||
| 01308b4bae | |||
| b7280e6949 | |||
| a63767d3f8 | |||
| 40c582ce82 | |||
| a52917a37d | |||
| e6f46c8d78 | |||
| f6d2c293e7 | |||
| 2ce5c65269 | |||
| 61917c3443 | |||
| 224316eaec | |||
| 5f6758dab5 | |||
| a6a45ff6c5 | |||
| 73e094e1dd | |||
| d79c0f0dec | |||
| db3e19b7b5 | |||
| 1fc151faec | |||
| 9ba999141b | |||
| f98f449f05 | |||
| e66040a6f0 | |||
| 44860482d2 | |||
| 4c90f1427f | |||
| fb63e2e40c | |||
| 583c585c81 | |||
| 4356635d12 | |||
| 4af38e5ac8 | |||
| 399186abfc | |||
| 6dce4934f0 | |||
| 874d0ce822 | |||
| abdf1ae15c | |||
| d7e3a1974b | |||
| e60148ecc3 | |||
| 0b5720faa5 | |||
| dd203ad41f | |||
| b2b29dcd49 | |||
| c97292b255 | |||
| b52271061d | |||
| d05d715a00 | |||
| 8d7ac18402 | |||
| 7e2510ef43 | |||
| feeb6af403 | |||
| d129ae6aec | |||
| 87c7127c28 | |||
| 2fc620d38d | |||
| a46ff50a1c | |||
| cabb5d71c4 | |||
| ba5811467a | |||
| 1b9042bcdd | |||
| 4d6370bf92 | |||
| c6eb186064 | |||
| 76c4cf5a56 | |||
| 797973944f | |||
| 6d97d8d87b | |||
| d404005339 | |||
| 868af6a062 | |||
| d2668cdbb0 | |||
| 6a02999054 | |||
| 9f97df2275 | |||
| d93e027e01 | |||
| 613d544a47 | |||
| 726a9a8fde | |||
| d00824f4a6 | |||
| 8f87c5d993 | |||
| c6673ad4d8 | |||
| 9ab09433de | |||
| 3067074d9c | |||
| 3efda6fb3a | |||
| 9cd472c031 | |||
| e0daa39cd3 | |||
| 70953e873a | |||
| eafc875ea9 | |||
| 03e0a010d1 | |||
| 3609a4af75 | |||
| 26748d06b4 | |||
| b40cacf5ce | |||
| 81413caea2 | |||
| dc9dd2e4b3 | |||
| 567d96c624 | |||
| 5d8b45c9fb | |||
| 0b381eb766 | |||
| 83ef61de10 |
@@ -25,7 +25,7 @@ Other menu items:
|
||||
|
||||
You can have a huge impact on the project by helping with its code. To contribute code to Caddy, first submit or comment in an issue to discuss your contribution, then open a [pull request](https://github.com/caddyserver/caddy/pulls) (PR). If you're new to our community, that's okay: **we gladly welcome pull requests from anyone, regardless of your native language or coding experience.** You can get familiar with Caddy's code base by using [code search at Sourcegraph](https://sourcegraph.com/github.com/caddyserver/caddy).
|
||||
|
||||
We hold contributions to a high standard for quality :bowtie:, so don't be surprised if we ask for revisions—even if it seems small or insignificant. Please don't take it personally. :blue_heart: If your change is on the right track, we can guide you to make it mergable.
|
||||
We hold contributions to a high standard for quality :bowtie:, so don't be surprised if we ask for revisions—even if it seems small or insignificant. Please don't take it personally. :blue_heart: If your change is on the right track, we can guide you to make it mergeable.
|
||||
|
||||
Here are some of the expectations we have of contributors:
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
GO_SEMVER: '~1.21.0'
|
||||
|
||||
- go: '1.22'
|
||||
GO_SEMVER: '~1.22.1'
|
||||
GO_SEMVER: '~1.22.3'
|
||||
|
||||
# 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)
|
||||
@@ -101,6 +101,12 @@ jobs:
|
||||
run: |
|
||||
go build -tags nobdger -trimpath -ldflags="-w -s" -v
|
||||
|
||||
- name: Smoke test Caddy
|
||||
working-directory: ./cmd/caddy
|
||||
run: |
|
||||
./caddy start
|
||||
./caddy stop
|
||||
|
||||
- name: Publish Build Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -169,7 +175,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: goreleaser/goreleaser-action@v5
|
||||
- uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
version: latest
|
||||
args: check
|
||||
|
||||
@@ -17,14 +17,12 @@ jobs:
|
||||
matrix:
|
||||
goos:
|
||||
- 'aix'
|
||||
- 'android'
|
||||
- 'linux'
|
||||
- 'solaris'
|
||||
- 'illumos'
|
||||
- 'dragonfly'
|
||||
- 'freebsd'
|
||||
- 'openbsd'
|
||||
- 'plan9'
|
||||
- 'windows'
|
||||
- 'darwin'
|
||||
- 'netbsd'
|
||||
@@ -35,7 +33,7 @@ jobs:
|
||||
# Set the minimum Go patch version for the given Go minor
|
||||
# Usable via ${{ matrix.GO_SEMVER }}
|
||||
- go: '1.22'
|
||||
GO_SEMVER: '~1.22.1'
|
||||
GO_SEMVER: '~1.22.3'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
@@ -69,7 +67,3 @@ jobs:
|
||||
working-directory: ./cmd/caddy
|
||||
run: |
|
||||
GOOS=$GOOS GOARCH=$GOARCH go build -tags nobadger -trimpath -o caddy-"$GOOS"-$GOARCH 2> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "::warning ::$GOOS Build Failed"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -43,17 +43,14 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '~1.22.1'
|
||||
go-version: '~1.22.3'
|
||||
check-latest: true
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v4
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: v1.55
|
||||
|
||||
# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
|
||||
skip-pkg-cache: true
|
||||
|
||||
# Windows times out frequently after about 5m50s if we don't set a longer timeout.
|
||||
args: --timeout 10m
|
||||
|
||||
@@ -66,5 +63,5 @@ jobs:
|
||||
- name: govulncheck
|
||||
uses: golang/govulncheck-action@v1
|
||||
with:
|
||||
go-version-input: '~1.22.1'
|
||||
go-version-input: '~1.22.3'
|
||||
check-latest: true
|
||||
|
||||
@@ -13,13 +13,13 @@ jobs:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
go:
|
||||
- '1.21'
|
||||
- '1.22'
|
||||
|
||||
include:
|
||||
# Set the minimum Go patch version for the given Go minor
|
||||
# Usable via ${{ matrix.GO_SEMVER }}
|
||||
- go: '1.21'
|
||||
GO_SEMVER: '~1.21.0'
|
||||
- go: '1.22'
|
||||
GO_SEMVER: '~1.22.3'
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
# https://github.com/sigstore/cosign/issues/1258#issuecomment-1002251233
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
run: syft version
|
||||
# GoReleaser will take care of publishing those artifacts into the release
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v5
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
version: latest
|
||||
args: release --clean --timeout 60m
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
version: 2
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# The build is done in this particular way to build Caddy in a designated directory named in .gitignore.
|
||||
|
||||
@@ -47,7 +47,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
// The hard-coded default `DefaultAdminListen` can be overidden
|
||||
// The hard-coded default `DefaultAdminListen` can be overridden
|
||||
// by setting the `CADDY_ADMIN` environment variable.
|
||||
// The environment variable may be used by packagers to change
|
||||
// the default admin address to something more appropriate for
|
||||
@@ -474,7 +474,6 @@ func manageIdentity(ctx Context, cfg *Config) error {
|
||||
// import the caddytls package -- but it works
|
||||
if cfg.Admin.Identity.IssuersRaw == nil {
|
||||
cfg.Admin.Identity.IssuersRaw = []json.RawMessage{
|
||||
json.RawMessage(`{"module": "zerossl"}`),
|
||||
json.RawMessage(`{"module": "acme"}`),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
@@ -397,6 +398,58 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
|
||||
// will want to use Run instead, which also
|
||||
// updates the config's raw state.
|
||||
func run(newCfg *Config, start bool) (Context, error) {
|
||||
ctx, err := provisionContext(newCfg, start)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
if !start {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// 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))
|
||||
for name, a := range ctx.cfg.apps {
|
||||
err := a.Start()
|
||||
if err != nil {
|
||||
// an app failed to start, so we need to stop
|
||||
// all other apps that were already started
|
||||
for _, otherAppName := range started {
|
||||
err2 := ctx.cfg.apps[otherAppName].Stop()
|
||||
if err2 != nil {
|
||||
err = fmt.Errorf("%v; additionally, aborting app %s: %v",
|
||||
err, otherAppName, err2)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s app module: start: %v", name, err)
|
||||
}
|
||||
started = append(started, name)
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// now that the user's config is running, finish setting up anything else,
|
||||
// such as remote admin endpoint, config loader, etc.
|
||||
return ctx, finishSettingUp(ctx, ctx.cfg)
|
||||
}
|
||||
|
||||
// provisionContext creates a new context from the given configuration and provisions
|
||||
// storage and apps.
|
||||
// If `newCfg` is nil a new empty configuration will be created.
|
||||
// If `replaceAdminServer` is true any currently active admin server will be replaced
|
||||
// with a new admin server based on the provided configuration.
|
||||
func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error) {
|
||||
// because we will need to roll back any state
|
||||
// modifications if this function errors, we
|
||||
// keep a single error value and scope all
|
||||
@@ -444,7 +497,7 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
}
|
||||
|
||||
// start the admin endpoint (and stop any prior one)
|
||||
if start {
|
||||
if replaceAdminServer {
|
||||
err = replaceLocalAdminServer(newCfg)
|
||||
if err != nil {
|
||||
return ctx, fmt.Errorf("starting caddy administration endpoint: %v", err)
|
||||
@@ -491,49 +544,16 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
if !start {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// Provision any admin routers which may need to access
|
||||
// some of the other apps at runtime
|
||||
err = newCfg.Admin.provisionAdminRouters(ctx)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// Start
|
||||
err = func() error {
|
||||
started := make([]string, 0, len(newCfg.apps))
|
||||
for name, a := range newCfg.apps {
|
||||
err := a.Start()
|
||||
if err != nil {
|
||||
// an app failed to start, so we need to stop
|
||||
// all other apps that were already started
|
||||
for _, otherAppName := range started {
|
||||
err2 := newCfg.apps[otherAppName].Stop()
|
||||
if err2 != nil {
|
||||
err = fmt.Errorf("%v; additionally, aborting app %s: %v",
|
||||
err, otherAppName, err2)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s app module: start: %v", name, err)
|
||||
}
|
||||
started = append(started, name)
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// now that the user's config is running, finish setting up anything else,
|
||||
// such as remote admin endpoint, config loader, etc.
|
||||
return ctx, finishSettingUp(ctx, newCfg)
|
||||
// ProvisionContext creates a new context from the configuration and provisions storage
|
||||
// and app modules.
|
||||
// The function is intended for testing and advanced use cases only, typically `Run` should be
|
||||
// use to ensure a fully functional caddy instance.
|
||||
// EXPERIMENTAL: While this is public the interface and implementation details of this function may change.
|
||||
func ProvisionContext(newCfg *Config) (Context, error) {
|
||||
return provisionContext(newCfg, false)
|
||||
}
|
||||
|
||||
// finishSettingUp should be run after all apps have successfully started.
|
||||
@@ -759,7 +779,10 @@ func exitProcess(ctx context.Context, logger *zap.Logger) {
|
||||
} else {
|
||||
logger.Error("unclean shutdown")
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
// check if we are in test environment, and dont call exit if we are
|
||||
if flag.Lookup("test.v") == nil && !strings.Contains(os.Args[0], ".test") {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
}()
|
||||
|
||||
if remoteAdminServer != nil {
|
||||
@@ -869,7 +892,7 @@ func InstanceID() (uuid.UUID, error) {
|
||||
if err != nil {
|
||||
return uuid, err
|
||||
}
|
||||
err = os.MkdirAll(appDataDir, 0o600)
|
||||
err = os.MkdirAll(appDataDir, 0o700)
|
||||
if err != nil {
|
||||
return uuid, err
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ type Dispenser struct {
|
||||
tokens []Token
|
||||
cursor int
|
||||
nesting int
|
||||
|
||||
// A map of arbitrary context data that can be used
|
||||
// to pass through some information to unmarshalers.
|
||||
context map[string]any
|
||||
}
|
||||
|
||||
// NewDispenser returns a Dispenser filled with the given tokens.
|
||||
@@ -454,6 +458,34 @@ func (d *Dispenser) DeleteN(amount int) []Token {
|
||||
return d.tokens
|
||||
}
|
||||
|
||||
// SetContext sets a key-value pair in the context map.
|
||||
func (d *Dispenser) SetContext(key string, value any) {
|
||||
if d.context == nil {
|
||||
d.context = make(map[string]any)
|
||||
}
|
||||
d.context[key] = value
|
||||
}
|
||||
|
||||
// GetContext gets the value of a key in the context map.
|
||||
func (d *Dispenser) GetContext(key string) any {
|
||||
if d.context == nil {
|
||||
return nil
|
||||
}
|
||||
return d.context[key]
|
||||
}
|
||||
|
||||
// GetContextString gets the value of a key in the context map
|
||||
// as a string, or an empty string if the key does not exist.
|
||||
func (d *Dispenser) GetContextString(key string) string {
|
||||
if d.context == nil {
|
||||
return ""
|
||||
}
|
||||
if val, ok := d.context[key].(string); ok {
|
||||
return val
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// isNewLine determines whether the current token is on a different
|
||||
// line (higher line number) than the previous token. It handles imported
|
||||
// tokens correctly. If there isn't a previous token, it returns true.
|
||||
@@ -485,3 +517,5 @@ func (d *Dispenser) isNextOnNewLine() bool {
|
||||
next := d.tokens[d.cursor+1]
|
||||
return isNextOnNewLine(curr, next)
|
||||
}
|
||||
|
||||
const MatcherNameCtxKey = "matcher_name"
|
||||
|
||||
@@ -340,6 +340,8 @@ func (l *lexer) finalizeHeredoc(val []rune, marker string) ([]rune, error) {
|
||||
return []rune(out), nil
|
||||
}
|
||||
|
||||
// Quoted returns true if the token was enclosed in quotes
|
||||
// (i.e. double quotes, backticks, or heredoc).
|
||||
func (t Token) Quoted() bool {
|
||||
return t.wasQuoted > 0
|
||||
}
|
||||
@@ -356,6 +358,19 @@ func (t Token) NumLineBreaks() int {
|
||||
return lineBreaks
|
||||
}
|
||||
|
||||
// Clone returns a deep copy of the token.
|
||||
func (t Token) Clone() Token {
|
||||
return Token{
|
||||
File: t.File,
|
||||
imports: append([]string{}, t.imports...),
|
||||
Line: t.Line,
|
||||
Text: t.Text,
|
||||
wasQuoted: t.wasQuoted,
|
||||
heredocMarker: t.heredocMarker,
|
||||
snippetName: t.snippetName,
|
||||
}
|
||||
}
|
||||
|
||||
var heredocMarkerRegexp = regexp.MustCompile("^[A-Za-z0-9_-]+$")
|
||||
|
||||
// isNextOnNewLine tests whether t2 is on a different line from t1
|
||||
|
||||
@@ -214,7 +214,12 @@ func (p *parser) addresses() error {
|
||||
value := p.Val()
|
||||
token := p.Token()
|
||||
|
||||
// special case: import directive replaces tokens during parse-time
|
||||
// Reject request matchers if trying to define them globally
|
||||
if strings.HasPrefix(value, "@") {
|
||||
return p.Errf("request matchers may not be defined globally, they must be in a site block; found %s", value)
|
||||
}
|
||||
|
||||
// Special case: import directive replaces tokens during parse-time
|
||||
if value == "import" && p.isNewLine() {
|
||||
err := p.doImport(0)
|
||||
if err != nil {
|
||||
@@ -359,9 +364,45 @@ func (p *parser) doImport(nesting int) error {
|
||||
// set up a replacer for non-variadic args replacement
|
||||
repl := makeArgsReplacer(args)
|
||||
|
||||
// grab all the tokens (if it exists) from within a block that follows the import
|
||||
var blockTokens []Token
|
||||
for currentNesting := p.Nesting(); p.NextBlock(currentNesting); {
|
||||
blockTokens = append(blockTokens, p.Token())
|
||||
}
|
||||
// initialize with size 1
|
||||
blockMapping := make(map[string][]Token, 1)
|
||||
if len(blockTokens) > 0 {
|
||||
// use such tokens to create a new dispenser, and then use it to parse each block
|
||||
bd := NewDispenser(blockTokens)
|
||||
for bd.Next() {
|
||||
// see if we can grab a key
|
||||
var currentMappingKey string
|
||||
if bd.Val() == "{" {
|
||||
return p.Err("anonymous blocks are not supported")
|
||||
}
|
||||
currentMappingKey = bd.Val()
|
||||
currentMappingTokens := []Token{}
|
||||
// read all args until end of line / {
|
||||
if bd.NextArg() {
|
||||
currentMappingTokens = append(currentMappingTokens, bd.Token())
|
||||
for bd.NextArg() {
|
||||
currentMappingTokens = append(currentMappingTokens, bd.Token())
|
||||
}
|
||||
// TODO(elee1766): we don't enter another mapping here because it's annoying to extract the { and } properly.
|
||||
// maybe someone can do that in the future
|
||||
} else {
|
||||
// attempt to enter a block and add tokens to the currentMappingTokens
|
||||
for mappingNesting := bd.Nesting(); bd.NextBlock(mappingNesting); {
|
||||
currentMappingTokens = append(currentMappingTokens, bd.Token())
|
||||
}
|
||||
}
|
||||
blockMapping[currentMappingKey] = currentMappingTokens
|
||||
}
|
||||
}
|
||||
|
||||
// splice out the import directive and its arguments
|
||||
// (2 tokens, plus the length of args)
|
||||
tokensBefore := p.tokens[:p.cursor-1-len(args)]
|
||||
tokensBefore := p.tokens[:p.cursor-1-len(args)-len(blockTokens)]
|
||||
tokensAfter := p.tokens[p.cursor+1:]
|
||||
var importedTokens []Token
|
||||
var nodes []string
|
||||
@@ -395,7 +436,6 @@ func (p *parser) doImport(nesting int) error {
|
||||
return p.Errf("Glob pattern may only contain one wildcard (*), but has others: %s", globPattern)
|
||||
}
|
||||
matches, err = filepath.Glob(globPattern)
|
||||
|
||||
if err != nil {
|
||||
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
|
||||
}
|
||||
@@ -491,6 +531,33 @@ func (p *parser) doImport(nesting int) error {
|
||||
maybeSnippet = false
|
||||
}
|
||||
}
|
||||
// if it is {block}, we substitute with all tokens in the block
|
||||
// if it is {blocks.*}, we substitute with the tokens in the mapping for the *
|
||||
var skip bool
|
||||
var tokensToAdd []Token
|
||||
switch {
|
||||
case token.Text == "{block}":
|
||||
tokensToAdd = blockTokens
|
||||
case strings.HasPrefix(token.Text, "{blocks.") && strings.HasSuffix(token.Text, "}"):
|
||||
// {blocks.foo.bar} will be extracted to key `foo.bar`
|
||||
blockKey := strings.TrimPrefix(strings.TrimSuffix(token.Text, "}"), "{blocks.")
|
||||
val, ok := blockMapping[blockKey]
|
||||
if ok {
|
||||
tokensToAdd = val
|
||||
}
|
||||
default:
|
||||
skip = true
|
||||
}
|
||||
if !skip {
|
||||
if len(tokensToAdd) == 0 {
|
||||
// if there is no content in the snippet block, don't do any replacement
|
||||
// this allows snippets which contained {block}/{block.*} before this change to continue functioning as normal
|
||||
tokensCopy = append(tokensCopy, token)
|
||||
} else {
|
||||
tokensCopy = append(tokensCopy, tokensToAdd...)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if maybeSnippet {
|
||||
tokensCopy = append(tokensCopy, token)
|
||||
@@ -512,7 +579,7 @@ func (p *parser) doImport(nesting int) error {
|
||||
// splice the imported tokens in the place of the import statement
|
||||
// and rewind cursor so Next() will land on first imported token
|
||||
p.tokens = append(tokensBefore, append(tokensCopy, tokensAfter...)...)
|
||||
p.cursor -= len(args) + 1
|
||||
p.cursor -= len(args) + len(blockTokens) + 1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -857,6 +857,29 @@ func TestSnippetAcrossMultipleFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectsGlobalMatcher(t *testing.T) {
|
||||
p := testParser(`
|
||||
@rejected path /foo
|
||||
|
||||
(common) {
|
||||
gzip foo
|
||||
errors stderr
|
||||
}
|
||||
|
||||
http://example.com {
|
||||
import common
|
||||
}
|
||||
`)
|
||||
_, err := p.parseAll()
|
||||
if err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
}
|
||||
expected := "request matchers may not be defined globally, they must be in a site block; found @rejected, at Testfile:2"
|
||||
if err.Error() != expected {
|
||||
t.Errorf("Expected error to be '%s' but got '%v'", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func testParser(input string) parser {
|
||||
return parser{Dispenser: NewTestDispenser(input)}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/mholt/acmez/acme"
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
@@ -51,6 +51,7 @@ func init() {
|
||||
RegisterDirective("log", parseLog)
|
||||
RegisterHandlerDirective("skip_log", parseLogSkip)
|
||||
RegisterHandlerDirective("log_skip", parseLogSkip)
|
||||
RegisterHandlerDirective("log_name", parseLogName)
|
||||
}
|
||||
|
||||
// parseBind parses the bind directive. Syntax:
|
||||
@@ -69,8 +70,7 @@ func parseBind(h Helper) ([]ConfigValue, error) {
|
||||
// curves <curves...>
|
||||
// client_auth {
|
||||
// mode [request|require|verify_if_given|require_and_verify]
|
||||
// trusted_ca_cert <base64_der>
|
||||
// trusted_ca_cert_file <filename>
|
||||
// trust_pool <module_name> [...]
|
||||
// trusted_leaf_cert <base64_der>
|
||||
// trusted_leaf_cert_file <filename>
|
||||
// }
|
||||
@@ -107,7 +107,6 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
var onDemand bool
|
||||
var reusePrivateKeys bool
|
||||
|
||||
// file certificate loader
|
||||
firstLine := h.RemainingArgs()
|
||||
switch len(firstLine) {
|
||||
case 0:
|
||||
@@ -117,13 +116,13 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
||||
} else if !strings.Contains(firstLine[0], "@") {
|
||||
return nil, h.Err("single argument must either be 'internal' or an email address")
|
||||
} else {
|
||||
if acmeIssuer == nil {
|
||||
acmeIssuer = new(caddytls.ACMEIssuer)
|
||||
acmeIssuer = &caddytls.ACMEIssuer{
|
||||
Email: firstLine[0],
|
||||
}
|
||||
acmeIssuer.Email = firstLine[0]
|
||||
}
|
||||
|
||||
case 2:
|
||||
// file certificate loader
|
||||
certFilename := firstLine[0]
|
||||
keyFilename := firstLine[1]
|
||||
|
||||
@@ -488,19 +487,24 @@ 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()
|
||||
defaultIssuers := caddytls.DefaultIssuers(acmeIssuer.Email)
|
||||
|
||||
// if a CA endpoint was set, override multiple implicit issuers since it's a specific one
|
||||
// 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}
|
||||
}
|
||||
|
||||
for _, issuer := range defaultIssuers {
|
||||
switch iss := issuer.(type) {
|
||||
case *caddytls.ACMEIssuer:
|
||||
issuer = acmeIssuer
|
||||
case *caddytls.ZeroSSLIssuer:
|
||||
iss.ACMEIssuer = acmeIssuer
|
||||
// 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",
|
||||
@@ -845,6 +849,7 @@ func parseInvoke(h Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||
// log <logger_name> {
|
||||
// hostnames <hostnames...>
|
||||
// output <writer_module> ...
|
||||
// core <core_module> ...
|
||||
// format <encoder_module> ...
|
||||
// level <level>
|
||||
// }
|
||||
@@ -911,7 +916,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
|
||||
// this is useful for setting up loggers per subdomain in a site block
|
||||
// with a wildcard domain
|
||||
customHostnames := []string{}
|
||||
|
||||
noHostname := false
|
||||
for h.NextBlock(0) {
|
||||
switch h.Val() {
|
||||
case "hostnames":
|
||||
@@ -956,6 +961,22 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
|
||||
}
|
||||
cl.WriterRaw = caddyconfig.JSONModuleObject(wo, "output", moduleName, h.warnings)
|
||||
|
||||
case "core":
|
||||
if !h.NextArg() {
|
||||
return nil, h.ArgErr()
|
||||
}
|
||||
moduleName := h.Val()
|
||||
moduleID := "caddy.logging.cores." + moduleName
|
||||
unm, err := caddyfile.UnmarshalModule(h.Dispenser, moduleID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
core, ok := unm.(zapcore.Core)
|
||||
if !ok {
|
||||
return nil, h.Errf("module %s (%T) is not a zapcore.Core", moduleID, unm)
|
||||
}
|
||||
cl.CoreRaw = caddyconfig.JSONModuleObject(core, "module", moduleName, h.warnings)
|
||||
|
||||
case "format":
|
||||
if !h.NextArg() {
|
||||
return nil, h.ArgErr()
|
||||
@@ -997,6 +1018,12 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
|
||||
cl.Exclude = append(cl.Exclude, h.Val())
|
||||
}
|
||||
|
||||
case "no_hostname":
|
||||
if h.NextArg() {
|
||||
return nil, h.ArgErr()
|
||||
}
|
||||
noHostname = true
|
||||
|
||||
default:
|
||||
return nil, h.Errf("unrecognized subdirective: %s", h.Val())
|
||||
}
|
||||
@@ -1004,7 +1031,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
|
||||
|
||||
var val namedCustomLog
|
||||
val.hostnames = customHostnames
|
||||
|
||||
val.noHostname = noHostname
|
||||
isEmptyConfig := reflect.DeepEqual(cl, new(caddy.CustomLog))
|
||||
|
||||
// Skip handling of empty logging configs
|
||||
@@ -1055,3 +1082,13 @@ func parseLogSkip(h Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||
}
|
||||
return caddyhttp.VarsMiddleware{"log_skip": true}, nil
|
||||
}
|
||||
|
||||
// parseLogName parses the log_name directive. Syntax:
|
||||
//
|
||||
// log_name <names...>
|
||||
func parseLogName(h Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||
h.Next() // consume directive name
|
||||
return caddyhttp.VarsMiddleware{
|
||||
caddyhttp.AccessLoggerNameVarKey: h.RemainingArgs(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -25,11 +25,12 @@ func TestLogDirectiveSyntax(t *testing.T) {
|
||||
{
|
||||
input: `:8080 {
|
||||
log {
|
||||
core mock
|
||||
output file foo.log
|
||||
}
|
||||
}
|
||||
`,
|
||||
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"writer":{"filename":"foo.log","output":"file"},"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":{"writer":{"filename":"foo.log","output":"file"},"core":{"module":"mock"},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
@@ -53,11 +54,12 @@ func TestLogDirectiveSyntax(t *testing.T) {
|
||||
{
|
||||
input: `:8080 {
|
||||
log name-override {
|
||||
core mock
|
||||
output file foo.log
|
||||
}
|
||||
}
|
||||
`,
|
||||
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.name-override"]},"name-override":{"writer":{"filename":"foo.log","output":"file"},"include":["http.log.access.name-override"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"name-override"}}}}}}`,
|
||||
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.name-override"]},"name-override":{"writer":{"filename":"foo.log","output":"file"},"core":{"module":"mock"},"include":["http.log.access.name-override"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"name-override"}}}}}}`,
|
||||
expectError: false,
|
||||
},
|
||||
} {
|
||||
|
||||
@@ -53,6 +53,7 @@ var defaultDirectiveOrder = []string{
|
||||
"log_append",
|
||||
"skip_log", // TODO: deprecated, renamed to log_skip
|
||||
"log_skip",
|
||||
"log_name",
|
||||
|
||||
"header",
|
||||
"copy_response_headers", // only in reverse_proxy's handle_response
|
||||
@@ -73,6 +74,7 @@ var defaultDirectiveOrder = []string{
|
||||
"request_header",
|
||||
"encode",
|
||||
"push",
|
||||
"intercept",
|
||||
"templates",
|
||||
|
||||
// special routing & dispatching directives
|
||||
|
||||
@@ -797,6 +797,15 @@ func (st *ServerType) serversFromPairings(
|
||||
sblockLogHosts := sblock.hostsFromKeys(true)
|
||||
for _, cval := range sblock.pile["custom_log"] {
|
||||
ncl := cval.Value.(namedCustomLog)
|
||||
|
||||
// if `no_hostname` is set, then this logger will not
|
||||
// be associated with any of the site block's hostnames,
|
||||
// and only be usable via the `log_name` directive
|
||||
// or the `access_logger_names` variable
|
||||
if ncl.noHostname {
|
||||
continue
|
||||
}
|
||||
|
||||
if sblock.hasHostCatchAllKey() && len(ncl.hostnames) == 0 {
|
||||
// all requests for hosts not able to be listed should use
|
||||
// this log because it's a catch-all-hosts server block
|
||||
@@ -805,22 +814,22 @@ func (st *ServerType) serversFromPairings(
|
||||
// if the logger overrides the hostnames, map that to the logger name
|
||||
for _, h := range ncl.hostnames {
|
||||
if srv.Logs.LoggerNames == nil {
|
||||
srv.Logs.LoggerNames = make(map[string]string)
|
||||
srv.Logs.LoggerNames = make(map[string]caddyhttp.StringArray)
|
||||
}
|
||||
srv.Logs.LoggerNames[h] = ncl.name
|
||||
srv.Logs.LoggerNames[h] = append(srv.Logs.LoggerNames[h], ncl.name)
|
||||
}
|
||||
} else {
|
||||
// otherwise, map each host to the logger name
|
||||
for _, h := range sblockLogHosts {
|
||||
if srv.Logs.LoggerNames == nil {
|
||||
srv.Logs.LoggerNames = make(map[string]string)
|
||||
}
|
||||
// strip the port from the host, if any
|
||||
host, _, err := net.SplitHostPort(h)
|
||||
if err != nil {
|
||||
host = h
|
||||
}
|
||||
srv.Logs.LoggerNames[host] = ncl.name
|
||||
if srv.Logs.LoggerNames == nil {
|
||||
srv.Logs.LoggerNames = make(map[string]caddyhttp.StringArray)
|
||||
}
|
||||
srv.Logs.LoggerNames[host] = append(srv.Logs.LoggerNames[host], ncl.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1282,19 +1291,24 @@ func matcherSetFromMatcherToken(
|
||||
if tkn.Text == "*" {
|
||||
// match all requests == no matchers, so nothing to do
|
||||
return nil, true, nil
|
||||
} else if strings.HasPrefix(tkn.Text, "/") {
|
||||
// convenient way to specify a single path match
|
||||
}
|
||||
|
||||
// convenient way to specify a single path match
|
||||
if strings.HasPrefix(tkn.Text, "/") {
|
||||
return caddy.ModuleMap{
|
||||
"path": caddyconfig.JSON(caddyhttp.MatchPath{tkn.Text}, warnings),
|
||||
}, true, nil
|
||||
} else if strings.HasPrefix(tkn.Text, matcherPrefix) {
|
||||
// pre-defined matcher
|
||||
}
|
||||
|
||||
// pre-defined matcher
|
||||
if strings.HasPrefix(tkn.Text, matcherPrefix) {
|
||||
m, ok := matcherDefs[tkn.Text]
|
||||
if !ok {
|
||||
return nil, false, fmt.Errorf("unrecognized matcher name: %+v", tkn.Text)
|
||||
}
|
||||
return m, true, nil
|
||||
}
|
||||
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
@@ -1397,6 +1411,14 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
|
||||
// given a matcher name and the tokens following it, parse
|
||||
// the tokens as a matcher module and record it
|
||||
makeMatcher := func(matcherName string, tokens []caddyfile.Token) error {
|
||||
// create a new dispenser from the tokens
|
||||
dispenser := caddyfile.NewDispenser(tokens)
|
||||
|
||||
// set the matcher name (without @) in the dispenser context so
|
||||
// that matcher modules can access it to use it as their name
|
||||
// (e.g. regexp matchers which use the name for capture groups)
|
||||
dispenser.SetContext(caddyfile.MatcherNameCtxKey, definitionName[1:])
|
||||
|
||||
mod, err := caddy.GetModule("http.matchers." + matcherName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting matcher module '%s': %v", matcherName, err)
|
||||
@@ -1405,7 +1427,7 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
|
||||
if !ok {
|
||||
return fmt.Errorf("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
|
||||
}
|
||||
err = unm.UnmarshalCaddyfile(caddyfile.NewDispenser(tokens))
|
||||
err = unm.UnmarshalCaddyfile(dispenser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1422,11 +1444,13 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
|
||||
if d.NextArg() {
|
||||
if d.Token().Quoted() {
|
||||
// since it was missing the matcher name, we insert a token
|
||||
// in front of the expression token itself
|
||||
err := makeMatcher("expression", []caddyfile.Token{
|
||||
{Text: "expression", File: d.File(), Line: d.Line()},
|
||||
d.Token(),
|
||||
})
|
||||
// in front of the expression token itself; we use Clone() to
|
||||
// make the new token to keep the same the import location as
|
||||
// the next token, if this is within a snippet or imported file.
|
||||
// see https://github.com/caddyserver/caddy/issues/6287
|
||||
expressionToken := d.Token().Clone()
|
||||
expressionToken.Text = "expression"
|
||||
err := makeMatcher("expression", []caddyfile.Token{expressionToken, d.Token()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1583,9 +1607,10 @@ func (c counter) nextGroup() string {
|
||||
}
|
||||
|
||||
type namedCustomLog struct {
|
||||
name string
|
||||
hostnames []string
|
||||
log *caddy.CustomLog
|
||||
name string
|
||||
hostnames []string
|
||||
log *caddy.CustomLog
|
||||
noHostname bool
|
||||
}
|
||||
|
||||
// sbAddrAssociation is a mapping from a list of
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/mholt/acmez/acme"
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
@@ -54,6 +54,7 @@ func init() {
|
||||
RegisterGlobalOption("auto_https", parseOptAutoHTTPS)
|
||||
RegisterGlobalOption("servers", parseServerOptions)
|
||||
RegisterGlobalOption("ocsp_stapling", parseOCSPStaplingOptions)
|
||||
RegisterGlobalOption("cert_lifetime", parseOptDuration)
|
||||
RegisterGlobalOption("log", parseLogOptions)
|
||||
RegisterGlobalOption("preferred_chains", parseOptPreferredChains)
|
||||
RegisterGlobalOption("persist_config", parseOptPersistConfig)
|
||||
@@ -212,9 +213,9 @@ func parseOptACMEDNS(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prov, ok := unm.(certmagic.ACMEDNSProvider)
|
||||
prov, ok := unm.(certmagic.DNSProvider)
|
||||
if !ok {
|
||||
return nil, d.Errf("module %s (%T) is not a certmagic.ACMEDNSProvider", modID, unm)
|
||||
return nil, d.Errf("module %s (%T) is not a certmagic.DNSProvider", modID, unm)
|
||||
}
|
||||
return prov, nil
|
||||
}
|
||||
@@ -345,9 +346,34 @@ func parseOptOnDemand(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||
if ond == nil {
|
||||
ond = new(caddytls.OnDemandConfig)
|
||||
}
|
||||
if ond.PermissionRaw != nil {
|
||||
return nil, d.Err("on-demand TLS permission module (or 'ask') already specified")
|
||||
}
|
||||
perm := caddytls.PermissionByHTTP{Endpoint: d.Val()}
|
||||
ond.PermissionRaw = caddyconfig.JSONModuleObject(perm, "module", "http", nil)
|
||||
|
||||
case "permission":
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
if ond == nil {
|
||||
ond = new(caddytls.OnDemandConfig)
|
||||
}
|
||||
if ond.PermissionRaw != nil {
|
||||
return nil, d.Err("on-demand TLS permission module (or 'ask') already specified")
|
||||
}
|
||||
modName := d.Val()
|
||||
modID := "tls.permission." + modName
|
||||
unm, err := caddyfile.UnmarshalModule(d, modID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
perm, ok := unm.(caddytls.OnDemandPermission)
|
||||
if !ok {
|
||||
return nil, d.Errf("module %s (%T) is not an on-demand TLS permission module", modID, unm)
|
||||
}
|
||||
ond.PermissionRaw = caddyconfig.JSONModuleObject(perm, "module", modName, nil)
|
||||
|
||||
case "interval":
|
||||
if !d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
|
||||
@@ -50,6 +50,7 @@ type serverOptions struct {
|
||||
ClientIPHeaders []string
|
||||
ShouldLogCredentials bool
|
||||
Metrics *caddyhttp.Metrics
|
||||
Trace bool // TODO: EXPERIMENTAL
|
||||
}
|
||||
|
||||
func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
@@ -246,39 +247,11 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
}
|
||||
serverOpts.Metrics = new(caddyhttp.Metrics)
|
||||
|
||||
// TODO: DEPRECATED. (August 2022)
|
||||
case "protocol":
|
||||
caddy.Log().Named("caddyfile").Warn("DEPRECATED: protocol sub-option will be removed soon")
|
||||
|
||||
for nesting := d.Nesting(); d.NextBlock(nesting); {
|
||||
switch d.Val() {
|
||||
case "allow_h2c":
|
||||
caddy.Log().Named("caddyfile").Warn("DEPRECATED: allow_h2c will be removed soon; use protocols option instead")
|
||||
|
||||
if d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
if sliceContains(serverOpts.Protocols, "h2c") {
|
||||
return nil, d.Errf("protocol h2c already specified")
|
||||
}
|
||||
serverOpts.Protocols = append(serverOpts.Protocols, "h2c")
|
||||
|
||||
case "strict_sni_host":
|
||||
caddy.Log().Named("caddyfile").Warn("DEPRECATED: protocol > strict_sni_host in this position will be removed soon; move up to the servers block instead")
|
||||
|
||||
if d.NextArg() && d.Val() != "insecure_off" && d.Val() != "on" {
|
||||
return nil, d.Errf("strict_sni_host only supports 'on' or 'insecure_off', got '%s'", d.Val())
|
||||
}
|
||||
boolVal := true
|
||||
if d.Val() == "insecure_off" {
|
||||
boolVal = false
|
||||
}
|
||||
serverOpts.StrictSNIHost = &boolVal
|
||||
|
||||
default:
|
||||
return nil, d.Errf("unrecognized protocol option '%s'", d.Val())
|
||||
}
|
||||
case "trace":
|
||||
if d.NextArg() {
|
||||
return nil, d.ArgErr()
|
||||
}
|
||||
serverOpts.Trace = true
|
||||
|
||||
default:
|
||||
return nil, d.Errf("unrecognized servers option '%s'", d.Val())
|
||||
@@ -291,7 +264,7 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
|
||||
func applyServerOptions(
|
||||
servers map[string]*caddyhttp.Server,
|
||||
options map[string]any,
|
||||
warnings *[]caddyconfig.Warning,
|
||||
_ *[]caddyconfig.Warning,
|
||||
) error {
|
||||
serverOpts, ok := options["servers"].([]serverOptions)
|
||||
if !ok {
|
||||
@@ -351,10 +324,17 @@ func applyServerOptions(
|
||||
server.Metrics = opts.Metrics
|
||||
if opts.ShouldLogCredentials {
|
||||
if server.Logs == nil {
|
||||
server.Logs = &caddyhttp.ServerLogConfig{}
|
||||
server.Logs = new(caddyhttp.ServerLogConfig)
|
||||
}
|
||||
server.Logs.ShouldLogCredentials = opts.ShouldLogCredentials
|
||||
}
|
||||
if opts.Trace {
|
||||
// TODO: THIS IS EXPERIMENTAL (MAY 2024)
|
||||
if server.Logs == nil {
|
||||
server.Logs = new(caddyhttp.ServerLogConfig)
|
||||
}
|
||||
server.Logs.Trace = opts.Trace
|
||||
}
|
||||
|
||||
if opts.Name != "" {
|
||||
nameReplacements[key] = opts.Name
|
||||
|
||||
@@ -36,6 +36,7 @@ func NewShorthandReplacer() ShorthandReplacer {
|
||||
{regexp.MustCompile(`{re\.([\w-\.]*)}`), "{http.regexp.$1}"},
|
||||
{regexp.MustCompile(`{vars\.([\w-]*)}`), "{http.vars.$1}"},
|
||||
{regexp.MustCompile(`{rp\.([\w-\.]*)}`), "{http.reverse_proxy.$1}"},
|
||||
{regexp.MustCompile(`{resp\.([\w-\.]*)}`), "{http.intercept.$1}"},
|
||||
{regexp.MustCompile(`{err\.([\w-\.]*)}`), "{http.error.$1}"},
|
||||
{regexp.MustCompile(`{file_match\.([\w-]*)}`), "{http.matchers.file.$1}"},
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/mholt/acmez/acme"
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
@@ -224,7 +224,7 @@ func (st ServerType) buildTLSApp(
|
||||
var internal, external []string
|
||||
for _, s := range ap.SubjectsRaw {
|
||||
// do not create Issuers for Tailscale domains; they will be given a Manager instead
|
||||
if strings.HasSuffix(strings.ToLower(s), ".ts.net") {
|
||||
if isTailscaleDomain(s) {
|
||||
continue
|
||||
}
|
||||
if !certmagic.SubjectQualifiesForCert(s) {
|
||||
@@ -344,7 +344,7 @@ func (st ServerType) buildTLSApp(
|
||||
internalAP := &caddytls.AutomationPolicy{
|
||||
IssuersRaw: []json.RawMessage{json.RawMessage(`{"module":"internal"}`)},
|
||||
}
|
||||
if autoHTTPS != "off" {
|
||||
if autoHTTPS != "off" && autoHTTPS != "disable_certs" {
|
||||
for h := range httpsHostsSharedWithHostlessKey {
|
||||
al = append(al, h)
|
||||
if !certmagic.SubjectQualifiesForPublicCert(h) {
|
||||
@@ -378,15 +378,12 @@ func (st ServerType) buildTLSApp(
|
||||
if len(ap.Issuers) == 0 && automationPolicyHasAllPublicNames(ap) {
|
||||
// for public names, create default issuers which will later be filled in with configured global defaults
|
||||
// (internal names will implicitly use the internal issuer at auto-https time)
|
||||
ap.Issuers = caddytls.DefaultIssuers()
|
||||
emailStr, _ := globalEmail.(string)
|
||||
ap.Issuers = caddytls.DefaultIssuers(emailStr)
|
||||
|
||||
// if a specific endpoint is configured, can't use multiple default issuers
|
||||
if globalACMECA != nil {
|
||||
if strings.Contains(globalACMECA.(string), "zerossl") {
|
||||
ap.Issuers = []certmagic.Issuer{&caddytls.ZeroSSLIssuer{ACMEIssuer: new(caddytls.ACMEIssuer)}}
|
||||
} else {
|
||||
ap.Issuers = []certmagic.Issuer{new(caddytls.ACMEIssuer)}
|
||||
}
|
||||
ap.Issuers = []certmagic.Issuer{new(caddytls.ACMEIssuer)}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -459,6 +456,8 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
|
||||
globalACMEDNS := options["acme_dns"]
|
||||
globalACMEEAB := options["acme_eab"]
|
||||
globalPreferredChains := options["preferred_chains"]
|
||||
globalCertLifetime := options["cert_lifetime"]
|
||||
globalHTTPPort, globalHTTPSPort := options["http_port"], options["https_port"]
|
||||
|
||||
if globalEmail != nil && acmeIssuer.Email == "" {
|
||||
acmeIssuer.Email = globalEmail.(string)
|
||||
@@ -482,6 +481,27 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
|
||||
if globalPreferredChains != nil && acmeIssuer.PreferredChains == nil {
|
||||
acmeIssuer.PreferredChains = globalPreferredChains.(*caddytls.ChainPreference)
|
||||
}
|
||||
if globalHTTPPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.HTTP == nil || acmeIssuer.Challenges.HTTP.AlternatePort == 0) {
|
||||
if acmeIssuer.Challenges == nil {
|
||||
acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
|
||||
}
|
||||
if acmeIssuer.Challenges.HTTP == nil {
|
||||
acmeIssuer.Challenges.HTTP = new(caddytls.HTTPChallengeConfig)
|
||||
}
|
||||
acmeIssuer.Challenges.HTTP.AlternatePort = globalHTTPPort.(int)
|
||||
}
|
||||
if globalHTTPSPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.TLSALPN == nil || acmeIssuer.Challenges.TLSALPN.AlternatePort == 0) {
|
||||
if acmeIssuer.Challenges == nil {
|
||||
acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
|
||||
}
|
||||
if acmeIssuer.Challenges.TLSALPN == nil {
|
||||
acmeIssuer.Challenges.TLSALPN = new(caddytls.TLSALPNChallengeConfig)
|
||||
}
|
||||
acmeIssuer.Challenges.TLSALPN.AlternatePort = globalHTTPSPort.(int)
|
||||
}
|
||||
if globalCertLifetime != nil && acmeIssuer.CertificateLifetime == 0 {
|
||||
acmeIssuer.CertificateLifetime = globalCertLifetime.(caddy.Duration)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -490,7 +510,11 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
|
||||
// for any other automation policies. A nil policy (and no error) will be
|
||||
// returned if there are no default/global options. However, if always is
|
||||
// true, a non-nil value will always be returned (unless there is an error).
|
||||
func newBaseAutomationPolicy(options map[string]any, warnings []caddyconfig.Warning, always bool) (*caddytls.AutomationPolicy, error) {
|
||||
func newBaseAutomationPolicy(
|
||||
options map[string]any,
|
||||
_ []caddyconfig.Warning,
|
||||
always bool,
|
||||
) (*caddytls.AutomationPolicy, error) {
|
||||
issuers, hasIssuers := options["cert_issuer"]
|
||||
_, hasLocalCerts := options["local_certs"]
|
||||
keyType, hasKeyType := options["key_type"]
|
||||
@@ -666,17 +690,33 @@ func automationPolicyShadows(i int, aps []*caddytls.AutomationPolicy) int {
|
||||
// subjectQualifiesForPublicCert is like certmagic.SubjectQualifiesForPublicCert() except
|
||||
// that this allows domains with multiple wildcard levels like '*.*.example.com' to qualify
|
||||
// if the automation policy has OnDemand enabled (i.e. this function is more lenient).
|
||||
//
|
||||
// IP subjects are considered as non-qualifying for public certs. Technically, there are
|
||||
// now public ACME CAs as well as non-ACME CAs that issue IP certificates. But this function
|
||||
// is used solely for implicit automation (defaults), where it gets really complicated to
|
||||
// keep track of which issuers support IP certificates in which circumstances. Currently,
|
||||
// issuers that support IP certificates are very few, and all require some sort of config
|
||||
// from the user anyway (such as an account credential). Since we cannot implicitly and
|
||||
// automatically get public IP certs without configuration from the user, we treat IPs as
|
||||
// not qualifying for public certificates. Users should expressly configure an issuer
|
||||
// that supports IP certs for that purpose.
|
||||
func subjectQualifiesForPublicCert(ap *caddytls.AutomationPolicy, subj string) bool {
|
||||
return !certmagic.SubjectIsIP(subj) &&
|
||||
!certmagic.SubjectIsInternal(subj) &&
|
||||
(strings.Count(subj, "*.") < 2 || ap.OnDemand)
|
||||
}
|
||||
|
||||
// automationPolicyHasAllPublicNames returns true if all the names on the policy
|
||||
// do NOT qualify for public certs OR are tailscale domains.
|
||||
func automationPolicyHasAllPublicNames(ap *caddytls.AutomationPolicy) bool {
|
||||
for _, subj := range ap.SubjectsRaw {
|
||||
if !subjectQualifiesForPublicCert(ap, subj) {
|
||||
if !subjectQualifiesForPublicCert(ap, subj) || isTailscaleDomain(subj) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isTailscaleDomain(name string) bool {
|
||||
return strings.HasSuffix(strings.ToLower(name), ".ts.net")
|
||||
}
|
||||
|
||||
@@ -181,19 +181,16 @@ func (hl HTTPLoader) makeClient(ctx caddy.Context) (*http.Client, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting server identity credentials: %v", err)
|
||||
}
|
||||
if tlsConfig == nil {
|
||||
tlsConfig = new(tls.Config)
|
||||
}
|
||||
tlsConfig.Certificates = certs
|
||||
// See https://github.com/securego/gosec/issues/1054#issuecomment-2072235199
|
||||
//nolint:gosec
|
||||
tlsConfig = &tls.Config{Certificates: certs}
|
||||
} else if hl.TLS.ClientCertificateFile != "" && hl.TLS.ClientCertificateKeyFile != "" {
|
||||
cert, err := tls.LoadX509KeyPair(hl.TLS.ClientCertificateFile, hl.TLS.ClientCertificateKeyFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tlsConfig == nil {
|
||||
tlsConfig = new(tls.Config)
|
||||
}
|
||||
tlsConfig.Certificates = []tls.Certificate{cert}
|
||||
//nolint:gosec
|
||||
tlsConfig = &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
}
|
||||
|
||||
// trusted server certs
|
||||
|
||||
+165
-391
@@ -1,42 +1,31 @@
|
||||
package caddytest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/aryann/difflib"
|
||||
|
||||
caddycmd "github.com/caddyserver/caddy/v2/cmd"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
// plug in Caddy modules here
|
||||
_ "github.com/caddyserver/caddy/v2/modules/standard"
|
||||
)
|
||||
|
||||
// Defaults store any configuration required to make the tests run
|
||||
type Defaults struct {
|
||||
// Port we expect caddy to listening on
|
||||
AdminPort int
|
||||
// Certificates we expect to be loaded before attempting to run the tests
|
||||
Certifcates []string
|
||||
Certificates []string
|
||||
// TestRequestTimeout is the time to wait for a http request to
|
||||
TestRequestTimeout time.Duration
|
||||
// LoadRequestTimeout is the time to wait for the config to be loaded against the caddy server
|
||||
@@ -45,29 +34,31 @@ type Defaults struct {
|
||||
|
||||
// Default testing values
|
||||
var Default = Defaults{
|
||||
AdminPort: 2999, // different from what a real server also running on a developer's machine might be
|
||||
Certifcates: []string{"/caddy.localhost.crt", "/caddy.localhost.key"},
|
||||
Certificates: []string{"/caddy.localhost.crt", "/caddy.localhost.key"},
|
||||
TestRequestTimeout: 5 * time.Second,
|
||||
LoadRequestTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
var (
|
||||
matchKey = regexp.MustCompile(`(/[\w\d\.]+\.key)`)
|
||||
matchCert = regexp.MustCompile(`(/[\w\d\.]+\.crt)`)
|
||||
)
|
||||
|
||||
// Tester represents an instance of a test client.
|
||||
type Tester struct {
|
||||
Client *http.Client
|
||||
configLoaded bool
|
||||
t testing.TB
|
||||
Client *http.Client
|
||||
|
||||
adminPort int
|
||||
|
||||
portOne int
|
||||
portTwo int
|
||||
|
||||
started atomic.Bool
|
||||
configLoaded bool
|
||||
configFileName string
|
||||
envFileName string
|
||||
}
|
||||
|
||||
// NewTester will create a new testing client with an attached cookie jar
|
||||
func NewTester(t testing.TB) *Tester {
|
||||
func NewTester() (*Tester, error) {
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create cookiejar: %s", err)
|
||||
return nil, fmt.Errorf("failed to create cookiejar: %w", err)
|
||||
}
|
||||
|
||||
return &Tester{
|
||||
@@ -77,8 +68,7 @@ func NewTester(t testing.TB) *Tester {
|
||||
Timeout: Default.TestRequestTimeout,
|
||||
},
|
||||
configLoaded: false,
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
type configLoadError struct {
|
||||
@@ -92,58 +82,90 @@ func timeElapsed(start time.Time, name string) {
|
||||
log.Printf("%s took %s", name, elapsed)
|
||||
}
|
||||
|
||||
// InitServer this will configure the server with a configurion of a specific
|
||||
// type. The configType must be either "json" or the adapter type.
|
||||
func (tc *Tester) InitServer(rawConfig string, configType string) {
|
||||
if err := tc.initServer(rawConfig, configType); err != nil {
|
||||
tc.t.Logf("failed to load config: %s", err)
|
||||
tc.t.Fail()
|
||||
// launch caddy will start the server
|
||||
func (tc *Tester) LaunchCaddy() error {
|
||||
if !tc.started.CompareAndSwap(false, true) {
|
||||
return fmt.Errorf("already launched caddy with this tester")
|
||||
}
|
||||
if err := tc.ensureConfigRunning(rawConfig, configType); err != nil {
|
||||
tc.t.Logf("failed ensuring config is running: %s", err)
|
||||
tc.t.Fail()
|
||||
if err := tc.startServer(); err != nil {
|
||||
return fmt.Errorf("failed to start server: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitServer this will configure the server with a configurion of a specific
|
||||
// type. The configType must be either "json" or the adapter type.
|
||||
func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||
if testing.Short() {
|
||||
tc.t.SkipNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
err := validateTestPrerequisites(tc.t)
|
||||
if err != nil {
|
||||
tc.t.Skipf("skipping tests as failed integration prerequisites. %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
tc.t.Cleanup(func() {
|
||||
if tc.t.Failed() && tc.configLoaded {
|
||||
res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
|
||||
if err != nil {
|
||||
tc.t.Log("unable to read the current config")
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
|
||||
var out bytes.Buffer
|
||||
_ = json.Indent(&out, body, "", " ")
|
||||
tc.t.Logf("----------- failed with config -----------\n%s", out.String())
|
||||
func (tc *Tester) CleanupCaddy() error {
|
||||
// now shutdown the server, since the test is done.
|
||||
defer func() {
|
||||
// try to remove pthe tmp config file we created
|
||||
if tc.configFileName != "" {
|
||||
os.Remove(tc.configFileName)
|
||||
}
|
||||
})
|
||||
if tc.envFileName != "" {
|
||||
os.Remove(tc.envFileName)
|
||||
}
|
||||
}()
|
||||
resp, err := http.Post(fmt.Sprintf("http://localhost:%d/stop", tc.adminPort), "", nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't stop caddytest server: %w", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
for retries := 0; retries < 10; retries++ {
|
||||
if tc.isCaddyAdminRunning() != nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
rawConfig = prependCaddyFilePath(rawConfig)
|
||||
return fmt.Errorf("timed out waiting for caddytest server to stop")
|
||||
}
|
||||
|
||||
func (tc *Tester) AdminPort() int {
|
||||
return tc.adminPort
|
||||
}
|
||||
|
||||
func (tc *Tester) PortOne() int {
|
||||
return tc.portOne
|
||||
}
|
||||
|
||||
func (tc *Tester) PortTwo() int {
|
||||
return tc.portTwo
|
||||
}
|
||||
|
||||
func (tc *Tester) ReplaceTestingPlaceholders(x string) string {
|
||||
x = strings.ReplaceAll(x, "{$TESTING_CADDY_ADMIN_BIND}", fmt.Sprintf("localhost:%d", tc.adminPort))
|
||||
x = strings.ReplaceAll(x, "{$TESTING_CADDY_ADMIN_PORT}", fmt.Sprintf("%d", tc.adminPort))
|
||||
x = strings.ReplaceAll(x, "{$TESTING_CADDY_PORT_ONE}", fmt.Sprintf("%d", tc.portOne))
|
||||
x = strings.ReplaceAll(x, "{$TESTING_CADDY_PORT_TWO}", fmt.Sprintf("%d", tc.portTwo))
|
||||
return x
|
||||
}
|
||||
|
||||
// LoadConfig loads the config to the tester server and also ensures that the config was loaded
|
||||
// it should not be run
|
||||
func (tc *Tester) LoadConfig(rawConfig string, configType string) error {
|
||||
if tc.adminPort == 0 {
|
||||
return fmt.Errorf("load config called where startServer didnt succeed")
|
||||
}
|
||||
rawConfig = tc.ReplaceTestingPlaceholders(rawConfig)
|
||||
// replace special testing placeholders so we can have our admin api be on a random port
|
||||
// normalize JSON config
|
||||
if configType == "json" {
|
||||
var conf any
|
||||
if err := json.Unmarshal([]byte(rawConfig), &conf); err != nil {
|
||||
return err
|
||||
}
|
||||
c, err := json.Marshal(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rawConfig = string(c)
|
||||
}
|
||||
client := &http.Client{
|
||||
Timeout: Default.LoadRequestTimeout,
|
||||
}
|
||||
start := time.Now()
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/load", Default.AdminPort), strings.NewReader(rawConfig))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/load", tc.adminPort), strings.NewReader(rawConfig))
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request. %s", err)
|
||||
return err
|
||||
return fmt.Errorf("failed to create request. %w", err)
|
||||
}
|
||||
|
||||
if configType == "json" {
|
||||
@@ -154,16 +176,14 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
tc.t.Errorf("unable to contact caddy server. %s", err)
|
||||
return err
|
||||
return fmt.Errorf("unable to contact caddy server. %w", err)
|
||||
}
|
||||
timeElapsed(start, "caddytest: config load time")
|
||||
|
||||
defer res.Body.Close()
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
tc.t.Errorf("unable to read response. %s", err)
|
||||
return err
|
||||
return fmt.Errorf("unable to read response. %w", err)
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
@@ -171,133 +191,115 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||
}
|
||||
|
||||
tc.configLoaded = true
|
||||
|
||||
// if the config is not loaded at this point, it is a bug in caddy's config.Load
|
||||
// the contract for config.Load states that the config must be loaded before it returns, and that it will
|
||||
// error if the config fails to apply
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error {
|
||||
expectedBytes := []byte(prependCaddyFilePath(rawConfig))
|
||||
if configType != "json" {
|
||||
adapter := caddyconfig.GetAdapter(configType)
|
||||
if adapter == nil {
|
||||
return fmt.Errorf("adapter of config type is missing: %s", configType)
|
||||
}
|
||||
expectedBytes, _, _ = adapter.Adapt([]byte(rawConfig), nil)
|
||||
}
|
||||
|
||||
var expected any
|
||||
err := json.Unmarshal(expectedBytes, &expected)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (tc *Tester) GetCurrentConfig(receiver any) error {
|
||||
client := &http.Client{
|
||||
Timeout: Default.LoadRequestTimeout,
|
||||
}
|
||||
|
||||
fetchConfig := func(client *http.Client) any {
|
||||
resp, err := client.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
actualBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var actual any
|
||||
err = json.Unmarshal(actualBytes, &actual)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return actual
|
||||
resp, err := client.Get(fmt.Sprintf("http://localhost:%d/config/", tc.adminPort))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for retries := 10; retries > 0; retries-- {
|
||||
if reflect.DeepEqual(expected, fetchConfig(client)) {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
defer resp.Body.Close()
|
||||
actualBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.t.Errorf("POSTed configuration isn't active")
|
||||
return errors.New("EnsureConfigRunning: POSTed configuration isn't active")
|
||||
err = json.Unmarshal(actualBytes, receiver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const initConfig = `{
|
||||
admin localhost:2999
|
||||
}
|
||||
`
|
||||
|
||||
// validateTestPrerequisites ensures the certificates are available in the
|
||||
// designated path and Caddy sub-process is running.
|
||||
func validateTestPrerequisites(t testing.TB) error {
|
||||
// check certificates are found
|
||||
for _, certName := range Default.Certifcates {
|
||||
if _, err := os.Stat(getIntegrationDir() + certName); errors.Is(err, fs.ErrNotExist) {
|
||||
return fmt.Errorf("caddy integration test certificates (%s) not found", certName)
|
||||
}
|
||||
func getFreePort() (int, error) {
|
||||
lr, err := net.Listen("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
port := strings.Split(lr.Addr().String(), ":")
|
||||
if len(port) < 2 {
|
||||
return 0, fmt.Errorf("no port available")
|
||||
}
|
||||
i, err := strconv.Atoi(port[1])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
err = lr.Close()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to close listener: %w", err)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
if isCaddyAdminRunning() != nil {
|
||||
// setup the init config file, and set the cleanup afterwards
|
||||
// launches caddy, and then ensures the Caddy sub-process is running.
|
||||
func (tc *Tester) startServer() error {
|
||||
if tc.isCaddyAdminRunning() == nil {
|
||||
return fmt.Errorf("caddy test admin port still in use")
|
||||
}
|
||||
a, err := getFreePort()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not find a open port to listen on: %w", err)
|
||||
}
|
||||
tc.adminPort = a
|
||||
tc.portOne, err = getFreePort()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not find a open portOne: %w", err)
|
||||
}
|
||||
tc.portTwo, err = getFreePort()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not find a open portOne: %w", err)
|
||||
}
|
||||
// setup the init config file, and set the cleanup afterwards
|
||||
{
|
||||
f, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
os.Remove(f.Name())
|
||||
})
|
||||
tc.configFileName = f.Name()
|
||||
|
||||
initConfig := fmt.Sprintf(`{
|
||||
admin localhost:%d
|
||||
}`, a)
|
||||
if _, err := f.WriteString(initConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// start inprocess caddy server
|
||||
os.Args = []string{"caddy", "run", "--config", f.Name(), "--adapter", "caddyfile"}
|
||||
go func() {
|
||||
caddycmd.Main()
|
||||
}()
|
||||
|
||||
// wait for caddy to start serving the initial config
|
||||
for retries := 10; retries > 0 && isCaddyAdminRunning() != nil; retries-- {
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
// start inprocess caddy server
|
||||
go func() {
|
||||
_ = caddycmd.MainForTesting("run", "--config", tc.configFileName, "--adapter", "caddyfile")
|
||||
}()
|
||||
// wait for caddy admin api to start. it should happen quickly.
|
||||
for retries := 10; retries > 0 && tc.isCaddyAdminRunning() != nil; retries-- {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
// one more time to return the error
|
||||
return isCaddyAdminRunning()
|
||||
return tc.isCaddyAdminRunning()
|
||||
}
|
||||
|
||||
func isCaddyAdminRunning() error {
|
||||
func (tc *Tester) isCaddyAdminRunning() error {
|
||||
// assert that caddy is running
|
||||
client := &http.Client{
|
||||
Timeout: Default.LoadRequestTimeout,
|
||||
}
|
||||
resp, err := client.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
|
||||
resp, err := client.Get(fmt.Sprintf("http://localhost:%d/config/", tc.adminPort))
|
||||
if err != nil {
|
||||
return fmt.Errorf("caddy integration test caddy server not running. Expected to be listening on localhost:%d", Default.AdminPort)
|
||||
return fmt.Errorf("caddy integration test caddy server not running. Expected to be listening on localhost:%d", tc.adminPort)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getIntegrationDir() string {
|
||||
_, filename, _, ok := runtime.Caller(1)
|
||||
if !ok {
|
||||
panic("unable to determine the current file path")
|
||||
}
|
||||
|
||||
return path.Dir(filename)
|
||||
}
|
||||
|
||||
// use the convention to replace /[certificatename].[crt|key] with the full path
|
||||
// this helps reduce the noise in test configurations and also allow this
|
||||
// to run in any path
|
||||
func prependCaddyFilePath(rawConfig string) string {
|
||||
r := matchKey.ReplaceAllString(rawConfig, getIntegrationDir()+"$1")
|
||||
r = matchCert.ReplaceAllString(r, getIntegrationDir()+"$1")
|
||||
return r
|
||||
}
|
||||
|
||||
// CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally
|
||||
func CreateTestingTransport() *http.Transport {
|
||||
dialer := net.Dialer{
|
||||
@@ -324,231 +326,3 @@ func CreateTestingTransport() *http.Transport {
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
|
||||
}
|
||||
}
|
||||
|
||||
// AssertLoadError will load a config and expect an error
|
||||
func AssertLoadError(t *testing.T, rawConfig string, configType string, expectedError string) {
|
||||
tc := NewTester(t)
|
||||
|
||||
err := tc.initServer(rawConfig, configType)
|
||||
if !strings.Contains(err.Error(), expectedError) {
|
||||
t.Errorf("expected error \"%s\" but got \"%s\"", expectedError, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// AssertRedirect makes a request and asserts the redirection happens
|
||||
func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, expectedStatusCode int) *http.Response {
|
||||
redirectPolicyFunc := func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
||||
// using the existing client, we override the check redirect policy for this test
|
||||
old := tc.Client.CheckRedirect
|
||||
tc.Client.CheckRedirect = redirectPolicyFunc
|
||||
defer func() { tc.Client.CheckRedirect = old }()
|
||||
|
||||
resp, err := tc.Client.Get(requestURI)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to call server %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if expectedStatusCode != resp.StatusCode {
|
||||
tc.t.Errorf("requesting \"%s\" expected status code: %d but got %d", requestURI, expectedStatusCode, resp.StatusCode)
|
||||
}
|
||||
|
||||
loc, err := resp.Location()
|
||||
if err != nil {
|
||||
tc.t.Errorf("requesting \"%s\" expected location: \"%s\" but got error: %s", requestURI, expectedToLocation, err)
|
||||
}
|
||||
if loc == nil && expectedToLocation != "" {
|
||||
tc.t.Errorf("requesting \"%s\" expected a Location header, but didn't get one", requestURI)
|
||||
}
|
||||
if loc != nil {
|
||||
if expectedToLocation != loc.String() {
|
||||
tc.t.Errorf("requesting \"%s\" expected location: \"%s\" but got \"%s\"", requestURI, expectedToLocation, loc.String())
|
||||
}
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// CompareAdapt adapts a config and then compares it against an expected result
|
||||
func CompareAdapt(t testing.TB, filename, rawConfig string, adapterName string, expectedResponse string) bool {
|
||||
cfgAdapter := caddyconfig.GetAdapter(adapterName)
|
||||
if cfgAdapter == nil {
|
||||
t.Logf("unrecognized config adapter '%s'", adapterName)
|
||||
return false
|
||||
}
|
||||
|
||||
options := make(map[string]any)
|
||||
|
||||
result, warnings, err := cfgAdapter.Adapt([]byte(rawConfig), options)
|
||||
if err != nil {
|
||||
t.Logf("adapting config using %s adapter: %v", adapterName, err)
|
||||
return false
|
||||
}
|
||||
|
||||
// prettify results to keep tests human-manageable
|
||||
var prettyBuf bytes.Buffer
|
||||
err = json.Indent(&prettyBuf, result, "", "\t")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
result = prettyBuf.Bytes()
|
||||
|
||||
if len(warnings) > 0 {
|
||||
for _, w := range warnings {
|
||||
t.Logf("warning: %s:%d: %s: %s", filename, w.Line, w.Directive, w.Message)
|
||||
}
|
||||
}
|
||||
|
||||
diff := difflib.Diff(
|
||||
strings.Split(expectedResponse, "\n"),
|
||||
strings.Split(string(result), "\n"))
|
||||
|
||||
// scan for failure
|
||||
failed := false
|
||||
for _, d := range diff {
|
||||
if d.Delta != difflib.Common {
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if failed {
|
||||
for _, d := range diff {
|
||||
switch d.Delta {
|
||||
case difflib.Common:
|
||||
fmt.Printf(" %s\n", d.Payload)
|
||||
case difflib.LeftOnly:
|
||||
fmt.Printf(" - %s\n", d.Payload)
|
||||
case difflib.RightOnly:
|
||||
fmt.Printf(" + %s\n", d.Payload)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AssertAdapt adapts a config and then tests it against an expected result
|
||||
func AssertAdapt(t testing.TB, rawConfig string, adapterName string, expectedResponse string) {
|
||||
ok := CompareAdapt(t, "Caddyfile", rawConfig, adapterName, expectedResponse)
|
||||
if !ok {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Generic request functions
|
||||
|
||||
func applyHeaders(t testing.TB, req *http.Request, requestHeaders []string) {
|
||||
requestContentType := ""
|
||||
for _, requestHeader := range requestHeaders {
|
||||
arr := strings.SplitAfterN(requestHeader, ":", 2)
|
||||
k := strings.TrimRight(arr[0], ":")
|
||||
v := strings.TrimSpace(arr[1])
|
||||
if k == "Content-Type" {
|
||||
requestContentType = v
|
||||
}
|
||||
t.Logf("Request header: %s => %s", k, v)
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
if requestContentType == "" {
|
||||
t.Logf("Content-Type header not provided")
|
||||
}
|
||||
}
|
||||
|
||||
// AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
|
||||
func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response {
|
||||
resp, err := tc.Client.Do(req)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("failed to call server %s", err)
|
||||
}
|
||||
|
||||
if expectedStatusCode != resp.StatusCode {
|
||||
tc.t.Errorf("requesting \"%s\" expected status code: %d but got %d", req.URL.RequestURI(), expectedStatusCode, resp.StatusCode)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// AssertResponse request a URI and assert the status code and the body contains a string
|
||||
func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
resp := tc.AssertResponseCode(req, expectedStatusCode)
|
||||
|
||||
defer resp.Body.Close()
|
||||
bytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to read the response body %s", err)
|
||||
}
|
||||
|
||||
body := string(bytes)
|
||||
|
||||
if body != expectedBody {
|
||||
tc.t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", req.RequestURI, expectedBody, body)
|
||||
}
|
||||
|
||||
return resp, body
|
||||
}
|
||||
|
||||
// Verb specific test functions
|
||||
|
||||
// AssertGetResponse GET a URI and expect a statusCode and body text
|
||||
func (tc *Tester) AssertGetResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("GET", requestURI, nil)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to create request %s", err)
|
||||
}
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertDeleteResponse request a URI and expect a statusCode and body text
|
||||
func (tc *Tester) AssertDeleteResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("DELETE", requestURI, nil)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to create request %s", err)
|
||||
}
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPostResponseBody POST to a URI and assert the response code and body
|
||||
func (tc *Tester) AssertPostResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("POST", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPutResponseBody PUT to a URI and assert the response code and body
|
||||
func (tc *Tester) AssertPutResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("PUT", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPatchResponseBody PATCH to a URI and assert the response code and body
|
||||
func (tc *Tester) AssertPatchResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("PATCH", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package caddytest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aryann/difflib"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
)
|
||||
|
||||
// AssertLoadError will load a config and expect an error
|
||||
func AssertLoadError(t *testing.T, rawConfig string, configType string, expectedError string) {
|
||||
tc, err := NewTester()
|
||||
require.NoError(t, err)
|
||||
err = tc.LaunchCaddy()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = tc.LoadConfig(rawConfig, configType)
|
||||
if !strings.Contains(err.Error(), expectedError) {
|
||||
t.Errorf("expected error \"%s\" but got \"%s\"", expectedError, err.Error())
|
||||
}
|
||||
_ = tc.CleanupCaddy()
|
||||
}
|
||||
|
||||
// CompareAdapt adapts a config and then compares it against an expected result
|
||||
func CompareAdapt(t testing.TB, filename, rawConfig string, adapterName string, expectedResponse string) bool {
|
||||
cfgAdapter := caddyconfig.GetAdapter(adapterName)
|
||||
if cfgAdapter == nil {
|
||||
t.Logf("unrecognized config adapter '%s'", adapterName)
|
||||
return false
|
||||
}
|
||||
|
||||
options := make(map[string]any)
|
||||
|
||||
result, warnings, err := cfgAdapter.Adapt([]byte(rawConfig), options)
|
||||
if err != nil {
|
||||
t.Logf("adapting config using %s adapter: %v", adapterName, err)
|
||||
return false
|
||||
}
|
||||
|
||||
// prettify results to keep tests human-manageable
|
||||
var prettyBuf bytes.Buffer
|
||||
err = json.Indent(&prettyBuf, result, "", "\t")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
result = prettyBuf.Bytes()
|
||||
|
||||
if len(warnings) > 0 {
|
||||
for _, w := range warnings {
|
||||
t.Logf("warning: %s:%d: %s: %s", filename, w.Line, w.Directive, w.Message)
|
||||
}
|
||||
}
|
||||
|
||||
diff := difflib.Diff(
|
||||
strings.Split(expectedResponse, "\n"),
|
||||
strings.Split(string(result), "\n"))
|
||||
|
||||
// scan for failure
|
||||
failed := false
|
||||
for _, d := range diff {
|
||||
if d.Delta != difflib.Common {
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if failed {
|
||||
for _, d := range diff {
|
||||
switch d.Delta {
|
||||
case difflib.Common:
|
||||
fmt.Printf(" %s\n", d.Payload)
|
||||
case difflib.LeftOnly:
|
||||
fmt.Printf(" - %s\n", d.Payload)
|
||||
case difflib.RightOnly:
|
||||
fmt.Printf(" + %s\n", d.Payload)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AssertAdapt adapts a config and then tests it against an expected result
|
||||
func AssertAdapt(t testing.TB, rawConfig string, adapterName string, expectedResponse string) {
|
||||
ok := CompareAdapt(t, "Caddyfile", rawConfig, adapterName, expectedResponse)
|
||||
if !ok {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Generic request functions
|
||||
|
||||
func applyHeaders(t testing.TB, req *http.Request, requestHeaders []string) {
|
||||
requestContentType := ""
|
||||
for _, requestHeader := range requestHeaders {
|
||||
arr := strings.SplitAfterN(requestHeader, ":", 2)
|
||||
k := strings.TrimRight(arr[0], ":")
|
||||
v := strings.TrimSpace(arr[1])
|
||||
if k == "Content-Type" {
|
||||
requestContentType = v
|
||||
}
|
||||
t.Logf("Request header: %s => %s", k, v)
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
if requestContentType == "" {
|
||||
t.Logf("Content-Type header not provided")
|
||||
}
|
||||
}
|
||||
+100
-3
@@ -1,20 +1,22 @@
|
||||
package caddytest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReplaceCertificatePaths(t *testing.T) {
|
||||
rawConfig := `a.caddy.localhost:9443 {
|
||||
rawConfig := `a.caddy.localhost:9443{
|
||||
tls /caddy.localhost.crt /caddy.localhost.key {
|
||||
}
|
||||
|
||||
redir / https://b.caddy.localhost:9443/version 301
|
||||
|
||||
|
||||
respond /version 200 {
|
||||
body "hello from a.caddy.localhost"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
r := prependCaddyFilePath(rawConfig)
|
||||
@@ -31,3 +33,98 @@ func TestReplaceCertificatePaths(t *testing.T) {
|
||||
t.Error("expected redirect uri to be unchanged")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadUnorderedJSON(t *testing.T) {
|
||||
harness := StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"logging": {
|
||||
"logs": {
|
||||
"default": {
|
||||
"level": "DEBUG",
|
||||
"writer": {
|
||||
"output": "stdout"
|
||||
}
|
||||
},
|
||||
"sStdOutLogs": {
|
||||
"level": "DEBUG",
|
||||
"writer": {
|
||||
"output": "stdout"
|
||||
},
|
||||
"include": [
|
||||
"http.*",
|
||||
"admin.*"
|
||||
]
|
||||
},
|
||||
"sFileLogs": {
|
||||
"level": "DEBUG",
|
||||
"writer": {
|
||||
"output": "stdout"
|
||||
},
|
||||
"include": [
|
||||
"http.*",
|
||||
"admin.*"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"admin": {
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
"certificate_authorities" : {
|
||||
"local" : {
|
||||
"install_trust": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"servers": {
|
||||
"s_server": {
|
||||
"listen": [
|
||||
":{$TESTING_CADDY_PORT_ONE}",
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "static_response",
|
||||
"body": "Hello"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost",
|
||||
"127.0.0.1"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"logs": {
|
||||
"default_logger_name": "sStdOutLogs",
|
||||
"logger_names": {
|
||||
"localhost": "sStdOutLogs",
|
||||
"127.0.0.1": "sFileLogs"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "json")
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), nil)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
harness.AssertResponseCode(req, 200)
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
"github.com/mholt/acmez"
|
||||
"github.com/mholt/acmez/acme"
|
||||
"github.com/mholt/acmez/v2"
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
smallstepacme "github.com/smallstep/certificates/acme"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -24,19 +24,13 @@ const acmeChallengePort = 9081
|
||||
// Test the basic functionality of Caddy's ACME server
|
||||
func TestACMEServerWithDefaults(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
local_certs
|
||||
}
|
||||
acme.localhost {
|
||||
@@ -44,10 +38,11 @@ func TestACMEServerWithDefaults(t *testing.T) {
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
logger := caddy.Log().Named("acmeserver")
|
||||
client := acmez.Client{
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Directory: fmt.Sprintf("https://acme.localhost:%d/acme/local/directory", harness.Tester().PortTwo()),
|
||||
HTTPClient: harness.Client(),
|
||||
Logger: logger,
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
@@ -77,7 +72,7 @@ func TestACMEServerWithDefaults(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
certs, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"localhost"})
|
||||
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
|
||||
if err != nil {
|
||||
t.Errorf("obtaining certificate: %v", err)
|
||||
return
|
||||
@@ -97,13 +92,13 @@ func TestACMEServerWithMismatchedChallenges(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := caddy.Log().Named("acmez")
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
local_certs
|
||||
}
|
||||
acme.localhost {
|
||||
@@ -115,8 +110,8 @@ func TestACMEServerWithMismatchedChallenges(t *testing.T) {
|
||||
|
||||
client := acmez.Client{
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Directory: fmt.Sprintf("https://acme.localhost:%d/acme/local/directory", harness.Tester().PortTwo()),
|
||||
HTTPClient: harness.Client(),
|
||||
Logger: logger,
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
@@ -146,7 +141,7 @@ func TestACMEServerWithMismatchedChallenges(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
certs, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"localhost"})
|
||||
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
|
||||
if len(certs) > 0 {
|
||||
t.Errorf("expected '0' certificates, but received '%d'", len(certs))
|
||||
}
|
||||
|
||||
@@ -5,50 +5,51 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
"github.com/mholt/acmez"
|
||||
"github.com/mholt/acmez/acme"
|
||||
"go.uber.org/zap"
|
||||
"github.com/mholt/acmez/v2"
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
)
|
||||
|
||||
func TestACMEServerDirectory(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
local_certs
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
pki {
|
||||
ca local {
|
||||
name "Caddy Local Authority"
|
||||
}
|
||||
}
|
||||
}
|
||||
acme.localhost:9443 {
|
||||
acme.localhost:{$TESTING_CADDY_PORT_TWO} {
|
||||
acme_server
|
||||
}
|
||||
`, "caddyfile")
|
||||
tester.AssertGetResponse(
|
||||
"https://acme.localhost:9443/acme/local/directory",
|
||||
harness.AssertGetResponse(
|
||||
fmt.Sprintf("https://acme.localhost:%d/acme/local/directory", harness.Tester().PortTwo()),
|
||||
200,
|
||||
`{"newNonce":"https://acme.localhost:9443/acme/local/new-nonce","newAccount":"https://acme.localhost:9443/acme/local/new-account","newOrder":"https://acme.localhost:9443/acme/local/new-order","revokeCert":"https://acme.localhost:9443/acme/local/revoke-cert","keyChange":"https://acme.localhost:9443/acme/local/key-change"}
|
||||
`)
|
||||
fmt.Sprintf(`{"newNonce":"https://acme.localhost:%[1]d/acme/local/new-nonce","newAccount":"https://acme.localhost:%[1]d/acme/local/new-account","newOrder":"https://acme.localhost:%[1]d/acme/local/new-order","revokeCert":"https://acme.localhost:%[1]d/acme/local/revoke-cert","keyChange":"https://acme.localhost:%[1]d/acme/local/key-change"}
|
||||
`, harness.Tester().PortTwo()))
|
||||
}
|
||||
|
||||
func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
local_certs
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
pki {
|
||||
ca local {
|
||||
name "Caddy Local Authority"
|
||||
@@ -66,16 +67,12 @@ func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
`, "caddyfile")
|
||||
|
||||
ctx := context.Background()
|
||||
logger, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
logger := caddy.Log().Named("acmez")
|
||||
|
||||
client := acmez.Client{
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Directory: fmt.Sprintf("https://acme.localhost:%d/acme/local/directory", harness.Tester().PortTwo()),
|
||||
HTTPClient: harness.Client(),
|
||||
Logger: logger,
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
@@ -105,12 +102,7 @@ func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
return
|
||||
}
|
||||
{
|
||||
certs, err := client.ObtainCertificate(
|
||||
ctx,
|
||||
account,
|
||||
certPrivateKey,
|
||||
[]string{"localhost"},
|
||||
)
|
||||
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
|
||||
if err != nil {
|
||||
t.Errorf("obtaining certificate for allowed domain: %v", err)
|
||||
return
|
||||
@@ -126,7 +118,7 @@ func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
{
|
||||
_, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"not-matching.localhost"})
|
||||
_, 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") {
|
||||
@@ -136,14 +128,14 @@ func TestACMEServerAllowPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestACMEServerDenyPolicy(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
local_certs
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
pki {
|
||||
ca local {
|
||||
name "Caddy Local Authority"
|
||||
@@ -160,16 +152,12 @@ func TestACMEServerDenyPolicy(t *testing.T) {
|
||||
`, "caddyfile")
|
||||
|
||||
ctx := context.Background()
|
||||
logger, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
logger := caddy.Log().Named("acmez")
|
||||
|
||||
client := acmez.Client{
|
||||
Client: &acme.Client{
|
||||
Directory: "https://acme.localhost:9443/acme/local/directory",
|
||||
HTTPClient: tester.Client,
|
||||
Directory: fmt.Sprintf("https://acme.localhost:%d/acme/local/directory", harness.Tester().PortTwo()),
|
||||
HTTPClient: harness.Client(),
|
||||
Logger: logger,
|
||||
},
|
||||
ChallengeSolvers: map[string]acmez.Solver{
|
||||
@@ -199,10 +187,10 @@ func TestACMEServerDenyPolicy(t *testing.T) {
|
||||
return
|
||||
}
|
||||
{
|
||||
_, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"deny.localhost"})
|
||||
_, 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -8,69 +9,69 @@ import (
|
||||
)
|
||||
|
||||
func TestAutoHTTPtoHTTPSRedirectsImplicitPort(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
skip_install_trust
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
}
|
||||
localhost
|
||||
respond "Yahaha! You found me!"
|
||||
`, "caddyfile")
|
||||
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost/", http.StatusPermanentRedirect)
|
||||
harness.AssertRedirect(fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), "https://localhost/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPtoHTTPSRedirectsExplicitPortSameAsHTTPSPort(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
}
|
||||
localhost:9443
|
||||
localhost:{$TESTING_CADDY_PORT_TWO}
|
||||
respond "Yahaha! You found me!"
|
||||
`, "caddyfile")
|
||||
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost/", http.StatusPermanentRedirect)
|
||||
harness.AssertRedirect(fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), "https://localhost/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPtoHTTPSRedirectsExplicitPortDifferentFromHTTPSPort(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
}
|
||||
localhost:1234
|
||||
respond "Yahaha! You found me!"
|
||||
`, "caddyfile")
|
||||
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost:1234/", http.StatusPermanentRedirect)
|
||||
harness.AssertRedirect(fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), "https://localhost:1234/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"servers": {
|
||||
"ingress_server": {
|
||||
"listen": [
|
||||
":9080",
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_ONE}",
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -94,52 +95,52 @@ func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
`, "json")
|
||||
tester.AssertRedirect("http://localhost:9080/", "https://localhost/", http.StatusPermanentRedirect)
|
||||
harness.AssertRedirect(fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), "https://localhost/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAll(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
local_certs
|
||||
}
|
||||
http://:9080 {
|
||||
http://:{$TESTING_CADDY_PORT_ONE} {
|
||||
respond "Foo"
|
||||
}
|
||||
http://baz.localhost:9080 {
|
||||
http://baz.localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
respond "Baz"
|
||||
}
|
||||
bar.localhost {
|
||||
respond "Bar"
|
||||
}
|
||||
`, "caddyfile")
|
||||
tester.AssertRedirect("http://bar.localhost:9080/", "https://bar.localhost/", http.StatusPermanentRedirect)
|
||||
tester.AssertGetResponse("http://foo.localhost:9080/", 200, "Foo")
|
||||
tester.AssertGetResponse("http://baz.localhost:9080/", 200, "Baz")
|
||||
harness.AssertRedirect(fmt.Sprintf("http://bar.localhost:%d/", harness.Tester().PortOne()), "https://bar.localhost/", http.StatusPermanentRedirect)
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://foo.localhost:%d/", harness.Tester().PortOne()), 200, "Foo")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://baz.localhost:%d/", harness.Tester().PortOne()), 200, "Baz")
|
||||
}
|
||||
|
||||
func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAllWithNoExplicitHTTPSite(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
local_certs
|
||||
}
|
||||
http://:9080 {
|
||||
http://:{$TESTING_CADDY_PORT_ONE} {
|
||||
respond "Foo"
|
||||
}
|
||||
bar.localhost {
|
||||
respond "Bar"
|
||||
}
|
||||
`, "caddyfile")
|
||||
tester.AssertRedirect("http://bar.localhost:9080/", "https://bar.localhost/", http.StatusPermanentRedirect)
|
||||
tester.AssertGetResponse("http://foo.localhost:9080/", 200, "Foo")
|
||||
tester.AssertGetResponse("http://baz.localhost:9080/", 200, "Foo")
|
||||
harness.AssertRedirect(fmt.Sprintf("http://bar.localhost:%d/", harness.Tester().PortOne()), "https://bar.localhost/", http.StatusPermanentRedirect)
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://foo.localhost:%d/", harness.Tester().PortOne()), 200, "Foo")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://baz.localhost:%d/", harness.Tester().PortOne()), 200, "Foo")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
pki {
|
||||
ca internal {
|
||||
name "Internal"
|
||||
root_cn "Internal Root Cert"
|
||||
intermediate_cn "Internal Intermediate Cert"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acme.example.com {
|
||||
acme_server {
|
||||
ca internal
|
||||
sign_with_root
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"acme.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"ca": "internal",
|
||||
"handler": "acme_server",
|
||||
"sign_with_root": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"pki": {
|
||||
"certificate_authorities": {
|
||||
"internal": {
|
||||
"name": "Internal",
|
||||
"root_common_name": "Internal Root Cert",
|
||||
"intermediate_common_name": "Internal Intermediate Cert"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
(snippet) {
|
||||
@g `{http.error.status_code} == 404`
|
||||
}
|
||||
|
||||
example.com
|
||||
|
||||
@a expression {http.error.status_code} == 400
|
||||
@@ -14,6 +18,12 @@ abort @d
|
||||
|
||||
@e expression `{http.error.status_code} == 404`
|
||||
abort @e
|
||||
|
||||
@f `{http.error.status_code} == 404`
|
||||
abort @f
|
||||
|
||||
import snippet
|
||||
abort @g
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
@@ -84,7 +94,10 @@ abort @e
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"expression": "{http.error.status_code} == 403"
|
||||
"expression": {
|
||||
"expr": "{http.error.status_code} == 403",
|
||||
"name": "d"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -97,7 +110,42 @@ abort @e
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"expression": "{http.error.status_code} == 404"
|
||||
"expression": {
|
||||
"expr": "{http.error.status_code} == 404",
|
||||
"name": "e"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"abort": true,
|
||||
"handler": "static_response"
|
||||
}
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"expression": {
|
||||
"expr": "{http.error.status_code} == 404",
|
||||
"name": "f"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"abort": true,
|
||||
"handler": "static_response"
|
||||
}
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"expression": {
|
||||
"expr": "{http.error.status_code} == 404",
|
||||
"name": "g"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
:8080 {
|
||||
root * ./
|
||||
file_server {
|
||||
etag_file_extensions .b3sum .sha256
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8080"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "vars",
|
||||
"root": "./"
|
||||
},
|
||||
{
|
||||
"etag_file_extensions": [
|
||||
".b3sum",
|
||||
".sha256"
|
||||
],
|
||||
"handler": "file_server",
|
||||
"hide": [
|
||||
"./Caddyfile"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,14 @@
|
||||
"issuers": [
|
||||
{
|
||||
"ca": "https://example.com",
|
||||
"challenges": {
|
||||
"http": {
|
||||
"alternate_port": 8080
|
||||
},
|
||||
"tls-alpn": {
|
||||
"alternate_port": 8443
|
||||
}
|
||||
},
|
||||
"email": "test@example.com",
|
||||
"external_account": {
|
||||
"key_id": "4K2scIVbBpNd-78scadB2g",
|
||||
|
||||
@@ -40,12 +40,6 @@ example.com
|
||||
"preferred_chains": {
|
||||
"smallest": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"module": "zerossl",
|
||||
"preferred_chains": {
|
||||
"smallest": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -72,8 +72,12 @@ b.example.com {
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"a.example.com": "log0",
|
||||
"b.example.com": "log1"
|
||||
"a.example.com": [
|
||||
"log0"
|
||||
],
|
||||
"b.example.com": [
|
||||
"log1"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
(snippet) {
|
||||
header {
|
||||
{block}
|
||||
}
|
||||
}
|
||||
|
||||
example.com {
|
||||
import snippet {
|
||||
foo bar
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Foo": [
|
||||
"bar"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
(snippet) {
|
||||
{block}
|
||||
}
|
||||
|
||||
example.com {
|
||||
import snippet {
|
||||
header foo bar
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Foo": [
|
||||
"bar"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
(snippet) {
|
||||
header {
|
||||
{blocks.foo}
|
||||
}
|
||||
header {
|
||||
{blocks.bar}
|
||||
}
|
||||
}
|
||||
|
||||
example.com {
|
||||
import snippet {
|
||||
foo {
|
||||
foo a
|
||||
}
|
||||
bar {
|
||||
bar b
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Foo": [
|
||||
"a"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Bar": [
|
||||
"b"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
(snippet) {
|
||||
header {
|
||||
{blocks.bar}
|
||||
}
|
||||
import sub_snippet {
|
||||
bar {
|
||||
{blocks.foo}
|
||||
}
|
||||
}
|
||||
}
|
||||
(sub_snippet) {
|
||||
header {
|
||||
{blocks.bar}
|
||||
}
|
||||
}
|
||||
example.com {
|
||||
import snippet {
|
||||
foo {
|
||||
foo a
|
||||
}
|
||||
bar {
|
||||
bar b
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Bar": [
|
||||
"b"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"handler": "headers",
|
||||
"response": {
|
||||
"set": {
|
||||
"Foo": [
|
||||
"a"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
localhost
|
||||
|
||||
respond "To intercept"
|
||||
|
||||
intercept {
|
||||
@500 status 500
|
||||
replace_status @500 400
|
||||
|
||||
@all status 2xx 3xx 4xx 5xx
|
||||
replace_status @all {http.error.status_code}
|
||||
|
||||
replace_status {http.error.status_code}
|
||||
|
||||
@accel header X-Accel-Redirect *
|
||||
handle_response @accel {
|
||||
respond "Header X-Accel-Redirect!"
|
||||
}
|
||||
|
||||
@another {
|
||||
header X-Another *
|
||||
}
|
||||
handle_response @another {
|
||||
respond "Header X-Another!"
|
||||
}
|
||||
|
||||
@401 status 401
|
||||
handle_response @401 {
|
||||
respond "Status 401!"
|
||||
}
|
||||
|
||||
handle_response {
|
||||
respond "Any! This should be last in the JSON!"
|
||||
}
|
||||
|
||||
@403 {
|
||||
status 403
|
||||
}
|
||||
handle_response @403 {
|
||||
respond "Status 403!"
|
||||
}
|
||||
|
||||
@multi {
|
||||
status 401 403
|
||||
status 404
|
||||
header Foo *
|
||||
header Bar *
|
||||
}
|
||||
handle_response @multi {
|
||||
respond "Headers Foo, Bar AND statuses 401, 403 and 404!"
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handle_response": [
|
||||
{
|
||||
"match": {
|
||||
"status_code": [
|
||||
500
|
||||
]
|
||||
},
|
||||
"status_code": 400
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"status_code": [
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
]
|
||||
},
|
||||
"status_code": "{http.error.status_code}"
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"headers": {
|
||||
"X-Accel-Redirect": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Header X-Accel-Redirect!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"headers": {
|
||||
"X-Another": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Header X-Another!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"status_code": [
|
||||
401
|
||||
]
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Status 401!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"status_code": [
|
||||
403
|
||||
]
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Status 403!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"headers": {
|
||||
"Bar": [
|
||||
"*"
|
||||
],
|
||||
"Foo": [
|
||||
"*"
|
||||
]
|
||||
},
|
||||
"status_code": [
|
||||
401,
|
||||
403,
|
||||
404
|
||||
]
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Headers Foo, Bar AND statuses 401, 403 and 404!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"status_code": "{http.error.status_code}"
|
||||
},
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Any! This should be last in the JSON!",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"handler": "intercept"
|
||||
},
|
||||
{
|
||||
"body": "To intercept",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,9 @@ http://localhost:2020 {
|
||||
},
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"localhost": ""
|
||||
"localhost": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"skip_unmapped_hosts": true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
localhost {
|
||||
log {
|
||||
output file ./caddy.access.log
|
||||
}
|
||||
log health_check_log {
|
||||
output file ./caddy.access.health.log
|
||||
no_hostname
|
||||
}
|
||||
log general_log {
|
||||
output file ./caddy.access.general.log
|
||||
no_hostname
|
||||
}
|
||||
@healthCheck `header_regexp('User-Agent', '^some-regexp$') || path('/healthz*')`
|
||||
handle @healthCheck {
|
||||
log_name health_check_log general_log
|
||||
respond "Healthy"
|
||||
}
|
||||
|
||||
handle {
|
||||
respond "Hello World"
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"logging": {
|
||||
"logs": {
|
||||
"default": {
|
||||
"exclude": [
|
||||
"http.log.access.general_log",
|
||||
"http.log.access.health_check_log",
|
||||
"http.log.access.log0"
|
||||
]
|
||||
},
|
||||
"general_log": {
|
||||
"writer": {
|
||||
"filename": "./caddy.access.general.log",
|
||||
"output": "file"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.general_log"
|
||||
]
|
||||
},
|
||||
"health_check_log": {
|
||||
"writer": {
|
||||
"filename": "./caddy.access.health.log",
|
||||
"output": "file"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.health_check_log"
|
||||
]
|
||||
},
|
||||
"log0": {
|
||||
"writer": {
|
||||
"filename": "./caddy.access.log",
|
||||
"output": "file"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.log0"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"group": "group2",
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"access_logger_names": [
|
||||
"health_check_log",
|
||||
"general_log"
|
||||
],
|
||||
"handler": "vars"
|
||||
},
|
||||
{
|
||||
"body": "Healthy",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"match": [
|
||||
{
|
||||
"expression": {
|
||||
"expr": "header_regexp('User-Agent', '^some-regexp$') || path('/healthz*')",
|
||||
"name": "healthCheck"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "group2",
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"body": "Hello World",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"localhost": [
|
||||
"log0"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
(log-both) {
|
||||
log {args[0]}-json {
|
||||
hostnames {args[0]}
|
||||
output file /var/log/{args[0]}.log
|
||||
format json
|
||||
}
|
||||
log {args[0]}-console {
|
||||
hostnames {args[0]}
|
||||
output file /var/log/{args[0]}.json
|
||||
format console
|
||||
}
|
||||
}
|
||||
|
||||
*.example.com {
|
||||
# Subdomains log to multiple files at once, with
|
||||
# different output files and formats.
|
||||
import log-both foo.example.com
|
||||
import log-both bar.example.com
|
||||
}
|
||||
----------
|
||||
{
|
||||
"logging": {
|
||||
"logs": {
|
||||
"bar.example.com-console": {
|
||||
"writer": {
|
||||
"filename": "/var/log/bar.example.com.json",
|
||||
"output": "file"
|
||||
},
|
||||
"encoder": {
|
||||
"format": "console"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.bar.example.com-console"
|
||||
]
|
||||
},
|
||||
"bar.example.com-json": {
|
||||
"writer": {
|
||||
"filename": "/var/log/bar.example.com.log",
|
||||
"output": "file"
|
||||
},
|
||||
"encoder": {
|
||||
"format": "json"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.bar.example.com-json"
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"exclude": [
|
||||
"http.log.access.bar.example.com-console",
|
||||
"http.log.access.bar.example.com-json",
|
||||
"http.log.access.foo.example.com-console",
|
||||
"http.log.access.foo.example.com-json"
|
||||
]
|
||||
},
|
||||
"foo.example.com-console": {
|
||||
"writer": {
|
||||
"filename": "/var/log/foo.example.com.json",
|
||||
"output": "file"
|
||||
},
|
||||
"encoder": {
|
||||
"format": "console"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.foo.example.com-console"
|
||||
]
|
||||
},
|
||||
"foo.example.com-json": {
|
||||
"writer": {
|
||||
"filename": "/var/log/foo.example.com.log",
|
||||
"output": "file"
|
||||
},
|
||||
"encoder": {
|
||||
"format": "json"
|
||||
},
|
||||
"include": [
|
||||
"http.log.access.foo.example.com-json"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":443"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"*.example.com"
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"bar.example.com": [
|
||||
"bar.example.com-json",
|
||||
"bar.example.com-console"
|
||||
],
|
||||
"foo.example.com": [
|
||||
"foo.example.com-json",
|
||||
"foo.example.com-console"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,15 @@ example.com:8443 {
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"bar.example.com": "log0",
|
||||
"baz.example.com": "log1",
|
||||
"foo.example.com": "log0"
|
||||
"bar.example.com": [
|
||||
"log0"
|
||||
],
|
||||
"baz.example.com": [
|
||||
"log1"
|
||||
],
|
||||
"foo.example.com": [
|
||||
"log0"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -99,7 +105,9 @@ example.com:8443 {
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"example.com": "log2"
|
||||
"example.com": [
|
||||
"log2"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,9 @@ http://localhost:8881 {
|
||||
},
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"localhost": "foo"
|
||||
"localhost": [
|
||||
"foo"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -81,7 +81,9 @@ http://localhost:8881 {
|
||||
},
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"localhost": "foo"
|
||||
"localhost": [
|
||||
"foo"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,9 @@ example.com {
|
||||
],
|
||||
"logs": {
|
||||
"logger_names": {
|
||||
"one.example.com": ""
|
||||
"one.example.com": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"skip_hosts": [
|
||||
"example.com",
|
||||
|
||||
@@ -46,6 +46,18 @@
|
||||
|
||||
@matcher12 client_ip private_ranges
|
||||
respond @matcher12 "client_ip matcher with private ranges"
|
||||
|
||||
@matcher13 {
|
||||
remote_ip 1.1.1.1
|
||||
remote_ip 2.2.2.2
|
||||
}
|
||||
respond @matcher13 "remote_ip merged"
|
||||
|
||||
@matcher14 {
|
||||
client_ip 1.1.1.1
|
||||
client_ip 2.2.2.2
|
||||
}
|
||||
respond @matcher14 "client_ip merged"
|
||||
}
|
||||
----------
|
||||
{
|
||||
@@ -146,6 +158,7 @@
|
||||
{
|
||||
"vars_regexp": {
|
||||
"{http.request.uri}": {
|
||||
"name": "matcher6",
|
||||
"pattern": "\\.([a-f0-9]{6})\\.(css|js)$"
|
||||
}
|
||||
}
|
||||
@@ -161,7 +174,10 @@
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"expression": "path('/foo*') \u0026\u0026 method('GET')"
|
||||
"expression": {
|
||||
"expr": "path('/foo*') \u0026\u0026 method('GET')",
|
||||
"name": "matcher7"
|
||||
}
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
@@ -275,6 +291,42 @@
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"remote_ip": {
|
||||
"ranges": [
|
||||
"1.1.1.1",
|
||||
"2.2.2.2"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"body": "remote_ip merged",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"client_ip": {
|
||||
"ranges": [
|
||||
"1.1.1.1",
|
||||
"2.2.2.2"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"body": "client_ip merged",
|
||||
"handler": "static_response"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
:8884 {
|
||||
reverse_proxy {
|
||||
dynamic srv {
|
||||
name foo
|
||||
refresh 5m
|
||||
grace_period 5s
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"dynamic_upstreams": {
|
||||
"grace_period": 5000000000,
|
||||
"name": "foo",
|
||||
"refresh": 300000000000,
|
||||
"source": "srv"
|
||||
},
|
||||
"handler": "reverse_proxy"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
:8884
|
||||
reverse_proxy 127.0.0.1:65535 {
|
||||
transport http {
|
||||
tls_trust_pool file {
|
||||
pem_file ../caddy.ca.cer
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"transport": {
|
||||
"protocol": "http",
|
||||
"tls": {
|
||||
"ca": {
|
||||
"pem_files": [
|
||||
"../caddy.ca.cer"
|
||||
],
|
||||
"provider": "file"
|
||||
}
|
||||
}
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:65535"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
:8884
|
||||
reverse_proxy 127.0.0.1:65535 {
|
||||
transport http {
|
||||
tls_trust_pool 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==
|
||||
}
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"transport": {
|
||||
"protocol": "http",
|
||||
"tls": {
|
||||
"ca": {
|
||||
"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=="
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:65535"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -36,6 +36,7 @@ respond @match "{re.1}"
|
||||
"match": [
|
||||
{
|
||||
"path_regexp": {
|
||||
"name": "match",
|
||||
"pattern": "^/foo(.*)$"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,9 @@ c.example.com {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"email": "abc@example.com",
|
||||
"module": "zerossl"
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -131,8 +131,9 @@ abc.de {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"email": "my.email@example.com",
|
||||
"module": "zerossl"
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -86,8 +86,9 @@ http://localhost:8081 {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"email": "abc@example.com",
|
||||
"module": "zerossl"
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+2
-1
@@ -54,8 +54,9 @@ example.com {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"ca": "https://acme.zerossl.com/v2/DV90",
|
||||
"email": "foo@bar",
|
||||
"module": "zerossl"
|
||||
"module": "acme"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -58,14 +58,6 @@ tls {
|
||||
}
|
||||
},
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"ttl": 310000000000
|
||||
}
|
||||
},
|
||||
"module": "zerossl"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ tls {
|
||||
issuer acme {
|
||||
dns_ttl 5m10s
|
||||
}
|
||||
issuer zerossl {
|
||||
issuer zerossl api_key {
|
||||
dns_ttl 10m20s
|
||||
}
|
||||
}
|
||||
@@ -65,10 +65,9 @@ tls {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"ttl": 620000000000
|
||||
}
|
||||
"api_key": "api_key",
|
||||
"cname_validation": {
|
||||
"ttl": 620000000000
|
||||
},
|
||||
"module": "zerossl"
|
||||
}
|
||||
|
||||
+5
-6
@@ -6,7 +6,7 @@ tls {
|
||||
propagation_delay 5m10s
|
||||
propagation_timeout 10m20s
|
||||
}
|
||||
issuer zerossl {
|
||||
issuer zerossl api_key {
|
||||
propagation_delay 5m30s
|
||||
propagation_timeout -1
|
||||
}
|
||||
@@ -68,11 +68,10 @@ tls {
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"propagation_delay": 330000000000,
|
||||
"propagation_timeout": -1
|
||||
}
|
||||
"api_key": "api_key",
|
||||
"cname_validation": {
|
||||
"propagation_delay": 330000000000,
|
||||
"propagation_timeout": -1
|
||||
},
|
||||
"module": "zerossl"
|
||||
}
|
||||
|
||||
@@ -60,15 +60,6 @@ tls {
|
||||
}
|
||||
},
|
||||
"module": "acme"
|
||||
},
|
||||
{
|
||||
"challenges": {
|
||||
"dns": {
|
||||
"propagation_delay": 310000000000,
|
||||
"propagation_timeout": 620000000000
|
||||
}
|
||||
},
|
||||
"module": "zerossl"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
@@ -10,62 +11,63 @@ import (
|
||||
|
||||
func TestRespond(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
respond /version 200 {
|
||||
body "hello from localhost"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne()), 200, "hello from localhost")
|
||||
}
|
||||
|
||||
func TestRedirect(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
|
||||
redir / http://localhost:9080/hello 301
|
||||
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
|
||||
redir / http://localhost:{$TESTING_CADDY_PORT_ONE}/hello 301
|
||||
|
||||
respond /hello 200 {
|
||||
body "hello from localhost"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
// act and assert
|
||||
tester.AssertRedirect("http://localhost:9080/", "http://localhost:9080/hello", 301)
|
||||
harness.AssertRedirect(target, target+"hello", 301)
|
||||
|
||||
// follow redirect
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "hello from localhost")
|
||||
harness.AssertGetResponse(target, 200, "hello from localhost")
|
||||
}
|
||||
|
||||
func TestDuplicateHosts(t *testing.T) {
|
||||
// act and assert
|
||||
caddytest.AssertLoadError(t,
|
||||
`
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
}
|
||||
`,
|
||||
"caddyfile",
|
||||
@@ -80,18 +82,18 @@ func TestReadCookie(t *testing.T) {
|
||||
}
|
||||
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie})
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.Client().Jar.SetCookies(localhost, []*http.Cookie{&cookie})
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
templates {
|
||||
root testdata
|
||||
}
|
||||
@@ -102,21 +104,22 @@ func TestReadCookie(t *testing.T) {
|
||||
`, "caddyfile")
|
||||
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/cookie.html", 200, "<h2>Cookie.ClientName caddytest</h2>")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"cookie.html", 200, "<h2>Cookie.ClientName caddytest</h2>")
|
||||
}
|
||||
|
||||
func TestReplIndex(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
templates {
|
||||
root testdata
|
||||
}
|
||||
@@ -128,7 +131,8 @@ func TestReplIndex(t *testing.T) {
|
||||
`, "caddyfile")
|
||||
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target, 200, "")
|
||||
}
|
||||
|
||||
func TestInvalidPrefix(t *testing.T) {
|
||||
@@ -481,40 +485,42 @@ func TestValidPrefix(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUriReplace(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri replace "\}" %7D
|
||||
uri replace "\{" %7B
|
||||
|
||||
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?test={%20content%20}", 200, "test=%7B%20content%20%7D")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?test={%20content%20}", 200, "test=%7B%20content%20%7D")
|
||||
}
|
||||
|
||||
func TestUriOps(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query +foo bar
|
||||
uri query -baz
|
||||
uri query taz test
|
||||
uri query key=value example
|
||||
uri query changethis>changed
|
||||
|
||||
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar0&baz=buz&taz=nottest&changethis=val", 200, "changed=val&foo=bar0&foo=bar&key%3Dvalue=example&taz=test")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar0&baz=buz&taz=nottest&changethis=val", 200, "changed=val&foo=bar0&foo=bar&key%3Dvalue=example&taz=test")
|
||||
}
|
||||
|
||||
// Tests the `http.request.local.port` placeholder.
|
||||
@@ -523,204 +529,215 @@ func TestUriOps(t *testing.T) {
|
||||
// refer to 127.0.0.1 or ::1.
|
||||
// TODO: Test each http version separately (especially http/3)
|
||||
func TestHttpRequestLocalPortPlaceholder(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
respond "{http.request.local.port}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "9080")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target, 200, fmt.Sprintf("%d", harness.Tester().PortOne()))
|
||||
}
|
||||
|
||||
func TestSetThenAddQueryParams(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo bar
|
||||
uri query +foo baz
|
||||
|
||||
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint", 200, "foo=bar&foo=baz")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint", 200, "foo=bar&foo=baz")
|
||||
}
|
||||
|
||||
func TestSetThenDeleteParams(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query bar foo{query.foo}
|
||||
uri query -foo
|
||||
|
||||
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar", 200, "bar=foobar")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar", 200, "bar=foobar")
|
||||
}
|
||||
|
||||
func TestRenameAndOtherOps(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo>bar
|
||||
uri query bar taz
|
||||
uri query +bar baz
|
||||
|
||||
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar", 200, "bar=taz&bar=baz")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar", 200, "bar=taz&bar=baz")
|
||||
}
|
||||
|
||||
func TestReplaceOps(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query foo bar baz
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo bar baz
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar", 200, "foo=baz")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar", 200, "foo=baz")
|
||||
}
|
||||
|
||||
func TestReplaceWithReplacementPlaceholder(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query foo bar {query.placeholder}
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo bar {query.placeholder}
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
|
||||
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
|
||||
}
|
||||
|
||||
func TestReplaceWithKeyPlaceholder(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query {query.placeholder} bar baz
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query {query.placeholder} bar baz
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=foo&foo=bar", 200, "foo=baz&placeholder=foo")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?placeholder=foo&foo=bar", 200, "foo=baz&placeholder=foo")
|
||||
}
|
||||
|
||||
func TestPartialReplacement(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query foo ar az
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo ar az
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar", 200, "foo=baz")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar", 200, "foo=baz")
|
||||
}
|
||||
|
||||
func TestNonExistingSearch(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query foo var baz
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query foo var baz
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar", 200, "foo=bar")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar", 200, "foo=bar")
|
||||
}
|
||||
|
||||
func TestReplaceAllOps(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
uri query * bar baz
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query * bar baz
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar&baz=bar", 200, "baz=baz&foo=baz")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar&baz=bar", 200, "baz=baz&foo=baz")
|
||||
}
|
||||
|
||||
func TestUriOpsBlock(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
|
||||
tester.InitServer(`
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
:9080
|
||||
:{$TESTING_CADDY_PORT_ONE}
|
||||
uri query {
|
||||
+foo bar
|
||||
-baz
|
||||
taz test
|
||||
}
|
||||
}
|
||||
respond "{query}"`, "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar0&baz=buz&taz=nottest", 200, "foo=bar0&foo=bar&taz=test")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"endpoint?foo=bar0&baz=buz&taz=nottest", 200, "foo=bar0&foo=bar&taz=test")
|
||||
}
|
||||
|
||||
func TestHandleErrorSimpleCodes(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
root * /srv
|
||||
error /private* "Unauthorized" 410
|
||||
error /hidden* "Not found" 404
|
||||
|
||||
|
||||
handle_errors 404 410 {
|
||||
respond "404 or 410 error"
|
||||
}
|
||||
}`, "caddyfile")
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/private", 410, "404 or 410 error")
|
||||
tester.AssertGetResponse("http://localhost:9080/hidden", 404, "404 or 410 error")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"private", 410, "404 or 410 error")
|
||||
harness.AssertGetResponse(target+"hidden", 404, "404 or 410 error")
|
||||
}
|
||||
|
||||
func TestHandleErrorRange(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
root * /srv
|
||||
error /private* "Unauthorized" 410
|
||||
error /hidden* "Not found" 404
|
||||
@@ -730,17 +747,18 @@ func TestHandleErrorRange(t *testing.T) {
|
||||
}
|
||||
}`, "caddyfile")
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/private", 410, "Error in the [400 .. 499] range")
|
||||
tester.AssertGetResponse("http://localhost:9080/hidden", 404, "Error in the [400 .. 499] range")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"private", 410, "Error in the [400 .. 499] range")
|
||||
harness.AssertGetResponse(target+"hidden", 404, "Error in the [400 .. 499] range")
|
||||
}
|
||||
|
||||
func TestHandleErrorSort(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
root * /srv
|
||||
error /private* "Unauthorized" 410
|
||||
error /hidden* "Not found" 404
|
||||
@@ -754,17 +772,18 @@ func TestHandleErrorSort(t *testing.T) {
|
||||
}
|
||||
}`, "caddyfile")
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/internalerr", 500, "Fallback route: code outside the [400..499] range")
|
||||
tester.AssertGetResponse("http://localhost:9080/hidden", 404, "Error in the [400 .. 499] range")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"internalerr", 500, "Fallback route: code outside the [400..499] range")
|
||||
harness.AssertGetResponse(target+"hidden", 404, "Error in the [400 .. 499] range")
|
||||
}
|
||||
|
||||
func TestHandleErrorRangeAndCodes(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
}
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
root * /srv
|
||||
error /private* "Unauthorized" 410
|
||||
error /threehundred* "Moved Permanently" 301
|
||||
@@ -778,9 +797,10 @@ func TestHandleErrorRangeAndCodes(t *testing.T) {
|
||||
}
|
||||
}`, "caddyfile")
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/internalerr", 500, "Error code is equal to 500 or in the [300..399] range")
|
||||
tester.AssertGetResponse("http://localhost:9080/threehundred", 301, "Error code is equal to 500 or in the [300..399] range")
|
||||
tester.AssertGetResponse("http://localhost:9080/private", 410, "Error in the [400 .. 499] range")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target+"internalerr", 500, "Error code is equal to 500 or in the [300..399] range")
|
||||
harness.AssertGetResponse(target+"threehundred", 301, "Error code is equal to 500 or in the [300..399] range")
|
||||
harness.AssertGetResponse(target+"private", 410, "Error in the [400 .. 499] range")
|
||||
}
|
||||
|
||||
func TestInvalidSiteAddressesAsDirectives(t *testing.T) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -8,24 +10,51 @@ import (
|
||||
)
|
||||
|
||||
func TestBrowse(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
http://localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
file_server browse
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), nil)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
tester.AssertResponseCode(req, 200)
|
||||
harness.AssertResponseCode(req, 200)
|
||||
}
|
||||
|
||||
func TestRespondWithJSON(t *testing.T) {
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
localhost {
|
||||
respond {http.request.body}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
res, _ := harness.AssertPostResponseBody(fmt.Sprintf("https://localhost:%d/", harness.Tester().PortTwo()),
|
||||
nil,
|
||||
bytes.NewBufferString(`{
|
||||
"greeting": "Hello, world!"
|
||||
}`), 200, `{
|
||||
"greeting": "Hello, world!"
|
||||
}`)
|
||||
if res.Header.Get("Content-Type") != "application/json" {
|
||||
t.Errorf("expected Content-Type to be application/json, but was %s", res.Header.Get("Content-Type"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
)
|
||||
|
||||
func TestIntercept(t *testing.T) {
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
skip_install_trust
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
respond /intercept "I'm a teapot" 408
|
||||
respond /no-intercept "I'm not a teapot"
|
||||
|
||||
intercept {
|
||||
@teapot status 408
|
||||
handle_response @teapot {
|
||||
respond /intercept "I'm a combined coffee/tea pot that is temporarily out of coffee" 503
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/intercept", harness.Tester().PortOne()), 503, "I'm a combined coffee/tea pot that is temporarily out of coffee")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/no-intercept", harness.Tester().PortOne()), 200, "I'm not a teapot")
|
||||
}
|
||||
@@ -7,21 +7,21 @@ import (
|
||||
)
|
||||
|
||||
func TestLeafCertLoaders(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
)
|
||||
|
||||
func setupListenerWrapperTest(t *testing.T, handlerFunc http.HandlerFunc) *caddytest.Tester {
|
||||
func setupListenerWrapperTest(t *testing.T, handlerFunc http.HandlerFunc) *caddytest.TestHarness {
|
||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to listen: %s", err)
|
||||
@@ -28,15 +28,15 @@ func setupListenerWrapperTest(t *testing.T, handlerFunc http.HandlerFunc) *caddy
|
||||
_ = srv.Close()
|
||||
_ = l.Close()
|
||||
})
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
local_certs
|
||||
servers :9443 {
|
||||
servers :{$TESTING_CADDY_PORT_TWO} {
|
||||
listener_wrappers {
|
||||
http_redirect
|
||||
tls
|
||||
@@ -47,7 +47,7 @@ func setupListenerWrapperTest(t *testing.T, handlerFunc http.HandlerFunc) *caddy
|
||||
reverse_proxy %s
|
||||
}
|
||||
`, l.Addr().String()), "caddyfile")
|
||||
return tester
|
||||
return harness
|
||||
}
|
||||
|
||||
func TestHTTPRedirectWrapperWithLargeUpload(t *testing.T) {
|
||||
@@ -56,7 +56,7 @@ func TestHTTPRedirectWrapperWithLargeUpload(t *testing.T) {
|
||||
body := make([]byte, uploadSize)
|
||||
rand.New(rand.NewSource(0)).Read(body)
|
||||
|
||||
tester := setupListenerWrapperTest(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||
harness := setupListenerWrapperTest(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||
buf := new(bytes.Buffer)
|
||||
_, err := buf.ReadFrom(request.Body)
|
||||
if err != nil {
|
||||
@@ -69,7 +69,7 @@ func TestHTTPRedirectWrapperWithLargeUpload(t *testing.T) {
|
||||
|
||||
writer.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
resp, err := tester.Client.Post("https://localhost:9443", "application/octet-stream", bytes.NewReader(body))
|
||||
resp, err := harness.Client().Post(fmt.Sprintf("https://localhost:%d", harness.Tester().PortTwo()), "application/octet-stream", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to post: %s", err)
|
||||
}
|
||||
@@ -80,14 +80,14 @@ func TestHTTPRedirectWrapperWithLargeUpload(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLargeHttpRequest(t *testing.T) {
|
||||
tester := setupListenerWrapperTest(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||
harness := setupListenerWrapperTest(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||
t.Fatal("not supposed to handle a request")
|
||||
})
|
||||
|
||||
// We never read the body in any way, set an extra long header instead.
|
||||
req, _ := http.NewRequest("POST", "http://localhost:9443", nil)
|
||||
req, _ := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d", harness.Tester().PortTwo()), nil)
|
||||
req.Header.Set("Long-Header", strings.Repeat("X", 1024*1024))
|
||||
_, err := tester.Client.Do(req)
|
||||
_, err := harness.Client().Do(req)
|
||||
if err == nil {
|
||||
t.Fatal("not supposed to succeed")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
@@ -9,16 +10,16 @@ import (
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
|
||||
map {http.request.method} {dest-1} {dest-2} {
|
||||
default unknown1 unknown2
|
||||
@@ -28,50 +29,50 @@ func TestMap(t *testing.T) {
|
||||
|
||||
respond /version 200 {
|
||||
body "hello from localhost {dest-1} {dest-2}"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost GET-called unknown2")
|
||||
tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne()), 200, "hello from localhost GET-called unknown2")
|
||||
harness.AssertPostResponseBody(fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne()), []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar")
|
||||
}
|
||||
|
||||
func TestMapRespondWithDefault(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
}
|
||||
|
||||
localhost:9080 {
|
||||
|
||||
|
||||
localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
|
||||
map {http.request.method} {dest-name} {
|
||||
default unknown
|
||||
GET get-called
|
||||
}
|
||||
|
||||
|
||||
respond /version 200 {
|
||||
body "hello from localhost {dest-name}"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
// act and assert
|
||||
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called")
|
||||
tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost unknown")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne()), 200, "hello from localhost get-called")
|
||||
harness.AssertPostResponseBody(fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne()), []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost unknown")
|
||||
}
|
||||
|
||||
func TestMapAsJSON(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
@@ -82,12 +83,12 @@ func TestMapAsJSON(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9080"
|
||||
":{$TESTING_CADDY_PORT_ONE}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -145,7 +146,7 @@ func TestMapAsJSON(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}`, "json")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called")
|
||||
tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called")
|
||||
target := fmt.Sprintf("http://localhost:%d/version", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target, 200, "hello from localhost get-called")
|
||||
harness.AssertPostResponseBody(target, []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called")
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ import (
|
||||
)
|
||||
|
||||
func TestSRVReverseProxy(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
@@ -87,11 +87,11 @@ func TestDialWithPlaceholderUnix(t *testing.T) {
|
||||
})
|
||||
runtime.Gosched() // Allow other goroutines to run
|
||||
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
@@ -135,15 +135,15 @@ func TestDialWithPlaceholderUnix(t *testing.T) {
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Caddy-Upstream-Dial", socketName)
|
||||
tester.AssertResponse(req, 200, "Hello, World!")
|
||||
harness.AssertResponse(req, 200, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
@@ -186,7 +186,7 @@ func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
|
||||
},
|
||||
"srv1": {
|
||||
"listen": [
|
||||
":9080"
|
||||
":{$TESTING_CADDY_PORT_ONE}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -199,7 +199,7 @@ func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
|
||||
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [
|
||||
{
|
||||
@@ -223,21 +223,21 @@ func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
|
||||
}
|
||||
`, "json")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "http://localhost:9080", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d", harness.Tester().PortOne()), nil)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Caddy-Upstream-Dial", "localhost:18080")
|
||||
tester.AssertResponse(req, 200, "Hello, World!")
|
||||
harness.AssertResponse(req, 200, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"pki": {
|
||||
@@ -280,7 +280,7 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
|
||||
},
|
||||
"srv1": {
|
||||
"listen": [
|
||||
":9080"
|
||||
":{$TESTING_CADDY_PORT_ONE}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -293,7 +293,7 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
|
||||
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [
|
||||
{
|
||||
@@ -317,23 +317,23 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
|
||||
}
|
||||
`, "json")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "http://localhost:9080", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d", harness.Tester().PortOne()), nil)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Caddy-Upstream-Dial", "localhost")
|
||||
tester.AssertResponse(req, 200, "Hello, World!")
|
||||
harness.AssertResponse(req, 200, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:2020 {
|
||||
@@ -342,10 +342,10 @@ func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
http://localhost:2021 {
|
||||
respond "ok"
|
||||
}
|
||||
http://localhost:9080 {
|
||||
http://localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
reverse_proxy {
|
||||
to localhost:2020
|
||||
|
||||
|
||||
health_uri /health
|
||||
health_port 2021
|
||||
health_interval 10ms
|
||||
@@ -357,14 +357,15 @@ func TestReverseProxyHealthCheck(t *testing.T) {
|
||||
`, "caddyfile")
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // TODO: for some reason this test seems particularly flaky, getting 503 when it should be 200, unless we wait
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target, 200, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.SkipNow()
|
||||
}
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
f, err := os.CreateTemp("", "*.sock")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create TempFile: %s", err)
|
||||
@@ -395,18 +396,18 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
|
||||
})
|
||||
runtime.Gosched() // Allow other goroutines to run
|
||||
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
harness.LoadConfig(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
http://localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
reverse_proxy {
|
||||
to unix/%s
|
||||
|
||||
|
||||
health_uri /health
|
||||
health_port 2021
|
||||
health_interval 2s
|
||||
@@ -415,14 +416,15 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
|
||||
}
|
||||
`, socketName), "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
target := fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne())
|
||||
harness.AssertGetResponse(target, 200, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.SkipNow()
|
||||
}
|
||||
tester := caddytest.NewTester(t)
|
||||
harness := caddytest.StartHarness(t)
|
||||
f, err := os.CreateTemp("", "*.sock")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create TempFile: %s", err)
|
||||
@@ -453,18 +455,18 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
|
||||
})
|
||||
runtime.Gosched() // Allow other goroutines to run
|
||||
|
||||
tester.InitServer(fmt.Sprintf(`
|
||||
harness.LoadConfig(fmt.Sprintf(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
http://localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
reverse_proxy {
|
||||
to unix/%s
|
||||
|
||||
|
||||
health_uri /health
|
||||
health_interval 2s
|
||||
health_timeout 5s
|
||||
@@ -472,5 +474,5 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
|
||||
}
|
||||
`, socketName), "caddyfile")
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
|
||||
harness.AssertGetResponse(fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), 200, "Hello, World!")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/caddytest"
|
||||
@@ -8,20 +9,20 @@ import (
|
||||
|
||||
func TestDefaultSNI(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -102,26 +103,27 @@ func TestDefaultSNI(t *testing.T) {
|
||||
|
||||
// act and assert
|
||||
// makes a request with no sni
|
||||
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
|
||||
target := fmt.Sprintf("https://127.0.0.1:%d/", harness.Tester().PortTwo())
|
||||
harness.AssertGetResponse(target+"version", 200, "hello from a.caddy.localhost")
|
||||
}
|
||||
|
||||
func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -206,26 +208,27 @@ func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
|
||||
|
||||
// act and assert
|
||||
// makes a request with no sni
|
||||
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
|
||||
target := fmt.Sprintf("https://127.0.0.1:%d/", harness.Tester().PortTwo())
|
||||
harness.AssertGetResponse(target+"version", 200, "hello from a")
|
||||
}
|
||||
|
||||
func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
|
||||
// arrange
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -282,7 +285,8 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
|
||||
|
||||
// act and assert
|
||||
// makes a request with no sni
|
||||
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
|
||||
target := fmt.Sprintf("https://127.0.0.1:%d/", harness.Tester().PortTwo())
|
||||
harness.AssertGetResponse(target+"version", 200, "hello from a.caddy.localhost")
|
||||
}
|
||||
|
||||
func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
|
||||
|
||||
@@ -20,21 +20,21 @@ import (
|
||||
|
||||
// (see https://github.com/caddyserver/caddy/issues/3556 for use case)
|
||||
func TestH2ToH2CStream(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"grace_period": 1,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -102,7 +102,7 @@ func TestH2ToH2CStream(t *testing.T) {
|
||||
|
||||
expectedBody := "some data to be echoed"
|
||||
// start the server
|
||||
server := testH2ToH2CStreamServeH2C(t)
|
||||
server := testH2ToH2CStreamServeH2C(harness, t)
|
||||
go server.ListenAndServe()
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
|
||||
@@ -116,7 +116,7 @@ func TestH2ToH2CStream(t *testing.T) {
|
||||
Body: io.NopCloser(r),
|
||||
URL: &url.URL{
|
||||
Scheme: "https",
|
||||
Host: "127.0.0.1:9443",
|
||||
Host: fmt.Sprintf("127.0.0.1:%d", harness.Tester().PortTwo()),
|
||||
Path: "/tov2ray",
|
||||
},
|
||||
Proto: "HTTP/2",
|
||||
@@ -127,7 +127,7 @@ func TestH2ToH2CStream(t *testing.T) {
|
||||
// Disable any compression method from server.
|
||||
req.Header.Set("Accept-Encoding", "identity")
|
||||
|
||||
resp := tester.AssertResponseCode(req, http.StatusOK)
|
||||
resp := harness.AssertResponseCode(req, http.StatusOK)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func TestH2ToH2CStream(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testH2ToH2CStreamServeH2C(t *testing.T) *http.Server {
|
||||
func testH2ToH2CStreamServeH2C(harness *caddytest.TestHarness, t *testing.T) *http.Server {
|
||||
h2s := &http2.Server{}
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
rstring, err := httputil.DumpRequest(r, false)
|
||||
@@ -163,7 +163,7 @@ func testH2ToH2CStreamServeH2C(t *testing.T) *http.Server {
|
||||
return
|
||||
}
|
||||
|
||||
if r.Host != "127.0.0.1:9443" {
|
||||
if r.Host != fmt.Sprintf("127.0.0.1:%d", harness.Tester().PortTwo()) {
|
||||
t.Errorf("r.Host doesn't match, %v!", r.Host)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
@@ -204,28 +204,21 @@ func testH2ToH2CStreamServeH2C(t *testing.T) *http.Server {
|
||||
|
||||
// (see https://github.com/caddyserver/caddy/issues/3606 for use case)
|
||||
func TestH2ToH1ChunkedResponse(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
"admin": {
|
||||
"listen": "localhost:2999"
|
||||
"listen": "{$TESTING_CADDY_ADMIN_BIND}"
|
||||
},
|
||||
"logging": {
|
||||
"logs": {
|
||||
"default": {
|
||||
"level": "DEBUG"
|
||||
}
|
||||
}
|
||||
},
|
||||
"apps": {
|
||||
"http": {
|
||||
"http_port": 9080,
|
||||
"https_port": 9443,
|
||||
"grace_period": 1,
|
||||
"http_port": {$TESTING_CADDY_PORT_ONE},
|
||||
"https_port": {$TESTING_CADDY_PORT_TWO},
|
||||
"grace_period": 1,
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":9443"
|
||||
":{$TESTING_CADDY_PORT_TWO}"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
@@ -312,7 +305,7 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
// start the server
|
||||
server := testH2ToH1ChunkedResponseServeH1(t)
|
||||
server := testH2ToH1ChunkedResponseServeH1(harness, t)
|
||||
go server.ListenAndServe()
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
|
||||
@@ -326,7 +319,7 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
|
||||
Body: io.NopCloser(r),
|
||||
URL: &url.URL{
|
||||
Scheme: "https",
|
||||
Host: "127.0.0.1:9443",
|
||||
Host: fmt.Sprintf("127.0.0.1:%d", harness.Tester().PortTwo()),
|
||||
Path: "/tov2ray",
|
||||
},
|
||||
Proto: "HTTP/2",
|
||||
@@ -334,13 +327,13 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
|
||||
ProtoMinor: 0,
|
||||
Header: make(http.Header),
|
||||
}
|
||||
// underlying transport will automaticlly add gzip
|
||||
// underlying transport will automatically add gzip
|
||||
// req.Header.Set("Accept-Encoding", "gzip")
|
||||
go func() {
|
||||
fmt.Fprint(w, expectedBody)
|
||||
w.Close()
|
||||
}()
|
||||
resp := tester.AssertResponseCode(req, http.StatusOK)
|
||||
resp := harness.AssertResponseCode(req, http.StatusOK)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return
|
||||
}
|
||||
@@ -358,9 +351,9 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testH2ToH1ChunkedResponseServeH1(t *testing.T) *http.Server {
|
||||
func testH2ToH1ChunkedResponseServeH1(harness *caddytest.TestHarness, t *testing.T) *http.Server {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Host != "127.0.0.1:9443" {
|
||||
if r.Host != fmt.Sprintf("127.0.0.1:%d", harness.Tester().PortTwo()) {
|
||||
t.Errorf("r.Host doesn't match, %v!", r.Host)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1,241 @@
|
||||
package caddytest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// use the convention to replace /[certificatename].[crt|key] with the full path
|
||||
// this helps reduce the noise in test configurations and also allow this
|
||||
// to run in any path
|
||||
func prependCaddyFilePath(rawConfig string) string {
|
||||
r := matchKey.ReplaceAllString(rawConfig, getIntegrationDir()+"$1")
|
||||
r = matchCert.ReplaceAllString(r, getIntegrationDir()+"$1")
|
||||
return r
|
||||
}
|
||||
|
||||
func getIntegrationDir() string {
|
||||
_, filename, _, ok := runtime.Caller(1)
|
||||
if !ok {
|
||||
panic("unable to determine the current file path")
|
||||
}
|
||||
|
||||
return path.Dir(filename)
|
||||
}
|
||||
|
||||
var (
|
||||
matchKey = regexp.MustCompile(`(/[\w\d\.]+\.key)`)
|
||||
matchCert = regexp.MustCompile(`(/[\w\d\.]+\.crt)`)
|
||||
)
|
||||
|
||||
type TestHarness struct {
|
||||
t testing.TB
|
||||
|
||||
tester *Tester
|
||||
}
|
||||
|
||||
// StartHarness creates and starts a test harness environment which spans the lifetime a single caddy instance
|
||||
// This is used for the integration tests
|
||||
func StartHarness(t *testing.T) *TestHarness {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return nil
|
||||
}
|
||||
o := &TestHarness{t: t}
|
||||
o.init()
|
||||
return o
|
||||
}
|
||||
|
||||
func (tc *TestHarness) Tester() *Tester {
|
||||
return tc.tester
|
||||
}
|
||||
|
||||
func (tc *TestHarness) Client() *http.Client {
|
||||
return tc.tester.Client
|
||||
}
|
||||
|
||||
func (tc *TestHarness) LoadConfig(rawConfig, configType string) {
|
||||
rawConfig = prependCaddyFilePath(rawConfig)
|
||||
err := tc.tester.LoadConfig(rawConfig, configType)
|
||||
require.NoError(tc.t, err)
|
||||
}
|
||||
|
||||
func (tc *TestHarness) init() {
|
||||
// start the server
|
||||
tester, err := NewTester()
|
||||
if err != nil {
|
||||
tc.t.Errorf("Failed to create caddy tester: %s", err)
|
||||
return
|
||||
}
|
||||
tc.tester = tester
|
||||
err = tc.tester.LaunchCaddy()
|
||||
if err != nil {
|
||||
tc.t.Errorf("Failed to launch caddy server: %s", err)
|
||||
tc.t.FailNow()
|
||||
return
|
||||
}
|
||||
// cleanup
|
||||
tc.t.Cleanup(func() {
|
||||
func() {
|
||||
if tc.t.Failed() {
|
||||
res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", tc.tester.adminPort))
|
||||
if err != nil {
|
||||
tc.t.Log("unable to read the current config")
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
|
||||
var out bytes.Buffer
|
||||
_ = json.Indent(&out, body, "", " ")
|
||||
tc.t.Logf("----------- failed with config -----------\n%s", out.String())
|
||||
}
|
||||
}()
|
||||
// shutdown server after extracing the config
|
||||
err = tc.tester.CleanupCaddy()
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to clean up caddy instance: %s", err)
|
||||
tc.t.FailNow()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// AssertRedirect makes a request and asserts the redirection happens
|
||||
func (tc *TestHarness) AssertRedirect(requestURI string, expectedToLocation string, expectedStatusCode int) *http.Response {
|
||||
redirectPolicyFunc := func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
||||
// using the existing client, we override the check redirect policy for this test
|
||||
old := tc.tester.Client.CheckRedirect
|
||||
tc.tester.Client.CheckRedirect = redirectPolicyFunc
|
||||
defer func() { tc.tester.Client.CheckRedirect = old }()
|
||||
|
||||
resp, err := tc.tester.Client.Get(requestURI)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to call server %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if expectedStatusCode != resp.StatusCode {
|
||||
tc.t.Errorf("requesting \"%s\" expected status code: %d but got %d", requestURI, expectedStatusCode, resp.StatusCode)
|
||||
}
|
||||
|
||||
loc, err := resp.Location()
|
||||
if err != nil {
|
||||
tc.t.Errorf("requesting \"%s\" expected location: \"%s\" but got error: %s", requestURI, expectedToLocation, err)
|
||||
}
|
||||
if loc == nil && expectedToLocation != "" {
|
||||
tc.t.Errorf("requesting \"%s\" expected a Location header, but didn't get one", requestURI)
|
||||
}
|
||||
if loc != nil {
|
||||
if expectedToLocation != loc.String() {
|
||||
tc.t.Errorf("requesting \"%s\" expected location: \"%s\" but got \"%s\"", requestURI, expectedToLocation, loc.String())
|
||||
}
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
|
||||
func (tc *TestHarness) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response {
|
||||
resp, err := tc.tester.Client.Do(req)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("failed to call server %s", err)
|
||||
}
|
||||
|
||||
if expectedStatusCode != resp.StatusCode {
|
||||
tc.t.Errorf("requesting \"%s\" expected status code: %d but got %d", req.URL.RequestURI(), expectedStatusCode, resp.StatusCode)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// AssertResponse request a URI and assert the status code and the body contains a string
|
||||
func (tc *TestHarness) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
resp := tc.AssertResponseCode(req, expectedStatusCode)
|
||||
|
||||
defer resp.Body.Close()
|
||||
bytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to read the response body %s", err)
|
||||
}
|
||||
|
||||
body := string(bytes)
|
||||
|
||||
if body != expectedBody {
|
||||
tc.t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", req.RequestURI, expectedBody, body)
|
||||
}
|
||||
|
||||
return resp, body
|
||||
}
|
||||
|
||||
// Verb specific test functions
|
||||
|
||||
// AssertGetResponse GET a URI and expect a statusCode and body text
|
||||
func (tc *TestHarness) AssertGetResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("GET", requestURI, nil)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to create request %s", err)
|
||||
}
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertDeleteResponse request a URI and expect a statusCode and body text
|
||||
func (tc *TestHarness) AssertDeleteResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("DELETE", requestURI, nil)
|
||||
if err != nil {
|
||||
tc.t.Fatalf("unable to create request %s", err)
|
||||
}
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPostResponseBody POST to a URI and assert the response code and body
|
||||
func (tc *TestHarness) AssertPostResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("POST", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPutResponseBody PUT to a URI and assert the response code and body
|
||||
func (tc *TestHarness) AssertPutResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("PUT", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
|
||||
// AssertPatchResponseBody PATCH to a URI and assert the response code and body
|
||||
func (tc *TestHarness) AssertPatchResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
|
||||
req, err := http.NewRequest("PATCH", requestURI, requestBody)
|
||||
if err != nil {
|
||||
tc.t.Errorf("failed to create request %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
applyHeaders(tc.t, req, requestHeaders)
|
||||
|
||||
return tc.AssertResponse(req, expectedStatusCode, expectedBody)
|
||||
}
|
||||
+6
-3
@@ -1,13 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
# USAGE: go run -exec ./setcap.sh main.go <args...>
|
||||
# USAGE:
|
||||
# go run -exec ./setcap.sh main.go <args...>
|
||||
#
|
||||
# (Example: `go run -exec ./setcap.sh main.go run --config caddy.json`)
|
||||
#
|
||||
# For some reason this does not work on my Arch system, so if you find that's
|
||||
# the case, you can instead do: go build && ./setcap.sh ./caddy <args...>
|
||||
# but this will leave the ./caddy binary laying around.
|
||||
# the case, you can instead do:
|
||||
#
|
||||
# go build && ./setcap.sh ./caddy <args...>
|
||||
#
|
||||
# but this will leave the ./caddy binary laying around.
|
||||
#
|
||||
|
||||
sudo setcap cap_net_bind_service=+ep "$1"
|
||||
|
||||
+15
-11
@@ -8,9 +8,10 @@ import (
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "caddy",
|
||||
Long: `Caddy is an extensible server platform written in Go.
|
||||
var defaultFactory = NewRootCommandFactory(func() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "caddy",
|
||||
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,23 +92,26 @@ package installers: https://caddyserver.com/docs/install
|
||||
Instructions for running Caddy in production are also available:
|
||||
https://caddyserver.com/docs/running
|
||||
`,
|
||||
Example: ` $ caddy run
|
||||
Example: ` $ caddy run
|
||||
$ caddy run --config caddy.json
|
||||
$ caddy reload --config caddy.json
|
||||
$ caddy stop`,
|
||||
|
||||
// kind of annoying to have all the help text printed out if
|
||||
// caddy has an error provisioning its modules, for instance...
|
||||
SilenceUsage: true,
|
||||
Version: onlyVersionText(),
|
||||
}
|
||||
// kind of annoying to have all the help text printed out if
|
||||
// caddy has an error provisioning its modules, for instance...
|
||||
SilenceUsage: true,
|
||||
Version: onlyVersionText(),
|
||||
}
|
||||
})
|
||||
|
||||
const fullDocsFooter = `Full documentation is available at:
|
||||
https://caddyserver.com/docs/command-line`
|
||||
|
||||
func init() {
|
||||
rootCmd.SetVersionTemplate("{{.Version}}\n")
|
||||
rootCmd.SetHelpTemplate(rootCmd.HelpTemplate() + "\n" + fullDocsFooter + "\n")
|
||||
defaultFactory.Use(func(cmd *cobra.Command) {
|
||||
cmd.SetVersionTemplate("{{.Version}}\n")
|
||||
cmd.SetHelpTemplate(cmd.HelpTemplate() + "\n" + fullDocsFooter + "\n")
|
||||
})
|
||||
}
|
||||
|
||||
func onlyVersionText() string {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package caddycmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type RootCommandFactory struct {
|
||||
constructor func() *cobra.Command
|
||||
options []func(*cobra.Command)
|
||||
}
|
||||
|
||||
func NewRootCommandFactory(fn func() *cobra.Command) *RootCommandFactory {
|
||||
return &RootCommandFactory{
|
||||
constructor: fn,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *RootCommandFactory) Use(fn func(cmd *cobra.Command)) {
|
||||
f.options = append(f.options, fn)
|
||||
}
|
||||
|
||||
func (f *RootCommandFactory) Build() *cobra.Command {
|
||||
o := f.constructor()
|
||||
for _, v := range f.options {
|
||||
v(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
+7
-1
@@ -20,6 +20,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
@@ -257,6 +258,7 @@ func cmdRun(fl Flags) (int, error) {
|
||||
|
||||
// if enabled, reload config file automatically on changes
|
||||
// (this better only be used in dev!)
|
||||
// do not enable this during tests, it will cause leaks
|
||||
if watchFlag {
|
||||
go watchConfigFile(configFile, configAdapterFlag)
|
||||
}
|
||||
@@ -280,7 +282,11 @@ func cmdRun(fl Flags) (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
select {}
|
||||
if flag.Lookup("test.v") == nil || !strings.Contains(os.Args[0], ".test") {
|
||||
select {}
|
||||
} else {
|
||||
return caddy.ExitCodeSuccess, nil
|
||||
}
|
||||
}
|
||||
|
||||
func cmdStop(fl Flags) (int, error) {
|
||||
|
||||
+29
-24
@@ -459,7 +459,8 @@ argument of --directory. If the directory does not exist, it will be created.
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return caddy.ExitCodeFailedQuit, err
|
||||
}
|
||||
if err := doc.GenManTree(rootCmd, &doc.GenManHeader{
|
||||
ccmd := defaultFactory.Build()
|
||||
if err := doc.GenManTree(ccmd, &doc.GenManHeader{
|
||||
Title: "Caddy",
|
||||
Section: "8", // https://en.wikipedia.org/wiki/Man_page#Manual_sections
|
||||
}, dir); err != nil {
|
||||
@@ -471,10 +472,11 @@ argument of --directory. If the directory does not exist, it will be created.
|
||||
})
|
||||
|
||||
// source: https://github.com/spf13/cobra/blob/main/shell_completions.md
|
||||
rootCmd.AddCommand(&cobra.Command{
|
||||
Use: "completion [bash|zsh|fish|powershell]",
|
||||
Short: "Generate completion script",
|
||||
Long: fmt.Sprintf(`To load completions:
|
||||
defaultFactory.Use(func(ccmd *cobra.Command) {
|
||||
ccmd.AddCommand(&cobra.Command{
|
||||
Use: "completion [bash|zsh|fish|powershell]",
|
||||
Short: "Generate completion script",
|
||||
Long: fmt.Sprintf(`To load completions:
|
||||
|
||||
Bash:
|
||||
|
||||
@@ -512,24 +514,25 @@ argument of --directory. If the directory does not exist, it will be created.
|
||||
# To load completions for every new session, run:
|
||||
PS> %[1]s completion powershell > %[1]s.ps1
|
||||
# and source this file from your PowerShell profile.
|
||||
`, rootCmd.Root().Name()),
|
||||
DisableFlagsInUseLine: true,
|
||||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
switch args[0] {
|
||||
case "bash":
|
||||
return cmd.Root().GenBashCompletion(os.Stdout)
|
||||
case "zsh":
|
||||
return cmd.Root().GenZshCompletion(os.Stdout)
|
||||
case "fish":
|
||||
return cmd.Root().GenFishCompletion(os.Stdout, true)
|
||||
case "powershell":
|
||||
return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
|
||||
default:
|
||||
return fmt.Errorf("unrecognized shell: %s", args[0])
|
||||
}
|
||||
},
|
||||
`, defaultFactory.constructor().Name()),
|
||||
DisableFlagsInUseLine: true,
|
||||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
switch args[0] {
|
||||
case "bash":
|
||||
return cmd.Root().GenBashCompletion(os.Stdout)
|
||||
case "zsh":
|
||||
return cmd.Root().GenZshCompletion(os.Stdout)
|
||||
case "fish":
|
||||
return cmd.Root().GenFishCompletion(os.Stdout, true)
|
||||
case "powershell":
|
||||
return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
|
||||
default:
|
||||
return fmt.Errorf("unrecognized shell: %s", args[0])
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -563,7 +566,9 @@ func RegisterCommand(cmd Command) {
|
||||
if !commandNameRegex.MatchString(cmd.Name) {
|
||||
panic("invalid command name")
|
||||
}
|
||||
rootCmd.AddCommand(caddyCmdToCobra(cmd))
|
||||
defaultFactory.Use(func(ccmd *cobra.Command) {
|
||||
ccmd.AddCommand(caddyCmdToCobra(cmd))
|
||||
})
|
||||
}
|
||||
|
||||
var commandNameRegex = regexp.MustCompile(`^[a-z0-9]$|^([a-z0-9]+-?[a-z0-9]*)+[a-z0-9]$`)
|
||||
|
||||
+51
-13
@@ -71,7 +71,7 @@ func Main() {
|
||||
if err != nil {
|
||||
caddy.Log().Warn("failed to set GOMAXPROCS", zap.Error(err))
|
||||
}
|
||||
|
||||
rootCmd := defaultFactory.Build()
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
var exitError *exitError
|
||||
if errors.As(err, &exitError) {
|
||||
@@ -81,6 +81,18 @@ func Main() {
|
||||
}
|
||||
}
|
||||
|
||||
// MainForTesting implements the main function of the caddy command, used internally for testing
|
||||
func MainForTesting(args ...string) error {
|
||||
// create a root command for testing which will not pollute the global namespace, and does not
|
||||
// call os.Exit().
|
||||
rootCmd := defaultFactory.Build()
|
||||
rootCmd.SetArgs(args)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handlePingbackConn reads from conn and ensures it matches
|
||||
// the bytes in expect, or returns an error if it doesn't.
|
||||
func handlePingbackConn(conn net.Conn, expect []byte) error {
|
||||
@@ -107,6 +119,40 @@ func LoadConfig(configFile, adapterName string) ([]byte, string, error) {
|
||||
return loadConfigWithLogger(caddy.Log(), configFile, adapterName)
|
||||
}
|
||||
|
||||
func isCaddyfile(configFile, adapterName string) (bool, error) {
|
||||
if adapterName == "caddyfile" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// as a special case, if a config file starts with "caddyfile" or
|
||||
// has a ".caddyfile" extension, and no adapter is specified, and
|
||||
// no adapter module name matches the extension, assume
|
||||
// caddyfile adapter for convenience
|
||||
baseConfig := strings.ToLower(filepath.Base(configFile))
|
||||
baseConfigExt := filepath.Ext(baseConfig)
|
||||
startsOrEndsInCaddyfile := strings.HasPrefix(baseConfig, "caddyfile") || strings.HasSuffix(baseConfig, ".caddyfile")
|
||||
|
||||
if baseConfigExt == ".json" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// If the adapter is not specified,
|
||||
// the config file starts with "caddyfile",
|
||||
// the config file has an extension,
|
||||
// and isn't a JSON file (e.g. Caddyfile.yaml),
|
||||
// then we don't know what the config format is.
|
||||
if adapterName == "" && startsOrEndsInCaddyfile {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// adapter is not empty,
|
||||
// adapter is not "caddyfile",
|
||||
// extension is not ".json",
|
||||
// extension is not ".caddyfile"
|
||||
// file does not start with "Caddyfile"
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([]byte, string, error) {
|
||||
// if no logger is provided, use a nop logger
|
||||
// just so we don't have to check for nil
|
||||
@@ -157,18 +203,10 @@ func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([
|
||||
}
|
||||
}
|
||||
|
||||
// as a special case, if a config file starts with "caddyfile" or
|
||||
// has a ".caddyfile" extension, and no adapter is specified, and
|
||||
// no adapter module name matches the extension, assume
|
||||
// caddyfile adapter for convenience
|
||||
baseConfig := strings.ToLower(filepath.Base(configFile))
|
||||
baseConfigExt := filepath.Ext(baseConfig)
|
||||
if (strings.HasPrefix(baseConfig, "caddyfile") ||
|
||||
strings.HasSuffix(baseConfig, ".caddyfile")) &&
|
||||
(len(baseConfigExt) == 0 || caddyconfig.GetAdapter(baseConfigExt[1:]) == nil) &&
|
||||
baseConfigExt != ".json" &&
|
||||
adapterName == "" {
|
||||
if yes, err := isCaddyfile(configFile, adapterName); yes {
|
||||
adapterName = "caddyfile"
|
||||
} else if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
// load config adapter
|
||||
@@ -199,7 +237,7 @@ func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([
|
||||
zap.Int("line", warn.Line))
|
||||
}
|
||||
config = adaptedConfig
|
||||
} else {
|
||||
} else if len(config) != 0 {
|
||||
// validate that the config is at least valid JSON
|
||||
err = json.Unmarshal(config, new(any))
|
||||
if err != nil {
|
||||
|
||||
@@ -168,3 +168,113 @@ here"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_isCaddyfile(t *testing.T) {
|
||||
type args struct {
|
||||
configFile string
|
||||
adapterName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "bare Caddyfile without adapter",
|
||||
args: args{
|
||||
configFile: "Caddyfile",
|
||||
adapterName: "",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "local Caddyfile without adapter",
|
||||
args: args{
|
||||
configFile: "./Caddyfile",
|
||||
adapterName: "",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "local caddyfile with adapter",
|
||||
args: args{
|
||||
configFile: "./Caddyfile",
|
||||
adapterName: "caddyfile",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ends with .caddyfile with adapter",
|
||||
args: args{
|
||||
configFile: "./conf.caddyfile",
|
||||
adapterName: "caddyfile",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ends with .caddyfile without adapter",
|
||||
args: args{
|
||||
configFile: "./conf.caddyfile",
|
||||
adapterName: "",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "config is Caddyfile.yaml with adapter",
|
||||
args: args{
|
||||
configFile: "./Caddyfile.yaml",
|
||||
adapterName: "yaml",
|
||||
},
|
||||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
|
||||
name: "json is not caddyfile but not error",
|
||||
args: args{
|
||||
configFile: "./Caddyfile.json",
|
||||
adapterName: "",
|
||||
},
|
||||
want: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
|
||||
name: "prefix of Caddyfile and ./ with any extension is Caddyfile",
|
||||
args: args{
|
||||
configFile: "./Caddyfile.prd",
|
||||
adapterName: "",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
|
||||
name: "prefix of Caddyfile without ./ with any extension is Caddyfile",
|
||||
args: args{
|
||||
configFile: "Caddyfile.prd",
|
||||
adapterName: "",
|
||||
},
|
||||
want: true,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := isCaddyfile(tt.args.configFile, tt.args.adapterName)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("isCaddyfile() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("isCaddyfile() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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 (
|
||||
// For running in minimal environments, this can ease
|
||||
// headaches related to establishing TLS connections.
|
||||
// "Package fallback embeds a set of fallback X.509 trusted
|
||||
// roots in the application by automatically invoking
|
||||
// x509.SetFallbackRoots. This allows the application to
|
||||
// work correctly even if the operating system does not
|
||||
// provide a verifier or system roots pool. ... It's
|
||||
// recommended that only binaries, and not libraries,
|
||||
// import this package. This package must be kept up to
|
||||
// date for security and compatibility reasons."
|
||||
//
|
||||
// This is in its own file only because of conflicts
|
||||
// between gci and goimports when in main.go.
|
||||
// See https://github.com/daixiang0/gci/issues/76
|
||||
_ "golang.org/x/crypto/x509roots/fallback"
|
||||
)
|
||||
+31
-15
@@ -453,25 +453,29 @@ func (ctx Context) App(name string) (any, error) {
|
||||
return modVal, nil
|
||||
}
|
||||
|
||||
// AppIfConfigured returns an app by its name if it has been
|
||||
// configured. Can be called instead of App() to avoid
|
||||
// instantiating an empty app when that's not desirable. If
|
||||
// the app has not been loaded, nil is returned.
|
||||
//
|
||||
// We return any type instead of the App type because it is not
|
||||
// intended for the caller of this method to be the one to start
|
||||
// or stop App modules. The caller is expected to assert to the
|
||||
// concrete type.
|
||||
func (ctx Context) AppIfConfigured(name string) any {
|
||||
// AppIfConfigured is like App, but it returns an error if the
|
||||
// app has not been configured. This is useful when the app is
|
||||
// required and its absence is a configuration error; or when
|
||||
// the app is optional and you don't want to instantiate a
|
||||
// new one that hasn't been explicitly configured. If the app
|
||||
// is not in the configuration, the error wraps ErrNotConfigured.
|
||||
func (ctx Context) AppIfConfigured(name string) (any, error) {
|
||||
if ctx.cfg == nil {
|
||||
// this can happen if the currently-active context
|
||||
// is being accessed, but no config has successfully
|
||||
// been loaded yet
|
||||
return nil
|
||||
return nil, fmt.Errorf("app module %s: %w", name, ErrNotConfigured)
|
||||
}
|
||||
return ctx.cfg.apps[name]
|
||||
if app, ok := ctx.cfg.apps[name]; ok {
|
||||
return app, nil
|
||||
}
|
||||
appRaw := ctx.cfg.AppsRaw[name]
|
||||
if appRaw == nil {
|
||||
return nil, fmt.Errorf("app module %s: %w", name, ErrNotConfigured)
|
||||
}
|
||||
return ctx.App(name)
|
||||
}
|
||||
|
||||
// ErrNotConfigured indicates a module is not configured.
|
||||
var ErrNotConfigured = fmt.Errorf("module not configured")
|
||||
|
||||
// Storage returns the configured Caddy storage implementation.
|
||||
func (ctx Context) Storage() certmagic.Storage {
|
||||
return ctx.cfg.storage
|
||||
@@ -556,3 +560,15 @@ func (ctx Context) Module() Module {
|
||||
}
|
||||
return ctx.ancestry[len(ctx.ancestry)-1]
|
||||
}
|
||||
|
||||
// WithValue returns a new context with the given key-value pair.
|
||||
func (ctx *Context) WithValue(key, value any) Context {
|
||||
return Context{
|
||||
Context: context.WithValue(ctx.Context, key, value),
|
||||
moduleInstances: ctx.moduleInstances,
|
||||
cfg: ctx.cfg,
|
||||
ancestry: ctx.ancestry,
|
||||
cleanupFuncs: ctx.cleanupFuncs,
|
||||
exitFuncs: ctx.exitFuncs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,47 @@
|
||||
module github.com/caddyserver/caddy/v2
|
||||
|
||||
go 1.21
|
||||
go 1.21.0
|
||||
|
||||
toolchain go1.21.4
|
||||
toolchain go1.22.2
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.3.2
|
||||
github.com/Masterminds/sprig/v3 v3.2.3
|
||||
github.com/alecthomas/chroma/v2 v2.13.0
|
||||
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b
|
||||
github.com/caddyserver/certmagic v0.20.0
|
||||
github.com/caddyserver/certmagic v0.21.3
|
||||
github.com/caddyserver/zerossl v0.1.3
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/go-chi/chi/v5 v5.0.12
|
||||
github.com/google/cel-go v0.20.0
|
||||
github.com/google/cel-go v0.20.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/klauspost/compress v1.17.0
|
||||
github.com/klauspost/cpuid/v2 v2.2.5
|
||||
github.com/mholt/acmez v1.2.0
|
||||
github.com/prometheus/client_golang v1.19.0
|
||||
github.com/quic-go/quic-go v0.42.0
|
||||
github.com/smallstep/certificates v0.25.3-rc5
|
||||
github.com/smallstep/nosql v0.6.0
|
||||
github.com/klauspost/compress v1.17.8
|
||||
github.com/klauspost/cpuid/v2 v2.2.7
|
||||
github.com/mholt/acmez/v2 v2.0.1
|
||||
github.com/prometheus/client_golang v1.19.1
|
||||
github.com/quic-go/quic-go v0.44.0
|
||||
github.com/smallstep/certificates v0.26.1
|
||||
github.com/smallstep/nosql v0.6.1
|
||||
github.com/smallstep/truststore v0.13.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/tailscale/tscert v0.0.0-20230806124524-28a91b69a046
|
||||
github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53
|
||||
github.com/yuin/goldmark v1.7.1
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.42.0
|
||||
go.opentelemetry.io/otel v1.21.0
|
||||
go.opentelemetry.io/otel v1.24.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
|
||||
go.opentelemetry.io/otel/sdk v1.21.0
|
||||
go.uber.org/automaxprocs v1.5.3
|
||||
go.uber.org/zap v1.27.0
|
||||
go.uber.org/zap/exp v0.2.0
|
||||
golang.org/x/crypto v0.22.0
|
||||
golang.org/x/net v0.24.0
|
||||
golang.org/x/crypto v0.23.0
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20240507223354-67b13616a595
|
||||
golang.org/x/net v0.25.0
|
||||
golang.org/x/sync v0.7.0
|
||||
golang.org/x/term v0.19.0
|
||||
golang.org/x/term v0.20.0
|
||||
golang.org/x/time v0.5.0
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@@ -71,9 +73,9 @@ require (
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.17.0 // indirect
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.17.0 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -112,12 +114,12 @@ require (
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
github.com/jackc/pgtype v1.14.0 // indirect
|
||||
github.com/jackc/pgx/v4 v4.18.3 // indirect
|
||||
github.com/libdns/libdns v0.2.1 // indirect
|
||||
github.com/libdns/libdns v0.2.2 // indirect
|
||||
github.com/manifoldco/promptui v0.9.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // 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.55 // indirect
|
||||
github.com/miekg/dns v1.1.59 // 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
|
||||
@@ -135,20 +137,20 @@ require (
|
||||
github.com/spf13/cast v1.4.1 // indirect
|
||||
github.com/stoewer/go-strcase v1.2.0 // indirect
|
||||
github.com/urfave/cli v1.22.14 // indirect
|
||||
go.etcd.io/bbolt v1.3.8 // indirect
|
||||
go.etcd.io/bbolt v1.3.9 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.21.0
|
||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.24.0
|
||||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
|
||||
go.step.sm/cli-utils v0.8.0 // indirect
|
||||
go.step.sm/crypto v0.42.1
|
||||
go.step.sm/cli-utils v0.9.0 // indirect
|
||||
go.step.sm/crypto v0.45.0
|
||||
go.step.sm/linkedca v0.20.1 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/mod v0.16.0 // indirect
|
||||
golang.org/x/sys v0.19.0
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.19.0 // indirect
|
||||
google.golang.org/grpc v1.62.1 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/sys v0.20.0
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
golang.org/x/tools v0.21.0 // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
howett.net/plist v1.0.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
cloud.google.com/go v0.111.0 h1:YHLKNupSD1KqjDbQ3+LVdQ81h/UJbJyZG203cEfnQgM=
|
||||
cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
|
||||
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
cloud.google.com/go/iam v1.1.5 h1:1jTsCu4bcsNsE4iiqNT5SHwrDRCfRmIaaaVFhRveTJI=
|
||||
cloud.google.com/go/iam v1.1.5/go.mod h1:rB6P/Ic3mykPbFio+vo7403drjlgvoWfYpJhMXEbzv8=
|
||||
cloud.google.com/go/kms v1.15.5 h1:pj1sRfut2eRbD9pFRjNnPNg/CzJPuQAzUujMIM1vVeM=
|
||||
cloud.google.com/go/kms v1.15.5/go.mod h1:cU2H5jnp6G2TDpUGZyqTCoy1n16fbubHZjmVXSMtwDI=
|
||||
cloud.google.com/go v0.112.1 h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
|
||||
cloud.google.com/go/auth v0.4.1 h1:Z7YNIhlWRtrnKlZke7z3GMqzvuYzdc2z98F9D1NV5Hg=
|
||||
cloud.google.com/go/auth v0.4.1/go.mod h1:QVBuVEKpCn4Zp58hzRGvL0tjRGU0YqdRTdCHM1IHnro=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q=
|
||||
cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg=
|
||||
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
|
||||
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
|
||||
cloud.google.com/go/iam v1.1.8 h1:r7umDwhj+BQyz0ScZMp4QrGXjSTI3ZINnpgU2nlB/K0=
|
||||
cloud.google.com/go/iam v1.1.8/go.mod h1:GvE6lyMmfxXauzNq8NbgJbeVQNspG+tcdL/W8QO1+zE=
|
||||
cloud.google.com/go/kms v1.16.0 h1:1yZsRPhmargZOmY+fVAh8IKiR9HzCb0U1zsxb5g2nRY=
|
||||
cloud.google.com/go/kms v1.16.0/go.mod h1:olQUXy2Xud+1GzYfiBO9N0RhjsJk5IJLU6n/ethLXVc=
|
||||
cloud.google.com/go/longrunning v0.5.7 h1:WLbHekDbjK1fVFD3ibpFFVoyizlLRl73I7YKuAKilhU=
|
||||
cloud.google.com/go/longrunning v0.5.7/go.mod h1:8GClkudohy1Fxm3owmBGid8W0pSgodEMwEAztp38Xng=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M=
|
||||
@@ -38,38 +43,40 @@ github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9
|
||||
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.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU=
|
||||
github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.26.6 h1:Z/7w9bUqlRI0FFQpetVuFYEsjzE3h7fpU6HuGmfPL/o=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.26.6/go.mod h1:uKU6cnDmYCvJ+pxO9S4cWDb2yWWIH5hra+32hVh1MI4=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 h1:8q6Rliyv0aUFAVtzaldUEcS+T5gbadPbWdV1WcAddK8=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.16.16/go.mod h1:UHVZrdUsv63hPXFo1H7c5fEneoVo9UXiz36QG1GEPi0=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 h1:c5I5iH+DZcH3xOIMlz3/tCKJDaHFwYEmxvlh2fAcFo8=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11/go.mod h1:cRrYDYAMUohBJUtUnOhydaMHtiK/1NZ0Otc9lIb6O0Y=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 h1:vF+Zgd9s+H4vOXd5BMaPWykta2a6Ih0AKLq/X6NYKn4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10/go.mod h1:6BkRjejp/GR4411UGqkX8+wFMbFbqsUIimfK4XjOKR4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 h1:nYPe006ktcqUji8S2mqXf9c/7NdiKriOwMvWQHgYztw=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10/go.mod h1:6UV4SZkVvmODfXKql4LCbaZUpF7HO2BX38FgBf9ZOLw=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 h1:n3GDfwqF2tzEkXlv5cuy4iy7LpKDtqDMcNLfZDu9rls=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 h1:/b31bi3YVNlkzkBrm9LfpaKoaYZUxIAj4sHfOTmLfqw=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4/go.mod h1:2aGXHFmbInwgP9ZfpmdIfOELL79zhdNYNmReK8qDfdQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 h1:DBYTXwIGQSGs9w4jKm60F5dmCQ3EEruxdc0MFh+3EY4=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10/go.mod h1:wohMUQiFdzo0NtxbBg0mSRGZ4vL3n0dKjLTINdcIino=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.27.9 h1:W9PbZAZAEcelhhjb7KuwUtf+Lbc+i7ByYJRuWLlnxyQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.27.9/go.mod h1:2tFmR7fQnOdQlM2ZCEPpFnBIQD1U8wmXmduBgZbOag0=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 h1:eajuO3nykDPdYicLlP3AGgOyVN3MOlFmZv7WGTuJPow=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7/go.mod h1:+mJNDdF+qiUlNKNC3fxn74WWNN+sOiGOEImje+3ScPM=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 h1:QPMJf+Jw8E1l7zqhZmMlFw6w1NmfkfiSK8mS4zOx3BA=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7/go.mod h1:ykf3COxYI0UJmxcfcxcVuz7b6uADi1FkiUz6Eb7AgM8=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 h1:NzO4Vrau795RkUdSHKEwiR01FaGzGOH1EETJ+5QHnm0=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7/go.mod h1:6h2YuIoxaMSCFf5fi1EgZAwdfkGMgDY+DVfa61uLe4U=
|
||||
github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM=
|
||||
github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
|
||||
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
|
||||
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.13 h1:WbKW8hOzrWoOA/+35S5okqO/2Ap8hkkFUzoW8Hzq24A=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.13/go.mod h1:XLiyiTMnguytjRER7u5RIkhIqS8Nyz41SwAWb4xEjxs=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.13 h1:XDCJDzk/u5cN7Aple7D/MiAhx1Rjo/0nueJ0La8mRuE=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.13/go.mod h1:FMNcjQrmuBYvOTZDtOLCIu0esmxjF7RuA/89iSXWzQI=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 h1:FVJ0r5XTHSmIHJV6KuDmdYhEpvlHpiSd38RQWhut5J4=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1/go.mod h1:zusuAeqezXzAB24LGuzuekqMAEgWkVYukBec3kr3jUg=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5/go.mod h1:FSaRudD0dXiMPK2UjknVwwTYyZMRsHv3TtkabsZih5I=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 h1:PG1F3OD1szkuQPzDw3CIQsRIrtTlUC3lP84taWzHlq0=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5/go.mod h1:jU1li6RFryMz+so64PpKtudI+QzbKoIEivqdf6LNpOc=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7/go.mod h1:YCsIZhXfRPLFFCl5xxY+1T9RKzOKjCut+28JSX2DnAk=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.31.1 h1:5wtyAwuUiJiM3DHYeGZmP5iMonM7DFBWAEaaVPHYZA0=
|
||||
github.com/aws/aws-sdk-go-v2/service/kms v1.31.1/go.mod h1:2snWQJQUKsbN66vAawJuOGX7dr37pfOq9hb0tZDGIqQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.6 h1:o5cTaeunSpfXiLTIBx5xo2enQmiChtu1IBbzXnfU9Hs=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.6/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.0 h1:Qe0r0lVURDDeBQJ4yP+BOrJkvkiCo/3FH/t+wY11dmw=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.0/go.mod h1:mUYPBhaF2lGiukDEjJX2BLRRKTmoUSitGDUgM4tRxak=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.7 h1:et3Ta53gotFR4ERLXXHIHl/Uuk1qYpP5uU7cvNql8ns=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.7/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw=
|
||||
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
|
||||
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
|
||||
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.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc=
|
||||
github.com/caddyserver/certmagic v0.20.0/go.mod h1:N4sXgpICQUskEWpj7zVzvWD41p3NYacrNoZYiRM2jTg=
|
||||
github.com/caddyserver/certmagic v0.21.3 h1:pqRRry3yuB4CWBVq9+cUqu+Y6E2z8TswbhNx1AZeYm0=
|
||||
github.com/caddyserver/certmagic v0.21.3/go.mod h1:Zq6pklO9nVRl3DIFUw9gVUfXKdpc/0qwTUAQMBlfgtI=
|
||||
github.com/caddyserver/zerossl v0.1.3 h1:onS+pxp3M8HnHpN5MMbOMyNjmTheJyWRaZYwn+YTAyA=
|
||||
github.com/caddyserver/zerossl v0.1.3/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
|
||||
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
@@ -164,8 +171,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.20.0 h1:h4n6DOCppEMpWERzllyNkntl7JrDyxoE543KWS6BLpc=
|
||||
github.com/google/cel-go v0.20.0/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
|
||||
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
|
||||
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
|
||||
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=
|
||||
@@ -174,8 +181,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
|
||||
github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47QWKfU=
|
||||
github.com/google/go-tpm-tools v0.4.2 h1:iyaCPKt2N5Rd0yz0G8ANa022SgCNZkMpp+db6QELtvI=
|
||||
github.com/google/go-tpm-tools v0.4.2/go.mod h1:fGUDZu4tw3V4hUVuFHmiYgRd0c58/IXivn9v3Ea/ck4=
|
||||
github.com/google/go-tpm-tools v0.4.4 h1:oiQfAIkc6xTy9Fl5NKTeTJkBTlXdHsxAofmQyxBKY98=
|
||||
github.com/google/go-tpm-tools v0.4.4/go.mod h1:T8jXkp2s+eltnCDIsXR84/MTcVU9Ja7bh3Mit0pa4AY=
|
||||
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/pprof v0.0.0-20231212022811-ec68065c825e h1:bwOy7hAFd0C91URzMIEBfr6BAz29yk7Qj0cy6S7DJlU=
|
||||
@@ -188,8 +195,8 @@ 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.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
|
||||
github.com/googleapis/gax-go/v2 v2.12.4 h1:9gWcmF85Wvq4ryPFvGFaOgPIs1AQX0d0bcbGw4Z96qg=
|
||||
github.com/googleapis/gax-go/v2 v2.12.4/go.mod h1:KYEYLorsnIGDi/rPC8b5TdlB9kbKoFubselGIoBMCwI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
@@ -253,11 +260,11 @@ github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
|
||||
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
@@ -275,8 +282,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
|
||||
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
|
||||
github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s=
|
||||
github.com/libdns/libdns v0.2.2/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
||||
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
|
||||
@@ -292,10 +299,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 v1.2.0 h1:1hhLxSgY5FvH5HCnGUuwbKY2VQVo8IU7rxXKSnZ7F30=
|
||||
github.com/mholt/acmez v1.2.0/go.mod h1:VT9YwH1xgNX1kmYY89gY8xPJC84BFAisjo8Egigt4kE=
|
||||
github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo=
|
||||
github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
|
||||
github.com/mholt/acmez/v2 v2.0.1 h1:3/3N0u1pLjMK4sNEAFSI+bcvzbPhRpY383sy1kLHJ6k=
|
||||
github.com/mholt/acmez/v2 v2.0.1/go.mod h1:fX4c9r5jYwMyMsC+7tkYRxHibkOTgta5DIFGoe67e1U=
|
||||
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
|
||||
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
|
||||
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
||||
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=
|
||||
@@ -322,8 +329,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
||||
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
|
||||
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
|
||||
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
||||
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
||||
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||
@@ -332,8 +339,8 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
|
||||
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
|
||||
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
|
||||
github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM=
|
||||
github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M=
|
||||
github.com/quic-go/quic-go v0.44.0 h1:So5wOr7jyO4vzL2sd8/pD9Kesciv91zSk8BoFngItQ0=
|
||||
github.com/quic-go/quic-go v0.44.0/go.mod h1:z4cx/9Ny9UtGITIPzmPTXh1ULfOyWh4qGQlpnPcWmek=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
@@ -362,12 +369,12 @@ github.com/slackhq/nebula v1.6.1 h1:/OCTR3abj0Sbf2nGoLUrdDXImrCv0ZVFpVPP5qa0DsM=
|
||||
github.com/slackhq/nebula v1.6.1/go.mod h1:UmkqnXe4O53QwToSl/gG7sM4BroQwAB7dd4hUaT6MlI=
|
||||
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.25.3-rc5 h1:a5ALBerbePSIxcDrrzDd4Q4iggfJt8qy1t2WIL/26RU=
|
||||
github.com/smallstep/certificates v0.25.3-rc5/go.mod h1:PI/5pMaKYcnufMK2eVmsHZOS3IAzezYeUIWu7/I2ILs=
|
||||
github.com/smallstep/certificates v0.26.1 h1:FIUliEBcExSfJJDhRFA/s8aZgMIFuorexnRSKQd884o=
|
||||
github.com/smallstep/certificates v0.26.1/go.mod h1:OQMrW39IrGKDViKSHrKcgSQArMZ8c7EcjhYKK7mYqis=
|
||||
github.com/smallstep/go-attestation v0.4.4-0.20240109183208-413678f90935 h1:kjYvkvS/Wdy0PVRDUAA0gGJIVSEZYhiAJtfwYgOYoGA=
|
||||
github.com/smallstep/go-attestation v0.4.4-0.20240109183208-413678f90935/go.mod h1:vNAduivU014fubg6ewygkAvQC0IQVXqdc8vaGl/0er4=
|
||||
github.com/smallstep/nosql v0.6.0 h1:ur7ysI8s9st0cMXnTvB8tA3+x5Eifmkb6hl4uqNV5jc=
|
||||
github.com/smallstep/nosql v0.6.0/go.mod h1:jOXwLtockXORUPPZ2MCUcIkGR6w0cN1QGZniY9DITQA=
|
||||
github.com/smallstep/nosql v0.6.1 h1:X8IBZFTRIp1gmuf23ne/jlD/BWKJtDQbtatxEn7Et1Y=
|
||||
github.com/smallstep/nosql v0.6.1/go.mod h1:vrN+CftYYNnDM+DQqd863ATynvYFm/6FuY9D4TeAm2Y=
|
||||
github.com/smallstep/pkcs7 v0.0.0-20231024181729-3b98ecc1ca81 h1:B6cED3iLJTgxpdh4tuqByDjRRKan2EvtnOfHr2zHJVg=
|
||||
github.com/smallstep/pkcs7 v0.0.0-20231024181729-3b98ecc1ca81/go.mod h1:SoUAr/4M46rZ3WaLstHxGhLEgoYIDRqxQEXLOmOEB0Y=
|
||||
github.com/smallstep/scep v0.0.0-20231024192529-aee96d7ad34d h1:06LUHn4Ia2X6syjIaCMNaXXDNdU+1N/oOHynJbWgpXw=
|
||||
@@ -408,8 +415,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tailscale/tscert v0.0.0-20230806124524-28a91b69a046 h1:8rUlviSVOEe7TMk7W0gIPrW8MqEzYfZHpsNWSf8s2vg=
|
||||
github.com/tailscale/tscert v0.0.0-20230806124524-28a91b69a046/go.mod h1:kNGUQ3VESx3VZwRwA9MSCUegIl6+saPL8Noq82ozCaU=
|
||||
github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53 h1:uxMgm0C+EjytfAqyfBG55ZONKQ7mvd7x4YYCWsf8QHQ=
|
||||
github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53/go.mod h1:kNGUQ3VESx3VZwRwA9MSCUegIl6+saPL8Noq82ozCaU=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
|
||||
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
|
||||
@@ -429,14 +436,14 @@ github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvv
|
||||
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
|
||||
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
|
||||
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
|
||||
go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI=
|
||||
go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.42.0 h1:s2RzYOAqHVgG23q8fPWYChobUoZM6rJZ98EnylJr66w=
|
||||
go.opentelemetry.io/contrib/propagators/autoprop v0.42.0/go.mod h1:Mv/tWNtZn+NbALDb2XcItP0OM3lWWZjAfSroINxfW+Y=
|
||||
go.opentelemetry.io/contrib/propagators/aws v1.17.0 h1:IX8d7l2uRw61BlmZBOTQFaK+y22j6vytMVTs9wFrO+c=
|
||||
@@ -447,24 +454,24 @@ go.opentelemetry.io/contrib/propagators/jaeger v1.17.0 h1:Zbpbmwav32Ea5jSotpmkWE
|
||||
go.opentelemetry.io/contrib/propagators/jaeger v1.17.0/go.mod h1:tcTUAlmO8nuInPDSBVfG+CP6Mzjy5+gNV4mPxMbL0IA=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.17.0 h1:ufo2Vsz8l76eI47jFjuVyjyB3Ae2DmfiCV/o6Vc8ii0=
|
||||
go.opentelemetry.io/contrib/propagators/ot v1.17.0/go.mod h1:SbKPj5XGp8K/sGm05XblaIABgMgw2jDczP8gGeuaVLk=
|
||||
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
|
||||
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
|
||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0=
|
||||
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
|
||||
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
|
||||
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
|
||||
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
|
||||
go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8=
|
||||
go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E=
|
||||
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
|
||||
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
|
||||
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
|
||||
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
|
||||
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
|
||||
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
|
||||
go.step.sm/cli-utils v0.8.0 h1:b/Tc1/m3YuQq+u3ghTFP7Dz5zUekZj6GUmd5pCvkEXQ=
|
||||
go.step.sm/cli-utils v0.8.0/go.mod h1:S77aISrC0pKuflqiDfxxJlUbiXcAanyJ4POOnzFSxD4=
|
||||
go.step.sm/crypto v0.42.1 h1:OmwHm3GJO8S4VGWL3k4+I+Q4P/F2s+j8msvTyGnh1Vg=
|
||||
go.step.sm/crypto v0.42.1/go.mod h1:yNcTLFQBnYCA75fC5bklBoTAT7y0dRZsB1TkinB8JMs=
|
||||
go.step.sm/cli-utils v0.9.0 h1:55jYcsQbnArNqepZyAwcato6Zy2MoZDRkWW+jF+aPfQ=
|
||||
go.step.sm/cli-utils v0.9.0/go.mod h1:Y/CRoWl1FVR9j+7PnAewufAwKmBOTzR6l9+7EYGAnp8=
|
||||
go.step.sm/crypto v0.45.0 h1:Z0WYAaaOYrJmKP9sJkPW+6wy3pgN3Ija8ek/D4serjc=
|
||||
go.step.sm/crypto v0.45.0/go.mod h1:6IYlT0L2jfj81nVyCPpvA5cORy0EVHPhieSgQyuwHIY=
|
||||
go.step.sm/linkedca v0.20.1 h1:bHDn1+UG1NgRrERkWbbCiAIvv4lD5NOFaswPDTyO5vU=
|
||||
go.step.sm/linkedca v0.20.1/go.mod h1:Vaq4+Umtjh7DLFI1KuIxeo598vfBzgSYZUjgVJ7Syxw=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
@@ -503,17 +510,19 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
|
||||
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20240507223354-67b13616a595 h1:TgSqweA595vD0Zt86JzLv3Pb/syKg8gd5KMGGbJPYFw=
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20240507223354-67b13616a595/go.mod h1:kNa9WdvYnzFwC79zRpLRMJbdEFlhyM5RPFBBZp/wWH8=
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
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.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
|
||||
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@@ -523,10 +532,10 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
|
||||
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
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=
|
||||
@@ -558,8 +567,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
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=
|
||||
@@ -567,8 +576,8 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
|
||||
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
|
||||
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@@ -578,8 +587,9 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -593,27 +603,25 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
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.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
|
||||
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
|
||||
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
|
||||
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.157.0 h1:ORAeqmbrrozeyw5NjnMxh7peHO0UzV4wWYSwZeCUb20=
|
||||
google.golang.org/api v0.157.0/go.mod h1:+z4v4ufbZ1WEpld6yMGHyggs+PmAHiaLNj5ytP3N01g=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 h1:rIo7ocm2roD9DcFIX67Ym8icoGCKSARAiPljFhh5suQ=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
|
||||
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
|
||||
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
google.golang.org/api v0.180.0 h1:M2D87Yo0rGBPWpo1orwfCLehUUL6E7/TYe5gvMQWDh4=
|
||||
google.golang.org/api v0.180.0/go.mod h1:51AiyoEg1MJPSZ9zvklA8VnRILPXxn1iVen9v25XHAE=
|
||||
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda h1:wu/KJm9KJwpfHWhkkZGohVC6KRrc1oJNr4jwtQMOQXw=
|
||||
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda/go.mod h1:g2LLCvCeCSir/JJSWosk19BR4NVxGqHUC6rxIRsd7Aw=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae h1:AH34z6WAGVNkllnKs5raNq3yRq93VnjBG6rpfub/jYk=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:FfiGhwUm6CJviekPrc0oJ+7h29e+DmWU6UtjX0ZvI7Y=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
|
||||
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
|
||||
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
+8
-8
@@ -149,11 +149,11 @@ func (na NetworkAddress) Listen(ctx context.Context, portOffset uint, config net
|
||||
|
||||
func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net.ListenConfig) (any, error) {
|
||||
var (
|
||||
ln any
|
||||
err error
|
||||
address string
|
||||
unixFileMode fs.FileMode
|
||||
isAbtractUnixSocket bool
|
||||
ln any
|
||||
err error
|
||||
address string
|
||||
unixFileMode fs.FileMode
|
||||
isAbstractUnixSocket bool
|
||||
)
|
||||
|
||||
// split unix socket addr early so lnKey
|
||||
@@ -164,7 +164,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isAbtractUnixSocket = strings.HasPrefix(address, "@")
|
||||
isAbstractUnixSocket = strings.HasPrefix(address, "@")
|
||||
} else {
|
||||
address = na.JoinHostPort(portOffset)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
|
||||
// if this is a unix socket, see if we already have it open,
|
||||
// force socket permissions on it and return early
|
||||
if socket, err := reuseUnixSocket(na.Network, address); socket != nil || err != nil {
|
||||
if !isAbtractUnixSocket {
|
||||
if !isAbstractUnixSocket {
|
||||
if err := os.Chmod(address, unixFileMode); err != nil {
|
||||
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
|
||||
}
|
||||
|
||||
if IsUnixNetwork(na.Network) {
|
||||
if !isAbtractUnixSocket {
|
||||
if !isAbstractUnixSocket {
|
||||
if err := os.Chmod(address, unixFileMode); err != nil {
|
||||
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
|
||||
}
|
||||
|
||||
+21
-2
@@ -16,6 +16,7 @@ package caddy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -292,6 +293,10 @@ type BaseLog struct {
|
||||
// The encoder is how the log entries are formatted or encoded.
|
||||
EncoderRaw json.RawMessage `json:"encoder,omitempty" caddy:"namespace=caddy.logging.encoders inline_key=format"`
|
||||
|
||||
// Tees entries through a zap.Core module which can extract
|
||||
// log entry metadata and fields for further processing.
|
||||
CoreRaw json.RawMessage `json:"core,omitempty" caddy:"namespace=caddy.logging.cores inline_key=module"`
|
||||
|
||||
// Level is the minimum level to emit, and is inclusive.
|
||||
// Possible levels: DEBUG, INFO, WARN, ERROR, PANIC, and FATAL
|
||||
Level string `json:"level,omitempty"`
|
||||
@@ -366,13 +371,21 @@ func (cl *BaseLog) provisionCommon(ctx Context, logging *Logging) error {
|
||||
cl.encoder = newDefaultProductionLogEncoder(cl.writerOpener)
|
||||
}
|
||||
cl.buildCore()
|
||||
if cl.CoreRaw != nil {
|
||||
mod, err := ctx.LoadModule(cl, "CoreRaw")
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading log core module: %v", err)
|
||||
}
|
||||
core := mod.(zapcore.Core)
|
||||
cl.core = zapcore.NewTee(cl.core, core)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cl *BaseLog) buildCore() {
|
||||
// logs which only discard their output don't need
|
||||
// to perform encoding or any other processing steps
|
||||
// at all, so just shorcut to a nop core instead
|
||||
// at all, so just shortcut to a nop core instead
|
||||
if _, ok := cl.writerOpener.(*DiscardWriter); ok {
|
||||
cl.core = zapcore.NewNopCore()
|
||||
return
|
||||
@@ -687,7 +700,13 @@ type defaultCustomLog struct {
|
||||
// and enables INFO-level logs and higher.
|
||||
func newDefaultProductionLog() (*defaultCustomLog, error) {
|
||||
cl := new(CustomLog)
|
||||
cl.writerOpener = StderrWriter{}
|
||||
f := flag.Lookup("test.v")
|
||||
if (f != nil && f.Value.String() != "true") || strings.Contains(os.Args[0], ".test") {
|
||||
cl.writerOpener = &DiscardWriter{}
|
||||
} else {
|
||||
cl.writerOpener = StderrWriter{}
|
||||
}
|
||||
|
||||
var err error
|
||||
cl.writer, err = cl.writerOpener.OpenWriter()
|
||||
if err != nil {
|
||||
|
||||
@@ -261,7 +261,9 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) E
|
||||
return nil, false
|
||||
})
|
||||
|
||||
logger.Debug("event", zap.Any("data", e.Data))
|
||||
logger = logger.With(zap.Any("data", e.Data))
|
||||
|
||||
logger.Debug("event")
|
||||
|
||||
// invoke handlers bound to the event by name and also all events; this for loop
|
||||
// iterates twice at most: once for the event name, once for "" (all events)
|
||||
@@ -282,6 +284,12 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) E
|
||||
default:
|
||||
}
|
||||
|
||||
// this log can be a useful sanity check to ensure your handlers are in fact being invoked
|
||||
// (see https://github.com/mholt/caddy-events-exec/issues/6)
|
||||
logger.Debug("invoking subscribed handler",
|
||||
zap.String("subscribed_to", eventName),
|
||||
zap.Any("handler", handler))
|
||||
|
||||
if err := handler.Handle(ctx, e); err != nil {
|
||||
aborted := errors.Is(err, ErrAborted)
|
||||
|
||||
@@ -347,6 +355,11 @@ type Event struct {
|
||||
origin caddy.Module
|
||||
}
|
||||
|
||||
func (e Event) ID() uuid.UUID { return e.id }
|
||||
func (e Event) Timestamp() time.Time { return e.ts }
|
||||
func (e Event) Name() string { return e.name }
|
||||
func (e Event) Origin() caddy.Module { return e.origin }
|
||||
|
||||
// CloudEvent exports event e as a structure that, when
|
||||
// serialized as JSON, is compatible with the
|
||||
// CloudEvents spec.
|
||||
|
||||
@@ -72,7 +72,7 @@ func (xs *Filesystems) Provision(ctx caddy.Context) error {
|
||||
ctx.Filesystems().Register(f.Key, f.fileSystem)
|
||||
// remember to unregister the module when we are done
|
||||
xs.defers = append(xs.defers, func() {
|
||||
ctx.Logger().Debug("registering fs", zap.String("fs", f.Key))
|
||||
ctx.Logger().Debug("unregistering fs", zap.String("fs", f.Key))
|
||||
ctx.Filesystems().Unregister(f.Key)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -198,6 +198,9 @@ func (app *App) Provision(ctx caddy.Context) error {
|
||||
// only enable access logs if configured
|
||||
if srv.Logs != nil {
|
||||
srv.accessLogger = app.logger.Named("log.access")
|
||||
if srv.Logs.Trace {
|
||||
srv.traceLogger = app.logger.Named("log.trace")
|
||||
}
|
||||
}
|
||||
|
||||
// the Go standard library does not let us serve only HTTP/2 using
|
||||
@@ -329,9 +332,10 @@ func (app *App) Provision(ctx caddy.Context) error {
|
||||
|
||||
// Validate ensures the app's configuration is valid.
|
||||
func (app *App) Validate() error {
|
||||
// each server must use distinct listener addresses
|
||||
lnAddrs := make(map[string]string)
|
||||
|
||||
for srvName, srv := range app.Servers {
|
||||
// each server must use distinct listener addresses
|
||||
for _, addr := range srv.Listen {
|
||||
listenAddr, err := caddy.ParseNetworkAddress(addr)
|
||||
if err != nil {
|
||||
@@ -347,6 +351,15 @@ func (app *App) Validate() error {
|
||||
lnAddrs[addr] = srvName
|
||||
}
|
||||
}
|
||||
|
||||
// logger names must not have ports
|
||||
if srv.Logs != nil {
|
||||
for host := range srv.Logs.LoggerNames {
|
||||
if _, _, err := net.SplitHostPort(host); err == nil {
|
||||
return fmt.Errorf("server %s: logger name must not have a port: %s", srvName, host)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -526,7 +539,7 @@ func (app *App) Stop() error {
|
||||
ctx := context.Background()
|
||||
|
||||
// see if any listeners in our config will be closing or if they are continuing
|
||||
// hrough a reload; because if any are closing, we will enforce shutdown delay
|
||||
// through a reload; because if any are closing, we will enforce shutdown delay
|
||||
var delay bool
|
||||
scheduledTime := time.Now().Add(time.Duration(app.ShutdownDelay))
|
||||
if app.ShutdownDelay > 0 {
|
||||
|
||||
@@ -117,7 +117,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
|
||||
srv.AutoHTTPS = new(AutoHTTPSConfig)
|
||||
}
|
||||
if srv.AutoHTTPS.Disabled {
|
||||
logger.Warn("automatic HTTPS is completely disabled for server", zap.String("server_name", srvName))
|
||||
logger.Info("automatic HTTPS is completely disabled for server", zap.String("server_name", srvName))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
|
||||
|
||||
// nothing left to do if auto redirects are disabled
|
||||
if srv.AutoHTTPS.DisableRedir {
|
||||
logger.Warn("automatic HTTP->HTTPS redirects are disabled", zap.String("server_name", srvName))
|
||||
logger.Info("automatic HTTP->HTTPS redirects are disabled", zap.String("server_name", srvName))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
|
||||
// port, we'll have to choose one, so prefer the HTTPS port
|
||||
if _, ok := redirDomains[d]; !ok ||
|
||||
addr.StartPort == uint(app.httpsPort()) {
|
||||
redirDomains[d] = []caddy.NetworkAddress{addr}
|
||||
redirDomains[d] = append(redirDomains[d], addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,6 +287,16 @@ uniqueDomainsLoop:
|
||||
for _, ap := range app.tlsApp.Automation.Policies {
|
||||
for _, apHost := range ap.Subjects() {
|
||||
if apHost == d {
|
||||
// if the automation policy has all internal subjects but no issuers,
|
||||
// it will default to CertMagic's issuers which are public CAs; use
|
||||
// our internal issuer instead
|
||||
if len(ap.Issuers) == 0 && ap.AllInternalSubjects() {
|
||||
iss := new(caddytls.InternalIssuer)
|
||||
if err := iss.Provision(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ap.Issuers = append(ap.Issuers, iss)
|
||||
}
|
||||
continue uniqueDomainsLoop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,10 @@ type MiddlewareHandler interface {
|
||||
}
|
||||
|
||||
// emptyHandler is used as a no-op handler.
|
||||
var emptyHandler Handler = HandlerFunc(func(http.ResponseWriter, *http.Request) error { return nil })
|
||||
var emptyHandler Handler = HandlerFunc(func(_ http.ResponseWriter, req *http.Request) error {
|
||||
SetVar(req.Context(), "unhandled", true)
|
||||
return nil
|
||||
})
|
||||
|
||||
// An implicit suffix middleware that, if reached, sets the StatusCode to the
|
||||
// error stored in the ErrorCtxKey. This is to prevent situations where the
|
||||
@@ -120,7 +123,7 @@ type ResponseHandler struct {
|
||||
Routes RouteList `json:"routes,omitempty"`
|
||||
}
|
||||
|
||||
// Provision sets up the routse in rh.
|
||||
// Provision sets up the routes in rh.
|
||||
func (rh *ResponseHandler) Provision(ctx caddy.Context) error {
|
||||
if rh.Routes != nil {
|
||||
err := rh.Routes.Provision(ctx)
|
||||
@@ -226,13 +229,22 @@ func StatusCodeMatches(actual, configured int) bool {
|
||||
// in the implementation of http.Dir. The root is assumed to
|
||||
// be a trusted path, but reqPath is not; and the output will
|
||||
// never be outside of root. The resulting path can be used
|
||||
// with the local file system.
|
||||
// with the local file system. If root is empty, the current
|
||||
// directory is assumed. If the cleaned request path is deemed
|
||||
// not local according to lexical processing (i.e. ignoring links),
|
||||
// it will be rejected as unsafe and only the root will be returned.
|
||||
func SanitizedPathJoin(root, reqPath string) string {
|
||||
if root == "" {
|
||||
root = "."
|
||||
}
|
||||
|
||||
path := filepath.Join(root, path.Clean("/"+reqPath))
|
||||
relPath := path.Clean("/" + reqPath)[1:] // clean path and trim the leading /
|
||||
if relPath != "" && !filepath.IsLocal(relPath) {
|
||||
// path is unsafe (see https://github.com/golang/go/issues/56336#issuecomment-1416214885)
|
||||
return root
|
||||
}
|
||||
|
||||
path := filepath.Join(root, filepath.FromSlash(relPath))
|
||||
|
||||
// filepath.Join also cleans the path, and cleaning strips
|
||||
// the trailing slash, so we need to re-add it afterwards.
|
||||
|
||||
@@ -3,6 +3,7 @@ package caddyhttp
|
||||
import (
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -12,9 +13,10 @@ func TestSanitizedPathJoin(t *testing.T) {
|
||||
// %2f = /
|
||||
// %5c = \
|
||||
for i, tc := range []struct {
|
||||
inputRoot string
|
||||
inputPath string
|
||||
expect string
|
||||
inputRoot string
|
||||
inputPath string
|
||||
expect string
|
||||
expectWindows string
|
||||
}{
|
||||
{
|
||||
inputPath: "",
|
||||
@@ -24,22 +26,28 @@ func TestSanitizedPathJoin(t *testing.T) {
|
||||
inputPath: "/",
|
||||
expect: ".",
|
||||
},
|
||||
{
|
||||
// fileserver.MatchFile passes an inputPath of "//" for some try_files values.
|
||||
// See https://github.com/caddyserver/caddy/issues/6352
|
||||
inputPath: "//",
|
||||
expect: filepath.FromSlash("./"),
|
||||
},
|
||||
{
|
||||
inputPath: "/foo",
|
||||
expect: "foo",
|
||||
},
|
||||
{
|
||||
inputPath: "/foo/",
|
||||
expect: "foo" + separator,
|
||||
expect: filepath.FromSlash("foo/"),
|
||||
},
|
||||
{
|
||||
inputPath: "/foo/bar",
|
||||
expect: filepath.Join("foo", "bar"),
|
||||
expect: filepath.FromSlash("foo/bar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "/a",
|
||||
inputPath: "/foo/bar",
|
||||
expect: filepath.Join("/", "a", "foo", "bar"),
|
||||
expect: filepath.FromSlash("/a/foo/bar"),
|
||||
},
|
||||
{
|
||||
inputPath: "/foo/../bar",
|
||||
@@ -48,32 +56,34 @@ func TestSanitizedPathJoin(t *testing.T) {
|
||||
{
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/foo/../bar",
|
||||
expect: filepath.Join("/", "a", "b", "bar"),
|
||||
expect: filepath.FromSlash("/a/b/bar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/..%2fbar",
|
||||
expect: filepath.Join("/", "a", "b", "bar"),
|
||||
expect: filepath.FromSlash("/a/b/bar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/%2e%2e%2fbar",
|
||||
expect: filepath.Join("/", "a", "b", "bar"),
|
||||
expect: filepath.FromSlash("/a/b/bar"),
|
||||
},
|
||||
{
|
||||
// inputPath fails the IsLocal test so only the root is returned,
|
||||
// but with a trailing slash since one was included in inputPath
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/%2e%2e%2f%2e%2e%2f",
|
||||
expect: filepath.Join("/", "a", "b") + separator,
|
||||
expect: filepath.FromSlash("/a/b/"),
|
||||
},
|
||||
{
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/foo%2fbar",
|
||||
expect: filepath.Join("/", "a", "b", "foo", "bar"),
|
||||
expect: filepath.FromSlash("/a/b/foo/bar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "/a/b",
|
||||
inputPath: "/foo%252fbar",
|
||||
expect: filepath.Join("/", "a", "b", "foo%2fbar"),
|
||||
expect: filepath.FromSlash("/a/b/foo%2fbar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "C:\\www",
|
||||
@@ -81,9 +91,40 @@ func TestSanitizedPathJoin(t *testing.T) {
|
||||
expect: filepath.Join("C:\\www", "foo", "bar"),
|
||||
},
|
||||
{
|
||||
inputRoot: "C:\\www",
|
||||
inputPath: "/D:\\foo\\bar",
|
||||
expect: filepath.Join("C:\\www", "D:\\foo\\bar"),
|
||||
inputRoot: "C:\\www",
|
||||
inputPath: "/D:\\foo\\bar",
|
||||
expect: filepath.Join("C:\\www", "D:\\foo\\bar"),
|
||||
expectWindows: "C:\\www", // inputPath fails IsLocal on Windows
|
||||
},
|
||||
{
|
||||
inputRoot: `C:\www`,
|
||||
inputPath: `/..\windows\win.ini`,
|
||||
expect: `C:\www/..\windows\win.ini`,
|
||||
expectWindows: `C:\www`,
|
||||
},
|
||||
{
|
||||
inputRoot: `C:\www`,
|
||||
inputPath: `/..\..\..\..\..\..\..\..\..\..\windows\win.ini`,
|
||||
expect: `C:\www/..\..\..\..\..\..\..\..\..\..\windows\win.ini`,
|
||||
expectWindows: `C:\www`,
|
||||
},
|
||||
{
|
||||
inputRoot: `C:\www`,
|
||||
inputPath: `/..%5cwindows%5cwin.ini`,
|
||||
expect: `C:\www/..\windows\win.ini`,
|
||||
expectWindows: `C:\www`,
|
||||
},
|
||||
{
|
||||
inputRoot: `C:\www`,
|
||||
inputPath: `/..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5cwindows%5cwin.ini`,
|
||||
expect: `C:\www/..\..\..\..\..\..\..\..\..\..\windows\win.ini`,
|
||||
expectWindows: `C:\www`,
|
||||
},
|
||||
{
|
||||
// https://github.com/golang/go/issues/56336#issuecomment-1416214885
|
||||
inputRoot: "root",
|
||||
inputPath: "/a/b/../../c",
|
||||
expect: filepath.FromSlash("root/c"),
|
||||
},
|
||||
} {
|
||||
// we don't *need* to use an actual parsed URL, but it
|
||||
@@ -96,6 +137,9 @@ func TestSanitizedPathJoin(t *testing.T) {
|
||||
t.Fatalf("Test %d: invalid URL: %v", i, err)
|
||||
}
|
||||
actual := SanitizedPathJoin(tc.inputRoot, u.Path)
|
||||
if runtime.GOOS == "windows" && tc.expectWindows != "" {
|
||||
tc.expect = tc.expectWindows
|
||||
}
|
||||
if actual != tc.expect {
|
||||
t.Errorf("Test %d: SanitizedPathJoin('%s', '%s') => '%s' (expected '%s')",
|
||||
i, tc.inputRoot, tc.inputPath, actual, tc.expect)
|
||||
|
||||
@@ -62,7 +62,12 @@ type MatchExpression struct {
|
||||
// The CEL expression to evaluate. Any Caddy placeholders
|
||||
// will be expanded and situated into proper CEL function
|
||||
// calls before evaluating.
|
||||
Expr string
|
||||
Expr string `json:"expr,omitempty"`
|
||||
|
||||
// Name is an optional name for this matcher.
|
||||
// This is used to populate the name for regexp
|
||||
// matchers that appear in the expression.
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
expandedExpr string
|
||||
prg cel.Program
|
||||
@@ -81,12 +86,36 @@ func (MatchExpression) CaddyModule() caddy.ModuleInfo {
|
||||
|
||||
// MarshalJSON marshals m's expression.
|
||||
func (m MatchExpression) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(m.Expr)
|
||||
// if the name is empty, then we can marshal just the expression string
|
||||
if m.Name == "" {
|
||||
return json.Marshal(m.Expr)
|
||||
}
|
||||
// otherwise, we need to marshal the full object, using an
|
||||
// anonymous struct to avoid infinite recursion
|
||||
return json.Marshal(struct {
|
||||
Expr string `json:"expr"`
|
||||
Name string `json:"name"`
|
||||
}{
|
||||
Expr: m.Expr,
|
||||
Name: m.Name,
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals m's expression.
|
||||
func (m *MatchExpression) UnmarshalJSON(data []byte) error {
|
||||
return json.Unmarshal(data, &m.Expr)
|
||||
// if the data is a string, then it's just the expression
|
||||
if data[0] == '"' {
|
||||
return json.Unmarshal(data, &m.Expr)
|
||||
}
|
||||
// otherwise, it's a full object, so unmarshal it,
|
||||
// using an temp map to avoid infinite recursion
|
||||
var tmpJson map[string]any
|
||||
err := json.Unmarshal(data, &tmpJson)
|
||||
*m = MatchExpression{
|
||||
Expr: tmpJson["expr"].(string),
|
||||
Name: tmpJson["name"].(string),
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Provision sets ups m.
|
||||
@@ -109,6 +138,11 @@ func (m *MatchExpression) Provision(ctx caddy.Context) error {
|
||||
matcherLibProducers = append(matcherLibProducers, p)
|
||||
}
|
||||
}
|
||||
|
||||
// add the matcher name to the context so that the matcher name
|
||||
// can be used by regexp matchers being provisioned
|
||||
ctx = ctx.WithValue(MatcherNameCtxKey, m.Name)
|
||||
|
||||
// Assemble the compilation and program options from the different library
|
||||
// producers into a single cel.Library implementation.
|
||||
matcherEnvOpts := []cel.EnvOption{}
|
||||
@@ -197,6 +231,11 @@ func (m *MatchExpression) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
// quoted string; commonly quotes are used in Caddyfile to
|
||||
// define the expression
|
||||
m.Expr = d.Val()
|
||||
|
||||
// use the named matcher's name, to fill regexp
|
||||
// matchers names by default
|
||||
m.Name = d.GetContextString(caddyfile.MatcherNameCtxKey)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -673,6 +712,8 @@ var httpRequestObjectType = cel.ObjectType("http.Request")
|
||||
// The name of the CEL function which accesses Replacer values.
|
||||
const placeholderFuncName = "caddyPlaceholder"
|
||||
|
||||
const MatcherNameCtxKey = "matcher_name"
|
||||
|
||||
// Interface guards
|
||||
var (
|
||||
_ caddy.Provisioner = (*MatchExpression)(nil)
|
||||
|
||||
@@ -380,7 +380,9 @@ func TestMatchExpressionMatch(t *testing.T) {
|
||||
for _, tst := range matcherTests {
|
||||
tc := tst
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.expression.Provision(caddy.Context{})
|
||||
caddyCtx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
err := tc.expression.Provision(caddyCtx)
|
||||
if err != nil {
|
||||
if !tc.wantErr {
|
||||
t.Errorf("MatchExpression.Provision() error = %v, wantErr %v", err, tc.wantErr)
|
||||
@@ -482,7 +484,9 @@ func TestMatchExpressionProvision(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := tt.expression.Provision(caddy.Context{}); (err != nil) != tt.wantErr {
|
||||
ctx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
if err := tt.expression.Provision(ctx); (err != nil) != tt.wantErr {
|
||||
t.Errorf("MatchExpression.Provision() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -156,6 +156,21 @@ func (enc *Encode) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyh
|
||||
}
|
||||
w = enc.openResponseWriter(encName, w)
|
||||
defer w.(*responseWriter).Close()
|
||||
|
||||
// to comply with RFC 9110 section 8.8.3(.3), we modify the Etag when encoding
|
||||
// by appending a hyphen and the encoder name; the problem is, the client will
|
||||
// send back that Etag in a If-None-Match header, but upstream handlers that set
|
||||
// the Etag in the first place don't know that we appended to their Etag! so here
|
||||
// we have to strip our addition so the upstream handlers can still honor client
|
||||
// caches without knowing about our changes...
|
||||
if etag := r.Header.Get("If-None-Match"); etag != "" && !strings.HasPrefix(etag, "W/") {
|
||||
ourSuffix := "-" + encName + `"`
|
||||
if strings.HasSuffix(etag, ourSuffix) {
|
||||
etag = strings.TrimSuffix(etag, ourSuffix) + `"`
|
||||
r.Header.Set("If-None-Match", etag)
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -220,6 +235,14 @@ type responseWriter struct {
|
||||
func (rw *responseWriter) WriteHeader(status int) {
|
||||
rw.statusCode = status
|
||||
|
||||
// See #5849 and RFC 9110 section 15.4.5 (https://www.rfc-editor.org/rfc/rfc9110.html#section-15.4.5) - 304
|
||||
// Not Modified must have certain headers set as if it was a 200 response, and according to the issue
|
||||
// we would miss the Vary header in this case when compression was also enabled; note that we set this
|
||||
// header in the responseWriter.init() method but that is only called if we are writing a response body
|
||||
if status == http.StatusNotModified && !hasVaryValue(rw.Header(), "Accept-Encoding") {
|
||||
rw.Header().Add("Vary", "Accept-Encoding")
|
||||
}
|
||||
|
||||
// write status immediately when status code is informational
|
||||
// see: https://caddy.community/t/disappear-103-early-hints-response-with-encode-enable-caddy-v2-7-6/23081/5
|
||||
if 100 <= status && status <= 199 {
|
||||
@@ -326,17 +349,44 @@ func (rw *responseWriter) Unwrap() http.ResponseWriter {
|
||||
|
||||
// init should be called before we write a response, if rw.buf has contents.
|
||||
func (rw *responseWriter) init() {
|
||||
if rw.Header().Get("Content-Encoding") == "" && isEncodeAllowed(rw.Header()) &&
|
||||
hdr := rw.Header()
|
||||
if hdr.Get("Content-Encoding") == "" && isEncodeAllowed(hdr) &&
|
||||
rw.config.Match(rw) {
|
||||
rw.w = rw.config.writerPools[rw.encodingName].Get().(Encoder)
|
||||
rw.w.Reset(rw.ResponseWriter)
|
||||
rw.Header().Del("Content-Length") // https://github.com/golang/go/issues/14975
|
||||
rw.Header().Set("Content-Encoding", rw.encodingName)
|
||||
rw.Header().Add("Vary", "Accept-Encoding")
|
||||
rw.Header().Del("Accept-Ranges") // we don't know ranges for dynamically-encoded content
|
||||
hdr.Del("Content-Length") // https://github.com/golang/go/issues/14975
|
||||
hdr.Set("Content-Encoding", rw.encodingName)
|
||||
if !hasVaryValue(hdr, "Accept-Encoding") {
|
||||
hdr.Add("Vary", "Accept-Encoding")
|
||||
}
|
||||
hdr.Del("Accept-Ranges") // we don't know ranges for dynamically-encoded content
|
||||
|
||||
// strong ETags need to be distinct depending on the encoding ("selected representation")
|
||||
// see RFC 9110 section 8.8.3.3:
|
||||
// https://www.rfc-editor.org/rfc/rfc9110.html#name-example-entity-tags-varying
|
||||
// I don't know a great way to do this... how about appending? That's a neat trick!
|
||||
// (We have to strip the value we append from If-None-Match headers before
|
||||
// sending subsequent requests back upstream, however, since upstream handlers
|
||||
// don't know about our appending to their Etag since they've already done their work)
|
||||
if etag := hdr.Get("Etag"); etag != "" && !strings.HasPrefix(etag, "W/") {
|
||||
etag = fmt.Sprintf(`%s-%s"`, strings.TrimSuffix(etag, `"`), rw.encodingName)
|
||||
hdr.Set("Etag", etag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hasVaryValue(hdr http.Header, target string) bool {
|
||||
for _, vary := range hdr.Values("Vary") {
|
||||
vals := strings.Split(vary, ",")
|
||||
for _, val := range vals {
|
||||
if strings.EqualFold(strings.TrimSpace(val), target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// AcceptedEncodings returns the list of encodings that the
|
||||
// client supports, in descending order of preference.
|
||||
// The client preference via q-factor and the server
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package caddyzstd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/klauspost/compress/zstd"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
@@ -27,7 +29,13 @@ func init() {
|
||||
}
|
||||
|
||||
// Zstd can create Zstandard encoders.
|
||||
type Zstd struct{}
|
||||
type Zstd struct {
|
||||
// The compression level. Accepted values: fastest, better, best, default.
|
||||
Level string `json:"level,omitempty"`
|
||||
|
||||
// Compression level refer to type constants value from zstd.SpeedFastest to zstd.SpeedBestCompression
|
||||
level zstd.EncoderLevel
|
||||
}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
func (Zstd) CaddyModule() caddy.ModuleInfo {
|
||||
@@ -39,6 +47,37 @@ func (Zstd) CaddyModule() caddy.ModuleInfo {
|
||||
|
||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens.
|
||||
func (z *Zstd) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
d.Next() // consume option name
|
||||
if !d.NextArg() {
|
||||
return nil
|
||||
}
|
||||
levelStr := d.Val()
|
||||
if ok, _ := zstd.EncoderLevelFromString(levelStr); !ok {
|
||||
return d.Errf("unexpected compression level, use one of '%s', '%s', '%s', '%s'",
|
||||
zstd.SpeedFastest,
|
||||
zstd.SpeedBetterCompression,
|
||||
zstd.SpeedBestCompression,
|
||||
zstd.SpeedDefault,
|
||||
)
|
||||
}
|
||||
z.Level = levelStr
|
||||
return nil
|
||||
}
|
||||
|
||||
// Provision provisions z's configuration.
|
||||
func (z *Zstd) Provision(ctx caddy.Context) error {
|
||||
if z.Level == "" {
|
||||
z.Level = zstd.SpeedDefault.String()
|
||||
}
|
||||
var ok bool
|
||||
if ok, z.level = zstd.EncoderLevelFromString(z.Level); !ok {
|
||||
return fmt.Errorf("unexpected compression level, use one of '%s', '%s', '%s', '%s'",
|
||||
zstd.SpeedFastest,
|
||||
zstd.SpeedDefault,
|
||||
zstd.SpeedBetterCompression,
|
||||
zstd.SpeedBestCompression,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -51,7 +90,13 @@ func (z Zstd) NewEncoder() encode.Encoder {
|
||||
// The default of 8MB for the window is
|
||||
// too large for many clients, so we limit
|
||||
// it to 128K to lighten their load.
|
||||
writer, _ := zstd.NewWriter(nil, zstd.WithWindowSize(128<<10), zstd.WithEncoderConcurrency(1), zstd.WithZeroFrames(true))
|
||||
writer, _ := zstd.NewWriter(
|
||||
nil,
|
||||
zstd.WithWindowSize(128<<10),
|
||||
zstd.WithEncoderConcurrency(1),
|
||||
zstd.WithZeroFrames(true),
|
||||
zstd.WithEncoderLevel(z.level),
|
||||
)
|
||||
return writer
|
||||
}
|
||||
|
||||
@@ -59,4 +104,5 @@ func (z Zstd) NewEncoder() encode.Encoder {
|
||||
var (
|
||||
_ encode.Encoding = (*Zstd)(nil)
|
||||
_ caddyfile.Unmarshaler = (*Zstd)(nil)
|
||||
_ caddy.Provisioner = (*Zstd)(nil)
|
||||
)
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"sync"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
@@ -104,6 +105,18 @@ func (fsrv *FileServer) serveBrowse(fileSystem fs.FS, root, dirPath string, w ht
|
||||
return caddyhttp.Error(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
w.Header().Add("Vary", "Accept, Accept-Encoding")
|
||||
|
||||
// speed up browser/client experience and caching by supporting If-Modified-Since
|
||||
if ifModSinceStr := r.Header.Get("If-Modified-Since"); ifModSinceStr != "" {
|
||||
ifModSince, err := time.ParseInLocation(http.TimeFormat, ifModSinceStr, time.Local)
|
||||
lastModTrunc := listing.lastModified.Truncate(time.Second)
|
||||
if err == nil && (lastModTrunc.Equal(ifModSince) || lastModTrunc.Before(ifModSince)) {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
fsrv.browseApplyQueryParams(w, r, listing)
|
||||
|
||||
buf := bufPool.Get().(*bytes.Buffer)
|
||||
@@ -111,6 +124,7 @@ func (fsrv *FileServer) serveBrowse(fileSystem fs.FS, root, dirPath string, w ht
|
||||
defer bufPool.Put(buf)
|
||||
|
||||
acceptHeader := strings.ToLower(strings.Join(r.Header["Accept"], ","))
|
||||
w.Header().Set("Last-Modified", listing.lastModified.Format(http.TimeFormat))
|
||||
|
||||
switch {
|
||||
case strings.Contains(acceptHeader, "application/json"):
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</svg>
|
||||
{{- else if .HasExt ".jpg" ".jpeg" ".png" ".gif" ".webp" ".tiff" ".bmp" ".heif" ".heic" ".svg"}}
|
||||
{{- if eq .Tpl.Layout "grid"}}
|
||||
<img loading="lazy" src="{{html .Name}}">
|
||||
<img loading="lazy" src="{{.Name | pathEscape}}">
|
||||
{{- else}}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-photo" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||
|
||||
@@ -63,6 +63,12 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
|
||||
continue
|
||||
}
|
||||
|
||||
// keep track of the most recently modified item in the listing
|
||||
modTime := info.ModTime()
|
||||
if tplCtx.lastModified.IsZero() || modTime.After(tplCtx.lastModified) {
|
||||
tplCtx.lastModified = modTime
|
||||
}
|
||||
|
||||
isDir := entry.IsDir() || fsrv.isSymlinkTargetDir(fileSystem, info, root, urlPath)
|
||||
|
||||
// add the slash after the escape of path to avoid escaping the slash as well
|
||||
@@ -108,7 +114,7 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
|
||||
Name: name,
|
||||
Size: size,
|
||||
URL: u.String(),
|
||||
ModTime: info.ModTime().UTC(),
|
||||
ModTime: modTime.UTC(),
|
||||
Mode: info.Mode(),
|
||||
Tpl: tplCtx, // a reference up to the template context is useful
|
||||
SymlinkPath: symlinkPath,
|
||||
@@ -126,7 +132,7 @@ type browseTemplateContext struct {
|
||||
// The full path of the request.
|
||||
Path string `json:"path"`
|
||||
|
||||
// Whether the parent directory is browseable.
|
||||
// Whether the parent directory is browsable.
|
||||
CanGoUp bool `json:"can_go_up"`
|
||||
|
||||
// The items (files and folders) in the path.
|
||||
@@ -155,6 +161,10 @@ type browseTemplateContext struct {
|
||||
|
||||
// Display format (list or grid)
|
||||
Layout string `json:"layout,omitempty"`
|
||||
|
||||
// The most recent file modification date in the listing.
|
||||
// Used for HTTP header purposes.
|
||||
lastModified time.Time
|
||||
}
|
||||
|
||||
// Breadcrumbs returns l.Path where every element maps
|
||||
|
||||
@@ -164,6 +164,13 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
}
|
||||
fsrv.PassThru = true
|
||||
|
||||
case "etag_file_extensions":
|
||||
etagFileExtensions := d.RemainingArgs()
|
||||
if len(etagFileExtensions) == 0 {
|
||||
return d.ArgErr()
|
||||
}
|
||||
fsrv.EtagFileExtensions = etagFileExtensions
|
||||
|
||||
default:
|
||||
return d.Errf("unknown subdirective '%s'", d.Val())
|
||||
}
|
||||
|
||||
@@ -360,7 +360,9 @@ func TestMatchExpressionMatch(t *testing.T) {
|
||||
for _, tst := range expressionTests {
|
||||
tc := tst
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.expression.Provision(caddy.Context{})
|
||||
caddyCtx, cancel := caddy.NewContext(caddy.Context{Context: context.Background()})
|
||||
defer cancel()
|
||||
err := tc.expression.Provision(caddyCtx)
|
||||
if err != nil {
|
||||
if !tc.wantErr {
|
||||
t.Errorf("MatchExpression.Provision() error = %v, wantErr %v", err, tc.wantErr)
|
||||
|
||||
@@ -60,7 +60,7 @@ func init() {
|
||||
// 404 response. Alternatively, file browsing can be enabled with
|
||||
// the "browse" parameter which shows a list of files when directories
|
||||
// are requested if no index file is present. If "browse" is enabled,
|
||||
// Caddy may serve a JSON array of the dirctory listing when the `Accept`
|
||||
// Caddy may serve a JSON array of the directory listing when the `Accept`
|
||||
// header mentions `application/json` with the following structure:
|
||||
//
|
||||
// [{
|
||||
@@ -161,6 +161,12 @@ type FileServer struct {
|
||||
PrecompressedOrder []string `json:"precompressed_order,omitempty"`
|
||||
precompressors map[string]encode.Precompressed
|
||||
|
||||
// List of file extensions to try to read Etags from.
|
||||
// If set, file Etags will be read from sidecar files
|
||||
// with any of these suffixes, instead of generating
|
||||
// our own Etag.
|
||||
EtagFileExtensions []string `json:"etag_file_extensions,omitempty"`
|
||||
|
||||
fsmap caddy.FileSystems
|
||||
|
||||
logger *zap.Logger
|
||||
@@ -365,9 +371,17 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||
}
|
||||
|
||||
var file fs.File
|
||||
respHeader := w.Header()
|
||||
|
||||
// etag is usually unset, but if the user knows what they're doing, let them override it
|
||||
etag := w.Header().Get("Etag")
|
||||
etag := respHeader.Get("Etag")
|
||||
|
||||
// static file responses are often compressed, either on-the-fly
|
||||
// or with precompressed sidecar files; in any case, the headers
|
||||
// should contain "Vary: Accept-Encoding" even when not compressed
|
||||
// so caches can craft a reliable key (according to REDbot results)
|
||||
// see #5849
|
||||
respHeader.Add("Vary", "Accept-Encoding")
|
||||
|
||||
// check for precompressed files
|
||||
for _, ae := range encode.AcceptedEncodings(r, fsrv.PrecompressedOrder) {
|
||||
@@ -392,9 +406,16 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||
continue
|
||||
}
|
||||
defer file.Close()
|
||||
w.Header().Set("Content-Encoding", ae)
|
||||
w.Header().Del("Accept-Ranges")
|
||||
w.Header().Add("Vary", "Accept-Encoding")
|
||||
respHeader.Set("Content-Encoding", ae)
|
||||
respHeader.Del("Accept-Ranges")
|
||||
|
||||
// try to get the etag from pre computed files if an etag suffix list was provided
|
||||
if etag == "" && fsrv.EtagFileExtensions != nil {
|
||||
etag, err = fsrv.getEtagFromFile(fileSystem, compressedFilename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// don't assign info = compressedInfo because sidecars are kind
|
||||
// of transparent; however we do need to set the Etag:
|
||||
@@ -420,7 +441,13 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||
return err // error is already structured
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// try to get the etag from pre computed files if an etag suffix list was provided
|
||||
if etag == "" && fsrv.EtagFileExtensions != nil {
|
||||
etag, err = fsrv.getEtagFromFile(fileSystem, filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if etag == "" {
|
||||
etag = calculateEtag(info)
|
||||
}
|
||||
@@ -434,7 +461,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||
// to repeat the error; just continue because we're probably
|
||||
// trying to write an error page response (see issue #5703)
|
||||
if _, ok := r.Context().Value(caddyhttp.ErrorCtxKey).(error); !ok {
|
||||
w.Header().Add("Allow", "GET, HEAD")
|
||||
respHeader.Add("Allow", "GET, HEAD")
|
||||
return caddyhttp.Error(http.StatusMethodNotAllowed, nil)
|
||||
}
|
||||
}
|
||||
@@ -442,16 +469,16 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||
// set the Etag - note that a conditional If-None-Match request is handled
|
||||
// by http.ServeContent below, which checks against this Etag value
|
||||
if etag != "" {
|
||||
w.Header().Set("Etag", etag)
|
||||
respHeader.Set("Etag", etag)
|
||||
}
|
||||
|
||||
if w.Header().Get("Content-Type") == "" {
|
||||
if respHeader.Get("Content-Type") == "" {
|
||||
mtyp := mime.TypeByExtension(filepath.Ext(filename))
|
||||
if mtyp == "" {
|
||||
// do not allow Go to sniff the content-type; see https://www.youtube.com/watch?v=8t8JYpt0egE
|
||||
w.Header()["Content-Type"] = nil
|
||||
respHeader["Content-Type"] = nil
|
||||
} else {
|
||||
w.Header().Set("Content-Type", mtyp)
|
||||
respHeader.Set("Content-Type", mtyp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,19 +651,48 @@ func (fsrv *FileServer) notFound(w http.ResponseWriter, r *http.Request, next ca
|
||||
return caddyhttp.Error(http.StatusNotFound, nil)
|
||||
}
|
||||
|
||||
// calculateEtag produces a strong etag by default, although, for
|
||||
// efficiency reasons, it does not actually consume the contents
|
||||
// of the file to make a hash of all the bytes. ¯\_(ツ)_/¯
|
||||
// Prefix the etag with "W/" to convert it into a weak etag.
|
||||
// See: https://tools.ietf.org/html/rfc7232#section-2.3
|
||||
// calculateEtag computes an entity tag using a strong validator
|
||||
// without consuming the contents of the file. It requires the
|
||||
// file info contain the correct size and modification time.
|
||||
// It strives to implement the semantics regarding ETags as defined
|
||||
// by RFC 9110 section 8.8.3 and 8.8.1. See
|
||||
// https://www.rfc-editor.org/rfc/rfc9110.html#section-8.8.3.
|
||||
//
|
||||
// As our implementation uses file modification timestamp and size,
|
||||
// note the following from RFC 9110 section 8.8.1: "A representation's
|
||||
// modification time, if defined with only one-second resolution,
|
||||
// might be a weak validator if it is possible for the representation to
|
||||
// be modified twice during a single second and retrieved between those
|
||||
// modifications." The ext4 file system, which underpins the vast majority
|
||||
// of Caddy deployments, stores mod times with millisecond precision,
|
||||
// which we consider precise enough to qualify as a strong validator.
|
||||
func calculateEtag(d os.FileInfo) string {
|
||||
mtime := d.ModTime().Unix()
|
||||
if mtime == 0 || mtime == 1 {
|
||||
mtime := d.ModTime()
|
||||
if mtimeUnix := mtime.Unix(); mtimeUnix == 0 || mtimeUnix == 1 {
|
||||
return "" // not useful anyway; see issue #5548
|
||||
}
|
||||
t := strconv.FormatInt(mtime, 36)
|
||||
s := strconv.FormatInt(d.Size(), 36)
|
||||
return `"` + t + s + `"`
|
||||
var sb strings.Builder
|
||||
sb.WriteRune('"')
|
||||
sb.WriteString(strconv.FormatInt(mtime.UnixNano(), 36))
|
||||
sb.WriteString(strconv.FormatInt(d.Size(), 36))
|
||||
sb.WriteRune('"')
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// Finds the first corresponding etag file for a given file in the file system and return its content
|
||||
func (fsrv *FileServer) getEtagFromFile(fileSystem fs.FS, filename string) (string, error) {
|
||||
for _, suffix := range fsrv.EtagFileExtensions {
|
||||
etagFilename := filename + suffix
|
||||
etag, err := fs.ReadFile(fileSystem, etagFilename)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot read etag from file %s: %v", etagFilename, err)
|
||||
}
|
||||
return string(etag), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// redirect performs a redirect to a given path. The 'toPath' parameter
|
||||
|
||||
@@ -184,7 +184,7 @@ type RespHeaderOps struct {
|
||||
Require *caddyhttp.ResponseMatcher `json:"require,omitempty"`
|
||||
|
||||
// If true, header operations will be deferred until
|
||||
// they are written out. Superceded if Require is set.
|
||||
// they are written out. Superseded if Require is set.
|
||||
// Usually you will need to set this to true if any
|
||||
// fields are being deleted.
|
||||
Deferred bool `json:"deferred,omitempty"`
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
// 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 intercept
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterModule(Intercept{})
|
||||
httpcaddyfile.RegisterHandlerDirective("intercept", parseCaddyfile)
|
||||
}
|
||||
|
||||
// Intercept is a middleware that intercepts then replaces or modifies the original response.
|
||||
// It can, for instance, be used to implement X-Sendfile/X-Accel-Redirect-like features
|
||||
// when using modules like FrankenPHP or Caddy Snake.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
type Intercept struct {
|
||||
// List of handlers and their associated matchers to evaluate
|
||||
// after successful response generation.
|
||||
// The first handler that matches the original response will
|
||||
// be invoked. The original response body will not be
|
||||
// written to the client;
|
||||
// it is up to the handler to finish handling the response.
|
||||
//
|
||||
// Three new placeholders are available in this handler chain:
|
||||
// - `{http.intercept.status_code}` The status code from the response
|
||||
// - `{http.intercept.status_text}` The status text from the response
|
||||
// - `{http.intercept.header.*}` The headers from the response
|
||||
HandleResponse []caddyhttp.ResponseHandler `json:"handle_response,omitempty"`
|
||||
|
||||
// Holds the named response matchers from the Caddyfile while adapting
|
||||
responseMatchers map[string]caddyhttp.ResponseMatcher
|
||||
|
||||
// Holds the handle_response Caddyfile tokens while adapting
|
||||
handleResponseSegments []*caddyfile.Dispenser
|
||||
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (Intercept) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
ID: "http.handlers.intercept",
|
||||
New: func() caddy.Module { return new(Intercept) },
|
||||
}
|
||||
}
|
||||
|
||||
// Provision ensures that i is set up properly before use.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (irh *Intercept) Provision(ctx caddy.Context) error {
|
||||
// set up any response routes
|
||||
for i, rh := range irh.HandleResponse {
|
||||
err := rh.Provision(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("provisioning response handler %d: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
irh.logger = ctx.Logger()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var bufPool = sync.Pool{
|
||||
New: func() any {
|
||||
return new(bytes.Buffer)
|
||||
},
|
||||
}
|
||||
|
||||
// TODO: handle status code replacement
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
type interceptedResponseHandler struct {
|
||||
caddyhttp.ResponseRecorder
|
||||
replacer *caddy.Replacer
|
||||
handler caddyhttp.ResponseHandler
|
||||
handlerIndex int
|
||||
statusCode int
|
||||
}
|
||||
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (irh interceptedResponseHandler) WriteHeader(statusCode int) {
|
||||
if irh.statusCode != 0 && (statusCode < 100 || statusCode >= 200) {
|
||||
irh.ResponseRecorder.WriteHeader(irh.statusCode)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
irh.ResponseRecorder.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (ir Intercept) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
|
||||
buf := bufPool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
defer bufPool.Put(buf)
|
||||
|
||||
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
|
||||
rec := interceptedResponseHandler{replacer: repl}
|
||||
rec.ResponseRecorder = caddyhttp.NewResponseRecorder(w, buf, func(status int, header http.Header) bool {
|
||||
// see if any response handler is configured for this original response
|
||||
for i, rh := range ir.HandleResponse {
|
||||
if rh.Match != nil && !rh.Match.Match(status, header) {
|
||||
continue
|
||||
}
|
||||
rec.handler = rh
|
||||
rec.handlerIndex = i
|
||||
|
||||
// if configured to only change the status code,
|
||||
// do that then stream
|
||||
if statusCodeStr := rh.StatusCode.String(); statusCodeStr != "" {
|
||||
sc, err := strconv.Atoi(repl.ReplaceAll(statusCodeStr, ""))
|
||||
if err != nil {
|
||||
rec.statusCode = http.StatusInternalServerError
|
||||
} else {
|
||||
rec.statusCode = sc
|
||||
}
|
||||
}
|
||||
|
||||
return rec.statusCode == 0
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if err := next.ServeHTTP(rec, r); err != nil {
|
||||
return err
|
||||
}
|
||||
if !rec.Buffered() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// set up the replacer so that parts of the original response can be
|
||||
// used for routing decisions
|
||||
for field, value := range r.Header {
|
||||
repl.Set("http.intercept.header."+field, strings.Join(value, ","))
|
||||
}
|
||||
repl.Set("http.intercept.status_code", rec.Status())
|
||||
|
||||
ir.logger.Debug("handling response", zap.Int("handler", rec.handlerIndex))
|
||||
|
||||
// pass the request through the response handler routes
|
||||
return rec.handler.Routes.Compile(next).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
||||
//
|
||||
// intercept [<matcher>] {
|
||||
// # intercept original responses
|
||||
// @name {
|
||||
// status <code...>
|
||||
// header <field> [<value>]
|
||||
// }
|
||||
// replace_status [<matcher>] <status_code>
|
||||
// handle_response [<matcher>] {
|
||||
// <directives...>
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// The FinalizeUnmarshalCaddyfile method should be called after this
|
||||
// to finalize parsing of "handle_response" blocks, if possible.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (i *Intercept) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
// collect the response matchers defined as subdirectives
|
||||
// prefixed with "@" for use with "handle_response" blocks
|
||||
i.responseMatchers = make(map[string]caddyhttp.ResponseMatcher)
|
||||
|
||||
d.Next() // consume the directive name
|
||||
for d.NextBlock(0) {
|
||||
// if the subdirective has an "@" prefix then we
|
||||
// parse it as a response matcher for use with "handle_response"
|
||||
if strings.HasPrefix(d.Val(), matcherPrefix) {
|
||||
err := caddyhttp.ParseNamedResponseMatcher(d.NewFromNextSegment(), i.responseMatchers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch d.Val() {
|
||||
case "handle_response":
|
||||
// delegate the parsing of handle_response to the caller,
|
||||
// since we need the httpcaddyfile.Helper to parse subroutes.
|
||||
// See h.FinalizeUnmarshalCaddyfile
|
||||
i.handleResponseSegments = append(i.handleResponseSegments, d.NewFromNextSegment())
|
||||
|
||||
case "replace_status":
|
||||
args := d.RemainingArgs()
|
||||
if len(args) != 1 && len(args) != 2 {
|
||||
return d.Errf("must have one or two arguments: an optional response matcher, and a status code")
|
||||
}
|
||||
|
||||
responseHandler := caddyhttp.ResponseHandler{}
|
||||
|
||||
if len(args) == 2 {
|
||||
if !strings.HasPrefix(args[0], matcherPrefix) {
|
||||
return d.Errf("must use a named response matcher, starting with '@'")
|
||||
}
|
||||
foundMatcher, ok := i.responseMatchers[args[0]]
|
||||
if !ok {
|
||||
return d.Errf("no named response matcher defined with name '%s'", args[0][1:])
|
||||
}
|
||||
responseHandler.Match = &foundMatcher
|
||||
responseHandler.StatusCode = caddyhttp.WeakString(args[1])
|
||||
} else if len(args) == 1 {
|
||||
responseHandler.StatusCode = caddyhttp.WeakString(args[0])
|
||||
}
|
||||
|
||||
// make sure there's no block, cause it doesn't make sense
|
||||
if nesting := d.Nesting(); d.NextBlock(nesting) {
|
||||
return d.Errf("cannot define routes for 'replace_status', use 'handle_response' instead.")
|
||||
}
|
||||
|
||||
i.HandleResponse = append(
|
||||
i.HandleResponse,
|
||||
responseHandler,
|
||||
)
|
||||
|
||||
default:
|
||||
return d.Errf("unrecognized subdirective %s", d.Val())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FinalizeUnmarshalCaddyfile finalizes the Caddyfile parsing which
|
||||
// requires having an httpcaddyfile.Helper to function, to parse subroutes.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change or removal.
|
||||
func (i *Intercept) FinalizeUnmarshalCaddyfile(helper httpcaddyfile.Helper) error {
|
||||
for _, d := range i.handleResponseSegments {
|
||||
// consume the "handle_response" token
|
||||
d.Next()
|
||||
args := d.RemainingArgs()
|
||||
|
||||
// TODO: Remove this check at some point in the future
|
||||
if len(args) == 2 {
|
||||
return d.Errf("configuring 'handle_response' for status code replacement is no longer supported. Use 'replace_status' instead.")
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
return d.Errf("too many arguments for 'handle_response': %s", args)
|
||||
}
|
||||
|
||||
var matcher *caddyhttp.ResponseMatcher
|
||||
if len(args) == 1 {
|
||||
// the first arg should always be a matcher.
|
||||
if !strings.HasPrefix(args[0], matcherPrefix) {
|
||||
return d.Errf("must use a named response matcher, starting with '@'")
|
||||
}
|
||||
|
||||
foundMatcher, ok := i.responseMatchers[args[0]]
|
||||
if !ok {
|
||||
return d.Errf("no named response matcher defined with name '%s'", args[0][1:])
|
||||
}
|
||||
matcher = &foundMatcher
|
||||
}
|
||||
|
||||
// parse the block as routes
|
||||
handler, err := httpcaddyfile.ParseSegmentAsSubroute(helper.WithDispenser(d.NewFromNextSegment()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
subroute, ok := handler.(*caddyhttp.Subroute)
|
||||
if !ok {
|
||||
return helper.Errf("segment was not parsed as a subroute")
|
||||
}
|
||||
i.HandleResponse = append(
|
||||
i.HandleResponse,
|
||||
caddyhttp.ResponseHandler{
|
||||
Match: matcher,
|
||||
Routes: subroute.Routes,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// move the handle_response entries without a matcher to the end.
|
||||
// we can't use sort.SliceStable because it will reorder the rest of the
|
||||
// entries which may be undesirable because we don't have a good
|
||||
// heuristic to use for sorting.
|
||||
withoutMatchers := []caddyhttp.ResponseHandler{}
|
||||
withMatchers := []caddyhttp.ResponseHandler{}
|
||||
for _, hr := range i.HandleResponse {
|
||||
if hr.Match == nil {
|
||||
withoutMatchers = append(withoutMatchers, hr)
|
||||
} else {
|
||||
withMatchers = append(withMatchers, hr)
|
||||
}
|
||||
}
|
||||
i.HandleResponse = append(withMatchers, withoutMatchers...)
|
||||
|
||||
// clean up the bits we only needed for adapting
|
||||
i.handleResponseSegments = nil
|
||||
i.responseMatchers = nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
const matcherPrefix = "@"
|
||||
|
||||
func parseCaddyfile(helper httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||
var ir Intercept
|
||||
if err := ir.UnmarshalCaddyfile(helper.Dispenser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := ir.FinalizeUnmarshalCaddyfile(helper); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ir, nil
|
||||
}
|
||||
|
||||
// Interface guards
|
||||
var (
|
||||
_ caddy.Provisioner = (*Intercept)(nil)
|
||||
_ caddyfile.Unmarshaler = (*Intercept)(nil)
|
||||
_ caddyhttp.MiddlewareHandler = (*Intercept)(nil)
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user