4
4
"""
5
5
6
6
import unittest
7
- from test .support import os_helper
7
+ from test .support import os_helper , warnings_helper
8
+
9
+ uu = warnings_helper .import_deprecated ("uu" )
8
10
9
11
import os
10
12
import stat
11
13
import sys
12
- import uu
13
14
import io
14
15
15
16
plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n "
@@ -57,8 +58,6 @@ def encodedtextwrapped(mode, filename, backtick=False):
57
58
58
59
class UUTest (unittest .TestCase ):
59
60
60
- # TODO: RUSTPYTHON
61
- @unittest .expectedFailure
62
61
def test_encode (self ):
63
62
inp = io .BytesIO (plaintext )
64
63
out = io .BytesIO ()
@@ -75,6 +74,7 @@ def test_encode(self):
75
74
with self .assertRaises (TypeError ):
76
75
uu .encode (inp , out , "t1" , 0o644 , True )
77
76
77
+ @os_helper .skip_unless_working_chmod
78
78
def test_decode (self ):
79
79
for backtick in True , False :
80
80
inp = io .BytesIO (encodedtextwrapped (0o666 , "t1" , backtick = backtick ))
@@ -138,8 +138,6 @@ def test_garbage_padding(self):
138
138
decoded = codecs .decode (encodedtext , "uu_codec" )
139
139
self .assertEqual (decoded , plaintext )
140
140
141
- # TODO: RUSTPYTHON
142
- @unittest .expectedFailure
143
141
def test_newlines_escaped (self ):
144
142
# Test newlines are escaped with uu.encode
145
143
inp = io .BytesIO (plaintext )
@@ -149,6 +147,34 @@ def test_newlines_escaped(self):
149
147
uu .encode (inp , out , filename )
150
148
self .assertIn (safefilename , out .getvalue ())
151
149
150
+ def test_no_directory_traversal (self ):
151
+ relative_bad = b"""\
152
+ begin 644 ../../../../../../../../tmp/test1
153
+ $86)C"@``
154
+ `
155
+ end
156
+ """
157
+ with self .assertRaisesRegex (uu .Error , 'directory' ):
158
+ uu .decode (io .BytesIO (relative_bad ))
159
+ if os .altsep :
160
+ relative_bad_bs = relative_bad .replace (b'/' , b'\\ ' )
161
+ with self .assertRaisesRegex (uu .Error , 'directory' ):
162
+ uu .decode (io .BytesIO (relative_bad_bs ))
163
+
164
+ absolute_bad = b"""\
165
+ begin 644 /tmp/test2
166
+ $86)C"@``
167
+ `
168
+ end
169
+ """
170
+ with self .assertRaisesRegex (uu .Error , 'directory' ):
171
+ uu .decode (io .BytesIO (absolute_bad ))
172
+ if os .altsep :
173
+ absolute_bad_bs = absolute_bad .replace (b'/' , b'\\ ' )
174
+ with self .assertRaisesRegex (uu .Error , 'directory' ):
175
+ uu .decode (io .BytesIO (absolute_bad_bs ))
176
+
177
+
152
178
class UUStdIOTest (unittest .TestCase ):
153
179
154
180
def setUp (self ):
@@ -202,6 +228,8 @@ def test_encode(self):
202
228
s = fout .read ()
203
229
self .assertEqual (s , encodedtextwrapped (0o644 , self .tmpin ))
204
230
231
+ # decode() calls chmod()
232
+ @os_helper .skip_unless_working_chmod
205
233
def test_decode (self ):
206
234
with open (self .tmpin , 'wb' ) as f :
207
235
f .write (encodedtextwrapped (0o644 , self .tmpout ))
@@ -214,6 +242,7 @@ def test_decode(self):
214
242
self .assertEqual (s , plaintext )
215
243
# XXX is there an xp way to verify the mode?
216
244
245
+ @os_helper .skip_unless_working_chmod
217
246
def test_decode_filename (self ):
218
247
with open (self .tmpin , 'wb' ) as f :
219
248
f .write (encodedtextwrapped (0o644 , self .tmpout ))
@@ -224,6 +253,7 @@ def test_decode_filename(self):
224
253
s = f .read ()
225
254
self .assertEqual (s , plaintext )
226
255
256
+ @os_helper .skip_unless_working_chmod
227
257
def test_decodetwice (self ):
228
258
# Verify that decode() will refuse to overwrite an existing file
229
259
with open (self .tmpin , 'wb' ) as f :
@@ -234,8 +264,7 @@ def test_decodetwice(self):
234
264
with open (self .tmpin , 'rb' ) as f :
235
265
self .assertRaises (uu .Error , uu .decode , f )
236
266
237
- # TODO: RUSTPYTHON
238
- @unittest .expectedFailure
267
+ @os_helper .skip_unless_working_chmod
239
268
def test_decode_mode (self ):
240
269
# Verify that decode() will set the given mode for the out_file
241
270
expected_mode = 0o444
0 commit comments