xref: /netbsd-src/tests/bin/pax/t_pax.sh (revision 96495ab18e34de1e482b27bdf3439f5b3510d50b)
1*96495ab1Sriastradh# $NetBSD: t_pax.sh,v 1.7 2024/08/05 06:03:54 riastradh Exp $
228604916Sjruoho#
328604916Sjruoho# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
428604916Sjruoho# All rights reserved.
528604916Sjruoho#
628604916Sjruoho# Redistribution and use in source and binary forms, with or without
728604916Sjruoho# modification, are permitted provided that the following conditions
828604916Sjruoho# are met:
928604916Sjruoho# 1. Redistributions of source code must retain the above copyright
1028604916Sjruoho#    notice, this list of conditions and the following disclaimer.
1128604916Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
1228604916Sjruoho#    notice, this list of conditions and the following disclaimer in the
1328604916Sjruoho#    documentation and/or other materials provided with the distribution.
1428604916Sjruoho#
1528604916Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1628604916Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1728604916Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1828604916Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1928604916Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2028604916Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2128604916Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2228604916Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2328604916Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2428604916Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2528604916Sjruoho# POSSIBILITY OF SUCH DAMAGE.
2628604916Sjruoho#
2728604916Sjruoho
2828604916Sjruohoatf_test_case append
2928604916Sjruohoappend_head() {
3028604916Sjruoho	atf_set "descr" "Ensure that appending a file to an archive" \
3128604916Sjruoho	                "produces the same results as if the file" \
3228604916Sjruoho	                "had been there during the archive's creation"
3328604916Sjruoho}
3428604916Sjruohoappend_body() {
3528604916Sjruoho	touch foo bar
3628604916Sjruoho
3728604916Sjruoho	# store both foo and bar into file1.tar
38d8f5b04cSrillig	atf_check -s exit:0 -o empty -e empty \
3928604916Sjruoho	    pax -w -b 512 -x ustar -f file1.tar foo bar
4028604916Sjruoho
4128604916Sjruoho	# store foo into file2.tar, then append bar to file2.tar
42d8f5b04cSrillig	atf_check -s exit:0 -o empty -e empty \
4328604916Sjruoho	    pax -w -b 512 -x ustar -f file2.tar foo
44d8f5b04cSrillig	atf_check -s exit:0 -o empty -e empty \
4528604916Sjruoho	    pax -w -b 512 -x ustar -f file2.tar -a bar
4628604916Sjruoho
4728604916Sjruoho	# ensure that file1.tar and file2.tar are equal
48d8f5b04cSrillig	atf_check -s exit:0 -o empty -e empty cmp file1.tar file2.tar
4928604916Sjruoho}
5028604916Sjruoho
51c8cbe873Sriastradhatf_test_case pr41736
52c8cbe873Sriastradhpr41736_head()
53c8cbe873Sriastradh{
54c8cbe873Sriastradh	atf_set "descr" "Test pax exits with 0 if stdin file list is empty"
55c8cbe873Sriastradh}
56c8cbe873Sriastradhpr41736_body()
57c8cbe873Sriastradh{
58c8cbe873Sriastradh	atf_check pax -rw . </dev/null
59c8cbe873Sriastradh}
60c8cbe873Sriastradh
6163d7862cSriastradhatf_test_case pr44498
6263d7862cSriastradhpr44498_head()
6363d7862cSriastradh{
6463d7862cSriastradh	atf_set "descr" "Ensure pax list operation works without getcwd"
6563d7862cSriastradh	atf_set "require.user" "unprivileged"
6663d7862cSriastradh}
6763d7862cSriastradhpr44498_body()
6863d7862cSriastradh{
6963d7862cSriastradh	mkdir foo foo/bar baz
7063d7862cSriastradh	chmod 111 foo
7163d7862cSriastradh	touch baz/quux
7263d7862cSriastradh	atf_check pax -w -x ustar -f baz.tar baz
7363d7862cSriastradh	atf_check -o 'inline:baz\nbaz/quux\n' \
7463d7862cSriastradh	    sh -c '{ cd foo/bar && exec pax; } <baz.tar'
7563d7862cSriastradh}
7663d7862cSriastradh
77d71f204cSriastradhatf_test_case pr44498_copy
78d71f204cSriastradhpr44498_copy_head()
79d71f204cSriastradh{
80d71f204cSriastradh	atf_set "descr" \
81d71f204cSriastradh	    "Ensure pax insecure copy operation works without getcwd"
82d71f204cSriastradh	atf_set "require.user" "unprivileged"
83d71f204cSriastradh}
84d71f204cSriastradhpr44498_copy_body()
85d71f204cSriastradh{
86d71f204cSriastradh	mkdir foo foo/bar foo/bar/baz
87d71f204cSriastradh	chmod 111 foo
88d71f204cSriastradh	touch foo/bar/quux
89d71f204cSriastradh	atf_check sh -c '{ cd foo/bar && exec pax -rw quux baz/.; }'
90d71f204cSriastradh}
91d71f204cSriastradh
92d71f204cSriastradhatf_test_case pr44498_insecureextract
93d71f204cSriastradhpr44498_insecureextract_head()
94d71f204cSriastradh{
95d71f204cSriastradh	atf_set "descr" \
96d71f204cSriastradh	    "Ensure pax insecure extract operation works without getcwd"
97d71f204cSriastradh	atf_set "require.user" "unprivileged"
98d71f204cSriastradh}
99d71f204cSriastradhpr44498_insecureextract_body()
100d71f204cSriastradh{
101d71f204cSriastradh	mkdir foo foo/bar baz
102d71f204cSriastradh	chmod 111 foo
103d71f204cSriastradh	touch baz/quux
104d71f204cSriastradh	atf_check pax -w -x ustar -f baz.tar baz
105d71f204cSriastradh	atf_check sh -c '{ cd foo/bar && exec pax -r --insecure; } <baz.tar'
106d71f204cSriastradh}
107d71f204cSriastradh
108d71f204cSriastradhatf_test_case pr44498_listwd
109d71f204cSriastradhpr44498_listwd_head()
110d71f204cSriastradh{
111d71f204cSriastradh	atf_set "descr" "Ensure pax list operation works without working dir"
112d71f204cSriastradh	atf_set "require.user" "unprivileged"
113d71f204cSriastradh}
114d71f204cSriastradhpr44498_listwd_body()
115d71f204cSriastradh{
116d71f204cSriastradh	mkdir foo baz
117d71f204cSriastradh	chmod 111 foo
118d71f204cSriastradh	touch baz/quux
119d71f204cSriastradh	atf_check pax -w -x ustar -f baz.tar baz
120d71f204cSriastradh	atf_check -o 'inline:baz\nbaz/quux\n' \
121d71f204cSriastradh	    sh -c '{ cd foo && exec pax; } <baz.tar'
122d71f204cSriastradh}
123d71f204cSriastradh
124d71f204cSriastradhatf_test_case pr44498_write
125d71f204cSriastradhpr44498_write_head()
126d71f204cSriastradh{
127d71f204cSriastradh	atf_set "descr" "Ensure pax write operation works without getcwd"
128d71f204cSriastradh	atf_set "require.user" "unprivileged"
129d71f204cSriastradh}
130d71f204cSriastradhpr44498_write_body()
131d71f204cSriastradh{
132d71f204cSriastradh	mkdir foo foo/bar
133d71f204cSriastradh	touch foo/bar/quux
134d71f204cSriastradh	chmod 111 foo
135d71f204cSriastradh	atf_check sh -c '{ cd foo/bar && pax -w -x ustar .; } >bar.tar'
136d71f204cSriastradh	atf_check -o 'inline:.\n./quux\n' pax -f bar.tar
137d71f204cSriastradh}
138d71f204cSriastradh
13928604916Sjruohoatf_init_test_cases()
14028604916Sjruoho{
14128604916Sjruoho	atf_add_test_case append
142c8cbe873Sriastradh	atf_add_test_case pr41736
14363d7862cSriastradh	atf_add_test_case pr44498
144d71f204cSriastradh	atf_add_test_case pr44498_copy
145d71f204cSriastradh	atf_add_test_case pr44498_insecureextract
146d71f204cSriastradh	atf_add_test_case pr44498_listwd
147d71f204cSriastradh	atf_add_test_case pr44498_write
14828604916Sjruoho}
149