From 5e240ab1f567f0e9ee6179242d58134d92399de8 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Thu, 9 May 2024 05:29:28 -0600 Subject: [PATCH] ExitWithError() - more r files Followup to #22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles all remaining test/e2e/r*_test.go Signed-off-by: Ed Santiago --- test/e2e/rename_test.go | 4 ++-- test/e2e/run_networking_test.go | 31 ++++++++++++------------------- test/e2e/run_signal_test.go | 2 +- test/e2e/run_staticip_test.go | 6 +++--- test/e2e/run_volume_test.go | 24 +++++++++++++----------- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/test/e2e/rename_test.go b/test/e2e/rename_test.go index ef82e6c73d..27698e937c 100644 --- a/test/e2e/rename_test.go +++ b/test/e2e/rename_test.go @@ -13,7 +13,7 @@ var _ = Describe("podman rename", func() { It("podman rename on non-existent container", func() { session := podmanTest.Podman([]string{"rename", "doesNotExist", "aNewName"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `no container with name or ID "doesNotExist" found: no such container`)) }) It("Podman rename on existing container with bad name", func() { @@ -25,7 +25,7 @@ var _ = Describe("podman rename", func() { newName := "invalid<>:char" rename := podmanTest.Podman([]string{"rename", ctrName, newName}) rename.WaitWithDefaultTimeout() - Expect(rename).To(ExitWithError()) + Expect(rename).To(ExitWithError(125, "names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: invalid argument")) ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", ctrName), "--format", "{{ .Names }}"}) ps.WaitWithDefaultTimeout() diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 8e26a5ee44..b6643c9fef 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -144,11 +144,9 @@ var _ = Describe("Podman run networking", func() { session := podmanTest.RunContainerWithNetworkTest("none") session.WaitWithDefaultTimeout() if _, found := os.LookupEnv("http_proxy"); found { - Expect(session).Should(Exit(5)) - Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve proxy:")) + Expect(session).Should(ExitWithError(5, "Could not resolve proxy:")) } else { - Expect(session).Should(Exit(6)) - Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve host: www.redhat.com")) + Expect(session).Should(ExitWithError(6, "Could not resolve host: www.redhat.com")) } }) @@ -498,7 +496,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) Expect(results.OutputToString()).To(ContainSubstring(strconv.Itoa(port2))) ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port1)}) - Expect(ncBusy).To(ExitWithError()) + Expect(ncBusy).To(ExitWithError(2, fmt.Sprintf("Ncat: bind to 0.0.0.0:%d: Address already in use. QUITTING.", port1))) }) It("podman run network expose host port 18081 to container port 8000 using rootlesskit port handler", func() { @@ -509,7 +507,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) Expect(session).Should(ExitCleanly()) ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port2)}) - Expect(ncBusy).To(ExitWithError()) + Expect(ncBusy).To(ExitWithError(2, fmt.Sprintf("Ncat: bind to [::]:%d: Address already in use. QUITTING.", port2))) }) It("podman run slirp4netns verify net.ipv6.conf.default.accept_dad=0", func() { @@ -534,13 +532,13 @@ EXPOSE 2004-2005/tcp`, ALPINE) It("podman run network expose host port 8080 to container port 8000 using invalid port handler", func() { session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:port_handler=invalid", "-dt", "-p", "8080:8000", ALPINE, "/bin/sh"}) - session.Wait(30) - Expect(session).To(ExitWithError()) + session.WaitWithDefaultTimeout() + Expect(session).To(ExitWithError(126, `unknown port_handler for slirp4netns: "invalid"`)) }) It("podman run slirp4netns network with host loopback", func() { session := podmanTest.Podman([]string{"run", "--cap-add", "net_raw", "--network", "slirp4netns:allow_host_loopback=true", ALPINE, "ping", "-c1", "10.0.2.2"}) - session.Wait(30) + session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) }) @@ -562,8 +560,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) if strings.Contains(slirp4netnsHelp.OutputToString(), "cidr") { Expect(session).Should(ExitCleanly()) } else { - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("cidr not supported")) + Expect(session).To(ExitWithError(125, "cidr not supported")) } }) @@ -585,8 +582,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) } else { session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", port}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported")) + Expect(session).To(ExitWithError(125, "outbound_addr not supported")) } }) @@ -615,8 +611,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) } else { session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", port}) session.Wait(30) - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported")) + Expect(session).To(ExitWithError(125, "outbound_addr not supported")) } }) @@ -723,8 +718,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) ctr2 := podmanTest.Podman([]string{"run", "-d", "--net=container:" + ctrName, "--add-host", "host1:127.0.0.1", ALPINE, "true"}) ctr2.WaitWithDefaultTimeout() - Expect(ctr2).Should(ExitWithError()) - Expect(ctr2.ErrorToString()).Should(ContainSubstring("cannot set extra host entries when the container is joined to another containers network namespace: invalid configuration")) + Expect(ctr2).Should(ExitWithError(125, "cannot set extra host entries when the container is joined to another containers network namespace: invalid configuration")) }) It("podman run --net container: copies hosts and resolv", func() { @@ -972,8 +966,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) It("podman run network in bogus user created network namespace", func() { session := podmanTest.Podman([]string{"run", "-dt", "--net", "ns:/run/netns/xxy", ALPINE, "wget", "www.redhat.com"}) session.Wait(90) - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("faccessat /run/netns/xxy: no such file or directory")) + Expect(session).To(ExitWithError(125, "faccessat /run/netns/xxy: no such file or directory")) }) It("podman run in custom CNI network with --static-ip", func() { diff --git a/test/e2e/run_signal_test.go b/test/e2e/run_signal_test.go index 45b394429d..8f81186aa8 100644 --- a/test/e2e/run_signal_test.go +++ b/test/e2e/run_signal_test.go @@ -110,7 +110,7 @@ var _ = Describe("Podman run with --sig-proxy", func() { Expect(killSession).Should(ExitCleanly()) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(2, "SIGFPE: floating-point exception")) Expect(session.OutputToString()).To(Not(ContainSubstring("Received"))) }) diff --git a/test/e2e/run_staticip_test.go b/test/e2e/run_staticip_test.go index b644ccbd6e..d0553c5b10 100644 --- a/test/e2e/run_staticip_test.go +++ b/test/e2e/run_staticip_test.go @@ -20,19 +20,19 @@ var _ = Describe("Podman run with --ip flag", func() { It("Podman run --ip with garbage address", func() { result := podmanTest.Podman([]string{"run", "--ip", "114232346", ALPINE, "ls"}) result.WaitWithDefaultTimeout() - Expect(result).To(ExitWithError()) + Expect(result).To(ExitWithError(125, `"114232346" is not an ip address`)) }) It("Podman run --ip with v6 address", func() { result := podmanTest.Podman([]string{"run", "--ip", "2001:db8:bad:beef::1", ALPINE, "ls"}) result.WaitWithDefaultTimeout() - Expect(result).To(ExitWithError()) + Expect(result).To(ExitWithError(126, "requested static ip 2001:db8:bad:beef::1 not in any subnet on network podman")) }) It("Podman run --ip with non-allocatable IP", func() { result := podmanTest.Podman([]string{"run", "--ip", "203.0.113.124", ALPINE, "ls"}) result.WaitWithDefaultTimeout() - Expect(result).To(ExitWithError()) + Expect(result).To(ExitWithError(126, "requested static ip 203.0.113.124 not in any subnet on network podman")) }) It("Podman run with specified static IP has correct IP", func() { diff --git a/test/e2e/run_volume_test.go b/test/e2e/run_volume_test.go index fbc6de0f70..df6fd368f8 100644 --- a/test/e2e/run_volume_test.go +++ b/test/e2e/run_volume_test.go @@ -97,7 +97,7 @@ var _ = Describe("Podman run with volumes", func() { session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=tmpfs,target=/etc/ssl,tmpcopyup,notmpcopyup", ALPINE, "ls", "/etc/ssl"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, "cannot pass 'tmpcopyup' and 'notmpcopyup' mnt.Options more than once: must provide an argument for option")) // test csv escaping session = podmanTest.Podman([]string{"run", "--rm", "--mount=type=tmpfs,tmpfs-size=512M,\"destination=/test,\"", ALPINE, "ls", "/test,"}) @@ -106,11 +106,11 @@ var _ = Describe("Podman run with volumes", func() { session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=bind,src=/tmp,target=/tmp,tmpcopyup", ALPINE, "true"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `"tmpcopyup" option not supported for "bind" mount types`)) session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=bind,src=/tmp,target=/tmp,notmpcopyup", ALPINE, "true"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `"notmpcopyup" option not supported for "bind" mount types`)) session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=tmpfs,target=/etc/ssl,notmpcopyup", ALPINE, "ls", "/etc/ssl"}) session.WaitWithDefaultTimeout() @@ -161,7 +161,7 @@ var _ = Describe("Podman run with volumes", func() { session = podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",ro=true,rw=false", ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, "cannot pass 'readonly', 'ro', or 'rw' mnt.Options more than once: must provide an argument for option")) }) It("podman run with volume flag and multiple named volumes", func() { @@ -344,7 +344,7 @@ var _ = Describe("Podman run with volumes", func() { It("podman run with noexec can't exec", func() { session := podmanTest.Podman([]string{"run", "--rm", "-v", "/bin:/hostbin:noexec", ALPINE, "/hostbin/ls", "/"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(126, "ermission denied")) }) It("podman run with tmpfs named volume mounts and unmounts", func() { @@ -569,7 +569,7 @@ RUN sh -c "cd /etc/apk && ln -s ../../testfile"`, ALPINE) volMount := podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:/tmp", volName), ALPINE, "ls"}) volMount.WaitWithDefaultTimeout() - Expect(volMount).To(ExitWithError()) + Expect(volMount).To(ExitWithError(126, "mounting volume testVol for container ")) }) It("Podman fix for CVE-2020-1726", func() { @@ -667,7 +667,7 @@ VOLUME /test/`, ALPINE) Expect(session).Should(ExitCleanly()) session = podmanTest.Podman([]string{"exec", "-l", "ls", "/run/test/container"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(1, "ls: /run/test/container: No such file or directory")) }) It("overlay volume conflicts with named volume and mounts", func() { @@ -688,18 +688,20 @@ VOLUME /test/`, ALPINE) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) + expectErr := fmt.Sprintf("%s: duplicate mount destination", mountDest) + // overlay and named volume destinations conflict session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "-v", fmt.Sprintf("%s:%s", volName, mountDest), ALPINE}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, expectErr)) // overlay and bind mount destinations conflict session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "--mount", fmt.Sprintf("type=bind,src=%s,target=%s", mountSrc, mountDest), ALPINE}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, expectErr)) // overlay and tmpfs mount destinations conflict session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "--mount", fmt.Sprintf("type=tmpfs,target=%s", mountDest), ALPINE}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, expectErr)) }) It("same volume in multiple places does not deadlock", func() { @@ -788,7 +790,7 @@ VOLUME /test/`, ALPINE) vol = "type=bind,src=" + mountPath + ",dst=" + dest + ",U=invalid" session = podmanTest.Podman([]string{"run", "--rm", "--user", "888:888", "--mount", vol, ALPINE, "stat", "-c", "%u:%g", dest}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `'U' or 'chown' must be set to true or false, instead received "invalid": must provide an argument for option`)) // true bind mount vol = "type=bind,src=" + mountPath + ",dst=" + dest + ",U=true"