fix: validation system

This commit is contained in:
Ludovic Fernandez 2019-04-01 15:30:07 +02:00 committed by Traefiker Bot
parent d6c9f51082
commit da20db862d
18 changed files with 235 additions and 324 deletions

View file

@ -1,8 +1,6 @@
[run] [run]
deadline = "10m" deadline = "10m"
skip-files = [ skip-files = []
"^old/.*",
]
[linters-settings] [linters-settings]
@ -52,12 +50,6 @@
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = ".+_test.go" path = ".+_test.go"
linters = ["goconst"] linters = ["goconst"]
[[issues.exclude-rules]]
path = "provider/label/internal/.+_test.go"
text = "U1000: field `(foo|fuu)` is unused"
[[issues.exclude-rules]]
path = "middlewares/recovery/recovery.go"
text = "`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`"
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "integration/.+_test.go" path = "integration/.+_test.go"
text = "Error return value of `cmd\\.Process\\.Kill` is not checked" text = "Error return value of `cmd\\.Process\\.Kill` is not checked"
@ -68,23 +60,26 @@
path = "integration/grpc_test.go" path = "integration/grpc_test.go"
text = "Error return value of `closer` is not checked" text = "Error return value of `closer` is not checked"
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "provider/kubernetes/builder_(endpoint|service)_test.go" path = "pkg/h2c/h2c.go"
text = "Error return value of `rw.Write` is not checked"
[[issues.exclude-rules]]
path = "pkg/middlewares/recovery/recovery.go"
text = "`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`"
[[issues.exclude-rules]]
path = "pkg/provider/docker/builder_test.go"
text = "(U1000: func )?`(.+)` is unused" text = "(U1000: func )?`(.+)` is unused"
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "provider/docker/builder_test.go" path = "pkg/provider/kubernetes/builder_(endpoint|service)_test.go"
text = "(U1000: func )?`(.+)` is unused" text = "(U1000: func )?`(.+)` is unused"
[[issues.exclude-rules]]
path = "pkg/provider/label/internal/.+_test.go"
text = "U1000: field `(foo|fuu)` is unused"
[[issues.exclude-rules]]
path = "pkg/server/service/bufferpool.go"
text = "SA6002: argument should be pointer-like to avoid allocations"
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "cmd/configuration.go" path = "cmd/configuration.go"
text = "string `traefik` has (\\d) occurrences, make it a constant" text = "string `traefik` has (\\d) occurrences, make it a constant"
[[issues.exclude-rules]]
path = "h2c/h2c.go"
text = "Error return value of `rw.Write` is not checked"
[[issues.exclude-rules]]
path = "server/service/bufferpool.go"
text = "SA6002: argument should be pointer-like to avoid allocations"
[[issues.exclude-rules]] # FIXME must be fixed
path = "acme/.+.go"
text = "(assignment copies lock value to domainsCerts|literal copies lock value from)"
[[issues.exclude-rules]] # FIXME must be fixed [[issues.exclude-rules]] # FIXME must be fixed
path = "cmd/context.go" path = "cmd/context.go"
text = "S1000: should use a simple channel send/receive instead of `select` with a single case" text = "S1000: should use a simple channel send/receive instead of `select` with a single case"

View file

@ -171,7 +171,7 @@
- **[acme]** Updates lego. ([#4376](https://github.com/containous/traefik/pull/4376) by [ldez](https://github.com/ldez)) - **[acme]** Updates lego. ([#4376](https://github.com/containous/traefik/pull/4376) by [ldez](https://github.com/ldez))
- **[docker]** Fixes docker swarm mode refresh second for KV. ([#4420](https://github.com/containous/traefik/pull/4420) by [ldez](https://github.com/ldez)) - **[docker]** Fixes docker swarm mode refresh second for KV. ([#4420](https://github.com/containous/traefik/pull/4420) by [ldez](https://github.com/ldez))
- **[ecs]** Generic awsvpc support, not just Fargate ([#4360](https://github.com/containous/traefik/pull/4360) by [maartenvanderhoef](https://github.com/maartenvanderhoef)) - **[ecs]** Generic awsvpc support, not just Fargate ([#4360](https://github.com/containous/traefik/pull/4360) by [maartenvanderhoef](https://github.com/maartenvanderhoef))
- **[ecs]** Cache exising task definitions to avoid rate limiting ([#4177](https://github.com/containous/traefik/pull/4177) by [hwhelan-CB](https://github.com/hwhelan-CB)) - **[ecs]** Cache existing task definitions to avoid rate limiting ([#4177](https://github.com/containous/traefik/pull/4177) by [hwhelan-CB](https://github.com/hwhelan-CB))
- **[tls]** Check for dynamic tls updates on configuration preload ([#4022](https://github.com/containous/traefik/pull/4022) by [ffilippopoulos](https://github.com/ffilippopoulos)) - **[tls]** Check for dynamic tls updates on configuration preload ([#4022](https://github.com/containous/traefik/pull/4022) by [ffilippopoulos](https://github.com/ffilippopoulos))
- **[tracing]** Support Datadog tracer priority sampling ([#4359](https://github.com/containous/traefik/pull/4359) by [jcassee](https://github.com/jcassee)) - **[tracing]** Support Datadog tracer priority sampling ([#4359](https://github.com/containous/traefik/pull/4359) by [jcassee](https://github.com/jcassee))
- Update to Go 1.11.5 [CVE-2019-6486](https://nvd.nist.gov/vuln/detail/CVE-2019-6486) - Update to Go 1.11.5 [CVE-2019-6486](https://nvd.nist.gov/vuln/detail/CVE-2019-6486)
@ -296,7 +296,7 @@
**Bug fixes:** **Bug fixes:**
- **[acme]** DNS challenge Cloudflare auth zone ([#4042](https://github.com/containous/traefik/pull/4042) by [ldez](https://github.com/ldez)) - **[acme]** DNS challenge Cloudflare auth zone ([#4042](https://github.com/containous/traefik/pull/4042) by [ldez](https://github.com/ldez))
- **[acme]** ACME DNS challenges ([#3998](https://github.com/containous/traefik/pull/3998) by [ldez](https://github.com/ldez)) - **[acme]** ACME DNS challenges ([#3998](https://github.com/containous/traefik/pull/3998) by [ldez](https://github.com/ldez))
- **[acme]** Don't initalize ACME provider if storage is empty ([#3988](https://github.com/containous/traefik/pull/3988) by [nmengin](https://github.com/nmengin)) - **[acme]** Don't initialize ACME provider if storage is empty ([#3988](https://github.com/containous/traefik/pull/3988) by [nmengin](https://github.com/nmengin))
- **[acme]** Fix: acme DNS providers ([#4021](https://github.com/containous/traefik/pull/4021) by [ldez](https://github.com/ldez)) - **[acme]** Fix: acme DNS providers ([#4021](https://github.com/containous/traefik/pull/4021) by [ldez](https://github.com/ldez))
- **[acme]** Prevent some malformed errors in LE. ([#4015](https://github.com/containous/traefik/pull/4015) by [ldez](https://github.com/ldez)) - **[acme]** Prevent some malformed errors in LE. ([#4015](https://github.com/containous/traefik/pull/4015) by [ldez](https://github.com/ldez))
- **[authentication,consulcatalog,docker,ecs,etcd,kv,marathon,mesos,rancher]** Add the AuthResponseHeaders to the labels ([#3973](https://github.com/containous/traefik/pull/3973) by [Crypto89](https://github.com/Crypto89)) - **[authentication,consulcatalog,docker,ecs,etcd,kv,marathon,mesos,rancher]** Add the AuthResponseHeaders to the labels ([#3973](https://github.com/containous/traefik/pull/3973) by [Crypto89](https://github.com/Crypto89))
@ -371,7 +371,7 @@
- **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez)) - **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez))
- **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab)) - **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab))
- **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej))
- **[k8s]** Substitude hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882)) - **[k8s]** Substitute hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
- **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez)) - **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez))
- **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej))
- **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej))
@ -668,7 +668,7 @@
- **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez)) - **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez))
- **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab)) - **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab))
- **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej))
- **[k8s]** Substitude hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882)) - **[k8s]** Substitute hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
- **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez)) - **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez))
- **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej))
- **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej)) - **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej))

1
Gopkg.lock generated
View file

@ -2222,7 +2222,6 @@
"github.com/opentracing/opentracing-go/log", "github.com/opentracing/opentracing-go/log",
"github.com/openzipkin/zipkin-go-opentracing", "github.com/openzipkin/zipkin-go-opentracing",
"github.com/patrickmn/go-cache", "github.com/patrickmn/go-cache",
"github.com/pkg/errors",
"github.com/prometheus/client_golang/prometheus", "github.com/prometheus/client_golang/prometheus",
"github.com/prometheus/client_golang/prometheus/promhttp", "github.com/prometheus/client_golang/prometheus/promhttp",
"github.com/prometheus/client_model/go", "github.com/prometheus/client_model/go",

View file

@ -36,17 +36,17 @@ required = [
non-go = false non-go = false
unused-packages = false unused-packages = false
[[constraint]] #[[constraint]]
branch = "master" # branch = "master"
name = "github.com/ArthurHlt/go-eureka-client" # name = "github.com/ArthurHlt/go-eureka-client"
[[constraint]] [[constraint]]
branch = "master" branch = "master"
name = "github.com/BurntSushi/toml" name = "github.com/BurntSushi/toml"
[[constraint]] #[[constraint]]
branch = "master" # branch = "master"
name = "github.com/BurntSushi/ty" # name = "github.com/BurntSushi/ty"
[[constraint]] [[constraint]]
branch = "master" branch = "master"
@ -61,9 +61,9 @@ required = [
branch = "master" branch = "master"
name = "github.com/armon/go-proxyproto" name = "github.com/armon/go-proxyproto"
[[constraint]] #[[constraint]]
name = "github.com/aws/aws-sdk-go" # name = "github.com/aws/aws-sdk-go"
version = "1.13.11" # version = "1.13.11"
[[constraint]] [[constraint]]
name = "github.com/cenkalti/backoff" name = "github.com/cenkalti/backoff"
@ -94,10 +94,10 @@ required = [
name = "github.com/coreos/go-systemd" name = "github.com/coreos/go-systemd"
version = "14.0.0" version = "14.0.0"
[[constraint]] #[[constraint]]
branch = "master" # branch = "master"
name = "github.com/docker/leadership" # name = "github.com/docker/leadership"
source = "github.com/containous/leadership" # source = "github.com/containous/leadership"
[[constraint]] [[constraint]]
name = "github.com/eapache/channels" name = "github.com/eapache/channels"
@ -125,9 +125,9 @@ required = [
branch = "master" branch = "master"
name = "github.com/gorilla/websocket" name = "github.com/gorilla/websocket"
[[constraint]] #[[constraint]]
name = "github.com/hashicorp/consul" # name = "github.com/hashicorp/consul"
version = "1.0.6" # version = "1.0.6"
[[constraint]] [[constraint]]
name = "github.com/influxdata/influxdb" name = "github.com/influxdata/influxdb"
@ -141,18 +141,18 @@ required = [
branch = "master" branch = "master"
name = "github.com/abronan/valkeyrie" name = "github.com/abronan/valkeyrie"
[[constraint]] #[[constraint]]
name = "github.com/mesosphere/mesos-dns" # name = "github.com/mesosphere/mesos-dns"
source = "https://github.com/containous/mesos-dns.git" # source = "https://github.com/containous/mesos-dns.git"
[[constraint]] [[constraint]]
name = "github.com/opentracing/opentracing-go" name = "github.com/opentracing/opentracing-go"
version = "1.0.2" version = "1.0.2"
[[constraint]] #[[constraint]]
branch = "containous-fork" # branch = "containous-fork"
name = "github.com/rancher/go-rancher-metadata" # name = "github.com/rancher/go-rancher-metadata"
source = "github.com/containous/go-rancher-metadata" # source = "github.com/containous/go-rancher-metadata"
[[constraint]] [[constraint]]
branch = "master" branch = "master"

View file

@ -93,7 +93,11 @@ test-integration: $(PRE_TARGET)
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK),TEST_CONTAINER=1) ./script/make.sh generate binary test-integration $(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK),TEST_CONTAINER=1) ./script/make.sh generate binary test-integration
TEST_HOST=1 ./script/make.sh test-integration TEST_HOST=1 ./script/make.sh test-integration
## Validate code, vendor ## Validate code and docs
validate-files: $(PRE_TARGET)
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell
## Validate code, docs, and vendor
validate: $(PRE_TARGET) validate: $(PRE_TARGET)
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell validate-vendor $(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell validate-vendor

View file

@ -2,6 +2,7 @@ package ipwhitelist
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net/http" "net/http"
@ -10,7 +11,6 @@ import (
"github.com/containous/traefik/pkg/middlewares" "github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing" "github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )

View file

@ -2,12 +2,11 @@ package redirect
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"github.com/containous/traefik/pkg/middlewares"
"github.com/pkg/errors"
"github.com/containous/traefik/pkg/config" "github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/middlewares"
) )
const ( const (

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
fmtlog "log" fmtlog "log"
@ -29,7 +30,6 @@ import (
legolog "github.com/go-acme/lego/log" legolog "github.com/go-acme/lego/log"
"github.com/go-acme/lego/providers/dns" "github.com/go-acme/lego/providers/dns"
"github.com/go-acme/lego/registration" "github.com/go-acme/lego/registration"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )

View file

@ -3,6 +3,7 @@ package file
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -18,7 +19,6 @@ import (
"github.com/containous/traefik/pkg/provider" "github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/safe" "github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/tls" "github.com/containous/traefik/pkg/tls"
"github.com/pkg/errors"
"gopkg.in/fsnotify.v1" "gopkg.in/fsnotify.v1"
) )

View file

@ -3,6 +3,7 @@ package crd
import ( import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"errors"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -20,7 +21,6 @@ import (
"github.com/containous/traefik/pkg/provider/kubernetes/k8s" "github.com/containous/traefik/pkg/provider/kubernetes/k8s"
"github.com/containous/traefik/pkg/safe" "github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/tls" "github.com/containous/traefik/pkg/tls"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
) )

View file

@ -2,6 +2,7 @@ package ingress
import ( import (
"context" "context"
"errors"
"flag" "flag"
"fmt" "fmt"
"math" "math"
@ -19,7 +20,6 @@ import (
"github.com/containous/traefik/pkg/provider/kubernetes/k8s" "github.com/containous/traefik/pkg/provider/kubernetes/k8s"
"github.com/containous/traefik/pkg/safe" "github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/tls" "github.com/containous/traefik/pkg/tls"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1" "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"

View file

@ -1,9 +1,9 @@
package rules package rules
import ( import (
"errors"
"strings" "strings"
"github.com/pkg/errors"
"github.com/vulcand/predicate" "github.com/vulcand/predicate"
) )

View file

@ -2,6 +2,7 @@ package middleware
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
@ -28,7 +29,6 @@ import (
"github.com/containous/traefik/pkg/middlewares/stripprefixregex" "github.com/containous/traefik/pkg/middlewares/stripprefixregex"
"github.com/containous/traefik/pkg/middlewares/tracing" "github.com/containous/traefik/pkg/middlewares/tracing"
"github.com/containous/traefik/pkg/server/internal" "github.com/containous/traefik/pkg/server/internal"
"github.com/pkg/errors"
) )
type middlewareStackType int type middlewareStackType int
@ -65,7 +65,7 @@ func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.C
} }
var err error var err error
if constructorContext, err = checkRecursivity(constructorContext, middlewareName); err != nil { if constructorContext, err = checkRecursion(constructorContext, middlewareName); err != nil {
return nil, err return nil, err
} }
@ -79,7 +79,7 @@ func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.C
return &chain return &chain
} }
func checkRecursivity(ctx context.Context, middlewareName string) (context.Context, error) { func checkRecursion(ctx context.Context, middlewareName string) (context.Context, error) {
currentStack, ok := ctx.Value(middlewareStackKey).([]string) currentStack, ok := ctx.Value(middlewareStackKey).([]string)
if !ok { if !ok {
currentStack = []string{} currentStack = []string{}
@ -92,242 +92,218 @@ func checkRecursivity(ctx context.Context, middlewareName string) (context.Conte
func (b *Builder) buildConstructor(ctx context.Context, middlewareName string, config config.Middleware) (alice.Constructor, error) { func (b *Builder) buildConstructor(ctx context.Context, middlewareName string, config config.Middleware) (alice.Constructor, error) {
var middleware alice.Constructor var middleware alice.Constructor
badConf := errors.New("cannot create middleware %q: multi-types middleware not supported, consider declaring two different pieces of middleware instead") badConf := errors.New("cannot create middleware: multi-types middleware not supported, consider declaring two different pieces of middleware instead")
// AddPrefix // AddPrefix
if config.AddPrefix != nil { if config.AddPrefix != nil {
if middleware == nil {
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return addprefix.New(ctx, next, *config.AddPrefix, middlewareName) return addprefix.New(ctx, next, *config.AddPrefix, middlewareName)
} }
} else {
return nil, badConf
}
} }
// BasicAuth // BasicAuth
if config.BasicAuth != nil { if config.BasicAuth != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return auth.NewBasic(ctx, next, *config.BasicAuth, middlewareName) return auth.NewBasic(ctx, next, *config.BasicAuth, middlewareName)
} }
} else {
return nil, badConf
}
} }
// Buffering // Buffering
if config.Buffering != nil && config.MaxConn.Amount != 0 { if config.Buffering != nil && config.MaxConn.Amount != 0 {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return buffering.New(ctx, next, *config.Buffering, middlewareName) return buffering.New(ctx, next, *config.Buffering, middlewareName)
} }
} else {
return nil, badConf
}
} }
// Chain // Chain
if config.Chain != nil { if config.Chain != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return chain.New(ctx, next, *config.Chain, b, middlewareName) return chain.New(ctx, next, *config.Chain, b, middlewareName)
} }
} else {
return nil, badConf
}
} }
// CircuitBreaker // CircuitBreaker
if config.CircuitBreaker != nil { if config.CircuitBreaker != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return circuitbreaker.New(ctx, next, *config.CircuitBreaker, middlewareName) return circuitbreaker.New(ctx, next, *config.CircuitBreaker, middlewareName)
} }
} else {
return nil, badConf
}
} }
// Compress // Compress
if config.Compress != nil { if config.Compress != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return compress.New(ctx, next, middlewareName) return compress.New(ctx, next, middlewareName)
} }
} else {
return nil, badConf
}
} }
// CustomErrors // CustomErrors
if config.Errors != nil { if config.Errors != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return customerrors.New(ctx, next, *config.Errors, b.serviceBuilder, middlewareName) return customerrors.New(ctx, next, *config.Errors, b.serviceBuilder, middlewareName)
} }
} else {
return nil, badConf
}
} }
// DigestAuth // DigestAuth
if config.DigestAuth != nil { if config.DigestAuth != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return auth.NewDigest(ctx, next, *config.DigestAuth, middlewareName) return auth.NewDigest(ctx, next, *config.DigestAuth, middlewareName)
} }
} else {
return nil, badConf
}
} }
// ForwardAuth // ForwardAuth
if config.ForwardAuth != nil { if config.ForwardAuth != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return auth.NewForward(ctx, next, *config.ForwardAuth, middlewareName) return auth.NewForward(ctx, next, *config.ForwardAuth, middlewareName)
} }
} else {
return nil, badConf
}
} }
// Headers // Headers
if config.Headers != nil { if config.Headers != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return headers.New(ctx, next, *config.Headers, middlewareName) return headers.New(ctx, next, *config.Headers, middlewareName)
} }
} else {
return nil, badConf
}
} }
// IPWhiteList // IPWhiteList
if config.IPWhiteList != nil { if config.IPWhiteList != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return ipwhitelist.New(ctx, next, *config.IPWhiteList, middlewareName) return ipwhitelist.New(ctx, next, *config.IPWhiteList, middlewareName)
} }
} else {
return nil, badConf
}
} }
// MaxConn // MaxConn
if config.MaxConn != nil && config.MaxConn.Amount != 0 { if config.MaxConn != nil && config.MaxConn.Amount != 0 {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return maxconnection.New(ctx, next, *config.MaxConn, middlewareName) return maxconnection.New(ctx, next, *config.MaxConn, middlewareName)
} }
} else {
return nil, badConf
}
} }
// PassTLSClientCert // PassTLSClientCert
if config.PassTLSClientCert != nil { if config.PassTLSClientCert != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return passtlsclientcert.New(ctx, next, *config.PassTLSClientCert, middlewareName) return passtlsclientcert.New(ctx, next, *config.PassTLSClientCert, middlewareName)
} }
} else {
return nil, badConf
}
} }
// RateLimit // RateLimit
if config.RateLimit != nil { if config.RateLimit != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return ratelimiter.New(ctx, next, *config.RateLimit, middlewareName) return ratelimiter.New(ctx, next, *config.RateLimit, middlewareName)
} }
} else {
return nil, badConf
}
} }
// RedirectRegex // RedirectRegex
if config.RedirectRegex != nil { if config.RedirectRegex != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return redirect.NewRedirectRegex(ctx, next, *config.RedirectRegex, middlewareName) return redirect.NewRedirectRegex(ctx, next, *config.RedirectRegex, middlewareName)
} }
} else {
return nil, badConf
}
} }
// RedirectScheme // RedirectScheme
if config.RedirectScheme != nil { if config.RedirectScheme != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return redirect.NewRedirectScheme(ctx, next, *config.RedirectScheme, middlewareName) return redirect.NewRedirectScheme(ctx, next, *config.RedirectScheme, middlewareName)
} }
} else {
return nil, badConf
}
} }
// ReplacePath // ReplacePath
if config.ReplacePath != nil { if config.ReplacePath != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return replacepath.New(ctx, next, *config.ReplacePath, middlewareName) return replacepath.New(ctx, next, *config.ReplacePath, middlewareName)
} }
} else {
return nil, badConf
}
} }
// ReplacePathRegex // ReplacePathRegex
if config.ReplacePathRegex != nil { if config.ReplacePathRegex != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return replacepathregex.New(ctx, next, *config.ReplacePathRegex, middlewareName) return replacepathregex.New(ctx, next, *config.ReplacePathRegex, middlewareName)
} }
} else {
return nil, badConf
}
} }
// Retry // Retry
if config.Retry != nil { if config.Retry != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
// FIXME missing metrics / accessLog // FIXME missing metrics / accessLog
return retry.New(ctx, next, *config.Retry, retry.Listeners{}, middlewareName) return retry.New(ctx, next, *config.Retry, retry.Listeners{}, middlewareName)
} }
} else {
return nil, badConf
}
} }
// StripPrefix // StripPrefix
if config.StripPrefix != nil { if config.StripPrefix != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return stripprefix.New(ctx, next, *config.StripPrefix, middlewareName) return stripprefix.New(ctx, next, *config.StripPrefix, middlewareName)
} }
} else {
return nil, badConf
}
} }
// StripPrefixRegex // StripPrefixRegex
if config.StripPrefixRegex != nil { if config.StripPrefixRegex != nil {
if middleware == nil { if middleware != nil {
return nil, badConf
}
middleware = func(next http.Handler) (http.Handler, error) { middleware = func(next http.Handler) (http.Handler, error) {
return stripprefixregex.New(ctx, next, *config.StripPrefixRegex, middlewareName) return stripprefixregex.New(ctx, next, *config.StripPrefixRegex, middlewareName)
} }
} else {
return nil, badConf
}
} }
if middleware == nil { if middleware == nil {
return nil, fmt.Errorf("middleware %q does not exist", middlewareName) return nil, errors.New("middleware does not exist")
} }
return tracing.Wrap(ctx, middleware), nil return tracing.Wrap(ctx, middleware), nil

View file

@ -13,58 +13,6 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestBuilder_buildConstructorCircuitBreaker(t *testing.T) {
testConfig := map[string]*config.Middleware{
"empty": {
CircuitBreaker: &config.CircuitBreaker{
Expression: "",
},
},
"foo": {
CircuitBreaker: &config.CircuitBreaker{
Expression: "NetworkErrorRatio() > 0.5",
},
},
}
middlewaresBuilder := NewBuilder(testConfig, nil)
emptyHandler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
testCases := []struct {
desc string
middlewareID string
expectedError bool
}{
{
desc: "Should fail at creating a circuit breaker with an empty expression",
expectedError: true,
middlewareID: "empty",
}, {
desc: "Should create a circuit breaker with a valid expression",
expectedError: false,
middlewareID: "foo",
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
require.NoError(t, err)
middleware, err2 := constructor(emptyHandler)
if test.expectedError {
require.Error(t, err2)
} else {
require.NoError(t, err)
require.NotNil(t, middleware)
}
})
}
}
func TestBuilder_BuildChainNilConfig(t *testing.T) { func TestBuilder_BuildChainNilConfig(t *testing.T) {
testConfig := map[string]*config.Middleware{ testConfig := map[string]*config.Middleware{
"empty": {}, "empty": {},
@ -87,59 +35,7 @@ func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
require.Error(t, err) require.Error(t, err)
} }
func TestBuilder_buildConstructorAddPrefix(t *testing.T) { func TestBuilder_BuildChainWithContext(t *testing.T) {
testConfig := map[string]*config.Middleware{
"empty": {
AddPrefix: &config.AddPrefix{
Prefix: "",
},
},
"foo": {
AddPrefix: &config.AddPrefix{
Prefix: "foo/",
},
},
}
middlewaresBuilder := NewBuilder(testConfig, nil)
testCases := []struct {
desc string
middlewareID string
expectedError bool
}{
{
desc: "Should not create an empty AddPrefix middleware when given an empty prefix",
middlewareID: "empty",
expectedError: true,
}, {
desc: "Should create an AddPrefix middleware when given a valid configuration",
middlewareID: "foo",
expectedError: false,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
require.NoError(t, err)
middleware, err2 := constructor(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}))
if test.expectedError {
require.Error(t, err2)
} else {
require.NoError(t, err)
require.NotNil(t, middleware)
}
})
}
}
func TestBuild_BuildChainWithContext(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
buildChain []string buildChain []string
@ -389,3 +285,76 @@ func TestBuild_BuildChainWithContext(t *testing.T) {
}) })
} }
} }
func TestBuilder_buildConstructor(t *testing.T) {
testConfig := map[string]*config.Middleware{
"cb-empty": {
CircuitBreaker: &config.CircuitBreaker{
Expression: "",
},
},
"cb-foo": {
CircuitBreaker: &config.CircuitBreaker{
Expression: "NetworkErrorRatio() > 0.5",
},
},
"ap-empty": {
AddPrefix: &config.AddPrefix{
Prefix: "",
},
},
"ap-foo": {
AddPrefix: &config.AddPrefix{
Prefix: "foo/",
},
},
}
middlewaresBuilder := NewBuilder(testConfig, nil)
testCases := []struct {
desc string
middlewareID string
expectedError bool
}{
{
desc: "Should fail at creating a circuit breaker with an empty expression",
middlewareID: "cb-empty",
expectedError: true,
},
{
desc: "Should create a circuit breaker with a valid expression",
middlewareID: "cb-foo",
expectedError: false,
},
{
desc: "Should not create an empty AddPrefix middleware when given an empty prefix",
middlewareID: "ap-empty",
expectedError: true,
},
{
desc: "Should create an AddPrefix middleware when given a valid configuration",
middlewareID: "ap-foo",
expectedError: false,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
require.NoError(t, err)
middleware, err2 := constructor(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
if test.expectedError {
require.Error(t, err2)
} else {
require.NoError(t, err)
require.NotNil(t, middleware)
}
})
}
}

View file

@ -3,6 +3,7 @@ package server
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"net" "net"
"net/http" "net/http"
"time" "time"
@ -10,7 +11,6 @@ import (
"github.com/containous/traefik/pkg/config/static" "github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log" "github.com/containous/traefik/pkg/log"
traefiktls "github.com/containous/traefik/pkg/tls" traefiktls "github.com/containous/traefik/pkg/tls"
"github.com/pkg/errors"
"golang.org/x/net/http2" "golang.org/x/net/http2"
) )

View file

@ -1,24 +0,0 @@
#!/usr/bin/env bash
if [ -z "${VALIDATE_UPSTREAM:-}" ]; then
# this is kind of an expensive check, so let's not do this twice if we
# are running more than one validate bundlescript
VALIDATE_REPO='https://github.com/containous/traefik.git'
## FIXME wrong assumption
VALIDATE_BRANCH='master'
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD"
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
validate_diff() {
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
git diff "$VALIDATE_COMMIT_DIFF" "$@"
fi
}
fi

View file

@ -1,9 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source "$(dirname "$BASH_SOURCE")/.validate"
IFS=$'\n' IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'docs/*.md') ) files=( $( git ls-files 'docs/*.md' *.md ) )
unset IFS unset IFS
errors=() errors=()

View file

@ -4,12 +4,8 @@ set -o pipefail
set -o nounset set -o nounset
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; export SCRIPT_DIR SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; export SCRIPT_DIR
source "${SCRIPT_DIR}/.validate"
vendor_dir="./vendor/" vendor_dir="./vendor/"
IFS=$'\n' files=( $(validate_diff --diff-filter=ACMR --name-only -- ${vendor_dir} || true) )
if [[ ${#files[@]} -gt 0 ]]; then
# We run dep install to and see if we have a diff afterwards # We run dep install to and see if we have a diff afterwards
echo "checking ${vendor_dir} for unintentional changes..." echo "checking ${vendor_dir} for unintentional changes..."
@ -29,6 +25,5 @@ if [[ ${#files[@]} -gt 0 ]]; then
} >&2 } >&2
exit 2 exit 2
fi fi
fi
echo 'Congratulations! All vendoring changes are done the right way.' echo 'Congratulations! All vendoring changes are done the right way.'