Add more content trust tests
Importing from moby's DockerTrustSuite tests.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 8b00c5cfd8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -35,7 +36,7 @@ func SetupConfigFile(t *testing.T) fs.Dir {
|
||||
},
|
||||
"experimental": "enabled"
|
||||
}
|
||||
`))
|
||||
`), fs.WithDir("trust", fs.WithDir("private")))
|
||||
return *dir
|
||||
}
|
||||
|
||||
@@ -75,3 +76,47 @@ func WithNotary(cmd *icmd.Cmd) {
|
||||
)
|
||||
cmd.Env = append(cmd.Env, env...)
|
||||
}
|
||||
|
||||
//WithHome sets the HOME environment variable
|
||||
func WithHome(path string) func(*icmd.Cmd) {
|
||||
return func(cmd *icmd.Cmd) {
|
||||
cmd.Env = append(cmd.Env, "HOME="+path)
|
||||
}
|
||||
}
|
||||
|
||||
//WithNotaryServer sets the location of the notary server
|
||||
func WithNotaryServer(notaryURL string) func(*icmd.Cmd) {
|
||||
return func(cmd *icmd.Cmd) {
|
||||
env := append(os.Environ(),
|
||||
"DOCKER_CONTENT_TRUST_SERVER="+notaryURL,
|
||||
)
|
||||
cmd.Env = append(cmd.Env, env...)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateMaskedTrustedRemoteImage creates a remote image that is signed with
|
||||
// content trust, then pushes a different untrusted image at the same tag.
|
||||
func CreateMaskedTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
|
||||
image := createTrustedRemoteImage(t, registryPrefix, repo, tag)
|
||||
createNamedUnsignedImageFromBusyBox(t, image)
|
||||
return image
|
||||
}
|
||||
|
||||
func createTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
|
||||
image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag)
|
||||
icmd.RunCommand("docker", "image", "pull", AlpineImage).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "image", "tag", AlpineImage, image).Assert(t, icmd.Success)
|
||||
result := icmd.RunCmd(
|
||||
icmd.Command("docker", "image", "push", image),
|
||||
WithPassphrase("root_password", "repo_password"), WithTrust, WithNotary)
|
||||
result.Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
|
||||
return image
|
||||
}
|
||||
|
||||
func createNamedUnsignedImageFromBusyBox(t *testing.T, image string) {
|
||||
icmd.RunCommand("docker", "image", "pull", BusyboxImage).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "image", "tag", BusyboxImage, image).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "image", "push", image).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user