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

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

Issue 3448029: FTP: fix directory listing parser for ftp.usa.hp.com (Closed)
Patch Set: attempt to fix Windows trybots Created 10 years, 2 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
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"
11 11
12 namespace { 12 namespace {
13 13
14 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserLsTest; 14 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserLsTest;
15 15
16 TEST_F(FtpDirectoryListingParserLsTest, Good) { 16 TEST_F(FtpDirectoryListingParserLsTest, Good) {
17 base::Time mock_current_time;
18 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT",
19 &mock_current_time));
20
21 const struct SingleLineTestData good_cases[] = { 17 const struct SingleLineTestData good_cases[] = {
22 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README", 18 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README",
23 net::FtpDirectoryListingEntry::FILE, "README", 528, 19 net::FtpDirectoryListingEntry::FILE, "README", 528,
24 2007, 11, 1, 0, 0 }, 20 2007, 11, 1, 0, 0 },
25 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory", 21 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory",
26 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1, 22 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1,
27 1994, 5, 15, 18, 11 }, 23 1994, 5, 15, 18, 11 },
28 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 24 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
29 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 25 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1,
30 2008, 9, 18, 0, 0 }, 26 2008, 9, 18, 0, 0 },
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 73
78 // Tests for "ls -l" style listing sent by Xplain FTP Server. 74 // Tests for "ls -l" style listing sent by Xplain FTP Server.
79 { "drwxr-xr-x folder 0 Jul 17 2006 online", 75 { "drwxr-xr-x folder 0 Jul 17 2006 online",
80 net::FtpDirectoryListingEntry::DIRECTORY, "online", -1, 76 net::FtpDirectoryListingEntry::DIRECTORY, "online", -1,
81 2006, 7, 17, 0, 0 }, 77 2006, 7, 17, 0, 0 },
82 }; 78 };
83 for (size_t i = 0; i < arraysize(good_cases); i++) { 79 for (size_t i = 0; i < arraysize(good_cases); i++) {
84 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 80 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
85 good_cases[i].input)); 81 good_cases[i].input));
86 82
87 net::FtpDirectoryListingParserLs parser(mock_current_time); 83 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
88 RunSingleLineTestCase(&parser, good_cases[i]); 84 RunSingleLineTestCase(&parser, good_cases[i]);
89 } 85 }
90 } 86 }
91 87
92 TEST_F(FtpDirectoryListingParserLsTest, Bad) { 88 TEST_F(FtpDirectoryListingParserLsTest, Bad) {
93 base::Time mock_current_time;
94 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT",
95 &mock_current_time));
96
97 const char* bad_cases[] = { 89 const char* bad_cases[] = {
90 " foo",
98 "garbage", 91 "garbage",
99 "-rw-r--r-- ftp ftp", 92 "-rw-r--r-- ftp ftp",
100 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README", 93 "-rw-r--rgb ftp ftp 528 Nov 01 2007 README",
101 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README", 94 "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README",
102 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README", 95 "qrwwr--r-- ftp ftp 528 Nov 01 2007 README",
103 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README", 96 "-rw-r--r-- ftp ftp -528 Nov 01 2007 README",
104 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", 97 "-rw-r--r-- ftp ftp 528 Foo 01 2007 README",
105 "-rw-r--r-- 1 ftp ftp", 98 "-rw-r--r-- 1 ftp ftp",
106 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 99 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
107 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 100 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
108 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", 101 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README",
109 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README", 102 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README",
110 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", 103 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
111 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio", 104 "drwxrwxrwx 1 owner group 0 Sep 13 0:3 audio",
112 105
113 "d-wx-wx-wt++ 4 ftp 989 512 Dec 8 15:54 incoming", 106 "d-wx-wx-wt++ 4 ftp 989 512 Dec 8 15:54 incoming",
114 "d-wx-wx-wt$ 4 ftp 989 512 Dec 8 15:54 incoming", 107 "d-wx-wx-wt$ 4 ftp 989 512 Dec 8 15:54 incoming",
115 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub", 108 "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub",
116 109
117 // Tests important for security: verify that after we detect the column 110 // Tests important for security: verify that after we detect the column
118 // offset we don't try to access invalid memory on malformed input. 111 // offset we don't try to access invalid memory on malformed input.
119 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11", 112 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
120 "drwxr-xr-x 3 ftp 4096 May 15 18:11", 113 "drwxr-xr-x 3 ftp 4096 May 15 18:11",
121 "drwxr-xr-x folder 0 May 15 18:11", 114 "drwxr-xr-x folder 0 May 15 18:11",
122 }; 115 };
123 for (size_t i = 0; i < arraysize(bad_cases); i++) { 116 for (size_t i = 0; i < arraysize(bad_cases); i++) {
124 net::FtpDirectoryListingParserLs parser(mock_current_time); 117 net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
125 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 118 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
126 } 119 }
127 } 120 }
128 121
129 } // namespace 122 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_hprc_unittest.cc ('k') | net/ftp/ftp_directory_listing_parser_mlsd_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698