mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
test-execute: Introduce tests for environment values containing newlines
Also fix one case where the presence of a newline was used to generate an invalid environment assignment. Tested: with mkosi, which builds the local tree and run ninja tests.
This commit is contained in:
parent
b4346b9a77
commit
9b796f3523
@ -466,7 +466,8 @@ static void test_exec_environmentfile(Manager *m) {
|
||||
"; comment2\n"
|
||||
" ; # comment3\n"
|
||||
"line without an equal\n"
|
||||
"VAR3='$word 5 6'\n";
|
||||
"VAR3='$word 5 6'\n"
|
||||
"VAR4='new\nline'\n";
|
||||
int r;
|
||||
|
||||
r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
|
||||
@ -492,12 +493,14 @@ static void test_exec_passenvironment(Manager *m) {
|
||||
assert_se(setenv("VAR1", "word1 word2", 1) == 0);
|
||||
assert_se(setenv("VAR2", "word3", 1) == 0);
|
||||
assert_se(setenv("VAR3", "$word 5 6", 1) == 0);
|
||||
assert_se(setenv("VAR4", "new\nline", 1) == 0);
|
||||
test(m, "exec-passenvironment.service", 0, CLD_EXITED);
|
||||
test(m, "exec-passenvironment-repeated.service", 0, CLD_EXITED);
|
||||
test(m, "exec-passenvironment-empty.service", 0, CLD_EXITED);
|
||||
assert_se(unsetenv("VAR1") == 0);
|
||||
assert_se(unsetenv("VAR2") == 0);
|
||||
assert_se(unsetenv("VAR3") == 0);
|
||||
assert_se(unsetenv("VAR4") == 0);
|
||||
test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
Description=Test for EnvironmentFile
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
EnvironmentFile=/tmp/test-exec_environmentfile.conf
|
||||
|
@ -2,6 +2,6 @@
|
||||
Description=Test for PassEnvironment with variables absent from the execution environment
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset"'
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
|
@ -2,7 +2,7 @@
|
||||
Description=Test for PassEnvironment and erasing the variable list
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset"'
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
PassEnvironment=
|
||||
|
@ -2,7 +2,8 @@
|
||||
Description=Test for PassEnvironment with a variable name repeated
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2
|
||||
PassEnvironment=VAR1 VAR3
|
||||
PassEnvironment=VAR1 VAR4
|
||||
|
@ -2,6 +2,6 @@
|
||||
Description=Test for PassEnvironment
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
|
Loading…
Reference in New Issue
Block a user