summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am1
-rw-r--r--tests/gensquashfs/Makemodule.am20
-rw-r--r--tests/gensquashfs/filemap_xattr.c98
-rw-r--r--tests/gensquashfs/xattr1.txt9
4 files changed, 128 insertions, 0 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 39db3ba..7f9f54e 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -3,6 +3,7 @@ include tests/libio/Makemodule.am
include tests/libfstree/Makemodule.am
include tests/libtar/Makemodule.am
include tests/libsqfs/Makemodule.am
+include tests/gensquashfs/Makemodule.am
if BUILD_TOOLS
if CORPORA_TESTS
diff --git a/tests/gensquashfs/Makemodule.am b/tests/gensquashfs/Makemodule.am
new file mode 100644
index 0000000..a20e6ef
--- /dev/null
+++ b/tests/gensquashfs/Makemodule.am
@@ -0,0 +1,20 @@
+GENDATADIR=$(top_srcdir)/tests/gensquashfs
+
+test_filemap_xattr_SOURCES = tests/gensquashfs/filemap_xattr.c \
+ bin/gensquashfs/filemap_xattr.c \
+ bin/gensquashfs/mkfs.h
+test_filemap_xattr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+test_filemap_xattr_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/xattr1.txt
+test_filemap_xattr_LDADD = libsquashfs.la libfstree.a libutil.a
+test_filemap_xattr_LDADD += libio.a libcompat.a
+
+GENSQUASHFS_TESTS = \
+ test_filemap_xattr
+
+if BUILD_TOOLS
+check_PROGRAMS += $(GENSQUASHFS_TESTS)
+TESTS += $(GENSQUASHFS_TESTS)
+endif
+
+EXTRA_DIST += $(GENDATADIR)/xattr1.txt
+
diff --git a/tests/gensquashfs/filemap_xattr.c b/tests/gensquashfs/filemap_xattr.c
new file mode 100644
index 0000000..d258d89
--- /dev/null
+++ b/tests/gensquashfs/filemap_xattr.c
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * filemap_xattr.c
+ *
+ * Copyright (C) 2022 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util/test.h"
+#include "mkfs.h"
+
+static const char *dev_selinux = "system_u:object_r:device_t:s0";
+static const char *zero_selinux = "system_u:object_r:zero_device_t:s0";
+static const char *rfkill_selinux = "system_u:object_r:wireless_device_t:s0";
+
+static const sqfs_u8 rfkill_acl[] = {
+ 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x06, 0x00,
+ 0xe8, 0x03, 0x00, 0x00, 0x04, 0x00, 0x06, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x06, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x20, 0x00, 0x04, 0x00,
+ 0xff, 0xff, 0xff, 0xff
+};
+
+int main(int argc, char **argv)
+{
+ struct XattrMapPattern *pat;
+ struct XattrMapEntry *ent;
+ struct XattrMap *map;
+ int ret;
+ (void)argc; (void)argv;
+
+ map = xattr_open_map_file(TEST_PATH);
+ TEST_NOT_NULL(map);
+
+ /* the third pattern */
+ pat = map->patterns;
+ TEST_NOT_NULL(pat);
+ TEST_STR_EQUAL(pat->path, "dev/rfkill");
+
+ ent = pat->entries;
+ TEST_NOT_NULL(ent);
+ TEST_STR_EQUAL(ent->key, "system.posix_acl_access");
+
+ TEST_EQUAL_UI(ent->value_len, sizeof(rfkill_acl));
+ ret = memcmp(ent->value, rfkill_acl, ent->value_len);
+ TEST_EQUAL_I(ret, 0);
+
+ ent = ent->next;
+ TEST_NOT_NULL(ent);
+ TEST_STR_EQUAL(ent->key, "security.selinux");
+
+ TEST_EQUAL_UI(ent->value_len, strlen(rfkill_selinux));
+ ret = memcmp(ent->value, rfkill_selinux, ent->value_len);
+ TEST_EQUAL_I(ret, 0);
+
+ ent = ent->next;
+ TEST_NULL(ent);
+
+ /* the second pattern */
+ pat = pat->next;
+ TEST_NOT_NULL(pat);
+ TEST_STR_EQUAL(pat->path, "dev/zero");
+
+ ent = pat->entries;
+ TEST_NOT_NULL(ent);
+ TEST_STR_EQUAL(ent->key, "security.selinux");
+
+ TEST_EQUAL_UI(ent->value_len, strlen(zero_selinux));
+ ret = memcmp(ent->value, zero_selinux, ent->value_len);
+ TEST_EQUAL_I(ret, 0);
+
+ ent = ent->next;
+ TEST_NULL(ent);
+
+ /* the first pattern */
+ pat = pat->next;
+ TEST_NOT_NULL(pat);
+ TEST_STR_EQUAL(pat->path, "dev");
+
+ ent = pat->entries;
+ TEST_NOT_NULL(ent);
+ TEST_STR_EQUAL(ent->key, "security.selinux");
+
+ TEST_EQUAL_UI(ent->value_len, strlen(dev_selinux));
+ ret = memcmp(ent->value, dev_selinux, ent->value_len);
+ TEST_EQUAL_I(ret, 0);
+
+ ent = ent->next;
+ TEST_NULL(ent);
+
+ /* no more patterns */
+ pat = pat->next;
+ TEST_NULL(pat);
+
+ xattr_close_map_file(map);
+ return EXIT_SUCCESS;
+}
diff --git a/tests/gensquashfs/xattr1.txt b/tests/gensquashfs/xattr1.txt
new file mode 100644
index 0000000..ffe5fec
--- /dev/null
+++ b/tests/gensquashfs/xattr1.txt
@@ -0,0 +1,9 @@
+# file: dev/
+security.selinux="system_u:object_r:device_t:s0"
+
+# file: dev/zero
+security.selinux="system_u:object_r:zero_device_t:s0"
+
+# file: dev/rfkill
+security.selinux="system_u:object_r:wireless_device_t:s0"
+system.posix_acl_access=0sAgAAAAEABgD/////AgAGAOgDAAAEAAYA/////xAABgD/////IAAEAP////8=