github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/trust_test.go (about) 1 // +build !remoteclient 2 3 package integration 4 5 import ( 6 "encoding/json" 7 "io/ioutil" 8 "os" 9 "path/filepath" 10 11 . "github.com/containers/libpod/test/utils" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Podman trust", func() { 17 var ( 18 tempdir string 19 err error 20 podmanTest *PodmanTestIntegration 21 ) 22 23 BeforeEach(func() { 24 tempdir, err = CreateTempDirInTempDir() 25 if err != nil { 26 os.Exit(1) 27 } 28 podmanTest = PodmanTestCreate(tempdir) 29 podmanTest.Setup() 30 podmanTest.SeedImages() 31 }) 32 33 AfterEach(func() { 34 podmanTest.Cleanup() 35 f := CurrentGinkgoTestDescription() 36 processTestResult(f) 37 38 }) 39 40 It("podman image trust show", func() { 41 path, err := os.Getwd() 42 if err != nil { 43 os.Exit(1) 44 } 45 session := podmanTest.Podman([]string{"image", "trust", "show", "--registrypath", filepath.Dir(path), "--policypath", filepath.Join(filepath.Dir(path), "policy.json")}) 46 session.WaitWithDefaultTimeout() 47 Expect(session.ExitCode()).To(Equal(0)) 48 outArray := session.OutputToStringArray() 49 Expect(len(outArray)).To(Equal(3)) 50 Expect(outArray[0]).Should(ContainSubstring("accept")) 51 Expect(outArray[1]).Should(ContainSubstring("reject")) 52 Expect(outArray[2]).Should(ContainSubstring("signed")) 53 }) 54 55 It("podman image trust set", func() { 56 path, err := os.Getwd() 57 if err != nil { 58 os.Exit(1) 59 } 60 session := podmanTest.Podman([]string{"image", "trust", "set", "--policypath", filepath.Join(filepath.Dir(path), "trust_set_test.json"), "-t", "accept", "default"}) 61 session.WaitWithDefaultTimeout() 62 Expect(session.ExitCode()).To(Equal(0)) 63 var teststruct map[string][]map[string]string 64 policyContent, err := ioutil.ReadFile(filepath.Join(filepath.Dir(path), "trust_set_test.json")) 65 if err != nil { 66 os.Exit(1) 67 } 68 err = json.Unmarshal(policyContent, &teststruct) 69 if err != nil { 70 os.Exit(1) 71 } 72 Expect(teststruct["default"][0]["type"]).To(Equal("insecureAcceptAnything")) 73 }) 74 })