mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 18:17:08 +08:00 
			
		
		
		
	chore: upgrade .golangci.yml and workflow to v2 (#6924)
* chore: upgrade .golangci.yml and workflow to v2 run `golangci-lint fmt` Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * run `golangci-lint run --fix` Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * more lint fixes Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * bring back comments to .golangci.yml Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * appease the linter some more Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * oops Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * use embedded structs Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * use embedded structs where they were used before Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * disable rule `-QF1006` Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * missed a spot Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> --------- Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							5b2eb66418
						
					
				
				
					commit
					e039a5bb5c
				
			
							
								
								
									
										2
									
								
								.github/workflows/lint.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/lint.yml
									
									
									
									
										vendored
									
									
								
							@ -51,7 +51,7 @@ jobs:
 | 
				
			|||||||
          check-latest: true
 | 
					          check-latest: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: golangci-lint
 | 
					      - name: golangci-lint
 | 
				
			||||||
        uses: golangci/golangci-lint-action@v6
 | 
					        uses: golangci/golangci-lint-action@v7
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          version: latest
 | 
					          version: latest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										218
									
								
								.golangci.yml
									
									
									
									
									
								
							
							
						
						
									
										218
									
								
								.golangci.yml
									
									
									
									
									
								
							@ -1,27 +1,15 @@
 | 
				
			|||||||
linters-settings:
 | 
					version: "2"
 | 
				
			||||||
  errcheck:
 | 
					run:
 | 
				
			||||||
    exclude-functions:
 | 
					  issues-exit-code: 1
 | 
				
			||||||
      - fmt.*
 | 
					  tests: false
 | 
				
			||||||
      - (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
 | 
					output:
 | 
				
			||||||
      - (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
 | 
					  formats:
 | 
				
			||||||
  gci:
 | 
					    text:
 | 
				
			||||||
    sections:
 | 
					      path: stdout
 | 
				
			||||||
      - standard # Standard section: captures all standard packages.
 | 
					      print-linter-name: true
 | 
				
			||||||
      - default # Default section: contains all imports that could not be matched to another section type.
 | 
					      print-issued-lines: true
 | 
				
			||||||
      - prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
 | 
					 | 
				
			||||||
      - prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
 | 
					 | 
				
			||||||
    # Skip generated files.
 | 
					 | 
				
			||||||
    # Default: true
 | 
					 | 
				
			||||||
    skip-generated: true
 | 
					 | 
				
			||||||
    # Enable custom order of sections.
 | 
					 | 
				
			||||||
    # If `true`, make the section order the same as the order of `sections`.
 | 
					 | 
				
			||||||
    # Default: false
 | 
					 | 
				
			||||||
    custom-order: true
 | 
					 | 
				
			||||||
  exhaustive:
 | 
					 | 
				
			||||||
    ignore-enum-types: reflect.Kind|svc.Cmd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
linters:
 | 
					linters:
 | 
				
			||||||
  disable-all: true
 | 
					  default: none
 | 
				
			||||||
  enable:
 | 
					  enable:
 | 
				
			||||||
    - asasalint
 | 
					    - asasalint
 | 
				
			||||||
    - asciicheck
 | 
					    - asciicheck
 | 
				
			||||||
@ -35,148 +23,96 @@ linters:
 | 
				
			|||||||
    - errcheck
 | 
					    - errcheck
 | 
				
			||||||
    - errname
 | 
					    - errname
 | 
				
			||||||
    - exhaustive
 | 
					    - exhaustive
 | 
				
			||||||
    - gci
 | 
					 | 
				
			||||||
    - gofmt
 | 
					 | 
				
			||||||
    - goimports
 | 
					 | 
				
			||||||
    - gofumpt
 | 
					 | 
				
			||||||
    - gosec
 | 
					    - gosec
 | 
				
			||||||
    - gosimple
 | 
					 | 
				
			||||||
    - govet
 | 
					    - govet
 | 
				
			||||||
    - ineffassign
 | 
					 | 
				
			||||||
    - importas
 | 
					    - importas
 | 
				
			||||||
 | 
					    - ineffassign
 | 
				
			||||||
    - misspell
 | 
					    - misspell
 | 
				
			||||||
    - prealloc
 | 
					    - prealloc
 | 
				
			||||||
    - promlinter
 | 
					    - promlinter
 | 
				
			||||||
    - sloglint
 | 
					    - sloglint
 | 
				
			||||||
    - sqlclosecheck
 | 
					    - sqlclosecheck
 | 
				
			||||||
    - staticcheck
 | 
					    - staticcheck
 | 
				
			||||||
    - tenv
 | 
					 | 
				
			||||||
    - testableexamples
 | 
					    - testableexamples
 | 
				
			||||||
    - testifylint
 | 
					    - testifylint
 | 
				
			||||||
    - tparallel
 | 
					    - tparallel
 | 
				
			||||||
    - typecheck
 | 
					 | 
				
			||||||
    - unconvert
 | 
					    - unconvert
 | 
				
			||||||
    - unused
 | 
					    - unused
 | 
				
			||||||
    - wastedassign
 | 
					    - wastedassign
 | 
				
			||||||
    - whitespace
 | 
					    - whitespace
 | 
				
			||||||
    - zerologlint
 | 
					    - zerologlint
 | 
				
			||||||
  # these are implicitly disabled:
 | 
					  settings:
 | 
				
			||||||
  # - containedctx
 | 
					    staticcheck:
 | 
				
			||||||
  # - contextcheck
 | 
					      checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022",  "-QF1006", "-QF1008"] # default, and exclude 1 more undesired check
 | 
				
			||||||
  # - cyclop
 | 
					    errcheck:
 | 
				
			||||||
  # - depguard
 | 
					      exclude-functions:
 | 
				
			||||||
  # - errchkjson
 | 
					        - fmt.*
 | 
				
			||||||
  # - errorlint
 | 
					        - (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
 | 
				
			||||||
  # - exhaustruct
 | 
					        - (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
 | 
				
			||||||
  # - execinquery
 | 
					    exhaustive:
 | 
				
			||||||
  # - exhaustruct
 | 
					      ignore-enum-types: reflect.Kind|svc.Cmd
 | 
				
			||||||
  # - forbidigo
 | 
					  exclusions:
 | 
				
			||||||
  # - forcetypeassert
 | 
					    generated: lax
 | 
				
			||||||
  # - funlen
 | 
					    presets:
 | 
				
			||||||
  # - ginkgolinter
 | 
					      - comments
 | 
				
			||||||
  # - gocheckcompilerdirectives
 | 
					      - common-false-positives
 | 
				
			||||||
  # - gochecknoglobals
 | 
					      - legacy
 | 
				
			||||||
  # - gochecknoinits
 | 
					      - std-error-handling
 | 
				
			||||||
  # - gochecksumtype
 | 
					    rules:
 | 
				
			||||||
  # - gocognit
 | 
					      - linters:
 | 
				
			||||||
  # - goconst
 | 
					 | 
				
			||||||
  # - gocritic
 | 
					 | 
				
			||||||
  # - gocyclo
 | 
					 | 
				
			||||||
  # - godot
 | 
					 | 
				
			||||||
  # - godox
 | 
					 | 
				
			||||||
  # - goerr113
 | 
					 | 
				
			||||||
  # - goheader
 | 
					 | 
				
			||||||
  # - gomnd
 | 
					 | 
				
			||||||
  # - gomoddirectives
 | 
					 | 
				
			||||||
  # - gomodguard
 | 
					 | 
				
			||||||
  # - goprintffuncname
 | 
					 | 
				
			||||||
  # - gosmopolitan
 | 
					 | 
				
			||||||
  # - grouper
 | 
					 | 
				
			||||||
  # - inamedparam
 | 
					 | 
				
			||||||
  # - interfacebloat
 | 
					 | 
				
			||||||
  # - ireturn
 | 
					 | 
				
			||||||
  # - lll
 | 
					 | 
				
			||||||
  # - loggercheck
 | 
					 | 
				
			||||||
  # - maintidx
 | 
					 | 
				
			||||||
  # - makezero
 | 
					 | 
				
			||||||
  # - mirror
 | 
					 | 
				
			||||||
  # - musttag
 | 
					 | 
				
			||||||
  # - nakedret
 | 
					 | 
				
			||||||
  # - nestif
 | 
					 | 
				
			||||||
  # - nilerr
 | 
					 | 
				
			||||||
  # - nilnil
 | 
					 | 
				
			||||||
  # - nlreturn
 | 
					 | 
				
			||||||
  # - noctx
 | 
					 | 
				
			||||||
  # - nolintlint
 | 
					 | 
				
			||||||
  # - nonamedreturns
 | 
					 | 
				
			||||||
  # - nosprintfhostport
 | 
					 | 
				
			||||||
  # - paralleltest
 | 
					 | 
				
			||||||
  # - perfsprint
 | 
					 | 
				
			||||||
  # - predeclared
 | 
					 | 
				
			||||||
  # - protogetter
 | 
					 | 
				
			||||||
  # - reassign
 | 
					 | 
				
			||||||
  # - revive
 | 
					 | 
				
			||||||
  # - rowserrcheck
 | 
					 | 
				
			||||||
  # - stylecheck
 | 
					 | 
				
			||||||
  # - tagalign
 | 
					 | 
				
			||||||
  # - tagliatelle
 | 
					 | 
				
			||||||
  # - testpackage
 | 
					 | 
				
			||||||
  # - thelper
 | 
					 | 
				
			||||||
  # - unparam
 | 
					 | 
				
			||||||
  # - usestdlibvars
 | 
					 | 
				
			||||||
  # - varnamelen
 | 
					 | 
				
			||||||
  # - wrapcheck
 | 
					 | 
				
			||||||
  # - wsl
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
run:
 | 
					 | 
				
			||||||
  # default concurrency is a available CPU number.
 | 
					 | 
				
			||||||
  # concurrency: 4 # explicitly omit this value to fully utilize available resources.
 | 
					 | 
				
			||||||
  timeout: 5m
 | 
					 | 
				
			||||||
  issues-exit-code: 1
 | 
					 | 
				
			||||||
  tests: false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# output configuration options
 | 
					 | 
				
			||||||
output:
 | 
					 | 
				
			||||||
  formats:
 | 
					 | 
				
			||||||
    - format: 'colored-line-number'
 | 
					 | 
				
			||||||
  print-issued-lines: true
 | 
					 | 
				
			||||||
  print-linter-name: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
issues:
 | 
					 | 
				
			||||||
  exclude-rules:
 | 
					 | 
				
			||||||
    - text: 'G115' # TODO: Either we should fix the issues or nuke the linter if it's bad
 | 
					 | 
				
			||||||
      linters:
 | 
					 | 
				
			||||||
          - gosec
 | 
					          - gosec
 | 
				
			||||||
    # we aren't calling unknown URL
 | 
					        text: G115 # TODO: Either we should fix the issues or nuke the linter if it's bad
 | 
				
			||||||
    - text: 'G107' # G107: Url provided to HTTP request as taint input
 | 
					      - linters:
 | 
				
			||||||
      linters:
 | 
					 | 
				
			||||||
          - gosec
 | 
					          - gosec
 | 
				
			||||||
    # as a web server that's expected to handle any template, this is totally in the hands of the user.
 | 
					        text: G107 # we aren't calling unknown URL
 | 
				
			||||||
    - text: 'G203' # G203: Use of unescaped data in HTML templates
 | 
					      - linters:
 | 
				
			||||||
      linters:
 | 
					 | 
				
			||||||
          - gosec
 | 
					          - gosec
 | 
				
			||||||
    # we're shelling out to known commands, not relying on user-defined input.
 | 
					        text: G203 # as a web server that's expected to handle any template, this is totally in the hands of the user.
 | 
				
			||||||
    - text: 'G204' # G204: Audit use of command execution
 | 
					      - linters:
 | 
				
			||||||
      linters:
 | 
					          - gosec
 | 
				
			||||||
 | 
					        text: G204 # we're shelling out to known commands, not relying on user-defined input.
 | 
				
			||||||
 | 
					      - linters:
 | 
				
			||||||
          - gosec
 | 
					          - gosec
 | 
				
			||||||
        # the choice of weakrand is deliberate, hence the named import "weakrand"
 | 
					        # the choice of weakrand is deliberate, hence the named import "weakrand"
 | 
				
			||||||
    - path: modules/caddyhttp/reverseproxy/selectionpolicies.go
 | 
					        path: modules/caddyhttp/reverseproxy/selectionpolicies.go
 | 
				
			||||||
      text: 'G404' # G404: Insecure random number source (rand)
 | 
					        text: G404
 | 
				
			||||||
      linters:
 | 
					      - linters:
 | 
				
			||||||
          - gosec
 | 
					          - gosec
 | 
				
			||||||
    - path: modules/caddyhttp/reverseproxy/streaming.go
 | 
					        path: modules/caddyhttp/reverseproxy/streaming.go
 | 
				
			||||||
      text: 'G404' # G404: Insecure random number source (rand)
 | 
					        text: G404
 | 
				
			||||||
      linters:
 | 
					      - linters:
 | 
				
			||||||
        - gosec
 | 
					 | 
				
			||||||
    - path: modules/logging/filters.go
 | 
					 | 
				
			||||||
      linters:
 | 
					 | 
				
			||||||
          - dupl
 | 
					          - dupl
 | 
				
			||||||
    - path: modules/caddyhttp/matchers.go
 | 
					        path: modules/logging/filters.go
 | 
				
			||||||
      linters:
 | 
					      - linters:
 | 
				
			||||||
          - dupl
 | 
					          - dupl
 | 
				
			||||||
    - path: modules/caddyhttp/vars.go
 | 
					        path: modules/caddyhttp/matchers.go
 | 
				
			||||||
      linters:
 | 
					      - linters:
 | 
				
			||||||
          - dupl
 | 
					          - dupl
 | 
				
			||||||
    - path: _test\.go
 | 
					        path: modules/caddyhttp/vars.go
 | 
				
			||||||
      linters:
 | 
					      - linters:
 | 
				
			||||||
          - errcheck
 | 
					          - errcheck
 | 
				
			||||||
 | 
					        path: _test\.go
 | 
				
			||||||
 | 
					    paths:
 | 
				
			||||||
 | 
					      - third_party$
 | 
				
			||||||
 | 
					      - builtin$
 | 
				
			||||||
 | 
					      - examples$
 | 
				
			||||||
 | 
					formatters:
 | 
				
			||||||
 | 
					  enable:
 | 
				
			||||||
 | 
					    - gci
 | 
				
			||||||
 | 
					    - gofmt
 | 
				
			||||||
 | 
					    - gofumpt
 | 
				
			||||||
 | 
					    - goimports
 | 
				
			||||||
 | 
					  settings:
 | 
				
			||||||
 | 
					    gci:
 | 
				
			||||||
 | 
					      sections:
 | 
				
			||||||
 | 
					        - standard # Standard section: captures all standard packages.
 | 
				
			||||||
 | 
					        - default # Default section: contains all imports that could not be matched to another section type.
 | 
				
			||||||
 | 
					        - prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
 | 
				
			||||||
 | 
					        - prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
 | 
				
			||||||
 | 
					      custom-order: true
 | 
				
			||||||
 | 
					  exclusions:
 | 
				
			||||||
 | 
					    generated: lax
 | 
				
			||||||
 | 
					    paths:
 | 
				
			||||||
 | 
					      - third_party$
 | 
				
			||||||
 | 
					      - builtin$
 | 
				
			||||||
 | 
					      - examples$
 | 
				
			||||||
 | 
				
			|||||||
@ -68,7 +68,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf
 | 
				
			|||||||
// TODO: also perform this check on imported files
 | 
					// TODO: also perform this check on imported files
 | 
				
			||||||
func FormattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) {
 | 
					func FormattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) {
 | 
				
			||||||
	// replace windows-style newlines to normalize comparison
 | 
						// replace windows-style newlines to normalize comparison
 | 
				
			||||||
	normalizedBody := bytes.Replace(body, []byte("\r\n"), []byte("\n"), -1)
 | 
						normalizedBody := bytes.ReplaceAll(body, []byte("\r\n"), []byte("\n"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	formatted := Format(normalizedBody)
 | 
						formatted := Format(normalizedBody)
 | 
				
			||||||
	if bytes.Equal(formatted, normalizedBody) {
 | 
						if bytes.Equal(formatted, normalizedBody) {
 | 
				
			||||||
 | 
				
			|||||||
@ -94,7 +94,7 @@ func Format(input []byte) []byte {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// detect whether we have the start of a heredoc
 | 
							// detect whether we have the start of a heredoc
 | 
				
			||||||
		if !quoted && !(heredoc != heredocClosed || heredocEscaped) &&
 | 
							if !quoted && (heredoc == heredocClosed && !heredocEscaped) &&
 | 
				
			||||||
			space && last == '<' && ch == '<' {
 | 
								space && last == '<' && ch == '<' {
 | 
				
			||||||
			write(ch)
 | 
								write(ch)
 | 
				
			||||||
			heredoc = heredocOpening
 | 
								heredoc = heredocOpening
 | 
				
			||||||
 | 
				
			|||||||
@ -137,7 +137,7 @@ func (l *lexer) next() (bool, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// detect whether we have the start of a heredoc
 | 
							// detect whether we have the start of a heredoc
 | 
				
			||||||
		if !(quoted || btQuoted) && !(inHeredoc || heredocEscaped) &&
 | 
							if (!quoted && !btQuoted) && (!inHeredoc && !heredocEscaped) &&
 | 
				
			||||||
			len(val) > 1 && string(val[:2]) == "<<" {
 | 
								len(val) > 1 && string(val[:2]) == "<<" {
 | 
				
			||||||
			// a space means it's just a regular token and not a heredoc
 | 
								// a space means it's just a regular token and not a heredoc
 | 
				
			||||||
			if ch == ' ' {
 | 
								if ch == ' ' {
 | 
				
			||||||
 | 
				
			|||||||
@ -174,10 +174,12 @@ func RegisterDirectiveOrder(dir string, position Positional, standardDir string)
 | 
				
			|||||||
		if d != standardDir {
 | 
							if d != standardDir {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if position == Before {
 | 
							switch position {
 | 
				
			||||||
 | 
							case Before:
 | 
				
			||||||
			newOrder = append(newOrder[:i], append([]string{dir}, newOrder[i:]...)...)
 | 
								newOrder = append(newOrder[:i], append([]string{dir}, newOrder[i:]...)...)
 | 
				
			||||||
		} else if position == After {
 | 
							case After:
 | 
				
			||||||
			newOrder = append(newOrder[:i+1], append([]string{dir}, newOrder[i+1:]...)...)
 | 
								newOrder = append(newOrder[:i+1], append([]string{dir}, newOrder[i+1:]...)...)
 | 
				
			||||||
 | 
							case First, Last:
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break
 | 
							break
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -281,7 +281,7 @@ func validateTestPrerequisites(tc *Tester) error {
 | 
				
			|||||||
		tc.t.Cleanup(func() {
 | 
							tc.t.Cleanup(func() {
 | 
				
			||||||
			os.Remove(f.Name())
 | 
								os.Remove(f.Name())
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		if _, err := f.WriteString(fmt.Sprintf(initConfig, tc.config.AdminPort)); err != nil {
 | 
							if _, err := fmt.Fprintf(f, initConfig, tc.config.AdminPort); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -12,13 +12,14 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2"
 | 
					 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddytest"
 | 
					 | 
				
			||||||
	"github.com/mholt/acmez/v3"
 | 
						"github.com/mholt/acmez/v3"
 | 
				
			||||||
	"github.com/mholt/acmez/v3/acme"
 | 
						"github.com/mholt/acmez/v3/acme"
 | 
				
			||||||
	smallstepacme "github.com/smallstep/certificates/acme"
 | 
						smallstepacme "github.com/smallstep/certificates/acme"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"go.uber.org/zap/exp/zapslog"
 | 
						"go.uber.org/zap/exp/zapslog"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2"
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2/caddytest"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const acmeChallengePort = 9081
 | 
					const acmeChallengePort = 9081
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,12 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddytest"
 | 
					 | 
				
			||||||
	"github.com/mholt/acmez/v3"
 | 
						"github.com/mholt/acmez/v3"
 | 
				
			||||||
	"github.com/mholt/acmez/v3/acme"
 | 
						"github.com/mholt/acmez/v3/acme"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"go.uber.org/zap/exp/zapslog"
 | 
						"go.uber.org/zap/exp/zapslog"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2/caddytest"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestACMEServerDirectory(t *testing.T) {
 | 
					func TestACMEServerDirectory(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,6 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddytest"
 | 
						"github.com/caddyserver/caddy/v2/caddytest"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	_ "github.com/caddyserver/caddy/v2/internal/testmocks"
 | 
						_ "github.com/caddyserver/caddy/v2/internal/testmocks"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -615,7 +615,6 @@ func TestReplaceWithReplacementPlaceholder(t *testing.T) {
 | 
				
			|||||||
	respond "{query}"`, "caddyfile")
 | 
						respond "{query}"`, "caddyfile")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
 | 
						tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestReplaceWithKeyPlaceholder(t *testing.T) {
 | 
					func TestReplaceWithKeyPlaceholder(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
@ -3,10 +3,11 @@ package integration
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2"
 | 
					 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
 | 
					 | 
				
			||||||
	"github.com/caddyserver/certmagic"
 | 
						"github.com/caddyserver/certmagic"
 | 
				
			||||||
	"github.com/libdns/libdns"
 | 
						"github.com/libdns/libdns"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2"
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
@ -55,7 +56,9 @@ func (MockDNSProvider) SetRecords(ctx context.Context, zone string, recs []libdn
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Interface guard
 | 
					// Interface guard
 | 
				
			||||||
var _ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
 | 
					var (
 | 
				
			||||||
var _ certmagic.DNSProvider = (*MockDNSProvider)(nil)
 | 
						_ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
 | 
				
			||||||
var _ caddy.Provisioner = (*MockDNSProvider)(nil)
 | 
						_ certmagic.DNSProvider = (*MockDNSProvider)(nil)
 | 
				
			||||||
var _ caddy.Module = (*MockDNSProvider)(nil)
 | 
						_ caddy.Provisioner     = (*MockDNSProvider)(nil)
 | 
				
			||||||
 | 
						_ caddy.Module          = (*MockDNSProvider)(nil)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
				
			|||||||
@ -13,9 +13,10 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddytest"
 | 
					 | 
				
			||||||
	"golang.org/x/net/http2"
 | 
						"golang.org/x/net/http2"
 | 
				
			||||||
	"golang.org/x/net/http2/h2c"
 | 
						"golang.org/x/net/http2/h2c"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2/caddytest"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// (see https://github.com/caddyserver/caddy/issues/3556 for use case)
 | 
					// (see https://github.com/caddyserver/caddy/issues/3556 for use case)
 | 
				
			||||||
 | 
				
			|||||||
@ -418,7 +418,7 @@ func parseEnvFile(envInput io.Reader) (map[string]string, error) {
 | 
				
			|||||||
		// quoted value: support newlines
 | 
							// quoted value: support newlines
 | 
				
			||||||
		if strings.HasPrefix(val, `"`) || strings.HasPrefix(val, "'") {
 | 
							if strings.HasPrefix(val, `"`) || strings.HasPrefix(val, "'") {
 | 
				
			||||||
			quote := string(val[0])
 | 
								quote := string(val[0])
 | 
				
			||||||
			for !(strings.HasSuffix(line, quote) && !strings.HasSuffix(line, `\`+quote)) {
 | 
								for !strings.HasSuffix(line, quote) || strings.HasSuffix(line, `\`+quote) {
 | 
				
			||||||
				val = strings.ReplaceAll(val, `\`+quote, quote)
 | 
									val = strings.ReplaceAll(val, `\`+quote, quote)
 | 
				
			||||||
				if !scanner.Scan() {
 | 
									if !scanner.Scan() {
 | 
				
			||||||
					break
 | 
										break
 | 
				
			||||||
 | 
				
			|||||||
@ -235,7 +235,6 @@ func Test_isCaddyfile(t *testing.T) {
 | 
				
			|||||||
			wantErr: false,
 | 
								wantErr: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
					 | 
				
			||||||
			name: "json is not caddyfile but not error",
 | 
								name: "json is not caddyfile but not error",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				configFile:  "./Caddyfile.json",
 | 
									configFile:  "./Caddyfile.json",
 | 
				
			||||||
@ -245,7 +244,6 @@ func Test_isCaddyfile(t *testing.T) {
 | 
				
			|||||||
			wantErr: false,
 | 
								wantErr: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
					 | 
				
			||||||
			name: "prefix of Caddyfile and ./ with any extension is Caddyfile",
 | 
								name: "prefix of Caddyfile and ./ with any extension is Caddyfile",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				configFile:  "./Caddyfile.prd",
 | 
									configFile:  "./Caddyfile.prd",
 | 
				
			||||||
@ -255,7 +253,6 @@ func Test_isCaddyfile(t *testing.T) {
 | 
				
			|||||||
			wantErr: false,
 | 
								wantErr: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
					 | 
				
			||||||
			name: "prefix of Caddyfile without ./ with any extension is Caddyfile",
 | 
								name: "prefix of Caddyfile without ./ with any extension is Caddyfile",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				configFile:  "Caddyfile.prd",
 | 
									configFile:  "Caddyfile.prd",
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ func cmdAddPackage(fl Flags) (int, error) {
 | 
				
			|||||||
			return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid module name: %v", err)
 | 
								return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid module name: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// only allow a version to be specified if it's different from the existing version
 | 
							// only allow a version to be specified if it's different from the existing version
 | 
				
			||||||
		if _, ok := pluginPkgs[module]; ok && !(version != "" && pluginPkgs[module].Version != version) {
 | 
							if _, ok := pluginPkgs[module]; ok && (version == "" || pluginPkgs[module].Version == version) {
 | 
				
			||||||
			return caddy.ExitCodeFailedStartup, fmt.Errorf("package is already added")
 | 
								return caddy.ExitCodeFailedStartup, fmt.Errorf("package is already added")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		pluginPkgs[module] = pluginPackage{Version: version, Path: module}
 | 
							pluginPkgs[module] = pluginPackage{Version: version, Path: module}
 | 
				
			||||||
 | 
				
			|||||||
@ -185,8 +185,7 @@ func TestParseNetworkAddress(t *testing.T) {
 | 
				
			|||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			input:      "",
 | 
								input:      "",
 | 
				
			||||||
			expectAddr: NetworkAddress{
 | 
								expectAddr: NetworkAddress{},
 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			input:          ":",
 | 
								input:          ":",
 | 
				
			||||||
@ -312,8 +311,7 @@ func TestParseNetworkAddressWithDefaults(t *testing.T) {
 | 
				
			|||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			input:      "",
 | 
								input:      "",
 | 
				
			||||||
			expectAddr: NetworkAddress{
 | 
								expectAddr: NetworkAddress{},
 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			input:          ":",
 | 
								input:          ":",
 | 
				
			||||||
 | 
				
			|||||||
@ -343,7 +343,7 @@ uniqueDomainsLoop:
 | 
				
			|||||||
		// match on known domain names, unless it's our special case of a
 | 
							// match on known domain names, unless it's our special case of a
 | 
				
			||||||
		// catch-all which is an empty string (common among catch-all sites
 | 
							// catch-all which is an empty string (common among catch-all sites
 | 
				
			||||||
		// that enable on-demand TLS for yet-unknown domain names)
 | 
							// that enable on-demand TLS for yet-unknown domain names)
 | 
				
			||||||
		if !(len(domains) == 1 && domains[0] == "") {
 | 
							if len(domains) != 1 || domains[0] != "" {
 | 
				
			||||||
			matcherSet = append(matcherSet, MatchHost(domains))
 | 
								matcherSet = append(matcherSet, MatchHost(domains))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -252,7 +252,7 @@ func celFileMatcherMacroExpander() parser.MacroExpander {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for _, arg := range args {
 | 
							for _, arg := range args {
 | 
				
			||||||
			if !(isCELStringLiteral(arg) || isCELCaddyPlaceholderCall(arg)) {
 | 
								if !isCELStringLiteral(arg) && !isCELCaddyPlaceholderCall(arg) {
 | 
				
			||||||
				return nil, &common.Error{
 | 
									return nil, &common.Error{
 | 
				
			||||||
					Location: eh.OffsetLocation(arg.ID()),
 | 
										Location: eh.OffsetLocation(arg.ID()),
 | 
				
			||||||
					Message:  "matcher only supports repeated string literal arguments",
 | 
										Message:  "matcher only supports repeated string literal arguments",
 | 
				
			||||||
@ -616,15 +616,16 @@ func isCELTryFilesLiteral(e ast.Expr) bool {
 | 
				
			|||||||
				return false
 | 
									return false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			mapKeyStr := mapKey.AsLiteral().ConvertToType(types.StringType).Value()
 | 
								mapKeyStr := mapKey.AsLiteral().ConvertToType(types.StringType).Value()
 | 
				
			||||||
			if mapKeyStr == "try_files" || mapKeyStr == "split_path" {
 | 
								switch mapKeyStr {
 | 
				
			||||||
 | 
								case "try_files", "split_path":
 | 
				
			||||||
				if !isCELStringListLiteral(mapVal) {
 | 
									if !isCELStringListLiteral(mapVal) {
 | 
				
			||||||
					return false
 | 
										return false
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else if mapKeyStr == "try_policy" || mapKeyStr == "root" {
 | 
								case "try_policy", "root":
 | 
				
			||||||
				if !(isCELStringExpr(mapVal)) {
 | 
									if !(isCELStringExpr(mapVal)) {
 | 
				
			||||||
					return false
 | 
										return false
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								default:
 | 
				
			||||||
				return false
 | 
									return false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -552,7 +552,6 @@ func (MatchPath) matchPatternWithEscapeSequence(escapedPath, matchPath string) b
 | 
				
			|||||||
		if iPattern >= len(matchPath) || iPath >= len(escapedPath) {
 | 
							if iPattern >= len(matchPath) || iPath >= len(escapedPath) {
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		// get the next character from the request path
 | 
							// get the next character from the request path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pathCh := string(escapedPath[iPath])
 | 
							pathCh := string(escapedPath[iPath])
 | 
				
			||||||
 | 
				
			|||||||
@ -9,8 +9,9 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2"
 | 
					 | 
				
			||||||
	"github.com/prometheus/client_golang/prometheus/testutil"
 | 
						"github.com/prometheus/client_golang/prometheus/testutil"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestServerNameFromContext(t *testing.T) {
 | 
					func TestServerNameFromContext(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
@ -363,13 +363,13 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		switch {
 | 
							switch key {
 | 
				
			||||||
		case key == "http.shutting_down":
 | 
							case "http.shutting_down":
 | 
				
			||||||
			server := req.Context().Value(ServerCtxKey).(*Server)
 | 
								server := req.Context().Value(ServerCtxKey).(*Server)
 | 
				
			||||||
			server.shutdownAtMu.RLock()
 | 
								server.shutdownAtMu.RLock()
 | 
				
			||||||
			defer server.shutdownAtMu.RUnlock()
 | 
								defer server.shutdownAtMu.RUnlock()
 | 
				
			||||||
			return !server.shutdownAt.IsZero(), true
 | 
								return !server.shutdownAt.IsZero(), true
 | 
				
			||||||
		case key == "http.time_until_shutdown":
 | 
							case "http.time_until_shutdown":
 | 
				
			||||||
			server := req.Context().Value(ServerCtxKey).(*Server)
 | 
								server := req.Context().Value(ServerCtxKey).(*Server)
 | 
				
			||||||
			server.shutdownAtMu.RLock()
 | 
								server.shutdownAtMu.RLock()
 | 
				
			||||||
			defer server.shutdownAtMu.RUnlock()
 | 
								defer server.shutdownAtMu.RUnlock()
 | 
				
			||||||
 | 
				
			|||||||
@ -665,9 +665,10 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
 | 
				
			|||||||
			if d.NextArg() {
 | 
								if d.NextArg() {
 | 
				
			||||||
				return d.ArgErr()
 | 
									return d.ArgErr()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if subdir == "request_buffers" {
 | 
								switch subdir {
 | 
				
			||||||
 | 
								case "request_buffers":
 | 
				
			||||||
				h.RequestBuffers = size
 | 
									h.RequestBuffers = size
 | 
				
			||||||
			} else if subdir == "response_buffers" {
 | 
								case "response_buffers":
 | 
				
			||||||
				h.ResponseBuffers = size
 | 
									h.ResponseBuffers = size
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -122,9 +122,10 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if fromAddr.Port == "" {
 | 
						if fromAddr.Port == "" {
 | 
				
			||||||
		if fromAddr.Scheme == "http" {
 | 
							switch fromAddr.Scheme {
 | 
				
			||||||
 | 
							case "http":
 | 
				
			||||||
			fromAddr.Port = httpPort
 | 
								fromAddr.Port = httpPort
 | 
				
			||||||
		} else if fromAddr.Scheme == "https" {
 | 
							case "https":
 | 
				
			||||||
			fromAddr.Port = httpsPort
 | 
								fromAddr.Port = httpsPort
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -484,7 +484,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	markHealthy := func() {
 | 
						markHealthy := func() {
 | 
				
			||||||
		// increment passes and then check if it has reached the threshold to be healthy
 | 
							// increment passes and then check if it has reached the threshold to be healthy
 | 
				
			||||||
		err := upstream.Host.countHealthPass(1)
 | 
							err := upstream.countHealthPass(1)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			if c := h.HealthChecks.Active.logger.Check(zapcore.ErrorLevel, "could not count active health pass"); c != nil {
 | 
								if c := h.HealthChecks.Active.logger.Check(zapcore.ErrorLevel, "could not count active health pass"); c != nil {
 | 
				
			||||||
				c.Write(
 | 
									c.Write(
 | 
				
			||||||
 | 
				
			|||||||
@ -1150,7 +1150,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int
 | 
				
			|||||||
		// we have to assume the upstream received the request, and
 | 
							// we have to assume the upstream received the request, and
 | 
				
			||||||
		// retries need to be carefully decided, because some requests
 | 
							// retries need to be carefully decided, because some requests
 | 
				
			||||||
		// are not idempotent
 | 
							// are not idempotent
 | 
				
			||||||
		if !isDialError && !(isHandlerError && errors.Is(herr, errNoUpstream)) {
 | 
							if !isDialError && (!isHandlerError || !errors.Is(herr, errNoUpstream)) {
 | 
				
			||||||
			if lb.RetryMatch == nil && req.Method != "GET" {
 | 
								if lb.RetryMatch == nil && req.Method != "GET" {
 | 
				
			||||||
				// by default, don't retry requests if they aren't GET
 | 
									// by default, don't retry requests if they aren't GET
 | 
				
			||||||
				return false
 | 
									return false
 | 
				
			||||||
 | 
				
			|||||||
@ -808,7 +808,7 @@ func leastRequests(upstreams []*Upstream) *Upstream {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var best []*Upstream
 | 
						var best []*Upstream
 | 
				
			||||||
	var bestReqs int = -1
 | 
						bestReqs := -1
 | 
				
			||||||
	for _, upstream := range upstreams {
 | 
						for _, upstream := range upstreams {
 | 
				
			||||||
		if upstream == nil {
 | 
							if upstream == nil {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
 | 
				
			|||||||
@ -52,5 +52,4 @@ func TestResolveIpVersion(t *testing.T) {
 | 
				
			|||||||
			t.Errorf("resolveIpVersion(): Expected %s got %s", test.expectedIpVersion, ipVersion)
 | 
								t.Errorf("resolveIpVersion(): Expected %s got %s", test.expectedIpVersion, ipVersion)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -377,11 +377,7 @@ func buildQueryString(qs string, repl *caddy.Replacer) string {
 | 
				
			|||||||
// performed in normalized/unescaped space.
 | 
					// performed in normalized/unescaped space.
 | 
				
			||||||
func trimPathPrefix(escapedPath, prefix string) string {
 | 
					func trimPathPrefix(escapedPath, prefix string) string {
 | 
				
			||||||
	var iPath, iPrefix int
 | 
						var iPath, iPrefix int
 | 
				
			||||||
	for {
 | 
						for iPath < len(escapedPath) && iPrefix < len(prefix) {
 | 
				
			||||||
		if iPath >= len(escapedPath) || iPrefix >= len(prefix) {
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		prefixCh := prefix[iPrefix]
 | 
							prefixCh := prefix[iPrefix]
 | 
				
			||||||
		ch := string(escapedPath[iPath])
 | 
							ch := string(escapedPath[iPath])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -171,6 +171,7 @@ func BenchmarkServer_LogRequest_WithTrace(b *testing.B) {
 | 
				
			|||||||
		s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, false)
 | 
							s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, false)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestServer_TrustedRealClientIP_NoTrustedHeaders(t *testing.T) {
 | 
					func TestServer_TrustedRealClientIP_NoTrustedHeaders(t *testing.T) {
 | 
				
			||||||
	req := httptest.NewRequest("GET", "/", nil)
 | 
						req := httptest.NewRequest("GET", "/", nil)
 | 
				
			||||||
	req.RemoteAddr = "192.0.2.1:12345"
 | 
						req.RemoteAddr = "192.0.2.1:12345"
 | 
				
			||||||
 | 
				
			|||||||
@ -388,10 +388,8 @@ func (ap *AutomationPolicy) onlyInternalIssuer() bool {
 | 
				
			|||||||
// isWildcardOrDefault determines if the subjects include any wildcard domains,
 | 
					// isWildcardOrDefault determines if the subjects include any wildcard domains,
 | 
				
			||||||
// or is the "default" policy (i.e. no subjects) which is unbounded.
 | 
					// or is the "default" policy (i.e. no subjects) which is unbounded.
 | 
				
			||||||
func (ap *AutomationPolicy) isWildcardOrDefault() bool {
 | 
					func (ap *AutomationPolicy) isWildcardOrDefault() bool {
 | 
				
			||||||
	isWildcardOrDefault := false
 | 
						isWildcardOrDefault := len(ap.subjects) == 0
 | 
				
			||||||
	if len(ap.subjects) == 0 {
 | 
					
 | 
				
			||||||
		isWildcardOrDefault = true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for _, sub := range ap.subjects {
 | 
						for _, sub := range ap.subjects {
 | 
				
			||||||
		if strings.HasPrefix(sub, "*") {
 | 
							if strings.HasPrefix(sub, "*") {
 | 
				
			||||||
			isWildcardOrDefault = true
 | 
								isWildcardOrDefault = true
 | 
				
			||||||
 | 
				
			|||||||
@ -317,7 +317,7 @@ func TestFileModeToJSON(t *testing.T) {
 | 
				
			|||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "none zero",
 | 
								name:    "none zero",
 | 
				
			||||||
			mode:    0644,
 | 
								mode:    0o644,
 | 
				
			||||||
			want:    `"0644"`,
 | 
								want:    `"0644"`,
 | 
				
			||||||
			wantErr: false,
 | 
								wantErr: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@ -358,7 +358,7 @@ func TestFileModeModification(t *testing.T) {
 | 
				
			|||||||
	defer os.RemoveAll(dir)
 | 
						defer os.RemoveAll(dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fpath := path.Join(dir, "test.log")
 | 
						fpath := path.Join(dir, "test.log")
 | 
				
			||||||
	f_tmp, err := os.OpenFile(fpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0600))
 | 
						f_tmp, err := os.OpenFile(fpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0o600))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("failed to create test file: %v", err)
 | 
							t.Fatalf("failed to create test file: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,9 +3,10 @@ package logging
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"go.uber.org/zap/zapcore"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2"
 | 
						"github.com/caddyserver/caddy/v2"
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/modules/caddyhttp"
 | 
						"github.com/caddyserver/caddy/v2/modules/caddyhttp"
 | 
				
			||||||
	"go.uber.org/zap/zapcore"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIPMaskSingleValue(t *testing.T) {
 | 
					func TestIPMaskSingleValue(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user