]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add testcase for environment file variables with backslashes
authorJoost Heitbrink <joostheitbrink@outlook.com>
Thu, 10 May 2018 13:28:10 +0000 (15:28 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 May 2018 04:15:16 +0000 (13:15 +0900)
systemd silently strips out backslashes in variables from environment
files. Add a testcase that explicitly tests for this behaviour.

src/test/test-execute.c
test/test-execute/exec-environmentfile.service
test/test-execute/exec-passenvironment-absent.service
test/test-execute/exec-passenvironment-empty.service
test/test-execute/exec-passenvironment-repeated.service
test/test-execute/exec-passenvironment.service

index 4943bfa689e75c2bf20b3268fb4b2f662d001874..9b0fac8bc98c71bacc201c0a4b3d2f0211d87964 100644 (file)
@@ -455,7 +455,8 @@ static void test_exec_environmentfile(Manager *m) {
                 " ; # comment3\n"
                 "line without an equal\n"
                 "VAR3='$word 5 6'\n"
-                "VAR4='new\nline'\n";
+                "VAR4='new\nline'\n"
+                "VAR5=password\\with\\backslashes";
         int r;
 
         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("VAR3", "$word 5 6", 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-repeated.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("VAR3") == 0);
         assert_se(unsetenv("VAR4") == 0);
+        assert_se(unsetenv("VAR5") == 0);
         test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
 }
 
index cd4747aa204b7395058639ca065ce0e23f119f22..9bcb133aecce4b25901ed0a78947d599c4a42a98 100644 (file)
@@ -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" && 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
 EnvironmentFile=/tmp/test-exec_environmentfile.conf
index 4a82206a2c6f0d4c29a2007e6de9597662f8a597..d257e48cda4d25203bcd1f4ac29ba2dcf6d7d335 100644 (file)
@@ -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" && 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
-PassEnvironment=VAR1 VAR2 VAR3 VAR4
+PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5
index 8716cdf6bbfcbf6fb035a16916db0674dda409ff..291259a34716c3be1e3575d4b5bfe9708fddc6f2 100644 (file)
@@ -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" && 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
-PassEnvironment=VAR1 VAR2 VAR3 VAR4
+PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5
 PassEnvironment=
index d518d7d8a58a0d6f83244d8108f74cbba91a2c62..e88699802f243ef82ba6abc7e9e906e3a76d28fa 100644 (file)
@@ -2,8 +2,9 @@
 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" && 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
 PassEnvironment=VAR1 VAR2
 PassEnvironment=VAR1 VAR3
 PassEnvironment=VAR1 VAR4
+PassEnvironment=VAR1 VAR5
index cca44ebf4ae1f5faa66082477ea3b5e53917b8d5..05c1bdfe882d88a8ae09fa154a6986f82a7db022 100644 (file)
@@ -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" && 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
-PassEnvironment=VAR1 VAR2 VAR3 VAR4
+PassEnvironment=VAR1 VAR2 VAR3 VAR4 VAR5