github.com/containers/podman/v4@v4.9.4/test/e2e/unshare_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/containers/podman/v4/test/utils"
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  // podman unshare --rootless-netns leaks the process by design.
    13  // Running a container will cause the cleanup to kick in when this container gets stopped.
    14  func cleanupRootlessSlirp4netns(p *PodmanTestIntegration) {
    15  	session := p.Podman([]string{"run", "--network", "bridge", ALPINE, "true"})
    16  	session.WaitWithDefaultTimeout()
    17  	Expect(session).Should(ExitCleanly())
    18  }
    19  
    20  var _ = Describe("Podman unshare", func() {
    21  	BeforeEach(func() {
    22  		if _, err := os.Stat("/proc/self/uid_map"); err != nil {
    23  			Skip("User namespaces not supported.")
    24  		}
    25  
    26  		if !isRootless() {
    27  			Skip("Use unshare in rootless only")
    28  		}
    29  	})
    30  
    31  	It("podman unshare", func() {
    32  		SkipIfRemote("podman-remote unshare is not supported")
    33  		userNS, _ := os.Readlink("/proc/self/ns/user")
    34  		session := podmanTest.Podman([]string{"unshare", "readlink", "/proc/self/ns/user"})
    35  		session.WaitWithDefaultTimeout()
    36  		Expect(session).Should(ExitCleanly())
    37  		Expect(session.OutputToString()).ToNot(ContainSubstring(userNS))
    38  	})
    39  
    40  	It("podman unshare --rootless-netns", func() {
    41  		SkipIfRemote("podman-remote unshare is not supported")
    42  		defer cleanupRootlessSlirp4netns(podmanTest)
    43  		session := podmanTest.Podman([]string{"unshare", "--rootless-netns", "ip", "addr"})
    44  		session.WaitWithDefaultTimeout()
    45  		Expect(session).Should(ExitCleanly())
    46  		Expect(session.OutputToString()).To(ContainSubstring("tap0"))
    47  	})
    48  
    49  	It("podman unshare exit codes", func() {
    50  		SkipIfRemote("podman-remote unshare is not supported")
    51  		session := podmanTest.Podman([]string{"unshare", "false"})
    52  		session.WaitWithDefaultTimeout()
    53  		Expect(session).Should(Exit(1))
    54  		Expect(session.OutputToString()).Should(Equal(""))
    55  		Expect(session.ErrorToString()).Should(Equal(""))
    56  
    57  		session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"})
    58  		session.WaitWithDefaultTimeout()
    59  		Expect(session).Should(Exit(127))
    60  		Expect(session.OutputToString()).Should(Equal(""))
    61  		Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory"))
    62  
    63  		session = podmanTest.Podman([]string{"unshare", "bogus"})
    64  		session.WaitWithDefaultTimeout()
    65  		Expect(session).Should(Exit(127))
    66  		Expect(session.OutputToString()).Should(Equal(""))
    67  		Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH"))
    68  
    69  		session = podmanTest.Podman([]string{"unshare", "/usr"})
    70  		session.WaitWithDefaultTimeout()
    71  		Expect(session).Should(Exit(126))
    72  		Expect(session.OutputToString()).Should(Equal(""))
    73  		Expect(session.ErrorToString()).Should(ContainSubstring("permission denied"))
    74  
    75  		session = podmanTest.Podman([]string{"unshare", "--bogus"})
    76  		session.WaitWithDefaultTimeout()
    77  		Expect(session).Should(Exit(125))
    78  		Expect(session.OutputToString()).Should(Equal(""))
    79  		Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus"))
    80  	})
    81  
    82  	It("podman unshare check remote error", func() {
    83  		SkipIfNotRemote("check for podman-remote unshare error")
    84  		session := podmanTest.Podman([]string{"unshare"})
    85  		session.WaitWithDefaultTimeout()
    86  		Expect(session).Should(Exit(125))
    87  		Expect(session.ErrorToString()).To(Equal(`Error: cannot use command "podman-remote unshare" with the remote podman client`))
    88  	})
    89  })