mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Before asking a user for the unlock key when they run docker swarm unlock
, actually
check to see if the node is part of a swarm, and if so, if it is unlocked first. If neither of these are true, abort the command. Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
@ -866,24 +866,24 @@ func checkSwarmUnlockedToLocked(c *check.C, d *daemon.Swarm) {
|
||||
func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *check.C) {
|
||||
d := s.AddDaemon(c, false, false)
|
||||
|
||||
// unlocking a normal engine should return an error
|
||||
// unlocking a normal engine should return an error - it does not even ask for the key
|
||||
cmd := d.Command("swarm", "unlock")
|
||||
cmd.Stdin = bytes.NewBufferString("wrong-secret-key")
|
||||
outs, err := cmd.CombinedOutput()
|
||||
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(outs)))
|
||||
c.Assert(string(outs), checker.Contains, "This node is not a swarm manager.")
|
||||
c.Assert(string(outs), checker.Contains, "Error: This node is not part of a swarm")
|
||||
c.Assert(string(outs), checker.Not(checker.Contains), "Please enter unlock key")
|
||||
|
||||
_, err = d.Cmd("swarm", "init")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// unlocking an unlocked swarm should return an error
|
||||
// unlocking an unlocked swarm should return an error - it does not even ask for the key
|
||||
cmd = d.Command("swarm", "unlock")
|
||||
cmd.Stdin = bytes.NewBufferString("wrong-secret-key")
|
||||
outs, err = cmd.CombinedOutput()
|
||||
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(outs)))
|
||||
c.Assert(string(outs), checker.Contains, "swarm is not locked")
|
||||
c.Assert(string(outs), checker.Contains, "Error: swarm is not locked")
|
||||
c.Assert(string(outs), checker.Not(checker.Contains), "Please enter unlock key")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) {
|
||||
|
Reference in New Issue
Block a user