1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2003-2010 Tim Kientzle
5 * All rights reserved.
6 */
7 #include "test.h"
8
DEFINE_TEST(test_option_uid_uname)9 DEFINE_TEST(test_option_uid_uname)
10 {
11 char *reference, *data;
12 size_t s;
13
14 assertUmask(0);
15 assertMakeFile("file", 0644, "1234567890");
16
17 /* Create archive with no special options. */
18 failure("Error invoking %s c", testprog);
19 assertEqualInt(0,
20 systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
21 testprog));
22 assertEmptyFile("stdout1.txt");
23 assertEmptyFile("stderr1.txt");
24 reference = slurpfile(&s, "archive1");
25
26 /* Again with both --uid and --uname */
27 failure("Error invoking %s c", testprog);
28 assertEqualInt(0,
29 systemf("%s cf archive2 --uid=65123 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
30 testprog));
31 assertEmptyFile("stdout2.txt");
32 assertEmptyFile("stderr2.txt");
33 data = slurpfile(&s, "archive2");
34 /* Should force uid and uname fields in ustar header. */
35 assertEqualMem(data + 108, "177143 \0", 8);
36 assertEqualMem(data + 265, "foofoofoo\0", 10);
37 free(data);
38
39 /* Again with just --uid */
40 failure("Error invoking %s c", testprog);
41 assertEqualInt(0,
42 systemf("%s cf archive3 --uid=65123 --format=ustar file >stdout3.txt 2>stderr3.txt",
43 testprog));
44 assertEmptyFile("stdout3.txt");
45 assertEmptyFile("stderr3.txt");
46 data = slurpfile(&s, "archive3");
47 assertEqualMem(data + 108, "177143 \0", 8);
48 /* Uname field in ustar header should be empty. */
49 assertEqualMem(data + 265, "\0", 1);
50 free(data);
51
52 /* Again with just --uname */
53 failure("Error invoking %s c", testprog);
54 assertEqualInt(0,
55 systemf("%s cf archive4 --uname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
56 testprog));
57 assertEmptyFile("stdout4.txt");
58 assertEmptyFile("stderr4.txt");
59 data = slurpfile(&s, "archive4");
60 /* Uid should be unchanged from original reference. */
61 assertEqualMem(data + 108, reference + 108, 8);
62 assertEqualMem(data + 265, "foofoofoo\0", 10);
63 free(data);
64
65 free(reference);
66 }
67