1# $NetBSD: t_pax.sh,v 1.7 2024/08/05 06:03:54 riastradh Exp $ 2# 3# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28atf_test_case append 29append_head() { 30 atf_set "descr" "Ensure that appending a file to an archive" \ 31 "produces the same results as if the file" \ 32 "had been there during the archive's creation" 33} 34append_body() { 35 touch foo bar 36 37 # store both foo and bar into file1.tar 38 atf_check -s exit:0 -o empty -e empty \ 39 pax -w -b 512 -x ustar -f file1.tar foo bar 40 41 # store foo into file2.tar, then append bar to file2.tar 42 atf_check -s exit:0 -o empty -e empty \ 43 pax -w -b 512 -x ustar -f file2.tar foo 44 atf_check -s exit:0 -o empty -e empty \ 45 pax -w -b 512 -x ustar -f file2.tar -a bar 46 47 # ensure that file1.tar and file2.tar are equal 48 atf_check -s exit:0 -o empty -e empty cmp file1.tar file2.tar 49} 50 51atf_test_case pr41736 52pr41736_head() 53{ 54 atf_set "descr" "Test pax exits with 0 if stdin file list is empty" 55} 56pr41736_body() 57{ 58 atf_check pax -rw . </dev/null 59} 60 61atf_test_case pr44498 62pr44498_head() 63{ 64 atf_set "descr" "Ensure pax list operation works without getcwd" 65 atf_set "require.user" "unprivileged" 66} 67pr44498_body() 68{ 69 mkdir foo foo/bar baz 70 chmod 111 foo 71 touch baz/quux 72 atf_check pax -w -x ustar -f baz.tar baz 73 atf_check -o 'inline:baz\nbaz/quux\n' \ 74 sh -c '{ cd foo/bar && exec pax; } <baz.tar' 75} 76 77atf_test_case pr44498_copy 78pr44498_copy_head() 79{ 80 atf_set "descr" \ 81 "Ensure pax insecure copy operation works without getcwd" 82 atf_set "require.user" "unprivileged" 83} 84pr44498_copy_body() 85{ 86 mkdir foo foo/bar foo/bar/baz 87 chmod 111 foo 88 touch foo/bar/quux 89 atf_check sh -c '{ cd foo/bar && exec pax -rw quux baz/.; }' 90} 91 92atf_test_case pr44498_insecureextract 93pr44498_insecureextract_head() 94{ 95 atf_set "descr" \ 96 "Ensure pax insecure extract operation works without getcwd" 97 atf_set "require.user" "unprivileged" 98} 99pr44498_insecureextract_body() 100{ 101 mkdir foo foo/bar baz 102 chmod 111 foo 103 touch baz/quux 104 atf_check pax -w -x ustar -f baz.tar baz 105 atf_check sh -c '{ cd foo/bar && exec pax -r --insecure; } <baz.tar' 106} 107 108atf_test_case pr44498_listwd 109pr44498_listwd_head() 110{ 111 atf_set "descr" "Ensure pax list operation works without working dir" 112 atf_set "require.user" "unprivileged" 113} 114pr44498_listwd_body() 115{ 116 mkdir foo baz 117 chmod 111 foo 118 touch baz/quux 119 atf_check pax -w -x ustar -f baz.tar baz 120 atf_check -o 'inline:baz\nbaz/quux\n' \ 121 sh -c '{ cd foo && exec pax; } <baz.tar' 122} 123 124atf_test_case pr44498_write 125pr44498_write_head() 126{ 127 atf_set "descr" "Ensure pax write operation works without getcwd" 128 atf_set "require.user" "unprivileged" 129} 130pr44498_write_body() 131{ 132 mkdir foo foo/bar 133 touch foo/bar/quux 134 chmod 111 foo 135 atf_check sh -c '{ cd foo/bar && pax -w -x ustar .; } >bar.tar' 136 atf_check -o 'inline:.\n./quux\n' pax -f bar.tar 137} 138 139atf_init_test_cases() 140{ 141 atf_add_test_case append 142 atf_add_test_case pr41736 143 atf_add_test_case pr44498 144 atf_add_test_case pr44498_copy 145 atf_add_test_case pr44498_insecureextract 146 atf_add_test_case pr44498_listwd 147 atf_add_test_case pr44498_write 148} 149