test: add testcase for environment file variables with backslashes
systemd silently strips out backslashes in variables from environment files. Add a testcase that explicitly tests for this behaviour.
This commit is contained in:
parent
a9a2f9b0b1
commit
b6887d7ae4
|
@ -455,7 +455,8 @@ static void test_exec_environmentfile(Manager *m) {
|
||||||
" ; # comment3\n"
|
" ; # comment3\n"
|
||||||
"line without an equal\n"
|
"line without an equal\n"
|
||||||
"VAR3='$word 5 6'\n"
|
"VAR3='$word 5 6'\n"
|
||||||
"VAR4='new\nline'\n";
|
"VAR4='new\nline'\n"
|
||||||
|
"VAR5=password\\with\\backslashes";
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
|
r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
|
||||||
|
@ -482,6 +483,7 @@ static void test_exec_passenvironment(Manager *m) {
|
||||||
assert_se(setenv("VAR2", "word3", 1) == 0);
|
assert_se(setenv("VAR2", "word3", 1) == 0);
|
||||||
assert_se(setenv("VAR3", "$word 5 6", 1) == 0);
|
assert_se(setenv("VAR3", "$word 5 6", 1) == 0);
|
||||||
assert_se(setenv("VAR4", "new\nline", 1) == 0);
|
assert_se(setenv("VAR4", "new\nline", 1) == 0);
|
||||||
|
assert_se(setenv("VAR5", "passwordwithbackslashes", 1) == 0);
|
||||||
test(m, "exec-passenvironment.service", 0, CLD_EXITED);
|
test(m, "exec-passenvironment.service", 0, CLD_EXITED);
|
||||||
test(m, "exec-passenvironment-repeated.service", 0, CLD_EXITED);
|
test(m, "exec-passenvironment-repeated.service", 0, CLD_EXITED);
|
||||||
test(m, "exec-passenvironment-empty.service", 0, CLD_EXITED);
|
test(m, "exec-passenvironment-empty.service", 0, CLD_EXITED);
|
||||||
|
@ -489,6 +491,7 @@ static void test_exec_passenvironment(Manager *m) {
|
||||||
assert_se(unsetenv("VAR2") == 0);
|
assert_se(unsetenv("VAR2") == 0);
|
||||||
assert_se(unsetenv("VAR3") == 0);
|
assert_se(unsetenv("VAR3") == 0);
|
||||||
assert_se(unsetenv("VAR4") == 0);
|
assert_se(unsetenv("VAR4") == 0);
|
||||||
|
assert_se(unsetenv("VAR5") == 0);
|
||||||
test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
|
test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
Description=Test for EnvironmentFile
|
Description=Test for EnvironmentFile
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline" && test "$$VAR5" = passwordwithbackslashes'
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
EnvironmentFile=/tmp/test-exec_environmentfile.conf
|
EnvironmentFile=/tmp/test-exec_environmentfile.conf
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
Description=Test for PassEnvironment with variables absent from the execution environment
|
Description=Test for PassEnvironment with variables absent from the execution environment
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset" && test "$${VAR5-unset}" = "unset"'
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Description=Test for PassEnvironment and erasing the variable list
|
Description=Test for PassEnvironment and erasing the variable list
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset" && test "$${VAR5-unset}" = "unset"'
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5
|
||||||
PassEnvironment=
|
PassEnvironment=
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
Description=Test for PassEnvironment with a variable name repeated
|
Description=Test for PassEnvironment with a variable name repeated
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline" && test "$$VAR5" = passwordwithbackslashes'
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
PassEnvironment=VAR1 VAR2
|
PassEnvironment=VAR1 VAR2
|
||||||
PassEnvironment=VAR1 VAR3
|
PassEnvironment=VAR1 VAR3
|
||||||
PassEnvironment=VAR1 VAR4
|
PassEnvironment=VAR1 VAR4
|
||||||
|
PassEnvironment=VAR1 VAR5
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
Description=Test for PassEnvironment
|
Description=Test for PassEnvironment
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline" && test "$$VAR5" = passwordwithbackslashes'
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5
|
||||||
|
|
Loading…
Reference in a new issue