From 2a524fcaec4e6f66461d7cdda1bb73ed7c50f026 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Wed, 15 Dec 2021 13:32:57 -0600 Subject: fix healthcheck timeouts and ut8 coercion this commit fixes two bugs and adds regression tests. when getting healthcheck values from an image, if the image does not have a timeout defined, this resulted in a 0 value for timeout. The default as described in the man pages is 30s. when inspecting a container with a healthcheck command, a customer observed that the &, <, and > characters were being converted into a unicode escape value. It turns out json marshalling will by default coerce string values to ut8. Fixes: bz2028408 Signed-off-by: Brent Baude --- test/e2e/healthcheck_run_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/e2e') diff --git a/test/e2e/healthcheck_run_test.go b/test/e2e/healthcheck_run_test.go index c2084a6fd..6a79006b6 100644 --- a/test/e2e/healthcheck_run_test.go +++ b/test/e2e/healthcheck_run_test.go @@ -2,7 +2,9 @@ package integration import ( "fmt" + "io/ioutil" "os" + "path/filepath" "time" define "github.com/containers/podman/v3/libpod/define" @@ -258,4 +260,40 @@ var _ = Describe("Podman healthcheck run", func() { Expect(startAgain.OutputToString()).To(Equal("hc")) Expect(startAgain.ErrorToString()).To(Equal("")) }) + + It("Verify default time is used and no utf-8 escapes", func() { + cwd, err := os.Getwd() + Expect(err).To(BeNil()) + + podmanTest.AddImageToRWStore(ALPINE) + // Write target and fake files + targetPath, err := CreateTempDirInTempDir() + Expect(err).To(BeNil()) + containerfile := fmt.Sprintf(`FROM %s +HEALTHCHECK CMD ls -l / 2>&1`, ALPINE) + containerfilePath := filepath.Join(targetPath, "Containerfile") + err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644) + Expect(err).To(BeNil()) + defer func() { + Expect(os.Chdir(cwd)).To(BeNil()) + Expect(os.RemoveAll(targetPath)).To(BeNil()) + }() + + // make cwd as context root path + Expect(os.Chdir(targetPath)).To(BeNil()) + + session := podmanTest.Podman([]string{"build", "--format", "docker", "-t", "test", "."}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + + run := podmanTest.Podman([]string{"run", "-dt", "--name", "hctest", "test", "ls"}) + run.WaitWithDefaultTimeout() + Expect(run).Should(Exit(0)) + + inspect := podmanTest.InspectContainer("hctest") + // Check to make sure a default time value was added + Expect(inspect[0].Config.Healthcheck.Timeout).To(BeNumerically("==", 30000000000)) + // Check to make sure characters were not coerced to utf8 + Expect(inspect[0].Config.Healthcheck.Test).To(Equal([]string{"CMD-SHELL", "ls -l / 2>&1"})) + }) }) -- cgit v1.2.3-54-g00ecf