diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-31 11:30:46 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-31 18:04:25 +0100 |
commit | 72c8155d9fc0eaeac72c053f46ebb7b231d4596a (patch) | |
tree | 5758865289c52fa93f56e3fe743bb40c283c5233 /lib/tar/test | |
parent | cdccc69c62579b0c13b35fad0728079652b8f3c9 (diff) |
Reintegrate test code with library code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/test')
39 files changed, 518 insertions, 0 deletions
diff --git a/lib/tar/test/data/CREDITS b/lib/tar/test/data/CREDITS new file mode 100644 index 0000000..7a2738f --- /dev/null +++ b/lib/tar/test/data/CREDITS @@ -0,0 +1,35 @@ +The tar archives in this directory have been obtained from here: + + https://github.com/mgorny/tar-test-inputs + + git commit hash a2110a6 + +This repository was linked in the following article on interoperability of +various different tar programs: + + https://dev.gentoo.org/~mgorny/articles/portability-of-tar-features.html + +The original intention of the example archives was to test various tar programs +for interoperability with each others extensions and format quirks. + +The following have been removed since there is no intention in adding support +for those features: + + - volume-label tests + - multi-volume tests + - longe user + group names + - sun tar samples + - star samples + - file flags tests + +In addition to that, the files in "file-size" are truncated, since we are only +interested in parsing the header. + +The following addtional files have been added: + - xattr/xattr-shily-binary.tar + Created from xattr/xattr-shily.tar by manually patching in a capability + xattr key/value pair. + - tar/format-acceptance/link_filled.tar + Contributed in GitHub issue #64. A tar ball that contains a hard link + where the 100 byte target field is completely filled without containing + a null-terminator. diff --git a/lib/tar/test/data/file-size/12-digit.tar b/lib/tar/test/data/file-size/12-digit.tar Binary files differnew file mode 100644 index 0000000..a6b3553 --- /dev/null +++ b/lib/tar/test/data/file-size/12-digit.tar diff --git a/lib/tar/test/data/file-size/gnu.tar b/lib/tar/test/data/file-size/gnu.tar Binary files differnew file mode 100644 index 0000000..aad726f --- /dev/null +++ b/lib/tar/test/data/file-size/gnu.tar diff --git a/lib/tar/test/data/file-size/pax.tar b/lib/tar/test/data/file-size/pax.tar Binary files differnew file mode 100644 index 0000000..e391fee --- /dev/null +++ b/lib/tar/test/data/file-size/pax.tar diff --git a/lib/tar/test/data/format-acceptance/gnu-g.tar b/lib/tar/test/data/format-acceptance/gnu-g.tar Binary files differnew file mode 100644 index 0000000..a72f60d --- /dev/null +++ b/lib/tar/test/data/format-acceptance/gnu-g.tar diff --git a/lib/tar/test/data/format-acceptance/gnu.tar b/lib/tar/test/data/format-acceptance/gnu.tar Binary files differnew file mode 100644 index 0000000..98e8157 --- /dev/null +++ b/lib/tar/test/data/format-acceptance/gnu.tar diff --git a/lib/tar/test/data/format-acceptance/link_filled.tar b/lib/tar/test/data/format-acceptance/link_filled.tar Binary files differnew file mode 100644 index 0000000..9b80f89 --- /dev/null +++ b/lib/tar/test/data/format-acceptance/link_filled.tar diff --git a/lib/tar/test/data/format-acceptance/pax.tar b/lib/tar/test/data/format-acceptance/pax.tar Binary files differnew file mode 100644 index 0000000..69a029f --- /dev/null +++ b/lib/tar/test/data/format-acceptance/pax.tar diff --git a/lib/tar/test/data/format-acceptance/ustar-pre-posix.tar b/lib/tar/test/data/format-acceptance/ustar-pre-posix.tar Binary files differnew file mode 100644 index 0000000..4230f5f --- /dev/null +++ b/lib/tar/test/data/format-acceptance/ustar-pre-posix.tar diff --git a/lib/tar/test/data/format-acceptance/ustar.tar b/lib/tar/test/data/format-acceptance/ustar.tar Binary files differnew file mode 100644 index 0000000..9a6d9b3 --- /dev/null +++ b/lib/tar/test/data/format-acceptance/ustar.tar diff --git a/lib/tar/test/data/format-acceptance/v7.tar b/lib/tar/test/data/format-acceptance/v7.tar Binary files differnew file mode 100644 index 0000000..5483b4b --- /dev/null +++ b/lib/tar/test/data/format-acceptance/v7.tar diff --git a/lib/tar/test/data/large-mtime/12-digit.tar b/lib/tar/test/data/large-mtime/12-digit.tar Binary files differnew file mode 100644 index 0000000..8202b28 --- /dev/null +++ b/lib/tar/test/data/large-mtime/12-digit.tar diff --git a/lib/tar/test/data/large-mtime/gnu.tar b/lib/tar/test/data/large-mtime/gnu.tar Binary files differnew file mode 100644 index 0000000..4e3dda2 --- /dev/null +++ b/lib/tar/test/data/large-mtime/gnu.tar diff --git a/lib/tar/test/data/large-mtime/pax.tar b/lib/tar/test/data/large-mtime/pax.tar Binary files differnew file mode 100644 index 0000000..8d32530 --- /dev/null +++ b/lib/tar/test/data/large-mtime/pax.tar diff --git a/lib/tar/test/data/long-paths/gnu.tar b/lib/tar/test/data/long-paths/gnu.tar Binary files differnew file mode 100644 index 0000000..4eee731 --- /dev/null +++ b/lib/tar/test/data/long-paths/gnu.tar diff --git a/lib/tar/test/data/long-paths/pax.tar b/lib/tar/test/data/long-paths/pax.tar Binary files differnew file mode 100644 index 0000000..1e63e9c --- /dev/null +++ b/lib/tar/test/data/long-paths/pax.tar diff --git a/lib/tar/test/data/long-paths/ustar.tar b/lib/tar/test/data/long-paths/ustar.tar Binary files differnew file mode 100644 index 0000000..812255c --- /dev/null +++ b/lib/tar/test/data/long-paths/ustar.tar diff --git a/lib/tar/test/data/negative-mtime/gnu.tar b/lib/tar/test/data/negative-mtime/gnu.tar Binary files differnew file mode 100644 index 0000000..a9b1272 --- /dev/null +++ b/lib/tar/test/data/negative-mtime/gnu.tar diff --git a/lib/tar/test/data/negative-mtime/pax.tar b/lib/tar/test/data/negative-mtime/pax.tar Binary files differnew file mode 100644 index 0000000..d0b3e6c --- /dev/null +++ b/lib/tar/test/data/negative-mtime/pax.tar diff --git a/lib/tar/test/data/sparse-files/gnu-small.tar b/lib/tar/test/data/sparse-files/gnu-small.tar Binary files differnew file mode 100644 index 0000000..7a1b222 --- /dev/null +++ b/lib/tar/test/data/sparse-files/gnu-small.tar diff --git a/lib/tar/test/data/sparse-files/gnu.tar b/lib/tar/test/data/sparse-files/gnu.tar Binary files differnew file mode 100644 index 0000000..3d641a2 --- /dev/null +++ b/lib/tar/test/data/sparse-files/gnu.tar diff --git a/lib/tar/test/data/sparse-files/pax-gnu0-0.tar b/lib/tar/test/data/sparse-files/pax-gnu0-0.tar Binary files differnew file mode 100644 index 0000000..628f09e --- /dev/null +++ b/lib/tar/test/data/sparse-files/pax-gnu0-0.tar diff --git a/lib/tar/test/data/sparse-files/pax-gnu0-1.tar b/lib/tar/test/data/sparse-files/pax-gnu0-1.tar Binary files differnew file mode 100644 index 0000000..87e362e --- /dev/null +++ b/lib/tar/test/data/sparse-files/pax-gnu0-1.tar diff --git a/lib/tar/test/data/sparse-files/pax-gnu1-0.tar b/lib/tar/test/data/sparse-files/pax-gnu1-0.tar Binary files differnew file mode 100644 index 0000000..edb0ccf --- /dev/null +++ b/lib/tar/test/data/sparse-files/pax-gnu1-0.tar diff --git a/lib/tar/test/data/user-group-largenum/8-digit.tar b/lib/tar/test/data/user-group-largenum/8-digit.tar Binary files differnew file mode 100644 index 0000000..a48ea5d --- /dev/null +++ b/lib/tar/test/data/user-group-largenum/8-digit.tar diff --git a/lib/tar/test/data/user-group-largenum/gnu.tar b/lib/tar/test/data/user-group-largenum/gnu.tar Binary files differnew file mode 100644 index 0000000..4c30f57 --- /dev/null +++ b/lib/tar/test/data/user-group-largenum/gnu.tar diff --git a/lib/tar/test/data/user-group-largenum/pax.tar b/lib/tar/test/data/user-group-largenum/pax.tar Binary files differnew file mode 100644 index 0000000..a9fe54c --- /dev/null +++ b/lib/tar/test/data/user-group-largenum/pax.tar diff --git a/lib/tar/test/data/xattr/acl.tar b/lib/tar/test/data/xattr/acl.tar Binary files differnew file mode 100644 index 0000000..a65c0af --- /dev/null +++ b/lib/tar/test/data/xattr/acl.tar diff --git a/lib/tar/test/data/xattr/xattr-libarchive.tar b/lib/tar/test/data/xattr/xattr-libarchive.tar Binary files differnew file mode 100644 index 0000000..3bd6125 --- /dev/null +++ b/lib/tar/test/data/xattr/xattr-libarchive.tar diff --git a/lib/tar/test/data/xattr/xattr-schily-binary.tar b/lib/tar/test/data/xattr/xattr-schily-binary.tar Binary files differnew file mode 100644 index 0000000..0312807 --- /dev/null +++ b/lib/tar/test/data/xattr/xattr-schily-binary.tar diff --git a/lib/tar/test/data/xattr/xattr-schily.tar b/lib/tar/test/data/xattr/xattr-schily.tar Binary files differnew file mode 100644 index 0000000..1cf525c --- /dev/null +++ b/lib/tar/test/data/xattr/xattr-schily.tar diff --git a/lib/tar/test/tar_big_file.c b/lib/tar/test/tar_big_file.c new file mode 100644 index 0000000..deb41f4 --- /dev/null +++ b/lib/tar/test/tar_big_file.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_big_file.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "tar/tar.h" +#include "io/file.h" +#include "util/test.h" + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + istream_t *fp; + (void)argc; (void)argv; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, 01750); + TEST_EQUAL_UI(hdr.gid, 01750); + TEST_EQUAL_UI(hdr.actual_size, 8589934592); + TEST_EQUAL_UI(hdr.mtime, 1542959190); + TEST_STR_EQUAL(hdr.name, "big-file.bin"); + TEST_ASSERT(!hdr.unknown_record); + clear_header(&hdr); + sqfs_drop(fp); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_fuzz.c b/lib/tar/test/tar_fuzz.c new file mode 100644 index 0000000..21e6978 --- /dev/null +++ b/lib/tar/test/tar_fuzz.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_fuzz.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" + +#include "io/file.h" +#include "tar/tar.h" + +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + istream_t *fp; + int ret; + + if (argc != 2) { + fputs("usage: tar_fuzz <tarball>\n", stderr); + return EXIT_FAILURE; + } + + fp = istream_open_file(argv[1]); + if (fp == NULL) + return EXIT_FAILURE; + + for (;;) { + ret = read_header(fp, &hdr); + if (ret > 0) + break; + if (ret < 0) + goto fail; + + ret = istream_skip(fp, hdr.record_size); + + clear_header(&hdr); + if (ret < 0) + goto fail; + } + + sqfs_drop(fp); + return EXIT_SUCCESS; +fail: + sqfs_drop(fp); + return EXIT_FAILURE; +} diff --git a/lib/tar/test/tar_simple.c b/lib/tar/test/tar_simple.c new file mode 100644 index 0000000..cb38abb --- /dev/null +++ b/lib/tar/test/tar_simple.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_simple.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +#ifndef TESTUID +#define TESTUID 1000 +#endif + +#ifndef TESTGID +#define TESTGID TESTUID +#endif + +#ifndef TESTFNAME +#define TESTFNAME input.txt +#endif + +#ifndef TESTTS +#define TESTTS 1542905892 +#endif + +#ifdef LONG_NAME_TEST +static const char *fname = +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/input.txt"; +#else +static const char *fname = STRVALUE(TESTFNAME); +#endif + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + char buffer[6]; + sqfs_s64 ts; + istream_t *fp; + (void)argc; (void)argv; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, TESTUID); + TEST_EQUAL_UI(hdr.gid, TESTGID); + TEST_EQUAL_UI(hdr.actual_size, 5); + + ts = TESTTS; + TEST_EQUAL_UI(hdr.mtime, ts); + TEST_STR_EQUAL(hdr.name, fname); + TEST_ASSERT(!hdr.unknown_record); + + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + clear_header(&hdr); + sqfs_drop(fp); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_sparse.c b/lib/tar/test/tar_sparse.c new file mode 100644 index 0000000..27ce053 --- /dev/null +++ b/lib/tar/test/tar_sparse.c @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_sparse.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +static void test_case_sparse(const char *path) +{ + tar_header_decoded_t hdr; + sparse_map_t *sparse; + istream_t *fp; + + fp = istream_open_file(path); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, 01750); + TEST_EQUAL_UI(hdr.gid, 01750); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); + + sparse = hdr.sparse; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); + + sparse = sparse->next; + TEST_NULL(sparse); + + clear_header(&hdr); + sqfs_drop(fp); +} + +int main(int argc, char **argv) +{ + (void)argc; (void)argv; + test_case_sparse( STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE) ); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_sparse_gnu.c b/lib/tar/test/tar_sparse_gnu.c new file mode 100644 index 0000000..19ddd0a --- /dev/null +++ b/lib/tar/test/tar_sparse_gnu.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_sparse_gnu.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + sparse_map_t *sparse; + istream_t *fp; + (void)argc; (void)argv; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = istream_open_file("sparse-files/gnu-small.tar"); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, 01750); + TEST_EQUAL_UI(hdr.gid, 01750); + TEST_EQUAL_UI(hdr.actual_size, 524288); + TEST_EQUAL_UI(hdr.record_size, 8192); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); + + sparse = hdr.sparse; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 0); + + TEST_NULL(sparse->next); + + clear_header(&hdr); + sqfs_drop(fp); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_target_filled.c b/lib/tar/test/tar_target_filled.c new file mode 100644 index 0000000..abc6a47 --- /dev/null +++ b/lib/tar/test/tar_target_filled.c @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_target_filled.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + char buffer[16]; + istream_t *fp; + (void)argc; (void)argv; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = istream_open_file("format-acceptance/link_filled.tar"); + TEST_NOT_NULL(fp); + + /* "deep" directory hierarchy containg 2 files */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "errored_file_tst"); + TEST_EQUAL_UI(hdr.actual_size, 5); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "some_test_file"); + TEST_EQUAL_UI(hdr.actual_size, 5); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + /* "deep" directory hierarchy containg a hard link */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/" + "01234567890123456789"); + TEST_ASSERT(hdr.is_hard_link); + + TEST_STR_EQUAL(hdr.link_target, "20_characters_here01/" + "20_characters_here02/20_characters_here03/" + "20_characters_here04/errored_file_tst"); + clear_header(&hdr); + + /* end of file */ + TEST_ASSERT(read_header(fp, &hdr) > 0); + sqfs_drop(fp); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_xattr.c b/lib/tar/test/tar_xattr.c new file mode 100644 index 0000000..122d1db --- /dev/null +++ b/lib/tar/test/tar_xattr.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_xattr.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + char buffer[6]; + istream_t *fp; + (void)argc; (void)argv; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, 01750); + TEST_EQUAL_UI(hdr.gid, 01750); + TEST_EQUAL_UI(hdr.actual_size, 5); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type"); + TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain"); + TEST_EQUAL_UI(hdr.xattr->value_len, 10); + TEST_NULL(hdr.xattr->next); + + clear_header(&hdr); + sqfs_drop(fp); + return EXIT_SUCCESS; +} diff --git a/lib/tar/test/tar_xattr_bin.c b/lib/tar/test/tar_xattr_bin.c new file mode 100644 index 0000000..90443a1 --- /dev/null +++ b/lib/tar/test/tar_xattr_bin.c @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_xattr_bin.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "io/file.h" +#include "tar/tar.h" +#include "util/test.h" + +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(int argc, char **argv) +{ + tar_header_decoded_t hdr; + char buffer[6]; + istream_t *fp; + (void)argc; (void)argv; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.uid, 01750); + TEST_EQUAL_UI(hdr.gid, 01750); + TEST_EQUAL_UI(hdr.actual_size, 5); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "security.capability"); + TEST_EQUAL_UI(hdr.xattr->value_len, sizeof(value)); + TEST_ASSERT(memcmp(hdr.xattr->value, value, sizeof(value)) == 0); + TEST_NULL(hdr.xattr->next); + + clear_header(&hdr); + sqfs_drop(fp); + return EXIT_SUCCESS; +} |