github.com/containers/podman/v5@v5.1.0-rc1/test/e2e/unshare_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 6 . "github.com/containers/podman/v5/test/utils" 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("Podman unshare", func() { 13 BeforeEach(func() { 14 if _, err := os.Stat("/proc/self/uid_map"); err != nil { 15 Skip("User namespaces not supported.") 16 } 17 18 if !isRootless() { 19 Skip("Use unshare in rootless only") 20 } 21 }) 22 23 It("podman unshare", func() { 24 SkipIfRemote("podman-remote unshare is not supported") 25 userNS, _ := os.Readlink("/proc/self/ns/user") 26 session := podmanTest.Podman([]string{"unshare", "readlink", "/proc/self/ns/user"}) 27 session.WaitWithDefaultTimeout() 28 Expect(session).Should(ExitCleanly()) 29 Expect(session.OutputToString()).ToNot(ContainSubstring(userNS)) 30 }) 31 32 It("podman unshare exit codes", func() { 33 SkipIfRemote("podman-remote unshare is not supported") 34 session := podmanTest.Podman([]string{"unshare", "false"}) 35 session.WaitWithDefaultTimeout() 36 Expect(session).Should(Exit(1)) 37 Expect(session.OutputToString()).Should(Equal("")) 38 Expect(session.ErrorToString()).Should(Equal("")) 39 40 session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"}) 41 session.WaitWithDefaultTimeout() 42 Expect(session).Should(Exit(127)) 43 Expect(session.OutputToString()).Should(Equal("")) 44 Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory")) 45 46 session = podmanTest.Podman([]string{"unshare", "bogus"}) 47 session.WaitWithDefaultTimeout() 48 Expect(session).Should(Exit(127)) 49 Expect(session.OutputToString()).Should(Equal("")) 50 Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH")) 51 52 session = podmanTest.Podman([]string{"unshare", "/usr"}) 53 session.WaitWithDefaultTimeout() 54 Expect(session).Should(Exit(126)) 55 Expect(session.OutputToString()).Should(Equal("")) 56 Expect(session.ErrorToString()).Should(ContainSubstring("permission denied")) 57 58 session = podmanTest.Podman([]string{"unshare", "--bogus"}) 59 session.WaitWithDefaultTimeout() 60 Expect(session).Should(Exit(125)) 61 Expect(session.OutputToString()).Should(Equal("")) 62 Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus")) 63 }) 64 65 It("podman unshare check remote error", func() { 66 SkipIfNotRemote("check for podman-remote unshare error") 67 session := podmanTest.Podman([]string{"unshare"}) 68 session.WaitWithDefaultTimeout() 69 Expect(session).Should(Exit(125)) 70 Expect(session.ErrorToString()).To(Equal(`Error: cannot use command "podman-remote unshare" with the remote podman client`)) 71 }) 72 })