github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/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/hanks177/podman/v4/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 tempGNUPGHOME := filepath.Join(podmanTest.TempDir, "tmpGPG") 32 err := os.Mkdir(tempGNUPGHOME, os.ModePerm) 33 Expect(err).To(BeNil()) 34 35 origGNUPGHOME = os.Getenv("GNUPGHOME") 36 err = os.Setenv("GNUPGHOME", tempGNUPGHOME) 37 Expect(err).To(BeNil()) 38 39 }) 40 41 AfterEach(func() { 42 podmanTest.Cleanup() 43 f := CurrentGinkgoTestDescription() 44 processTestResult(f) 45 os.Setenv("GNUPGHOME", origGNUPGHOME) 46 }) 47 48 It("podman sign image", func() { 49 cmd := exec.Command("gpg", "--import", "sign/secret-key.asc") 50 err := cmd.Run() 51 Expect(err).To(BeNil()) 52 sigDir := filepath.Join(podmanTest.TempDir, "test-sign") 53 err = os.MkdirAll(sigDir, os.ModePerm) 54 Expect(err).To(BeNil()) 55 session := podmanTest.Podman([]string{"image", "sign", "--directory", sigDir, "--sign-by", "foo@bar.com", "docker://library/alpine"}) 56 session.WaitWithDefaultTimeout() 57 Expect(session).Should(Exit(0)) 58 _, err = os.Stat(filepath.Join(sigDir, "library")) 59 Expect(err).To(BeNil()) 60 }) 61 62 It("podman sign --all multi-arch image", func() { 63 cmd := exec.Command("gpg", "--import", "sign/secret-key.asc") 64 err := cmd.Run() 65 Expect(err).To(BeNil()) 66 sigDir := filepath.Join(podmanTest.TempDir, "test-sign-multi") 67 err = os.MkdirAll(sigDir, os.ModePerm) 68 Expect(err).To(BeNil()) 69 session := podmanTest.Podman([]string{"image", "sign", "--all", "--directory", sigDir, "--sign-by", "foo@bar.com", "docker://library/alpine"}) 70 session.WaitWithDefaultTimeout() 71 Expect(session).Should(Exit(0)) 72 fInfos, err := ioutil.ReadDir(filepath.Join(sigDir, "library")) 73 Expect(err).To(BeNil()) 74 Expect(len(fInfos)).To(BeNumerically(">", 1), "len(fInfos)") 75 }) 76 })