summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am12
-rw-r--r--tests/filename_sane.c67
2 files changed, 77 insertions, 2 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index ec4e4c5..6853487 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -48,6 +48,12 @@ test_fstree_init_SOURCES = tests/fstree_init.c
test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
test_fstree_init_LDADD = libfstree.a libcompat.a
+test_filename_sane_SOURCES = tests/filename_sane.c lib/fstree/filename_sane.c
+
+test_filename_sane_w32_SOURCES = tests/filename_sane.c
+test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c
+test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1
+
test_tar_gnu_SOURCES = tests/tar_gnu.c
test_tar_gnu_LDADD = libtar.a libcompat.a
test_tar_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
@@ -97,7 +103,8 @@ tar_fuzz_LDADD = libtar.a libcompat.a
check_PROGRAMS += test_mknode_simple test_mknode_slink test_mknode_reg
check_PROGRAMS += test_mknode_dir test_gen_inode_numbers test_add_by_path
check_PROGRAMS += test_get_path test_fstree_sort test_fstree_from_file
-check_PROGRAMS += test_fstree_init test_tar_ustar test_tar_pax test_tar_gnu
+check_PROGRAMS += test_fstree_init test_filename_sane test_filename_sane_w32
+check_PROGRAMS += test_tar_ustar test_tar_pax test_tar_gnu
check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu1 test_tar_sparse_gnu2
check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily
check_PROGRAMS += test_tar_xattr_schily_bin
@@ -108,7 +115,8 @@ noinst_PROGRAMS += fstree_fuzz tar_fuzz
TESTS += test_mknode_simple test_mknode_slink
TESTS += test_mknode_reg test_mknode_dir test_gen_inode_numbers
TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
-TESTS += test_fstree_init test_tar_ustar test_tar_pax
+TESTS += test_fstree_init test_filename_sane test_filename_sane_w32
+TESTS += test_tar_ustar test_tar_pax
TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1
TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily
TESTS += test_tar_xattr_schily_bin tests/cantrbry.sh tests/test_tar_sqfs.sh
diff --git a/tests/filename_sane.c b/tests/filename_sane.c
new file mode 100644
index 0000000..4d75326
--- /dev/null
+++ b/tests/filename_sane.c
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * filename_sane.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "fstree.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+
+static const char *must_work[] = {
+ "foobar",
+ "test.txt",
+ NULL,
+};
+
+static const char *must_not_work[] = {
+ ".",
+ "..",
+ "/foo",
+ "\\foo",
+ "foo/",
+ "foo\\",
+ "foo/bar",
+ "foo\\bar",
+ NULL,
+};
+
+static const char *must_not_work_here[] = {
+#if defined(_WIN32) || defined(__WINDOWS__)
+ "fo<o", "fo>o", "fo:o", "fo\"o",
+ "fo|o", "fo?o", "fo*o", "fo\ro",
+ "CON", "PRN", "AUX", "NUL",
+ "COM1", "COM2", "LPT1", "LPT2",
+ "con", "prn", "aux", "nul",
+ "com1", "com2", "lpt1", "lpt2",
+ "foo.AUX", "foo.NUL", "foo.aux", "foo.nul",
+ "NUL.txt", "nul.txt"
+#endif
+ NULL,
+};
+
+int main(void)
+{
+ size_t i;
+
+ for (i = 0; must_work[i] != NULL; ++i) {
+ assert(is_filename_sane(must_work[i], false));
+ assert(is_filename_sane(must_work[i], true));
+ }
+
+ for (i = 0; must_not_work[i] != NULL; ++i) {
+ assert(!is_filename_sane(must_not_work[i], false));
+ assert(!is_filename_sane(must_not_work[i], true));
+ }
+
+ for (i = 0; must_not_work_here[i] != NULL; ++i) {
+ assert( is_filename_sane(must_not_work_here[i], false));
+ assert(!is_filename_sane(must_not_work_here[i], true));
+ }
+
+ return EXIT_SUCCESS;
+}