2016-12-12 17:30:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2017-05-17 13:22:44 +00:00
|
|
|
"github.com/containous/traefik/integration/try"
|
2016-12-12 17:30:31 +00:00
|
|
|
"github.com/go-check/check"
|
|
|
|
checker "github.com/vdemeester/shakers"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ACME test suites (using libcompose)
|
|
|
|
type AcmeSuite struct {
|
|
|
|
BaseSuite
|
2017-05-17 13:22:44 +00:00
|
|
|
boulderIP string
|
2016-12-12 17:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AcmeSuite) SetUpSuite(c *check.C) {
|
|
|
|
s.createComposeProject(c, "boulder")
|
|
|
|
s.composeProject.Start(c)
|
|
|
|
|
2017-05-17 13:22:44 +00:00
|
|
|
s.boulderIP = s.composeProject.Container(c, "boulder").NetworkSettings.IPAddress
|
2016-12-12 17:30:31 +00:00
|
|
|
|
|
|
|
// wait for boulder
|
2017-05-17 13:22:44 +00:00
|
|
|
err := try.GetRequest("http://"+s.boulderIP+":4000/directory", 120*time.Second, try.StatusCodeIs(http.StatusOK))
|
2016-12-12 17:30:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AcmeSuite) TearDownSuite(c *check.C) {
|
|
|
|
// shutdown and delete compose project
|
|
|
|
if s.composeProject != nil {
|
|
|
|
s.composeProject.Stop(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AcmeSuite) TestRetrieveAcmeCertificate(c *check.C) {
|
2017-05-17 13:22:44 +00:00
|
|
|
file := s.adaptFile(c, "fixtures/acme/acme.toml", struct{ BoulderHost string }{s.boulderIP})
|
2016-12-12 17:30:31 +00:00
|
|
|
defer os.Remove(file)
|
2017-05-17 13:22:44 +00:00
|
|
|
cmd, output := s.cmdTraefikWithConfigFile(file)
|
|
|
|
|
2016-12-12 17:30:31 +00:00
|
|
|
err := cmd.Start()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cmd.Process.Kill()
|
|
|
|
|
2017-05-17 13:22:44 +00:00
|
|
|
backend := startTestServer("9010", http.StatusOK)
|
2016-12-12 17:30:31 +00:00
|
|
|
defer backend.Close()
|
|
|
|
|
|
|
|
tr := &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
}
|
|
|
|
client := &http.Client{Transport: tr}
|
|
|
|
|
|
|
|
// wait for traefik (generating acme account take some seconds)
|
2017-05-17 13:22:44 +00:00
|
|
|
err = try.Do(90*time.Second, func() error {
|
2016-12-12 17:30:31 +00:00
|
|
|
_, err := client.Get("https://127.0.0.1:5001")
|
2017-05-17 13:22:44 +00:00
|
|
|
return err
|
2016-12-12 17:30:31 +00:00
|
|
|
})
|
2017-05-17 13:22:44 +00:00
|
|
|
// TODO: waiting a refactor of integration tests
|
|
|
|
s.displayTraefikLog(c, output)
|
2016-12-12 17:30:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
tr = &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
ServerName: "traefik.acme.wtf",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
client = &http.Client{Transport: tr}
|
|
|
|
req, _ := http.NewRequest("GET", "https://127.0.0.1:5001/", nil)
|
|
|
|
req.Host = "traefik.acme.wtf"
|
|
|
|
req.Header.Set("Host", "traefik.acme.wtf")
|
|
|
|
req.Header.Set("Accept", "*/*")
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
// Expected a 200
|
2017-05-17 13:22:44 +00:00
|
|
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
2016-12-12 17:30:31 +00:00
|
|
|
}
|