1361280Smm/*-
2361280Smm * Copyright (c) 2016 IBM Corporation
3361280Smm * Copyright (c) 2003-2007 Tim Kientzle
4361280Smm *
5361280Smm * All rights reserved.
6361280Smm *
7361280Smm * Redistribution and use in source and binary forms, with or without
8361280Smm * modification, are permitted provided that the following conditions
9361280Smm * are met:
10361280Smm * 1. Redistributions of source code must retain the above copyright
11361280Smm *    notice, this list of conditions and the following disclaimer.
12361280Smm * 2. Redistributions in binary form must reproduce the above copyright
13361280Smm *    notice, this list of conditions and the following disclaimer in the
14361280Smm *    documentation and/or other materials provided with the distribution.
15361280Smm *
16361280Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17361280Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18361280Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19361280Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20361280Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21361280Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22361280Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23361280Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24361280Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25361280Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26361280Smm *
27361280Smm * This test case's code has been derived from test_entry.c
28361280Smm */
29361280Smm#include "test.h"
30361280Smm
31361280SmmDEFINE_TEST(test_read_pax_xattr_schily)
32361280Smm{
33361280Smm	struct archive *a;
34361280Smm	struct archive_entry *ae;
35361280Smm	const char *refname = "test_read_pax_xattr_schily.tar";
36361280Smm	const char *xname; /* For xattr tests. */
37361280Smm	const void *xval; /* For xattr tests. */
38361280Smm	size_t xsize; /* For xattr tests. */
39361280Smm	const char *string, *array;
40361280Smm
41361280Smm	assert((a = archive_read_new()) != NULL);
42361280Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
43361280Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
44361280Smm
45361280Smm	extract_reference_file(refname);
46361280Smm	assertEqualIntA(a, ARCHIVE_OK,
47361280Smm	    archive_read_open_filename(a, refname, 10240));
48361280Smm
49361280Smm	assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
50361280Smm	assertEqualInt(2, archive_entry_xattr_count(ae));
51361280Smm	assertEqualInt(2, archive_entry_xattr_reset(ae));
52361280Smm
53361280Smm	assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize));
54361280Smm	assertEqualString(xname, "security.selinux");
55361280Smm	string = "system_u:object_r:unlabeled_t:s0";
56361280Smm	assertEqualString(xval, string);
57361280Smm	/* the xattr's value also contains the terminating \0 */
58361280Smm	assertEqualInt((int)xsize, strlen(string) + 1);
59361280Smm
60361280Smm	assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize));
61361280Smm	assertEqualString(xname, "security.ima");
62361280Smm	assertEqualInt((int)xsize, 265);
63361280Smm	/* we only compare the first 12 bytes */
64361280Smm	array = "\x03\x02\x04\xb0\xe9\xd6\x79\x01\x00\x2b\xad\x1e";
65361280Smm	assertEqualMem(xval, array, 12);
66361280Smm
67361280Smm	/* Close the archive. */
68361280Smm	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
69361280Smm	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
70361280Smm}
71