diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/info_test.go | 8 | ||||
-rw-r--r-- | test/e2e/login_logout_test.go | 23 | ||||
-rw-r--r-- | test/e2e/run_userns_test.go | 131 | ||||
-rw-r--r-- | test/system/005-info.bats | 32 | ||||
-rw-r--r-- | test/system/030-run.bats | 2 | ||||
-rw-r--r-- | test/system/065-cp.bats | 2 | ||||
-rw-r--r-- | test/system/400-unprivileged-access.bats | 4 | ||||
-rw-r--r-- | test/system/helpers.bash | 2 |
8 files changed, 169 insertions, 35 deletions
diff --git a/test/e2e/info_test.go b/test/e2e/info_test.go index d16661d5b..446dbc16e 100644 --- a/test/e2e/info_test.go +++ b/test/e2e/info_test.go @@ -43,10 +43,16 @@ var _ = Describe("Podman Info", func() { Expect(session.ExitCode()).To(Equal(0)) }) - It("podman info --format GO template", func() { + It("podman info --format JSON GO template", func() { session := podmanTest.Podman([]string{"info", "--format", "{{ json .}}"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) Expect(session.IsJSONOutputValid()).To(BeTrue()) }) + + It("podman info --format GO template", func() { + session := podmanTest.Podman([]string{"info", "--format", "{{ .Store.GraphRoot }}"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) diff --git a/test/e2e/login_logout_test.go b/test/e2e/login_logout_test.go index 42698d270..3f76daa67 100644 --- a/test/e2e/login_logout_test.go +++ b/test/e2e/login_logout_test.go @@ -24,6 +24,7 @@ var _ = Describe("Podman login and logout", func() { podmanTest *PodmanTestIntegration authPath string certPath string + certDirPath string port int server string testImg string @@ -70,12 +71,12 @@ var _ = Describe("Podman login and logout", func() { testImg = strings.Join([]string{server, "test-apline"}, "/") - os.MkdirAll(filepath.Join("/etc/containers/certs.d", server), os.ModePerm) - + certDirPath = filepath.Join(os.Getenv("HOME"), ".config/containers/certs.d", server) + os.MkdirAll(certDirPath, os.ModePerm) cwd, _ := os.Getwd() certPath = filepath.Join(cwd, "../", "certs") - setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join("/etc/containers/certs.d", server, "ca.crt")}) + setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join(certDirPath, "ca.crt")}) setup.WaitWithDefaultTimeout() session = podmanTest.Podman([]string{"run", "-d", "-p", strings.Join([]string{strconv.Itoa(port), strconv.Itoa(port)}, ":"), @@ -95,11 +96,10 @@ var _ = Describe("Podman login and logout", func() { AfterEach(func() { podmanTest.Cleanup() os.RemoveAll(authPath) - os.RemoveAll(filepath.Join("/etc/containers/certs.d", server)) + os.RemoveAll(certDirPath) }) It("podman login and logout", func() { - SkipIfRootless() session := podmanTest.Podman([]string{"login", "-u", "podmantest", "-p", "test", server}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) @@ -150,7 +150,6 @@ var _ = Describe("Podman login and logout", func() { }) It("podman login and logout with flag --authfile", func() { - SkipIfRootless() authFile := filepath.Join(podmanTest.TempDir, "auth.json") session := podmanTest.Podman([]string{"login", "--username", "podmantest", "--password", "test", "--authfile", authFile, server}) session.WaitWithDefaultTimeout() @@ -183,7 +182,6 @@ var _ = Describe("Podman login and logout", func() { }) It("podman login and logout with --tls-verify", func() { - SkipIfRootless() session := podmanTest.Podman([]string{"login", "--username", "podmantest", "--password", "test", "--tls-verify=false", server}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) @@ -197,7 +195,6 @@ var _ = Describe("Podman login and logout", func() { Expect(session.ExitCode()).To(Equal(0)) }) It("podman login and logout with --cert-dir", func() { - SkipIfRootless() certDir := filepath.Join(podmanTest.TempDir, "certs") os.MkdirAll(certDir, os.ModePerm) @@ -208,7 +205,7 @@ var _ = Describe("Podman login and logout", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"push", ALPINE, testImg}) + session = podmanTest.Podman([]string{"push", "--cert-dir", certDir, ALPINE, testImg}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) @@ -217,15 +214,15 @@ var _ = Describe("Podman login and logout", func() { Expect(session.ExitCode()).To(Equal(0)) }) It("podman login and logout with multi registry", func() { - SkipIfRootless() - os.MkdirAll("/etc/containers/certs.d/localhost:9001", os.ModePerm) + certDir := filepath.Join(os.Getenv("HOME"), ".config/containers/certs.d", "localhost:9001") + os.MkdirAll(certDir, os.ModePerm) cwd, _ := os.Getwd() certPath = filepath.Join(cwd, "../", "certs") - setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:9001/ca.crt"}) + setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join(certDir, "ca.crt")}) setup.WaitWithDefaultTimeout() - defer os.RemoveAll("/etc/containers/certs.d/localhost:9001") + defer os.RemoveAll(certDir) session := podmanTest.Podman([]string{"run", "-d", "-p", "9001:9001", "-e", "REGISTRY_HTTP_ADDR=0.0.0.0:9001", "--name", "registry1", "-v", strings.Join([]string{authPath, "/auth"}, ":"), "-e", "REGISTRY_AUTH=htpasswd", "-e", diff --git a/test/e2e/run_userns_test.go b/test/e2e/run_userns_test.go index e873f5abe..25f12ec2e 100644 --- a/test/e2e/run_userns_test.go +++ b/test/e2e/run_userns_test.go @@ -4,7 +4,10 @@ package integration import ( "fmt" + "io/ioutil" "os" + "os/user" + "strings" . "github.com/containers/libpod/test/utils" . "github.com/onsi/ginkgo" @@ -86,6 +89,134 @@ var _ = Describe("Podman UserNS support", func() { Expect(ok).To(BeTrue()) }) + It("podman --userns=auto", func() { + u, err := user.Current() + Expect(err).To(BeNil()) + name := u.Name + if name == "root" { + name = "containers" + } + + content, err := ioutil.ReadFile("/etc/subuid") + if err != nil { + Skip("cannot read /etc/subuid") + } + if !strings.Contains(string(content), name) { + Skip("cannot find mappings for the current user") + } + + m := make(map[string]string) + for i := 0; i < 5; i++ { + session := podmanTest.Podman([]string{"run", "--userns=auto", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + l := session.OutputToString() + Expect(strings.Contains(l, "1024")).To(BeTrue()) + m[l] = l + } + // check for no duplicates + Expect(len(m)).To(Equal(5)) + }) + + It("podman --userns=auto:size=%d", func() { + u, err := user.Current() + Expect(err).To(BeNil()) + + name := u.Name + if name == "root" { + name = "containers" + } + + content, err := ioutil.ReadFile("/etc/subuid") + if err != nil { + Skip("cannot read /etc/subuid") + } + if !strings.Contains(string(content), name) { + Skip("cannot find mappings for the current user") + } + + session := podmanTest.Podman([]string{"run", "--userns=auto:size=500", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ := session.GrepString("500") + + session = podmanTest.Podman([]string{"run", "--userns=auto:size=3000", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ = session.GrepString("3000") + + session = podmanTest.Podman([]string{"run", "--userns=auto", "--user=2000:3000", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ = session.GrepString("3001") + + session = podmanTest.Podman([]string{"run", "--userns=auto", "--user=4000:1000", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ = session.GrepString("4001") + Expect(ok).To(BeTrue()) + }) + + It("podman --userns=auto:uidmapping=", func() { + u, err := user.Current() + Expect(err).To(BeNil()) + + name := u.Name + if name == "root" { + name = "containers" + } + + content, err := ioutil.ReadFile("/etc/subuid") + if err != nil { + Skip("cannot read /etc/subuid") + } + if !strings.Contains(string(content), name) { + Skip("cannot find mappings for the current user") + } + + session := podmanTest.Podman([]string{"run", "--userns=auto:uidmapping=0:0:1", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + output := session.OutputToString() + Expect(output).To(MatchRegexp("\\s0\\s0\\s1")) + + session = podmanTest.Podman([]string{"run", "--userns=auto:size=8192,uidmapping=0:0:1", "alpine", "cat", "/proc/self/uid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ := session.GrepString("8191") + Expect(ok).To(BeTrue()) + }) + + It("podman --userns=auto:gidmapping=", func() { + u, err := user.Current() + Expect(err).To(BeNil()) + + name := u.Name + if name == "root" { + name = "containers" + } + + content, err := ioutil.ReadFile("/etc/subuid") + if err != nil { + Skip("cannot read /etc/subuid") + } + if !strings.Contains(string(content), name) { + Skip("cannot find mappings for the current user") + } + + session := podmanTest.Podman([]string{"run", "--userns=auto:gidmapping=0:0:1", "alpine", "cat", "/proc/self/gid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + output := session.OutputToString() + Expect(output).To(MatchRegexp("\\s0\\s0\\s1")) + + session = podmanTest.Podman([]string{"run", "--userns=auto:size=8192,gidmapping=0:0:1", "alpine", "cat", "/proc/self/gid_map"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + ok, _ := session.GrepString("8191") + Expect(ok).To(BeTrue()) + }) + It("podman --userns=container:CTR", func() { ctrName := "userns-ctr" session := podmanTest.Podman([]string{"run", "-d", "--uidmap=0:0:1", "--uidmap=1:1:4998", "--name", ctrName, "alpine", "top"}) diff --git a/test/system/005-info.bats b/test/system/005-info.bats index f229b0886..c53ba8125 100644 --- a/test/system/005-info.bats +++ b/test/system/005-info.bats @@ -8,19 +8,19 @@ load helpers run_podman info expected_keys=" -BuildahVersion: *[0-9.]\\\+ -Conmon:\\\s\\\+package: -Distribution: -OCIRuntime:\\\s\\\+name: +buildahVersion: *[0-9.]\\\+ +conmon:\\\s\\\+package: +distribution: +ociRuntime:\\\s\\\+name: os: rootless: registries: store: -GraphDriverName: -GraphRoot: -GraphStatus: -ImageStore:\\\s\\\+number: 1 -RunRoot: +graphDriverName: +graphRoot: +graphStatus: +imageStore:\\\s\\\+number: 1 +runRoot: " while read expect; do is "$output" ".*$expect" "output includes '$expect'" @@ -36,13 +36,13 @@ RunRoot: expr_path="/[a-z0-9\\\/.-]\\\+\\\$" tests=" -host.BuildahVersion | [0-9.] -host.Conmon.path | $expr_path -host.OCIRuntime.path | $expr_path -store.ConfigFile | $expr_path -store.GraphDriverName | [a-z0-9]\\\+\\\$ -store.GraphRoot | $expr_path -store.ImageStore.number | 1 +host.buildahVersion | [0-9.] +host.conmon.path | $expr_path +host.ociRuntime.path | $expr_path +store.configFile | $expr_path +store.graphDriverName | [a-z0-9]\\\+\\\$ +store.graphRoot | $expr_path +store.imageStore.number | 1 " parse_table "$tests" | while read field expect; do diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 98c65f788..56e9fed3b 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -12,7 +12,7 @@ load helpers err_no_exec_dir="Error: .*: starting container process caused .*exec:.* permission denied" # ...but check the configured runtime engine, and switch to crun as needed - run_podman info --format '{{ .host.OCIRuntime.path }}' + run_podman info --format '{{ .Host.OCIRuntime.Path }}' if expr "$output" : ".*/crun"; then err_no_such_cmd="Error: executable file not found in \$PATH: No such file or directory: OCI runtime command not found error" err_no_exec_dir="Error: open executable: Operation not permitted: OCI runtime permission denied error" diff --git a/test/system/065-cp.bats b/test/system/065-cp.bats index 0701055f9..a350c2173 100644 --- a/test/system/065-cp.bats +++ b/test/system/065-cp.bats @@ -187,7 +187,7 @@ load helpers chmod 644 $srcdir/$rand_filename # Determine path to podman storage (eg /var/lib/c/s, or $HOME/.local/...) - run_podman info --format '{{.store.GraphRoot}}' + run_podman info --format '{{.Store.GraphRoot}}' graphroot=$output # Create that directory in the container, and sleep (to keep container diff --git a/test/system/400-unprivileged-access.bats b/test/system/400-unprivileged-access.bats index 56c40e9c8..98f8b8211 100644 --- a/test/system/400-unprivileged-access.bats +++ b/test/system/400-unprivileged-access.bats @@ -70,10 +70,10 @@ EOF chmod 755 $PODMAN_TMPDIR $test_script # get podman image and container storage directories - run_podman info --format '{{.store.GraphRoot}}' + run_podman info --format '{{.Store.GraphRoot}}' is "$output" "/var/lib/containers/storage" "GraphRoot in expected place" GRAPH_ROOT="$output" - run_podman info --format '{{.store.RunRoot}}' + run_podman info --format '{{.Store.RunRoot}}' is "$output" "/var/run/containers/storage" "RunRoot in expected place" RUN_ROOT="$output" diff --git a/test/system/helpers.bash b/test/system/helpers.bash index 2e856930e..51240edc9 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -391,7 +391,7 @@ function random_string() { # Return exec_pid hash files if exists, otherwise, return nothing # function find_exec_pid_files() { - run_podman info --format '{{.store.RunRoot}}' + run_podman info --format '{{.Store.RunRoot}}' local storage_path="$output" if [ -d $storage_path ]; then find $storage_path -type f -iname 'exec_pid_*' |