6
. "github.com/containers/podman/v5/test/utils"
7
. "github.com/onsi/ginkgo/v2"
8
. "github.com/onsi/gomega"
9
. "github.com/onsi/gomega/gexec"
12
var _ = Describe("Podman run", func() {
14
It("podman run environment test", func() {
15
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "HOME"})
16
session.WaitWithDefaultTimeout()
17
Expect(session).Should(ExitCleanly())
18
Expect(session.OutputToString()).To(ContainSubstring("/root"))
20
session = podmanTest.Podman([]string{"run", "--rm", "--user", "2", ALPINE, "printenv", "HOME"})
21
session.WaitWithDefaultTimeout()
22
Expect(session).Should(ExitCleanly())
23
Expect(session.OutputToString()).To(ContainSubstring("/sbin"))
25
session = podmanTest.Podman([]string{"run", "--rm", "--env", "HOME=/foo", ALPINE, "printenv", "HOME"})
26
session.WaitWithDefaultTimeout()
27
Expect(session).Should(ExitCleanly())
28
Expect(session.OutputToString()).To(ContainSubstring("/foo"))
30
session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO=BAR,BAZ", ALPINE, "printenv", "FOO"})
31
session.WaitWithDefaultTimeout()
32
Expect(session).Should(ExitCleanly())
33
Expect(session.OutputToString()).To(ContainSubstring("BAR,BAZ"))
35
session = podmanTest.Podman([]string{"run", "--rm", "--env", "PATH=/bin", ALPINE, "printenv", "PATH"})
36
session.WaitWithDefaultTimeout()
37
Expect(session).Should(ExitCleanly())
38
Expect(session.OutputToString()).To(ContainSubstring("/bin"))
40
// Verify environ keys with spaces do not blow up podman command
41
os.Setenv("FOO BAR", "BAZ")
42
session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "true"})
43
session.WaitWithDefaultTimeout()
44
Expect(session).Should(ExitCleanly())
45
os.Unsetenv("FOO BAR")
47
os.Setenv("FOO", "BAR")
48
session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO", ALPINE, "printenv", "FOO"})
49
session.WaitWithDefaultTimeout()
50
Expect(session).Should(ExitCleanly())
51
Expect(session.OutputToString()).To(ContainSubstring("BAR"))
54
session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO", ALPINE, "printenv", "FOO"})
55
session.WaitWithDefaultTimeout()
56
Expect(session.OutputToString()).To(BeEmpty())
57
Expect(session).Should(Exit(1))
59
session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv"})
60
session.WaitWithDefaultTimeout()
61
Expect(session).Should(ExitCleanly())
63
// This currently does not work
64
// Re-enable when hostname is an env variable
65
session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "sh", "-c", "printenv"})
67
Expect(session).Should(ExitCleanly())
68
Expect(session.OutputToString()).To(ContainSubstring("HOSTNAME"))
71
It("podman run with --env-merge", func() {
72
dockerfile := `FROM quay.io/libpod/alpine:latest
75
podmanTest.BuildImage(dockerfile, "test", "false")
76
session := podmanTest.Podman([]string{"run", "--rm", "--env-merge", "hello=${hello}-earth", "test", "env"})
77
session.WaitWithDefaultTimeout()
78
Expect(session).Should(ExitCleanly())
79
Expect(session.OutputToString()).To(ContainSubstring("world-earth"))
81
session = podmanTest.Podman([]string{"run", "--rm", "--env-merge", "foo=${bar}-earth", "test", "printenv", "foo"})
82
session.WaitWithDefaultTimeout()
83
Expect(session).Should(ExitCleanly())
84
Expect(session.OutputToString()).To(Equal("-earth"))
87
It("podman run --env-host environment test", func() {
88
env := append(os.Environ(), "FOO=BAR")
89
session := podmanTest.PodmanAsUser([]string{"run", "--rm", "--env-host", ALPINE, "/bin/printenv", "FOO"}, 0, 0, "", env)
90
session.WaitWithDefaultTimeout()
92
// podman-remote does not support --env-host
93
Expect(session).Should(Exit(125))
94
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag: --env-host"))
97
Expect(session).Should(ExitCleanly())
98
Expect(session.OutputToString()).To(ContainSubstring("BAR"))
100
session = podmanTest.PodmanAsUser([]string{"run", "--rm", "--env", "FOO=BAR1", "--env-host", ALPINE, "/bin/printenv", "FOO"}, 0, 0, "", env)
101
session.WaitWithDefaultTimeout()
102
Expect(session).Should(ExitCleanly())
103
Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
107
It("podman run --http-proxy test", func() {
108
if env, found := os.LookupEnv("http_proxy"); found {
109
defer os.Setenv("http_proxy", env)
111
defer os.Unsetenv("http_proxy")
113
os.Setenv("http_proxy", "1.2.3.4")
115
podmanTest.StopRemoteService()
116
podmanTest.StartRemoteService()
117
// set proxy env again so it will only effect the client
118
// the remote client should still use the proxy that was set for the server
119
os.Setenv("http_proxy", "127.0.0.2")
121
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "http_proxy"})
122
session.WaitWithDefaultTimeout()
123
Expect(session).Should(ExitCleanly())
124
Expect(session.OutputToString()).To(ContainSubstring("1.2.3.4"))
126
session = podmanTest.Podman([]string{"run", "--http-proxy=false", ALPINE, "printenv", "http_proxy"})
127
session.WaitWithDefaultTimeout()
128
Expect(session).Should(Exit(1))
129
Expect(session.OutputToString()).To(Equal(""))
131
session = podmanTest.Podman([]string{"run", "--env", "http_proxy=5.6.7.8", ALPINE, "printenv", "http_proxy"})
132
session.WaitWithDefaultTimeout()
133
Expect(session).Should(ExitCleanly())
134
Expect(session.OutputToString()).To(ContainSubstring("5.6.7.8"))
136
session = podmanTest.Podman([]string{"run", "--http-proxy=false", "--env", "http_proxy=5.6.7.8", ALPINE, "printenv", "http_proxy"})
137
session.WaitWithDefaultTimeout()
138
Expect(session).Should(ExitCleanly())
139
Expect(session.OutputToString()).To(ContainSubstring("5.6.7.8"))