|
@@ -23,6 +23,7 @@ import (
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
|
|
"github.com/docker/docker/pkg/testutil"
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
|
|
+ "github.com/docker/docker/pkg/testutil/tempfile"
|
|
|
"github.com/docker/libnetwork/driverapi"
|
|
|
"github.com/docker/libnetwork/ipamapi"
|
|
|
remoteipam "github.com/docker/libnetwork/ipams/remote/api"
|
|
@@ -53,11 +54,29 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
|
|
|
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
|
|
|
|
|
|
// passing an external CA (this is without starting a root rotation) does not fail
|
|
|
- out, err = d.Cmd("swarm", "update", "--external-ca", "protocol=cfssl,url=https://something.org")
|
|
|
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
|
|
|
+ cli.Docker(cli.Args("swarm", "update", "--external-ca", "protocol=cfssl,url=https://something.org",
|
|
|
+ "--external-ca", "protocol=cfssl,url=https://somethingelse.org,cacert=fixtures/https/ca.pem"),
|
|
|
+ cli.Daemon(d.Daemon)).Assert(c, icmd.Success)
|
|
|
+
|
|
|
+ expected, err := ioutil.ReadFile("fixtures/https/ca.pem")
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
|
|
spec = getSpec()
|
|
|
- c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 1)
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 2)
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
|
|
|
+
|
|
|
+ // passing an invalid external CA fails
|
|
|
+ tempFile := tempfile.NewTempFile(c, "testfile", "fakecert")
|
|
|
+ defer tempFile.Remove()
|
|
|
+
|
|
|
+ result := cli.Docker(cli.Args("swarm", "update",
|
|
|
+ "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://something.org,cacert=%s", tempFile.Name())),
|
|
|
+ cli.Daemon(d.Daemon))
|
|
|
+ result.Assert(c, icmd.Expected{
|
|
|
+ ExitCode: 125,
|
|
|
+ Err: "must be in PEM format",
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
|
@@ -68,17 +87,34 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
|
|
return sw.Spec
|
|
|
}
|
|
|
|
|
|
+ // passing an invalid external CA fails
|
|
|
+ tempFile := tempfile.NewTempFile(c, "testfile", "fakecert")
|
|
|
+ defer tempFile.Remove()
|
|
|
+
|
|
|
+ result := cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s",
|
|
|
+ "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://somethingelse.org,cacert=%s", tempFile.Name())),
|
|
|
+ cli.Daemon(d.Daemon))
|
|
|
+ result.Assert(c, icmd.Expected{
|
|
|
+ ExitCode: 125,
|
|
|
+ Err: "must be in PEM format",
|
|
|
+ })
|
|
|
+
|
|
|
cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s",
|
|
|
- "--external-ca", "protocol=cfssl,url=https://something.org"),
|
|
|
+ "--external-ca", "protocol=cfssl,url=https://something.org",
|
|
|
+ "--external-ca", "protocol=cfssl,url=https://somethingelse.org,cacert=fixtures/https/ca.pem"),
|
|
|
cli.Daemon(d.Daemon)).Assert(c, icmd.Success)
|
|
|
|
|
|
+ expected, err := ioutil.ReadFile("fixtures/https/ca.pem")
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
+
|
|
|
spec := getSpec()
|
|
|
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
|
|
|
c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second)
|
|
|
- c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 1)
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 2)
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
|
|
|
+ c.Assert(spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
|
|
|
|
|
|
c.Assert(d.Leave(true), checker.IsNil)
|
|
|
- time.Sleep(500 * time.Millisecond) // https://github.com/docker/swarmkit/issues/1421
|
|
|
cli.Docker(cli.Args("swarm", "init"), cli.Daemon(d.Daemon)).Assert(c, icmd.Success)
|
|
|
|
|
|
spec = getSpec()
|