summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/common_test.go
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-02-01 14:40:12 +0100
committerPaul Holzinger <paul.holzinger@web.de>2021-02-01 14:40:12 +0100
commit5352df226bc3f345836e78b73063de91d34b4e85 (patch)
tree4532290710da4bb2d9eb32f7ffe3673d0f5288ac /pkg/systemd/generate/common_test.go
parentb045c173756dddcedf6a99a70f520bf423072826 (diff)
downloadpodman-5352df226bc3f345836e78b73063de91d34b4e85.tar.gz
podman-5352df226bc3f345836e78b73063de91d34b4e85.tar.bz2
podman-5352df226bc3f345836e78b73063de91d34b4e85.zip
Fix podman generate systemd --new special char handling
In a systemd unit dollar and percent signs are used for variables. A backslash is used for escape sequences. If any of these characters are used in the create command we have to properly escape them so systemd does not try to interpret them. Fixes #9176 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'pkg/systemd/generate/common_test.go')
-rw-r--r--pkg/systemd/generate/common_test.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/pkg/systemd/generate/common_test.go b/pkg/systemd/generate/common_test.go
index d0ec5637c..a0691d1ad 100644
--- a/pkg/systemd/generate/common_test.go
+++ b/pkg/systemd/generate/common_test.go
@@ -29,7 +29,7 @@ func TestFilterPodFlags(t *testing.T) {
}
}
-func TestQuoteArguments(t *testing.T) {
+func TestEscapeSystemdArguments(t *testing.T) {
tests := []struct {
input []string
output []string
@@ -46,10 +46,46 @@ func TestQuoteArguments(t *testing.T) {
[]string{"foo", "bar=\"arg with\ttab\""},
[]string{"foo", "\"bar=\\\"arg with\\ttab\\\"\""},
},
+ {
+ []string{"$"},
+ []string{"$$"},
+ },
+ {
+ []string{"foo", "command with dollar sign $"},
+ []string{"foo", "\"command with dollar sign $$\""},
+ },
+ {
+ []string{"foo", "command with two dollar signs $$"},
+ []string{"foo", "\"command with two dollar signs $$$$\""},
+ },
+ {
+ []string{"%"},
+ []string{"%%"},
+ },
+ {
+ []string{"foo", "command with percent sign %"},
+ []string{"foo", "\"command with percent sign %%\""},
+ },
+ {
+ []string{"foo", "command with two percent signs %%"},
+ []string{"foo", "\"command with two percent signs %%%%\""},
+ },
+ {
+ []string{`\`},
+ []string{`\\`},
+ },
+ {
+ []string{"foo", `command with backslash \`},
+ []string{"foo", `"command with backslash \\"`},
+ },
+ {
+ []string{"foo", `command with two backslashs \\`},
+ []string{"foo", `"command with two backslashs \\\\"`},
+ },
}
for _, test := range tests {
- quoted := quoteArguments(test.input)
+ quoted := escapeSystemdArguments(test.input)
assert.Equal(t, test.output, quoted)
}
}