1
0
Fork 0

Merge v2.8 into master

This commit is contained in:
romain 2022-09-13 17:17:58 +02:00
commit 693d5da1b9
44 changed files with 263 additions and 151 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/gorilla/mux"
"github.com/traefik/traefik/v2/pkg/config/runtime"
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/tls"
)
type routerRepresentation struct {
@ -20,6 +21,10 @@ type routerRepresentation struct {
}
func newRouterRepresentation(name string, rt *runtime.RouterInfo) routerRepresentation {
if rt.TLS != nil && rt.TLS.Options == "" {
rt.TLS.Options = tls.DefaultTLSConfigName
}
return routerRepresentation{
RouterInfo: rt,
Name: name,

View file

@ -223,6 +223,52 @@ func TestHandler_HTTP(t *testing.T) {
jsonFile: "testdata/router-bar.json",
},
},
{
desc: "one router by id, implicitly using default TLS options",
path: "/api/http/routers/baz@myprovider",
conf: runtime.Configuration{
Routers: map[string]*runtime.RouterInfo{
"baz@myprovider": {
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.baz`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
TLS: &dynamic.RouterTLSConfig{},
},
Status: "enabled",
},
},
},
expected: expected{
statusCode: http.StatusOK,
jsonFile: "testdata/router-baz-default-tls-options.json",
},
},
{
desc: "one router by id, using specific TLS options",
path: "/api/http/routers/baz@myprovider",
conf: runtime.Configuration{
Routers: map[string]*runtime.RouterInfo{
"baz@myprovider": {
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.baz`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
TLS: &dynamic.RouterTLSConfig{
Options: "myTLS",
},
},
Status: "enabled",
},
},
},
expected: expected{
statusCode: http.StatusOK,
jsonFile: "testdata/router-baz-custom-tls-options.json",
},
},
{
desc: "one router by id, that does not exist",
path: "/api/http/routers/foo@myprovider",
@ -811,6 +857,7 @@ func TestHandler_HTTP(t *testing.T) {
// To lazily initialize the Statuses.
rtConf.PopulateUsedBy()
rtConf.GetRoutersByEntryPoints(context.Background(), []string{"web"}, false)
rtConf.GetRoutersByEntryPoints(context.Background(), []string{"web"}, true)
handler := New(static.Configuration{API: &static.API{}, Global: &static.Global{}}, rtConf)
server := httptest.NewServer(handler.createRouter())

View file

@ -0,0 +1,20 @@
{
"entryPoints": [
"web"
],
"middlewares": [
"auth",
"addPrefixTest@anotherprovider"
],
"name": "baz@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.baz`)",
"service": "foo-service@myprovider",
"tls": {
"options": "myTLS"
},
"status": "enabled",
"using": [
"web"
]
}

View file

@ -0,0 +1,20 @@
{
"entryPoints": [
"web"
],
"middlewares": [
"auth",
"addPrefixTest@anotherprovider"
],
"name": "baz@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.baz`)",
"service": "foo-service@myprovider",
"tls": {
"options": "default"
},
"status": "enabled",
"using": [
"web"
]
}

View file

@ -49,11 +49,16 @@ func (r *RequestDecorator) ServeHTTP(rw http.ResponseWriter, req *http.Request,
func parseHost(addr string) string {
if !strings.Contains(addr, ":") {
// IPv4 without port or empty address
return addr
}
// IPv4 with port or IPv6
host, _, err := net.SplitHostPort(addr)
if err != nil {
if addr[0] == '[' && addr[len(addr)-1] == ']' {
return addr[1 : len(addr)-1]
}
return addr
}
return host

View file

@ -104,7 +104,7 @@ func TestRequestFlattening(t *testing.T) {
}
}
func TestRequestHostParseHost(t *testing.T) {
func Test_parseHost(t *testing.T) {
testCases := []struct {
desc string
host string
@ -130,6 +130,46 @@ func TestRequestHostParseHost(t *testing.T) {
host: "127.0.0.1:",
expected: "127.0.0.1",
},
{
desc: "host with : and without port",
host: "fe80::215:5dff:fe20:cd6a",
expected: "fe80::215:5dff:fe20:cd6a",
},
{
desc: "IPv6 host with : and with port",
host: "[fe80::215:5dff:fe20:cd6a]:123",
expected: "fe80::215:5dff:fe20:cd6a",
},
{
desc: "IPv6 host with : and without port",
host: "[fe80::215:5dff:fe20:cd6a]:",
expected: "fe80::215:5dff:fe20:cd6a",
},
{
desc: "IPv6 host without : and without port",
host: "[fe80::215:5dff:fe20:cd6a]",
expected: "fe80::215:5dff:fe20:cd6a",
},
{
desc: "invalid IPv6: missing [",
host: "fe80::215:5dff:fe20:cd6a]",
expected: "fe80::215:5dff:fe20:cd6a]",
},
{
desc: "invalid IPv6: missing ]",
host: "[fe80::215:5dff:fe20:cd6a",
expected: "[fe80::215:5dff:fe20:cd6a",
},
{
desc: "empty address",
host: "",
expected: "",
},
{
desc: "only :",
host: ":",
expected: "",
},
}
for _, test := range testCases {

View file

@ -164,7 +164,12 @@ func (c *Client) Download(ctx context.Context, pName, pVersion string) (string,
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode == http.StatusOK {
switch resp.StatusCode {
case http.StatusNotModified:
// noop
return hash, nil
case http.StatusOK:
err = os.MkdirAll(filepath.Dir(filename), 0o755)
if err != nil {
return "", fmt.Errorf("failed to create directory: %w", err)
@ -189,15 +194,11 @@ func (c *Client) Download(ctx context.Context, pName, pVersion string) (string,
}
return hash, nil
}
if resp.StatusCode == http.StatusNotModified {
// noop
return hash, nil
default:
data, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("error: %d: %s", resp.StatusCode, string(data))
}
data, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("error: %d: %s", resp.StatusCode, string(data))
}
// Check checks the plugin archive integrity.

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"reflect"
"strings"
"github.com/containous/alice"
@ -340,7 +341,7 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (
}
// Plugin
if config.Plugin != nil {
if config.Plugin != nil && !reflect.ValueOf(b.pluginBuilder).IsNil() { // Using "reflect" because "b.pluginBuilder" is an interface.
if middleware != nil {
return nil, badConf
}