2018-08-29 09:36:03 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/integration/try"
|
2018-08-29 09:36:03 +00:00
|
|
|
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 cmd.Process.Kill()
|
|
|
|
|
2019-05-16 08:58:06 +00:00
|
|
|
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 2*time.Second, try.BodyContains("PathPrefix(`/`)"))
|
2018-08-29 09:36:03 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
request, err := http.NewRequest(http.MethodGet, "https://127.0.0.1:8443", 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: MIIDKjCCAhICCQDKAJTeuq3LHjANBgkqhkiG9w0BAQsFADBXMQswCQYDVQQGEwJGUjEPMA0GA1UECAwGRlJBTkNFMREwDwYDVQQHDAhUT1VMT1VTRTETMBEGA1UECgwKY29udGFpbm91czEPMA0GA1UEAwwGc2VydmVyMB4XDTE4MDMyMTEzNDM0MVoXDTIxMDEwODEzNDM0MVowVzELMAkGA1UEBhMCRlIxDzANBgNVBAgMBkZSQU5DRTERMA8GA1UEBwwIVE9VTE9VU0UxEzARBgNVBAoMCmNvbnRhaW5vdXMxDzANBgNVBAMMBnNlcnZlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKNHrqc7QcRHIc%2F%2FQW3oAcyl9%2BWFLdEtl86f5hTPoV0MpVgxwc98BA%2B0fPb97GOnj05P7QE%2BZerio5kP80ZUBX%2B0LVVilLWKvK47hZ%2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