github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/unshare_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/hanks177/podman/v4/test/utils"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("Podman unshare", func() {
    13  	var (
    14  		tempdir    string
    15  		err        error
    16  		podmanTest *PodmanTestIntegration
    17  	)
    18  	BeforeEach(func() {
    19  		if _, err := os.Stat("/proc/self/uid_map"); err != nil {
    20  			Skip("User namespaces not supported.")
    21  		}
    22  
    23  		if os.Geteuid() == 0 {
    24  			Skip("Use unshare in rootless only")
    25  		}
    26  
    27  		tempdir, err = CreateTempDirInTempDir()
    28  		if err != nil {
    29  			os.Exit(1)
    30  		}
    31  		podmanTest = PodmanTestCreate(tempdir)
    32  		podmanTest.CgroupManager = "cgroupfs"
    33  		podmanTest.StorageOptions = ROOTLESS_STORAGE_OPTIONS
    34  		podmanTest.Setup()
    35  	})
    36  
    37  	AfterEach(func() {
    38  		podmanTest.Cleanup()
    39  		f := CurrentGinkgoTestDescription()
    40  		processTestResult(f)
    41  	})
    42  
    43  	It("podman unshare", func() {
    44  		SkipIfRemote("podman-remote unshare is not supported")
    45  		userNS, _ := os.Readlink("/proc/self/ns/user")
    46  		session := podmanTest.Podman([]string{"unshare", "readlink", "/proc/self/ns/user"})
    47  		session.WaitWithDefaultTimeout()
    48  		Expect(session).Should(Exit(0))
    49  		Expect(session.OutputToString()).ToNot(ContainSubstring(userNS))
    50  	})
    51  
    52  	It("podman unshare --rootless-cni", func() {
    53  		SkipIfRemote("podman-remote unshare is not supported")
    54  		session := podmanTest.Podman([]string{"unshare", "--rootless-netns", "ip", "addr"})
    55  		session.WaitWithDefaultTimeout()
    56  		Expect(session).Should(Exit(0))
    57  		Expect(session.OutputToString()).To(ContainSubstring("tap0"))
    58  	})
    59  
    60  	It("podman unshare exit codes", func() {
    61  		SkipIfRemote("podman-remote unshare is not supported")
    62  		session := podmanTest.Podman([]string{"unshare", "false"})
    63  		session.WaitWithDefaultTimeout()
    64  		Expect(session).Should(Exit(1))
    65  		Expect(session.OutputToString()).Should(Equal(""))
    66  		Expect(session.ErrorToString()).Should(Equal(""))
    67  
    68  		session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"})
    69  		session.WaitWithDefaultTimeout()
    70  		Expect(session).Should(Exit(127))
    71  		Expect(session.OutputToString()).Should(Equal(""))
    72  		Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory"))
    73  
    74  		session = podmanTest.Podman([]string{"unshare", "bogus"})
    75  		session.WaitWithDefaultTimeout()
    76  		Expect(session).Should(Exit(127))
    77  		Expect(session.OutputToString()).Should(Equal(""))
    78  		Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH"))
    79  
    80  		session = podmanTest.Podman([]string{"unshare", "/usr"})
    81  		session.WaitWithDefaultTimeout()
    82  		Expect(session).Should(Exit(126))
    83  		Expect(session.OutputToString()).Should(Equal(""))
    84  		Expect(session.ErrorToString()).Should(ContainSubstring("permission denied"))
    85  
    86  		session = podmanTest.Podman([]string{"unshare", "--bogus"})
    87  		session.WaitWithDefaultTimeout()
    88  		Expect(session).Should(Exit(125))
    89  		Expect(session.OutputToString()).Should(Equal(""))
    90  		Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus"))
    91  	})
    92  
    93  	It("podman unshare check remote error", func() {
    94  		SkipIfNotRemote("check for podman-remote unshare error")
    95  		session := podmanTest.Podman([]string{"unshare"})
    96  		session.WaitWithDefaultTimeout()
    97  		Expect(session).Should(Exit(0))
    98  		Expect(session.OutputToString()).To(Equal(`Error: cannot use command "podman-remote unshare" with the remote podman client`))
    99  	})
   100  })