|
1 | 1 | from __future__ import unicode_literals |
2 | 2 |
|
| 3 | +import textwrap |
3 | 4 | import time |
4 | 5 | import unittest |
5 | 6 |
|
@@ -33,23 +34,25 @@ def test_parse_time(self, mock_localtime): |
33 | 34 | self.assertEqual(ftp_parse._parse_time("notadate", formats=["%b %d %Y"]), None) |
34 | 35 |
|
35 | 36 | def test_parse(self): |
36 | | - self.assertEqual(ftp_parse.parse([""]), []) |
| 37 | + self.assertListEqual(ftp_parse.parse([""]), []) |
37 | 38 |
|
38 | 39 | def test_parse_line(self): |
39 | 40 | self.assertIs(ftp_parse.parse_line("not a dir"), None) |
40 | 41 |
|
41 | 42 | @mock.patch("time.localtime") |
42 | 43 | def test_decode_linux(self, mock_localtime): |
43 | 44 | 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 | + ) |
53 | 56 |
|
54 | 57 | expected = [ |
55 | 58 | { |
@@ -158,25 +161,27 @@ def test_decode_linux(self, mock_localtime): |
158 | 161 | }, |
159 | 162 | ] |
160 | 163 |
|
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) |
163 | 166 |
|
164 | 167 | @mock.patch("time.localtime") |
165 | 168 | def test_decode_windowsnt(self, mock_localtime): |
166 | 169 | 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 | + ) |
180 | 185 | expected = [ |
181 | 186 | { |
182 | 187 | "basic": {"is_dir": True, "name": "docs"}, |
@@ -230,5 +235,94 @@ def test_decode_windowsnt(self, mock_localtime): |
230 | 235 | }, |
231 | 236 | ] |
232 | 237 |
|
233 | | - parsed = ftp_parse.parse(directory.splitlines()) |
| 238 | + parsed = ftp_parse.parse(directory.strip().splitlines()) |
234 | 239 | 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