package integration import ( "crypto/tls" "io/ioutil" "net/http" "os" "time" "github.com/go-check/check" "github.com/traefik/traefik/v2/integration/try" checker "github.com/vdemeester/shakers" ) const ( rootCertPath = "./fixtures/tlsclientheaders/root.pem" certPemPath = "./fixtures/tlsclientheaders/server.pem" certKeyPath = "./fixtures/tlsclientheaders/server.key" ) type TLSClientHeadersSuite struct{ BaseSuite } func (s *TLSClientHeadersSuite) SetUpSuite(c *check.C) { s.createComposeProject(c, "tlsclientheaders") s.composeProject.Start(c) } func (s *TLSClientHeadersSuite) TestTLSClientHeaders(c *check.C) { rootCertContent, err := ioutil.ReadFile(rootCertPath) c.Assert(err, check.IsNil) serverCertContent, err := ioutil.ReadFile(certPemPath) c.Assert(err, check.IsNil) ServerKeyContent, err := ioutil.ReadFile(certKeyPath) c.Assert(err, check.IsNil) file := s.adaptFile(c, "fixtures/tlsclientheaders/simple.toml", struct { RootCertContent string ServerCertContent string ServerKeyContent string }{ RootCertContent: string(rootCertContent), ServerCertContent: string(serverCertContent), ServerKeyContent: string(ServerKeyContent), }) defer os.Remove(file) cmd, display := s.traefikCmd(withConfigFile(file)) defer display(c) err = cmd.Start() c.Assert(err, checker.IsNil) defer s.killCmd(cmd) err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 2*time.Second, try.BodyContains("PathPrefix(`/foo`)")) c.Assert(err, checker.IsNil) request, err := http.NewRequest(http.MethodGet, "https://127.0.0.1:8443/foo", nil) c.Assert(err, checker.IsNil) certificate, err := tls.LoadX509KeyPair(certPemPath, certKeyPath) c.Assert(err, checker.IsNil) tr := &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, Certificates: []tls.Certificate{certificate}, }, } err = try.RequestWithTransport(request, 2*time.Second, tr, try.BodyContains("Forwarded-Tls-Client-Cert: MIIDNTCCAh0CFD0QQcHXUJuKwMBYDA%2BbBExVSP26MA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNVBAYTAkZSMQ8wDQYDVQQIDAZGcmFuY2UxFT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