1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from samba
import safe_tarfile
20 from samba
.tests
import TestCaseInTempDir
25 info
.name
= prefix
+ info
.name
30 class SafeTarFileTestCase(TestCaseInTempDir
):
33 filename
= os
.path
.join(self
.tempdir
, 'x')
34 tarname
= os
.path
.join(self
.tempdir
, 'tar.tar')
35 f
= open(filename
, 'w')
39 tf
= tarfile
.open(tarname
, 'w')
40 tf
.add(filename
, filter=filterer('../../'))
43 stf
= safe_tarfile
.open(tarname
)
45 # If we have data_filter, we have a patched python to address
47 if hasattr(tarfile
, "data_filter"):
48 self
.assertRaises(tarfile
.OutsideDestinationError
,
52 self
.assertRaises(tarfile
.ExtractError
,
55 self
.rm_files('x', 'tar.tar')
58 filename
= os
.path
.join(self
.tempdir
, 'x')
59 tarname
= os
.path
.join(self
.tempdir
, 'tar.tar')
60 f
= open(filename
, 'w')
64 tf
= tarfile
.open(tarname
, 'w')
65 tf
.add(filename
, filter=filterer('/'))
68 stf
= safe_tarfile
.open(tarname
)
70 # If we have data_filter, we have a patched python to address
72 if hasattr(tarfile
, "data_filter"):
73 self
.assertRaises(NotADirectoryError
,
77 self
.assertRaises(tarfile
.ExtractError
,
81 self
.rm_files('x', 'tar.tar')