github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/unshare_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/containers/podman/v3/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  		SkipIfRemote("podman-remote unshare is not supported")
    20  		if _, err := os.Stat("/proc/self/uid_map"); err != nil {
    21  			Skip("User namespaces not supported.")
    22  		}
    23  
    24  		if os.Geteuid() == 0 {
    25  			Skip("Use unshare in rootless only")
    26  		}
    27  
    28  		tempdir, err = CreateTempDirInTempDir()
    29  		if err != nil {
    30  			os.Exit(1)
    31  		}
    32  		podmanTest = PodmanTestCreate(tempdir)
    33  		podmanTest.CgroupManager = "cgroupfs"
    34  		podmanTest.StorageOptions = ROOTLESS_STORAGE_OPTIONS
    35  		podmanTest.Setup()
    36  		podmanTest.SeedImages()
    37  	})
    38  
    39  	AfterEach(func() {
    40  		podmanTest.Cleanup()
    41  		f := CurrentGinkgoTestDescription()
    42  		processTestResult(f)
    43  	})
    44  
    45  	It("podman unshare", func() {
    46  		userNS, _ := os.Readlink("/proc/self/ns/user")
    47  		session := podmanTest.Podman([]string{"unshare", "readlink", "/proc/self/ns/user"})
    48  		session.WaitWithDefaultTimeout()
    49  		Expect(session).Should(Exit(0))
    50  		Expect(session.OutputToString()).ToNot(ContainSubstring(userNS))
    51  	})
    52  
    53  	It("podman unshare --rootles-cni", func() {
    54  		session := podmanTest.Podman([]string{"unshare", "--rootless-cni", "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  		session := podmanTest.Podman([]string{"unshare", "false"})
    62  		session.WaitWithDefaultTimeout()
    63  		Expect(session).Should(Exit(1))
    64  		Expect(session.OutputToString()).Should(Equal(""))
    65  		Expect(session.ErrorToString()).Should(Equal(""))
    66  
    67  		session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"})
    68  		session.WaitWithDefaultTimeout()
    69  		Expect(session).Should(Exit(127))
    70  		Expect(session.OutputToString()).Should(Equal(""))
    71  		Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory"))
    72  
    73  		session = podmanTest.Podman([]string{"unshare", "bogus"})
    74  		session.WaitWithDefaultTimeout()
    75  		Expect(session).Should(Exit(127))
    76  		Expect(session.OutputToString()).Should(Equal(""))
    77  		Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH"))
    78  
    79  		session = podmanTest.Podman([]string{"unshare", "/usr"})
    80  		session.WaitWithDefaultTimeout()
    81  		Expect(session).Should(Exit(126))
    82  		Expect(session.OutputToString()).Should(Equal(""))
    83  		Expect(session.ErrorToString()).Should(ContainSubstring("permission denied"))
    84  
    85  		session = podmanTest.Podman([]string{"unshare", "--bogus"})
    86  		session.WaitWithDefaultTimeout()
    87  		Expect(session).Should(Exit(125))
    88  		Expect(session.OutputToString()).Should(Equal(""))
    89  		Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus"))
    90  	})
    91  })