OLD | NEW |
1 // Copyright (c) 2011 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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/ftp/ftp_directory_listing_parser_ls.h" | 10 #include "net/ftp/ftp_directory_listing_parser_ls.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 std::vector<FtpDirectoryListingEntry> entries; | 160 std::vector<FtpDirectoryListingEntry> entries; |
161 EXPECT_TRUE(ParseFtpDirectoryListingLs( | 161 EXPECT_TRUE(ParseFtpDirectoryListingLs( |
162 GetSingleLineTestCase(good_cases[i].input), | 162 GetSingleLineTestCase(good_cases[i].input), |
163 GetMockCurrentTime(), | 163 GetMockCurrentTime(), |
164 &entries)); | 164 &entries)); |
165 VerifySingleLineTestCase(good_cases[i], entries); | 165 VerifySingleLineTestCase(good_cases[i], entries); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 TEST_F(FtpDirectoryListingParserLsTest, Ignored) { | 169 TEST_F(FtpDirectoryListingParserLsTest, Ignored) { |
170 const char* ignored_cases[] = { | 170 const char* const ignored_cases[] = { |
171 "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065 | 171 "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065 |
172 | 172 |
173 "ftpd: .: Permission denied", | 173 "ftpd: .: Permission denied", |
174 "ftpd-BSD: .: Permission denied", | 174 "ftpd-BSD: .: Permission denied", |
175 "ls: .: EDC5111I Permission denied.", | 175 "ls: .: EDC5111I Permission denied.", |
176 | 176 |
177 // Tests important for security: verify that after we detect the column | 177 // Tests important for security: verify that after we detect the column |
178 // offset we don't try to access invalid memory on malformed input. | 178 // offset we don't try to access invalid memory on malformed input. |
179 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11", | 179 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11", |
180 "drwxr-xr-x 3 ftp 4096 May 15 18:11", | 180 "drwxr-xr-x 3 ftp 4096 May 15 18:11", |
181 "drwxr-xr-x folder 0 May 15 18:11", | 181 "drwxr-xr-x folder 0 May 15 18:11", |
182 }; | 182 }; |
183 for (size_t i = 0; i < arraysize(ignored_cases); i++) { | 183 for (size_t i = 0; i < arraysize(ignored_cases); i++) { |
184 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 184 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
185 ignored_cases[i])); | 185 ignored_cases[i])); |
186 | 186 |
187 std::vector<FtpDirectoryListingEntry> entries; | 187 std::vector<FtpDirectoryListingEntry> entries; |
188 EXPECT_TRUE(ParseFtpDirectoryListingLs( | 188 EXPECT_TRUE(ParseFtpDirectoryListingLs( |
189 GetSingleLineTestCase(ignored_cases[i]), | 189 GetSingleLineTestCase(ignored_cases[i]), |
190 GetMockCurrentTime(), | 190 GetMockCurrentTime(), |
191 &entries)); | 191 &entries)); |
192 EXPECT_EQ(0U, entries.size()); | 192 EXPECT_EQ(0U, entries.size()); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 TEST_F(FtpDirectoryListingParserLsTest, Bad) { | 196 TEST_F(FtpDirectoryListingParserLsTest, Bad) { |
197 const char* bad_cases[] = { | 197 const char* const bad_cases[] = { |
198 " foo", | 198 " foo", |
199 "garbage", | 199 "garbage", |
200 "-rw-r--r-- ftp ftp", | 200 "-rw-r--r-- ftp ftp", |
201 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", | 201 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", |
202 "-rw-r--r-- 1 ftp ftp", | 202 "-rw-r--r-- 1 ftp ftp", |
203 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", | 203 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", |
204 | 204 |
205 // Invalid month value (30). | 205 // Invalid month value (30). |
206 "drwxrwxrwx 2 root root 4096 2012-30-07 00:31 notas_servico", | 206 "drwxrwxrwx 2 root root 4096 2012-30-07 00:31 notas_servico", |
207 }; | 207 }; |
208 for (size_t i = 0; i < arraysize(bad_cases); i++) { | 208 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
209 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 209 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
210 bad_cases[i])); | 210 bad_cases[i])); |
211 | 211 |
212 std::vector<FtpDirectoryListingEntry> entries; | 212 std::vector<FtpDirectoryListingEntry> entries; |
213 EXPECT_FALSE(ParseFtpDirectoryListingLs(GetSingleLineTestCase(bad_cases[i]), | 213 EXPECT_FALSE(ParseFtpDirectoryListingLs(GetSingleLineTestCase(bad_cases[i]), |
214 GetMockCurrentTime(), | 214 GetMockCurrentTime(), |
215 &entries)); | 215 &entries)); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 } // namespace | 219 } // namespace |
220 | 220 |
221 } // namespace net | 221 } // namespace net |
OLD | NEW |