github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/image_sign_test.go (about) 1 package integration 2 3 import ( 4 "io/ioutil" 5 "os" 6 "os/exec" 7 "path/filepath" 8 9 . "github.com/containers/podman/v3/test/utils" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("Podman image sign", func() { 16 var ( 17 origGNUPGHOME string 18 tempdir string 19 err error 20 podmanTest *PodmanTestIntegration 21 ) 22 23 BeforeEach(func() { 24 SkipIfRemote("podman-remote image sign is not supported") 25 tempdir, err = CreateTempDirInTempDir() 26 if err != nil { 27 os.Exit(1) 28 } 29 podmanTest = PodmanTestCreate(tempdir) 30 podmanTest.Setup() 31 podmanTest.SeedImages() 32 33 tempGNUPGHOME := filepath.Join(podmanTest.TempDir, "tmpGPG") 34 err := os.Mkdir(tempGNUPGHOME, os.ModePerm) 35 Expect(err).To(BeNil()) 36 37 origGNUPGHOME = os.Getenv("GNUPGHOME") 38 err = os.Setenv("GNUPGHOME", tempGNUPGHOME) 39 Expect(err).To(BeNil()) 40 41 }) 42 43 AfterEach(func() { 44 podmanTest.Cleanup() 45 f := CurrentGinkgoTestDescription() 46 processTestResult(f) 47 os.Setenv("GNUPGHOME", origGNUPGHOME) 48 }) 49 50 It("podman sign image", func() { 51 cmd := exec.Command("gpg", "--import", "sign/secret-key.asc") 52 err := cmd.Run() 53 Expect(err).To(BeNil()) 54 sigDir := filepath.Join(podmanTest.TempDir, "test-sign") 55 err = os.MkdirAll(sigDir, os.ModePerm) 56 Expect(err).To(BeNil()) 57 session := podmanTest.Podman([]string{"image", "sign", "--directory", sigDir, "--sign-by", "foo@bar.com", "docker://library/alpine"}) 58 session.WaitWithDefaultTimeout() 59 Expect(session).Should(Exit(0)) 60 _, err = os.Stat(filepath.Join(sigDir, "library")) 61 Expect(err).To(BeNil()) 62 }) 63 64 It("podman sign --all multi-arch image", func() { 65 cmd := exec.Command("gpg", "--import", "sign/secret-key.asc") 66 err := cmd.Run() 67 Expect(err).To(BeNil()) 68 sigDir := filepath.Join(podmanTest.TempDir, "test-sign-multi") 69 err = os.MkdirAll(sigDir, os.ModePerm) 70 Expect(err).To(BeNil()) 71 session := podmanTest.Podman([]string{"image", "sign", "--all", "--directory", sigDir, "--sign-by", "foo@bar.com", "docker://library/alpine"}) 72 session.WaitWithDefaultTimeout() 73 Expect(session).Should(Exit(0)) 74 fInfos, err := ioutil.ReadDir(filepath.Join(sigDir, "library")) 75 Expect(err).To(BeNil()) 76 Expect(len(fInfos) > 1).To(BeTrue()) 77 }) 78 })