Skip to content

Commit bbaa041

Browse files
committed
Add regression test for #451 to tests.test_ftp_parse
1 parent 3df9836 commit bbaa041

File tree

1 file changed

+120
-26
lines changed

1 file changed

+120
-26
lines changed

tests/test_ftp_parse.py

Lines changed: 120 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
import textwrap
34
import time
45
import unittest
56

@@ -33,23 +34,25 @@ def test_parse_time(self, mock_localtime):
3334
self.assertEqual(ftp_parse._parse_time("notadate", formats=["%b %d %Y"]), None)
3435

3536
def test_parse(self):
36-
self.assertEqual(ftp_parse.parse([""]), [])
37+
self.assertListEqual(ftp_parse.parse([""]), [])
3738

3839
def test_parse_line(self):
3940
self.assertIs(ftp_parse.parse_line("not a dir"), None)
4041

4142
@mock.patch("time.localtime")
4243
def test_decode_linux(self, mock_localtime):
4344
mock_localtime.return_value = time2017
44-
directory = """\
45-
lrwxrwxrwx 1 0 0 19 Jan 18 2006 debian -> ./pub/mirror/debian
46-
drwxr-xr-x 10 0 0 4096 Aug 03 09:21 debian-archive
47-
lrwxrwxrwx 1 0 0 27 Nov 30 2015 debian-backports -> pub/mirror/debian-backports
48-
drwxr-xr-x 12 0 0 4096 Sep 29 13:13 pub
49-
-rw-r--r-- 1 0 0 26 Mar 04 2010 robots.txt
50-
drwxr-xr-x 8 foo bar 4096 Oct 4 09:05 test
51-
drwxr-xr-x 2 foo-user foo-group 0 Jan 5 11:59 240485
52-
"""
45+
directory = textwrap.dedent(
46+
"""
47+
lrwxrwxrwx 1 0 0 19 Jan 18 2006 debian -> ./pub/mirror/debian
48+
drwxr-xr-x 10 0 0 4096 Aug 03 09:21 debian-archive
49+
lrwxrwxrwx 1 0 0 27 Nov 30 2015 debian-backports -> pub/mirror/debian-backports
50+
drwxr-xr-x 12 0 0 4096 Sep 29 13:13 pub
51+
-rw-r--r-- 1 0 0 26 Mar 04 2010 robots.txt
52+
drwxr-xr-x 8 foo bar 4096 Oct 4 09:05 test
53+
drwxr-xr-x 2 foo-user foo-group 0 Jan 5 11:59 240485
54+
"""
55+
)
5356

5457
expected = [
5558
{
@@ -158,25 +161,27 @@ def test_decode_linux(self, mock_localtime):
158161
},
159162
]
160163

161-
parsed = ftp_parse.parse(directory.splitlines())
162-
self.assertEqual(parsed, expected)
164+
parsed = ftp_parse.parse(directory.strip().splitlines())
165+
self.assertListEqual(parsed, expected)
163166

164167
@mock.patch("time.localtime")
165168
def test_decode_windowsnt(self, mock_localtime):
166169
mock_localtime.return_value = time2017
167-
directory = """\
168-
unparsable line
169-
11-02-17 02:00AM <DIR> docs
170-
11-02-17 02:12PM <DIR> images
171-
11-02-17 02:12PM <DIR> AM to PM
172-
11-02-17 03:33PM 9276 logo.gif
173-
05-11-20 22:11 <DIR> src
174-
11-02-17 01:23 1 12
175-
11-02-17 4:54 0 icon.bmp
176-
11-02-17 4:54AM 0 icon.gif
177-
11-02-17 4:54PM 0 icon.png
178-
11-02-17 16:54 0 icon.jpg
179-
"""
170+
directory = textwrap.dedent(
171+
"""
172+
unparsable line
173+
11-02-17 02:00AM <DIR> docs
174+
11-02-17 02:12PM <DIR> images
175+
11-02-17 02:12PM <DIR> AM to PM
176+
11-02-17 03:33PM 9276 logo.gif
177+
05-11-20 22:11 <DIR> src
178+
11-02-17 01:23 1 12
179+
11-02-17 4:54 0 icon.bmp
180+
11-02-17 4:54AM 0 icon.gif
181+
11-02-17 4:54PM 0 icon.png
182+
11-02-17 16:54 0 icon.jpg
183+
"""
184+
)
180185
expected = [
181186
{
182187
"basic": {"is_dir": True, "name": "docs"},
@@ -230,5 +235,94 @@ def test_decode_windowsnt(self, mock_localtime):
230235
},
231236
]
232237

233-
parsed = ftp_parse.parse(directory.splitlines())
238+
parsed = ftp_parse.parse(directory.strip().splitlines())
234239
self.assertEqual(parsed, expected)
240+
241+
@mock.patch("time.localtime")
242+
def test_decode_linux_suid(self, mock_localtime):
243+
# reported in #451
244+
mock_localtime.return_value = time2017
245+
directory = textwrap.dedent(
246+
"""
247+
drwxr-sr-x 66 ftp ftp 8192 Mar 16 17:54 pub
248+
-rw-r--r-- 1 ftp ftp 25 Mar 18 19:34 robots.txt
249+
"""
250+
)
251+
expected = [
252+
{
253+
"access": {
254+
"group": "ftp",
255+
"permissions": [
256+
"g_r",
257+
"g_s",
258+
"o_r",
259+
"o_x",
260+
"u_r",
261+
"u_w",
262+
"u_x",
263+
],
264+
"user": "ftp",
265+
},
266+
"basic": {"is_dir": True, "name": "pub"},
267+
"details": {"modified": 1489686840.0, "size": 8192, "type": 1},
268+
"ftp": {
269+
"ls": "drwxr-sr-x 66 ftp ftp 8192 Mar 16 17:54 pub"
270+
},
271+
},
272+
{
273+
"access": {
274+
"group": "ftp",
275+
"permissions": [
276+
"g_r",
277+
"o_r",
278+
"u_r",
279+
"u_w",
280+
],
281+
"user": "ftp",
282+
},
283+
"basic": {"is_dir": False, "name": "robots.txt"},
284+
"details": {"modified": 1489865640.0, "size": 25, "type": 2},
285+
"ftp": {
286+
"ls": "-rw-r--r-- 1 ftp ftp 25 Mar 18 19:34 robots.txt"
287+
},
288+
}
289+
]
290+
291+
parsed = ftp_parse.parse(directory.strip().splitlines())
292+
self.assertListEqual(parsed, expected)
293+
294+
@mock.patch("time.localtime")
295+
def test_decode_linux_sticky(self, mock_localtime):
296+
# reported in #451
297+
mock_localtime.return_value = time2017
298+
directory = textwrap.dedent(
299+
"""
300+
drwxr-xr-t 66 ftp ftp 8192 Mar 16 17:54 pub
301+
"""
302+
)
303+
expected = [
304+
{
305+
"access": {
306+
"group": "ftp",
307+
"permissions": [
308+
"g_r",
309+
"g_x",
310+
"o_r",
311+
"o_t",
312+
"u_r",
313+
"u_w",
314+
"u_x",
315+
],
316+
"user": "ftp",
317+
},
318+
"basic": {"is_dir": True, "name": "pub"},
319+
"details": {"modified": 1489686840.0, "size": 8192, "type": 1},
320+
"ftp": {
321+
"ls": "drwxr-xr-t 66 ftp ftp 8192 Mar 16 17:54 pub"
322+
},
323+
},
324+
]
325+
326+
self.maxDiff = None
327+
parsed = ftp_parse.parse(directory.strip().splitlines())
328+
self.assertListEqual(parsed, expected)

0 commit comments

Comments
 (0)