Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: net/ftp/ftp_directory_listing_parser_ls_unittest.cc

Issue 6670085: FTP: Detect the character encoding only after the entire listing is received. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test coverage Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/ftp/ftp_directory_listing_parser_unittest.h" 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "net/ftp/ftp_directory_listing_parser_ls.h" 10 #include "net/ftp/ftp_directory_listing_parser_ls.h"
11 11
12 namespace net {
13
12 namespace { 14 namespace {
13 15
14 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserLsTest; 16 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserLsTest;
15 17
16 TEST_F(FtpDirectoryListingParserLsTest, Good) { 18 TEST_F(FtpDirectoryListingParserLsTest, Good) {
17 const struct SingleLineTestData good_cases[] = { 19 const struct SingleLineTestData good_cases[] = {
18 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README", 20 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README",
19 net::FtpDirectoryListingEntry::FILE, "README", 528, 21 FtpDirectoryListingEntry::FILE, "README", 528,
20 2007, 11, 1, 0, 0 }, 22 2007, 11, 1, 0, 0 },
21 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory", 23 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory",
22 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1, 24 FtpDirectoryListingEntry::DIRECTORY, "directory", -1,
23 1994, 5, 15, 18, 11 }, 25 1994, 5, 15, 18, 11 },
24 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 26 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
25 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 27 FtpDirectoryListingEntry::SYMLINK, "pub", -1,
26 2008, 9, 18, 0, 0 }, 28 2008, 9, 18, 0, 0 },
27 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub", 29 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub",
28 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1, 30 FtpDirectoryListingEntry::SYMLINK, "mirror", -1,
29 1994, 10, 12, 13, 37 }, 31 1994, 10, 12, 13, 37 },
30 { "drwxrwsr-x 4 501 501 4096 Feb 20 2007 pub", 32 { "drwxrwsr-x 4 501 501 4096 Feb 20 2007 pub",
31 net::FtpDirectoryListingEntry::DIRECTORY, "pub", -1, 33 FtpDirectoryListingEntry::DIRECTORY, "pub", -1,
32 2007, 2, 20, 0, 0 }, 34 2007, 2, 20, 0, 0 },
33 { "drwxr-xr-x 4 (?) (?) 4096 Apr 8 2007 jigdo", 35 { "drwxr-xr-x 4 (?) (?) 4096 Apr 8 2007 jigdo",
34 net::FtpDirectoryListingEntry::DIRECTORY, "jigdo", -1, 36 FtpDirectoryListingEntry::DIRECTORY, "jigdo", -1,
35 2007, 4, 8, 0, 0 }, 37 2007, 4, 8, 0, 0 },
36 { "drwx-wx-wt 2 root wheel 512 Jul 1 02:15 incoming", 38 { "drwx-wx-wt 2 root wheel 512 Jul 1 02:15 incoming",
37 net::FtpDirectoryListingEntry::DIRECTORY, "incoming", -1, 39 FtpDirectoryListingEntry::DIRECTORY, "incoming", -1,
38 1994, 7, 1, 2, 15 }, 40 1994, 7, 1, 2, 15 },
39 { "-rw-r--r-- 1 2 3 3447432 May 18 2009 Foo - Manual.pdf", 41 { "-rw-r--r-- 1 2 3 3447432 May 18 2009 Foo - Manual.pdf",
40 net::FtpDirectoryListingEntry::FILE, "Foo - Manual.pdf", 3447432, 42 FtpDirectoryListingEntry::FILE, "Foo - Manual.pdf", 3447432,
41 2009, 5, 18, 0, 0 }, 43 2009, 5, 18, 0, 0 },
42 { "d-wx-wx-wt+ 4 ftp 989 512 Dec 8 15:54 incoming", 44 { "d-wx-wx-wt+ 4 ftp 989 512 Dec 8 15:54 incoming",
43 net::FtpDirectoryListingEntry::DIRECTORY, "incoming", -1, 45 FtpDirectoryListingEntry::DIRECTORY, "incoming", -1,
44 1993, 12, 8, 15, 54 }, 46 1993, 12, 8, 15, 54 },
45 { "drwxrwxrwx 1 owner group 0 Sep 13 0:30 audio", 47 { "drwxrwxrwx 1 owner group 0 Sep 13 0:30 audio",
46 net::FtpDirectoryListingEntry::DIRECTORY, "audio", -1, 48 FtpDirectoryListingEntry::DIRECTORY, "audio", -1,
47 1994, 9, 13, 0, 30 }, 49 1994, 9, 13, 0, 30 },
48 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub", 50 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub",
49 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 51 FtpDirectoryListingEntry::SYMLINK, "pub", -1,
50 2008, 9, 18, 0, 0 }, 52 2008, 9, 18, 0, 0 },
51 53
52 // Tests for the wu-ftpd variant: 54 // Tests for the wu-ftpd variant:
53 { "drwxr-xr-x 2 sys 512 Mar 27 2009 pub", 55 { "drwxr-xr-x 2 sys 512 Mar 27 2009 pub",
54 net::FtpDirectoryListingEntry::DIRECTORY, "pub", -1, 56 FtpDirectoryListingEntry::DIRECTORY, "pub", -1,
55 2009, 3, 27, 0, 0 }, 57 2009, 3, 27, 0, 0 },
56 { "lrwxrwxrwx 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 58 { "lrwxrwxrwx 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
57 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 59 FtpDirectoryListingEntry::SYMLINK, "pub", -1,
58 2008, 9, 18, 0, 0 }, 60 2008, 9, 18, 0, 0 },
59 { "drwxr-xr-x (?) (?) 4096 Apr 8 2007 jigdo", 61 { "drwxr-xr-x (?) (?) 4096 Apr 8 2007 jigdo",
60 net::FtpDirectoryListingEntry::DIRECTORY, "jigdo", -1, 62 FtpDirectoryListingEntry::DIRECTORY, "jigdo", -1,
61 2007, 4, 8, 0, 0 }, 63 2007, 4, 8, 0, 0 },
62 { "-rw-r--r-- 2 3 3447432 May 18 2009 Foo - Manual.pdf", 64 { "-rw-r--r-- 2 3 3447432 May 18 2009 Foo - Manual.pdf",
63 net::FtpDirectoryListingEntry::FILE, "Foo - Manual.pdf", 3447432, 65 FtpDirectoryListingEntry::FILE, "Foo - Manual.pdf", 3447432,
64 2009, 5, 18, 0, 0 }, 66 2009, 5, 18, 0, 0 },
65 67
66 // Tests for "ls -l" style listings sent by an OS/2 server (FtpServer): 68 // Tests for "ls -l" style listings sent by an OS/2 server (FtpServer):
67 { "-r--r--r-- 1 ftp -A--- 13274 Mar 1 2006 UpTime.exe", 69 { "-r--r--r-- 1 ftp -A--- 13274 Mar 1 2006 UpTime.exe",
68 net::FtpDirectoryListingEntry::FILE, "UpTime.exe", 13274, 70 FtpDirectoryListingEntry::FILE, "UpTime.exe", 13274,
69 2006, 3, 1, 0, 0 }, 71 2006, 3, 1, 0, 0 },
70 { "dr--r--r-- 1 ftp ----- 0 Nov 17 17:08 kernels", 72 { "dr--r--r-- 1 ftp ----- 0 Nov 17 17:08 kernels",
71 net::FtpDirectoryListingEntry::DIRECTORY, "kernels", -1, 73 FtpDirectoryListingEntry::DIRECTORY, "kernels", -1,
72 1993, 11, 17, 17, 8 }, 74 1993, 11, 17, 17, 8 },
73 75
74 // Tests for "ls -l" style listing sent by Xplain FTP Server. 76 // Tests for "ls -l" style listing sent by Xplain FTP Server.
75 { "drwxr-xr-x folder 0 Jul 17 2006 online", 77 { "drwxr-xr-x folder 0 Jul 17 2006 online",
76 net::FtpDirectoryListingEntry::DIRECTORY, "online", -1, 78 FtpDirectoryListingEntry::DIRECTORY, "online", -1,
77 2006, 7, 17, 0, 0 }, 79 2006, 7, 17, 0, 0 },
78 80
79 // Tests for "ls -l" style listing with owning group name 81 // Tests for "ls -l" style listing with owning group name
80 // not separated from file size (http://crbug.com/58963). 82 // not separated from file size (http://crbug.com/58963).
81 { "-rw-r--r-- 1 ftpadmin ftpadmin125435904 Apr 9 2008 .pureftpd-upload", 83 { "-rw-r--r-- 1 ftpadmin ftpadmin125435904 Apr 9 2008 .pureftpd-upload",
82 net::FtpDirectoryListingEntry::FILE, ".pureftpd-upload", 0, 84 FtpDirectoryListingEntry::FILE, ".pureftpd-upload", 0,
83 2008, 4, 9, 0, 0 }, 85 2008, 4, 9, 0, 0 },
84 86
85 // Tests for "ls -l" style listing with number of links 87 // Tests for "ls -l" style listing with number of links
86 // not separated from permission listing (http://crbug.com/70394). 88 // not separated from permission listing (http://crbug.com/70394).
87 { "drwxr-xr-x1732 266 111 90112 Jun 21 2001 .rda_2", 89 { "drwxr-xr-x1732 266 111 90112 Jun 21 2001 .rda_2",
88 net::FtpDirectoryListingEntry::DIRECTORY, ".rda_2", -1, 90 FtpDirectoryListingEntry::DIRECTORY, ".rda_2", -1,
89 2001, 6, 21, 0, 0 }, 91 2001, 6, 21, 0, 0 },
90 }; 92 };
91 for (size_t i = 0; i < arraysize(good_cases); i++) { 93 for (size_t i = 0; i < arraysize(good_cases); i++) {
92 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 94 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
93 good_cases[i].input)); 95 good_cases[i].input));
94 96
95 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime()); 97 std::vector<FtpDirectoryListingEntry> entries;
96 RunSingleLineTestCase(&parser, good_cases[i]); 98 EXPECT_TRUE(ParseFtpDirectoryListingLs(
99 GetSingleLineTestCase(good_cases[i].input),
100 GetMockCurrentTime(),
101 &entries));
102 VerifySingleLineTestCase(good_cases[i], entries);
97 } 103 }
98 } 104 }
99 105
100 TEST_F(FtpDirectoryListingParserLsTest, Ignored) { 106 TEST_F(FtpDirectoryListingParserLsTest, Ignored) {
101 const char* ignored_cases[] = { 107 const char* ignored_cases[] = {
102 "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065 108 "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065
103 109
104 "ftpd: .: Permission denied", 110 "ftpd: .: Permission denied",
105 "ftpd-BSD: .: Permission denied", 111 "ftpd-BSD: .: Permission denied",
106 112
107 // Tests important for security: verify that after we detect the column 113 // Tests important for security: verify that after we detect the column
108 // offset we don't try to access invalid memory on malformed input. 114 // offset we don't try to access invalid memory on malformed input.
109 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11", 115 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
110 "drwxr-xr-x 3 ftp 4096 May 15 18:11", 116 "drwxr-xr-x 3 ftp 4096 May 15 18:11",
111 "drwxr-xr-x folder 0 May 15 18:11", 117 "drwxr-xr-x folder 0 May 15 18:11",
112 }; 118 };
113 for (size_t i = 0; i < arraysize(ignored_cases); i++) { 119 for (size_t i = 0; i < arraysize(ignored_cases); i++) {
114 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 120 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
115 ignored_cases[i])); 121 ignored_cases[i]));
116 122
117 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime()); 123 std::vector<FtpDirectoryListingEntry> entries;
118 EXPECT_TRUE(parser.ConsumeLine(UTF8ToUTF16(ignored_cases[i]))); 124 EXPECT_TRUE(ParseFtpDirectoryListingLs(
119 EXPECT_FALSE(parser.EntryAvailable()); 125 GetSingleLineTestCase(ignored_cases[i]),
120 EXPECT_TRUE(parser.OnEndOfInput()); 126 GetMockCurrentTime(),
121 EXPECT_FALSE(parser.EntryAvailable()); 127 &entries));
128 EXPECT_EQ(0U, entries.size());
122 } 129 }
123 } 130 }
124 131
125 TEST_F(FtpDirectoryListingParserLsTest, Bad) { 132 TEST_F(FtpDirectoryListingParserLsTest, Bad) {
126 const char* bad_cases[] = { 133 const char* bad_cases[] = {
127 " foo", 134 " foo",
128 "garbage", 135 "garbage",
129 "-rw-r--r-- ftp ftp", 136 "-rw-r--r-- ftp ftp",
130 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README", 137 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README",
131 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README", 138 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README",
132 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README", 139 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README",
133 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README", 140 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README",
134 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", 141 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README",
135 "-rw-r--r-- 1 ftp ftp", 142 "-rw-r--r-- 1 ftp ftp",
136 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 143 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
137 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 144 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
138 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", 145 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README",
139 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README", 146 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README",
140 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", 147 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
141 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio", 148 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio",
142 149
143 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub", 150 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub",
144 }; 151 };
145 for (size_t i = 0; i < arraysize(bad_cases); i++) { 152 for (size_t i = 0; i < arraysize(bad_cases); i++) {
146 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime()); 153 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
147 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 154 bad_cases[i]));
155
156 std::vector<FtpDirectoryListingEntry> entries;
157 EXPECT_FALSE(ParseFtpDirectoryListingLs(GetSingleLineTestCase(bad_cases[i]),
158 GetMockCurrentTime(),
159 &entries));
148 } 160 }
149 } 161 }
150 162
151 } // namespace 163 } // namespace
164
165 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_ls.cc ('k') | net/ftp/ftp_directory_listing_parser_netware.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698