aboutsummaryrefslogtreecommitdiff
path: root/tests/gensquashfs/filemap_xattr.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-16 10:45:30 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-16 15:06:52 +0100
commit0f68ca18f491b4e53cec788b327a752cbeb43377 (patch)
treeefdbc4e3628124e0260405439841d14333523ddd /tests/gensquashfs/filemap_xattr.c
parentdfba31880be3d3cc5d56707cd05ab306149392e2 (diff)
filemap xattr: Add a test case
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/gensquashfs/filemap_xattr.c')
-rw-r--r--tests/gensquashfs/filemap_xattr.c98
1 files changed, 98 insertions, 0 deletions
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;
+}