summaryrefslogtreecommitdiff
path: root/tests/tar_xattr_schily_bin.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-14 01:03:02 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-14 01:03:02 +0100
commit5cb28dc91a2e23e6f8f7e875e2ea725634526dfe (patch)
tree2cdbff93cfe4518e7f527daca0c395db35ef0c49 /tests/tar_xattr_schily_bin.c
parent76e9644ba9e7ce3535eb72ab041ac3be8486c22c (diff)
Add a test case for reading binary xattrs from pax/schily headers
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/tar_xattr_schily_bin.c')
-rw-r--r--tests/tar_xattr_schily_bin.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/tar_xattr_schily_bin.c b/tests/tar_xattr_schily_bin.c
new file mode 100644
index 0000000..d8d5161
--- /dev/null
+++ b/tests/tar_xattr_schily_bin.c
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * tar_xattr_schily_bin.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "tar.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#define STR(x) #x
+#define STRVALUE(x) STR(x)
+
+#define TEST_PATH STRVALUE(TESTPATH)
+
+static FILE *open_read(const char *path)
+{
+ FILE *fp = fopen(path, "rb");
+
+ if (fp == NULL) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ return fp;
+}
+
+static const uint8_t value[] = {
+ 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x30, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+int main(void)
+{
+ tar_header_decoded_t hdr;
+ char buffer[6];
+ FILE *fp;
+
+ assert(chdir(TEST_PATH) == 0);
+
+ fp = open_read("xattr/xattr-schily-binary.tar");
+ assert(read_header(fp, &hdr) == 0);
+ assert(hdr.sb.st_mode == (S_IFREG | 0644));
+ assert(hdr.sb.st_uid == 01750);
+ assert(hdr.sb.st_gid == 01750);
+ assert(hdr.sb.st_size == 5);
+ assert(hdr.sb.st_mtime == 1543094477);
+ assert(hdr.mtime == 1543094477);
+ assert(strcmp(hdr.name, "input.txt") == 0);
+ assert(!hdr.unknown_record);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
+ buffer[5] = '\0';
+ assert(strcmp(buffer, "test\n") == 0);
+
+ assert(hdr.xattr != NULL);
+ assert(strcmp(hdr.xattr->key, "security.capability") == 0);
+ assert(hdr.xattr->value_len == sizeof(value));
+ assert(memcmp(hdr.xattr->value, value, sizeof(value)) == 0);
+ assert(hdr.xattr->next == NULL);
+
+ clear_header(&hdr);
+ fclose(fp);
+ return EXIT_SUCCESS;
+}