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

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

Issue 4182002: FTP: fix directory listing parser for ftp://ftp.dd-wrt.com/others/juno6/ (Closed)
Patch Set: typo Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 }; 84 };
85 for (size_t i = 0; i < arraysize(good_cases); i++) { 85 for (size_t i = 0; i < arraysize(good_cases); i++) {
86 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 86 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
87 good_cases[i].input)); 87 good_cases[i].input));
88 88
89 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime()); 89 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
90 RunSingleLineTestCase(&parser, good_cases[i]); 90 RunSingleLineTestCase(&parser, good_cases[i]);
91 } 91 }
92 } 92 }
93 93
94 TEST_F(FtpDirectoryListingParserLsTest, Ignored) {
95 const char* ignored_cases[] = {
96 "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065
97
98 // Tests important for security: verify that after we detect the column
99 // offset we don't try to access invalid memory on malformed input.
100 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
101 "drwxr-xr-x 3 ftp 4096 May 15 18:11",
102 "drwxr-xr-x folder 0 May 15 18:11",
103 };
104 for (size_t i = 0; i < arraysize(ignored_cases); i++) {
105 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
106 ignored_cases[i]));
107
108 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
109 EXPECT_TRUE(parser.ConsumeLine(UTF8ToUTF16(ignored_cases[i])));
wtc 2010/10/28 01:05:41 In the original code, we EXPECT_FALSE here (see li
Paweł Hajdan Jr. 2010/10/28 07:15:34 When ConsumeLine returns false, it means that the
110 EXPECT_FALSE(parser.EntryAvailable());
111 EXPECT_TRUE(parser.OnEndOfInput());
112 EXPECT_FALSE(parser.EntryAvailable());
113 }
114 }
115
94 TEST_F(FtpDirectoryListingParserLsTest, Bad) { 116 TEST_F(FtpDirectoryListingParserLsTest, Bad) {
95 const char* bad_cases[] = { 117 const char* bad_cases[] = {
96 " foo", 118 " foo",
97 "garbage", 119 "garbage",
98 "-rw-r--r-- ftp ftp", 120 "-rw-r--r-- ftp ftp",
99 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README", 121 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README",
100 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README", 122 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README",
101 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README", 123 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README",
102 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README", 124 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README",
103 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", 125 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README",
104 "-rw-r--r-- 1 ftp ftp", 126 "-rw-r--r-- 1 ftp ftp",
105 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 127 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
106 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 128 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
107 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", 129 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README",
108 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README", 130 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README",
109 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", 131 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
110 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio", 132 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio",
111 133
112 "d-wx-wx-wt++ 4 ftp 989 512 Dec 8 15:54 incoming", 134 "d-wx-wx-wt++ 4 ftp 989 512 Dec 8 15:54 incoming",
113 "d-wx-wx-wt$ 4 ftp 989 512 Dec 8 15:54 incoming", 135 "d-wx-wx-wt$ 4 ftp 989 512 Dec 8 15:54 incoming",
114 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub", 136 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub",
115
116 // Tests important for security: verify that after we detect the column
117 // offset we don't try to access invalid memory on malformed input.
118 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
119 "drwxr-xr-x 3 ftp 4096 May 15 18:11",
120 "drwxr-xr-x folder 0 May 15 18:11",
121 }; 137 };
122 for (size_t i = 0; i < arraysize(bad_cases); i++) { 138 for (size_t i = 0; i < arraysize(bad_cases); i++) {
123 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime()); 139 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
124 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 140 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
125 } 141 }
126 } 142 }
127 143
128 } // namespace 144 } // namespace
OLDNEW
« net/ftp/ftp_directory_listing_parser_ls.cc ('K') | « net/ftp/ftp_directory_listing_parser_ls.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698