|
|
8d419f |
From 402854a52a0a659fd914279eae17b4e065a9c294 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
8d419f |
Date: Wed, 19 Jan 2022 10:15:50 +0100
|
|
|
8d419f |
Subject: [PATCH] test-env-file: add tests for quoting in env files
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit e9e982a29d52834375e5fb553cecb45bc905cf91)
|
|
|
8d419f |
|
|
|
8d419f |
Related: #2017035
|
|
|
8d419f |
---
|
|
|
8d419f |
src/test/test-env-file.c | 68 +++++++++++++++++++++++++++++-----------
|
|
|
8d419f |
1 file changed, 50 insertions(+), 18 deletions(-)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/test/test-env-file.c b/src/test/test-env-file.c
|
|
|
8d419f |
index 6cc2455c1f..7b132447bf 100644
|
|
|
8d419f |
--- a/src/test/test-env-file.c
|
|
|
8d419f |
+++ b/src/test/test-env-file.c
|
|
|
8d419f |
@@ -13,11 +13,11 @@
|
|
|
8d419f |
"a=a\n" \
|
|
|
8d419f |
"b=b\\\n" \
|
|
|
8d419f |
"c\n" \
|
|
|
8d419f |
- "d=d\\\n" \
|
|
|
8d419f |
- "e\\\n" \
|
|
|
8d419f |
- "f\n" \
|
|
|
8d419f |
+ "d= d\\\n" \
|
|
|
8d419f |
+ "e \\\n" \
|
|
|
8d419f |
+ "f \n" \
|
|
|
8d419f |
"g=g\\ \n" \
|
|
|
8d419f |
- "h=h\n" \
|
|
|
8d419f |
+ "h= ąęół\\ śćńźżµ \n" \
|
|
|
8d419f |
"i=i\\"
|
|
|
8d419f |
|
|
|
8d419f |
#define env_file_2 \
|
|
|
8d419f |
@@ -26,22 +26,34 @@
|
|
|
8d419f |
#define env_file_3 \
|
|
|
8d419f |
"#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\\n" \
|
|
|
8d419f |
"#--nouser-config \\\n" \
|
|
|
8d419f |
- "normal=line"
|
|
|
8d419f |
-
|
|
|
8d419f |
-#define env_file_4 \
|
|
|
8d419f |
- "# Generated\n" \
|
|
|
8d419f |
- "\n" \
|
|
|
8d419f |
- "HWMON_MODULES=\"coretemp f71882fg\"\n" \
|
|
|
8d419f |
- "\n" \
|
|
|
8d419f |
- "# For compatibility reasons\n" \
|
|
|
8d419f |
- "\n" \
|
|
|
8d419f |
- "MODULE_0=coretemp\n" \
|
|
|
8d419f |
- "MODULE_1=f71882fg"
|
|
|
8d419f |
+ "normal=line \\\n" \
|
|
|
8d419f |
+ ";normal=ignored \\\n" \
|
|
|
8d419f |
+ "normal_ignored \\\n" \
|
|
|
8d419f |
+ "normal ignored \\\n"
|
|
|
8d419f |
+
|
|
|
8d419f |
+#define env_file_4 \
|
|
|
8d419f |
+ "# Generated\n" \
|
|
|
8d419f |
+ "\n" \
|
|
|
8d419f |
+ "HWMON_MODULES=\"coretemp f71882fg\"\n" \
|
|
|
8d419f |
+ "\n" \
|
|
|
8d419f |
+ "# For compatibility reasons\n" \
|
|
|
8d419f |
+ "\n" \
|
|
|
8d419f |
+ "MODULE_0=coretemp\n" \
|
|
|
8d419f |
+ "MODULE_1=f71882fg"
|
|
|
8d419f |
|
|
|
8d419f |
#define env_file_5 \
|
|
|
8d419f |
- "a=\n" \
|
|
|
8d419f |
+ "a=\n" \
|
|
|
8d419f |
"b="
|
|
|
8d419f |
|
|
|
8d419f |
+#define env_file_6 \
|
|
|
8d419f |
+ "a=\\ \\n \\t \\x \\y \\' \n" \
|
|
|
8d419f |
+ "b= \\$' \n" \
|
|
|
8d419f |
+ "c= ' \\n\\t\\$\\`\\\\\n" \
|
|
|
8d419f |
+ "' \n" \
|
|
|
8d419f |
+ "d= \" \\n\\t\\$\\`\\\\\n" \
|
|
|
8d419f |
+ "\" \n"
|
|
|
8d419f |
+
|
|
|
8d419f |
+
|
|
|
8d419f |
TEST(load_env_file_1) {
|
|
|
8d419f |
_cleanup_strv_free_ char **data = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
@@ -57,9 +69,9 @@ TEST(load_env_file_1) {
|
|
|
8d419f |
assert_se(r == 0);
|
|
|
8d419f |
assert_se(streq(data[0], "a=a"));
|
|
|
8d419f |
assert_se(streq(data[1], "b=bc"));
|
|
|
8d419f |
- assert_se(streq(data[2], "d=def"));
|
|
|
8d419f |
+ assert_se(streq(data[2], "d=de f"));
|
|
|
8d419f |
assert_se(streq(data[3], "g=g "));
|
|
|
8d419f |
- assert_se(streq(data[4], "h=h"));
|
|
|
8d419f |
+ assert_se(streq(data[4], "h=ąęół śćńźżµ"));
|
|
|
8d419f |
assert_se(streq(data[5], "i=i"));
|
|
|
8d419f |
assert_se(data[6] == NULL);
|
|
|
8d419f |
}
|
|
|
8d419f |
@@ -133,6 +145,26 @@ TEST(load_env_file_5) {
|
|
|
8d419f |
assert_se(data[2] == NULL);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
+TEST(load_env_file_6) {
|
|
|
8d419f |
+ _cleanup_strv_free_ char **data = NULL;
|
|
|
8d419f |
+ int r;
|
|
|
8d419f |
+
|
|
|
8d419f |
+ _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-load-env-file.XXXXXX";
|
|
|
8d419f |
+ _cleanup_close_ int fd;
|
|
|
8d419f |
+
|
|
|
8d419f |
+ fd = mkostemp_safe(name);
|
|
|
8d419f |
+ assert_se(fd >= 0);
|
|
|
8d419f |
+ assert_se(write(fd, env_file_6, strlen(env_file_6)) == strlen(env_file_6));
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = load_env_file(NULL, name, &data);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(streq(data[0], "a= n t x y '"));
|
|
|
8d419f |
+ assert_se(streq(data[1], "b=$'"));
|
|
|
8d419f |
+ assert_se(streq(data[2], "c= \\n\\t\\$\\`\\\\\n"));
|
|
|
8d419f |
+ assert_se(streq(data[3], "d= \\n\\t$`\\\n"));
|
|
|
8d419f |
+ assert_se(data[4] == NULL);
|
|
|
8d419f |
+}
|
|
|
8d419f |
+
|
|
|
8d419f |
TEST(write_and_load_env_file) {
|
|
|
8d419f |
const char *v;
|
|
|
8d419f |
|