2016-11-03 17:28:56 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-19 20:41:11 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2016-11-03 17:28:56 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-11-03 17:28:56 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2016-11-28 15:18:15 -05:00
|
|
|
// Test case for 28884
|
|
|
|
func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
2017-01-05 18:22:51 -05:00
|
|
|
name := "test_secret"
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
2017-03-20 04:27:51 -04:00
|
|
|
Annotations: swarm.Annotations{
|
2016-11-28 15:18:15 -05:00
|
|
|
Name: name,
|
|
|
|
},
|
2017-03-20 04:27:51 -04:00
|
|
|
Data: []byte("foo"),
|
2016-11-28 15:18:15 -05:00
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
fake := d.CreateSecret(c, swarm.SecretSpec{
|
2017-03-20 04:27:51 -04:00
|
|
|
Annotations: swarm.Annotations{
|
2016-11-28 15:18:15 -05:00
|
|
|
Name: id,
|
|
|
|
},
|
2017-03-20 04:27:51 -04:00
|
|
|
Data: []byte("fake foo"),
|
2016-11-28 15:18:15 -05:00
|
|
|
})
|
|
|
|
c.Assert(fake, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", fake))
|
|
|
|
|
|
|
|
out, err := d.Cmd("secret", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, name)
|
|
|
|
c.Assert(out, checker.Contains, fake)
|
|
|
|
|
|
|
|
out, err = d.Cmd("secret", "rm", id)
|
2018-07-09 13:40:34 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-11-28 15:18:15 -05:00
|
|
|
c.Assert(out, checker.Contains, id)
|
|
|
|
|
|
|
|
// Fake one will remain
|
|
|
|
out, err = d.Cmd("secret", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
|
|
|
c.Assert(out, checker.Contains, fake)
|
|
|
|
|
|
|
|
// Remove based on name prefix of the fake one
|
|
|
|
// (which is the same as the ID of foo one) should not work
|
|
|
|
// as search is only done based on:
|
|
|
|
// - Full ID
|
|
|
|
// - Full Name
|
|
|
|
// - Partial ID (prefix)
|
|
|
|
out, err = d.Cmd("secret", "rm", id[:5])
|
2018-07-09 13:40:34 -04:00
|
|
|
c.Assert(err, checker.Not(checker.IsNil))
|
2016-11-28 15:18:15 -05:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), id)
|
|
|
|
out, err = d.Cmd("secret", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
|
|
|
c.Assert(out, checker.Contains, fake)
|
|
|
|
|
|
|
|
// Remove based on ID prefix of the fake one should succeed
|
|
|
|
out, err = d.Cmd("secret", "rm", fake[:5])
|
2018-07-09 13:40:34 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-07 14:06:07 -05:00
|
|
|
c.Assert(out, checker.Contains, fake[:5])
|
2016-11-28 15:18:15 -05:00
|
|
|
out, err = d.Cmd("secret", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), id)
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), fake)
|
|
|
|
}
|
2016-11-19 20:41:11 -05:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestSecretCreateWithFile(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
testFile, err := ioutil.TempFile("", "secretCreateTest")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
|
|
|
defer os.Remove(testFile.Name())
|
|
|
|
|
|
|
|
testData := "TESTINGDATA"
|
|
|
|
_, err = testFile.Write([]byte(testData))
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to write to temporary file"))
|
|
|
|
|
|
|
|
testName := "test_secret"
|
2017-01-06 15:06:02 -05:00
|
|
|
out, err := d.Cmd("secret", "create", testName, testFile.Name())
|
2016-11-19 20:41:11 -05:00
|
|
|
c.Assert(err, checker.IsNil)
|
2018-08-14 03:45:39 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "", check.Commentf("%s", out))
|
2016-11-19 20:41:11 -05:00
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
secret := d.GetSecret(c, id)
|
|
|
|
c.Assert(secret.Spec.Name, checker.Equals, testName)
|
|
|
|
}
|