mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
migrated integration tests from integration-cli/docker_cli_secret_create_test.go to integration/secret
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
parent
9ebed53c54
commit
05a9e6239a
2 changed files with 61 additions and 73 deletions
|
@ -7,72 +7,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
|
||||||
"github.com/docker/docker/integration-cli/checker"
|
"github.com/docker/docker/integration-cli/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test case for 28884
|
|
||||||
func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
|
|
||||||
d := s.AddDaemon(c, true, true)
|
|
||||||
|
|
||||||
name := "test_secret"
|
|
||||||
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
||||||
Annotations: swarm.Annotations{
|
|
||||||
Name: name,
|
|
||||||
},
|
|
||||||
Data: []byte("foo"),
|
|
||||||
})
|
|
||||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
||||||
|
|
||||||
fake := d.CreateSecret(c, swarm.SecretSpec{
|
|
||||||
Annotations: swarm.Annotations{
|
|
||||||
Name: id,
|
|
||||||
},
|
|
||||||
Data: []byte("fake foo"),
|
|
||||||
})
|
|
||||||
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)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
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])
|
|
||||||
c.Assert(err, checker.Not(checker.IsNil))
|
|
||||||
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])
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
c.Assert(out, checker.Contains, fake[:5])
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *DockerSwarmSuite) TestSecretCreateWithFile(c *check.C) {
|
func (s *DockerSwarmSuite) TestSecretCreateWithFile(c *check.C) {
|
||||||
d := s.AddDaemon(c, true, true)
|
d := s.AddDaemon(c, true, true)
|
||||||
|
|
||||||
|
|
|
@ -62,19 +62,10 @@ func TestSecretList(t *testing.T) {
|
||||||
// create secret test1
|
// create secret test1
|
||||||
secret1ID := createSecret(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
|
secret1ID := createSecret(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
|
||||||
|
|
||||||
names := func(entries []swarmtypes.Secret) []string {
|
|
||||||
var values []string
|
|
||||||
for _, entry := range entries {
|
|
||||||
values = append(values, entry.Spec.Name)
|
|
||||||
}
|
|
||||||
sort.Strings(values)
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
|
|
||||||
// test by `secret ls`
|
// test by `secret ls`
|
||||||
entries, err := client.SecretList(ctx, types.SecretListOptions{})
|
entries, err := client.SecretList(ctx, types.SecretListOptions{})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.DeepEqual(names(entries), testNames))
|
assert.Check(t, is.DeepEqual(secretNamesFromList(entries), testNames))
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
|
@ -109,7 +100,7 @@ func TestSecretList(t *testing.T) {
|
||||||
Filters: tc.filters,
|
Filters: tc.filters,
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.DeepEqual(names(entries), tc.expected))
|
assert.Check(t, is.DeepEqual(secretNamesFromList(entries), tc.expected))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,6 +333,56 @@ func TestTemplatedSecret(t *testing.T) {
|
||||||
assertAttachedStream(t, attach, "tmpfs on /run/secrets/templated_secret type tmpfs")
|
assertAttachedStream(t, attach, "tmpfs on /run/secrets/templated_secret type tmpfs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test case for 28884
|
||||||
|
func TestSecretCreateResolve(t *testing.T) {
|
||||||
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
||||||
|
|
||||||
|
defer setupTest(t)()
|
||||||
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
|
defer d.Stop(t)
|
||||||
|
client := d.NewClientT(t)
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
testName := "test_secret_" + t.Name()
|
||||||
|
secretID := createSecret(ctx, t, client, testName, []byte("foo"), nil)
|
||||||
|
|
||||||
|
fakeName := secretID
|
||||||
|
fakeID := createSecret(ctx, t, client, fakeName, []byte("fake foo"), nil)
|
||||||
|
|
||||||
|
entries, err := client.SecretList(ctx, types.SecretListOptions{})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Check(t, is.Contains(secretNamesFromList(entries), testName))
|
||||||
|
assert.Check(t, is.Contains(secretNamesFromList(entries), fakeName))
|
||||||
|
|
||||||
|
err = client.SecretRemove(ctx, secretID)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
// Fake one will remain
|
||||||
|
entries, err = client.SecretList(ctx, types.SecretListOptions{})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
|
||||||
|
|
||||||
|
// Remove based on name prefix of the fake one should not work
|
||||||
|
// as search is only done based on:
|
||||||
|
// - Full ID
|
||||||
|
// - Full Name
|
||||||
|
// - Partial ID (prefix)
|
||||||
|
err = client.SecretRemove(ctx, fakeName[:5])
|
||||||
|
assert.Assert(t, nil != err)
|
||||||
|
entries, err = client.SecretList(ctx, types.SecretListOptions{})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
|
||||||
|
|
||||||
|
// Remove based on ID prefix of the fake one should succeed
|
||||||
|
err = client.SecretRemove(ctx, fakeID[:5])
|
||||||
|
assert.NilError(t, err)
|
||||||
|
entries, err = client.SecretList(ctx, types.SecretListOptions{})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Assert(t, is.Equal(0, len(entries)))
|
||||||
|
}
|
||||||
|
|
||||||
func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) {
|
func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
_, err := stdcopy.StdCopy(buf, buf, attach.Reader)
|
_, err := stdcopy.StdCopy(buf, buf, attach.Reader)
|
||||||
|
@ -364,3 +405,12 @@ func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func secretNamesFromList(entries []swarmtypes.Secret) []string {
|
||||||
|
var values []string
|
||||||
|
for _, entry := range entries {
|
||||||
|
values = append(values, entry.Spec.Name)
|
||||||
|
}
|
||||||
|
sort.Strings(values)
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue