Skip to content

Commit

Permalink
fix(tests): Allow TLS
Browse files Browse the repository at this point in the history
Fixes deis#2230
  • Loading branch information
johanneswuerbach committed Nov 3, 2014
1 parent 68f81c7 commit 7a4ac38
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/dockercli/dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ package dockercli

import (
"bufio"
"crypto/tls"
"log"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -18,6 +21,11 @@ import (
"github.com/docker/docker/api/client"
)

const (
defaultKeyFile = "key.pem"
defaultCertFile = "cert.pem"
)

// CloseWrap ensures that an io.Writer is closed.
func CloseWrap(args ...io.Closer) error {
e := false
Expand Down Expand Up @@ -88,7 +96,33 @@ func NewClient() (
cli *client.DockerCli, stdout *io.PipeReader, stdoutPipe *io.PipeWriter) {
proto, addr, _ := DockerHost()
stdout, stdoutPipe = io.Pipe()
cli = client.NewDockerCli(nil, stdoutPipe, nil, nil, proto, addr, nil)

dockerCertPath := os.Getenv("DOCKER_CERT_PATH")
// Boot2docker use TLS per default, Jenkins not
if dockerCertPath != "" {
var (
tlsConfig tls.Config
)
tlsConfig.InsecureSkipVerify = true

flCert := filepath.Join(dockerCertPath, defaultCertFile)
flKey := filepath.Join(dockerCertPath, defaultKeyFile)

_, errCert := os.Stat(flCert)
_, errKey := os.Stat(flKey)
if errCert == nil && errKey == nil {
cert, err := tls.LoadX509KeyPair(flCert, flKey)
if err != nil {
log.Fatalf("Couldn't load X509 key pair: %s. Key encrypted?", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
}
// Avoid fallback to SSL protocols < TLS1.0
tlsConfig.MinVersion = tls.VersionTLS10
cli = client.NewDockerCli(nil, stdoutPipe, nil, nil, proto, addr, &tlsConfig)
} else {
cli = client.NewDockerCli(nil, stdoutPipe, nil, nil, proto, addr, nil)
}
return
}

Expand Down

0 comments on commit 7a4ac38

Please sign in to comment.