Fix ipv6 handling in redirect middleware

This commit is contained in:
Romain
2020-06-19 10:08:04 +02:00
committed by GitHub
parent bb14c3e812
commit c65277a6f0
2 changed files with 29 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ import (
)
const (
defaultRedirectRegex = `^(?:https?:\/\/)?([\w\._-]+)(?::\d+)?(.*)$`
defaultRedirectRegex = `^(?:https?:\/\/)?(\[[\w:.]+\]|[\w\._-]+)(?::\d+)?(.*)$`
)
// NewEntryPointHandler create a new redirection handler base on entry point

View File

@@ -84,6 +84,34 @@ func TestNewEntryPointHandler(t *testing.T) {
url: "http://foo:80",
errorExpected: true,
},
{
desc: "IPV6 HTTP to HTTP",
entryPoint: &configuration.EntryPoint{Address: ":8080"},
url: "http://[::1]",
expectedURL: "http://[::1]:8080",
expectedStatus: http.StatusFound,
},
{
desc: "IPV6 HTTP to HTTPS",
entryPoint: &configuration.EntryPoint{Address: ":443", TLS: &tls.TLS{}},
url: "http://[::1]",
expectedURL: "https://[::1]:443",
expectedStatus: http.StatusFound,
},
{
desc: "IPV6 HTTP with port 80 to HTTP",
entryPoint: &configuration.EntryPoint{Address: ":8080"},
url: "http://[::1]:80",
expectedURL: "http://[::1]:8080",
expectedStatus: http.StatusFound,
},
{
desc: "IPV6 HTTP with port 80 to HTTPS",
entryPoint: &configuration.EntryPoint{Address: ":443", TLS: &tls.TLS{}},
url: "http://[::1]:80",
expectedURL: "https://[::1]:443",
expectedStatus: http.StatusFound,
},
}
for _, test := range testCases {