test_read_pax_xattr_schily.c revision 361280
1296465Sdelphij/*- 2160814Ssimon * Copyright (c) 2016 IBM Corporation 3160814Ssimon * Copyright (c) 2003-2007 Tim Kientzle 4160814Ssimon * 5160814Ssimon * All rights reserved. 6160814Ssimon * 7160814Ssimon * Redistribution and use in source and binary forms, with or without 8160814Ssimon * modification, are permitted provided that the following conditions 9160814Ssimon * are met: 10160814Ssimon * 1. Redistributions of source code must retain the above copyright 11160814Ssimon * notice, this list of conditions and the following disclaimer. 12160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 13160814Ssimon * notice, this list of conditions and the following disclaimer in the 14160814Ssimon * documentation and/or other materials provided with the distribution. 15160814Ssimon * 16160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 17160814Ssimon * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18160814Ssimon * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19160814Ssimon * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 20160814Ssimon * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22160814Ssimon * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23160814Ssimon * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24160814Ssimon * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25160814Ssimon * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26160814Ssimon * 27160814Ssimon * This test case's code has been derived from test_entry.c 28160814Ssimon */ 29160814Ssimon#include "test.h" 30160814Ssimon 31160814SsimonDEFINE_TEST(test_read_pax_xattr_schily) 32160814Ssimon{ 33160814Ssimon struct archive *a; 34160814Ssimon struct archive_entry *ae; 35160814Ssimon const char *refname = "test_read_pax_xattr_schily.tar"; 36160814Ssimon const char *xname; /* For xattr tests. */ 37160814Ssimon const void *xval; /* For xattr tests. */ 38160814Ssimon size_t xsize; /* For xattr tests. */ 39160814Ssimon const char *string, *array; 40160814Ssimon 41160814Ssimon assert((a = archive_read_new()) != NULL); 42160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 43160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 44160814Ssimon 45160814Ssimon extract_reference_file(refname); 46160814Ssimon assertEqualIntA(a, ARCHIVE_OK, 47160814Ssimon archive_read_open_filename(a, refname, 10240)); 48160814Ssimon 49160814Ssimon assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); 50160814Ssimon assertEqualInt(2, archive_entry_xattr_count(ae)); 51160814Ssimon assertEqualInt(2, archive_entry_xattr_reset(ae)); 52160814Ssimon 53160814Ssimon assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize)); 54160814Ssimon assertEqualString(xname, "security.selinux"); 55160814Ssimon string = "system_u:object_r:unlabeled_t:s0"; 56160814Ssimon assertEqualString(xval, string); 57160814Ssimon /* the xattr's value also contains the terminating \0 */ 58160814Ssimon assertEqualInt((int)xsize, strlen(string) + 1); 59160814Ssimon 60160814Ssimon assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize)); 61160814Ssimon assertEqualString(xname, "security.ima"); 62160814Ssimon assertEqualInt((int)xsize, 265); 63160814Ssimon /* we only compare the first 12 bytes */ 64160814Ssimon array = "\x03\x02\x04\xb0\xe9\xd6\x79\x01\x00\x2b\xad\x1e"; 65160814Ssimon assertEqualMem(xval, array, 12); 66160814Ssimon 67160814Ssimon /* Close the archive. */ 68160814Ssimon assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 69160814Ssimon assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 70160814Ssimon} 71160814Ssimon