1
0
Fork 0

Allow matching with FQDN hosts with trailing periods

This commit is contained in:
Daniel Tomcej 2019-05-06 08:16:03 -07:00 committed by Traefiker Bot
parent 72397ef90c
commit 5a173fa968
5 changed files with 117 additions and 1 deletions

View file

@ -0,0 +1,28 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":8000"
[providers]
[providers.file]
[http.routers]
[http.routers.router1]
rule = "Host(`test.localhost`)"
service = "service1"
[http.routers.router2]
rule = "Host(`test.foo.localhost.`)"
service = "service1"
[http.services]
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
URL = "{{.Server}}"
weight = 10

View file

@ -481,3 +481,54 @@ func (s *SimpleSuite) TestMultiprovider(c *check.C) {
c.Assert(err, checker.IsNil)
}
func (s *SimpleSuite) TestSimpleConfigurationHostRequestTrailingPeriod(c *check.C) {
s.createComposeProject(c, "base")
s.composeProject.Start(c)
server := "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress
file := s.adaptFile(c, "fixtures/file/simple-hosts.toml", struct {
Server string
}{Server: server})
defer os.Remove(file)
cmd, output := s.traefikCmd(withConfigFile(file))
defer output(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
testCases := []struct {
desc string
requestHost string
}{
{
desc: "Request host without trailing period, rule without trailing period",
requestHost: "test.localhost",
},
{
desc: "Request host with trailing period, rule without trailing period",
requestHost: "test.localhost.",
},
{
desc: "Request host without trailing period, rule with trailing period",
requestHost: "test.foo.localhost",
},
{
desc: "Request host with trailing period, rule with trailing period",
requestHost: "test.foo.localhost.",
},
}
for _, test := range testCases {
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000", nil)
c.Assert(err, checker.IsNil)
req.Host = test.requestHost
err = try.Request(req, 1*time.Second, try.StatusCodeIs(http.StatusOK))
if err != nil {
c.Fatalf("Error while testing %s: %v", test.desc, err)
}
}
}