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

Side by Side Diff: content/common/database_identifier_unittest.cc

Issue 2397873002: Reject some previuosly-escaped chars in hostnames.
Patch Set: Some tests fixed Created 4 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
« no previous file with comments | « components/search_engines/template_url_unittest.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "storage/common/database/database_identifier.h" 5 #include "storage/common/database/database_identifier.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // This tests the encoding of a hostname including every character in the range 52 // This tests the encoding of a hostname including every character in the range
53 // [\x1f, \x80]. 53 // [\x1f, \x80].
54 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars) { 54 TEST(DatabaseIdentifierTest, CreateIdentifierAllHostChars) {
55 struct Case { 55 struct Case {
56 std::string hostname; 56 std::string hostname;
57 std::string expected; 57 std::string expected;
58 bool shouldRoundTrip; 58 bool shouldRoundTrip;
59 } cases[] = { 59 } cases[] = {
60 {"x\x1Fx", "__0", false}, 60 {"x\x1Fx", "__0", false},
61 {"x\x20x", "http_x%20x_0", false}, 61 {"x\x20x", "__0", false},
62 {"x\x21x", "http_x%21x_0", false}, 62 {"x\x21x", "__0", false},
63 {"x\x22x", "http_x%22x_0", false}, 63 {"x\x22x", "__0", false},
64 {"x\x23x", "http_x_0", false}, // 'x#x', the # and following are ignored. 64 {"x\x23x", "http_x_0", false}, // 'x#x', the # and following are ignored.
65 {"x\x24x", "http_x%24x_0", false}, 65 {"x\x24x", "__0", false},
66 {"x\x25x", "__0", false}, 66 {"x\x25x", "__0", false},
67 {"x\x26x", "http_x%26x_0", false}, 67 {"x\x26x", "__0", false},
68 {"x\x27x", "http_x%27x_0", false}, 68 {"x\x27x", "__0", false},
69 {"x\x28x", "http_x%28x_0", false}, 69 {"x\x28x", "__0", false},
70 {"x\x29x", "http_x%29x_0", false}, 70 {"x\x29x", "__0", false},
71 {"x\x2ax", "http_x%2ax_0", false}, 71 {"x\x2ax", "__0", false},
72 {"x\x2bx", "http_x+x_0", false}, 72 {"x\x2bx", "__0", false},
73 {"x\x2cx", "http_x%2cx_0", false}, 73 {"x\x2cx", "__0", false},
74 {"x\x2dx", "http_x-x_0", true}, 74 {"x\x2dx", "http_x-x_0", true},
75 {"x\x2ex", "http_x.x_0", true}, 75 {"x\x2ex", "http_x.x_0", true},
76 {"x\x2fx", "http_x_0", false}, // 'x/x', the / and following are ignored. 76 {"x\x2fx", "http_x_0", false}, // 'x/x', the / and following are ignored.
77 {"x\x30x", "http_x0x_0", true}, 77 {"x\x30x", "http_x0x_0", true},
78 {"x\x31x", "http_x1x_0", true}, 78 {"x\x31x", "http_x1x_0", true},
79 {"x\x32x", "http_x2x_0", true}, 79 {"x\x32x", "http_x2x_0", true},
80 {"x\x33x", "http_x3x_0", true}, 80 {"x\x33x", "http_x3x_0", true},
81 {"x\x34x", "http_x4x_0", true}, 81 {"x\x34x", "http_x4x_0", true},
82 {"x\x35x", "http_x5x_0", true}, 82 {"x\x35x", "http_x5x_0", true},
83 {"x\x36x", "http_x6x_0", true}, 83 {"x\x36x", "http_x6x_0", true},
84 {"x\x37x", "http_x7x_0", true}, 84 {"x\x37x", "http_x7x_0", true},
85 {"x\x38x", "http_x8x_0", true}, 85 {"x\x38x", "http_x8x_0", true},
86 {"x\x39x", "http_x9x_0", true}, 86 {"x\x39x", "http_x9x_0", true},
87 {"x\x3ax", "__0", false}, 87 {"x\x3ax", "__0", false},
88 {"x\x3bx", "__0", false}, 88 {"x\x3bx", "__0", false},
89 {"x\x3cx", "http_x%3cx_0", false}, 89 {"x\x3cx", "__0", false},
90 {"x\x3dx", "http_x%3dx_0", false}, 90 {"x\x3dx", "__0", false},
91 {"x\x3ex", "http_x%3ex_0", false}, 91 {"x\x3ex", "__0", false},
92 {"x\x3fx", "http_x_0", false}, // 'x?x', the ? and following are ignored. 92 {"x\x3fx", "http_x_0", false}, // 'x?x', the ? and following are ignored.
93 {"x\x40x", "http_x_0", false}, // 'x@x', the @ and following are ignored. 93 {"x\x40x", "http_x_0", false}, // 'x@x', the @ and following are ignored.
94 {"x\x41x", "http_xax_0", true}, 94 {"x\x41x", "http_xax_0", true},
95 {"x\x42x", "http_xbx_0", true}, 95 {"x\x42x", "http_xbx_0", true},
96 {"x\x43x", "http_xcx_0", true}, 96 {"x\x43x", "http_xcx_0", true},
97 {"x\x44x", "http_xdx_0", true}, 97 {"x\x44x", "http_xdx_0", true},
98 {"x\x45x", "http_xex_0", true}, 98 {"x\x45x", "http_xex_0", true},
99 {"x\x46x", "http_xfx_0", true}, 99 {"x\x46x", "http_xfx_0", true},
100 {"x\x47x", "http_xgx_0", true}, 100 {"x\x47x", "http_xgx_0", true},
101 {"x\x48x", "http_xhx_0", true}, 101 {"x\x48x", "http_xhx_0", true},
(...skipping 13 matching lines...) Expand all
115 {"x\x56x", "http_xvx_0", true}, 115 {"x\x56x", "http_xvx_0", true},
116 {"x\x57x", "http_xwx_0", true}, 116 {"x\x57x", "http_xwx_0", true},
117 {"x\x58x", "http_xxx_0", true}, 117 {"x\x58x", "http_xxx_0", true},
118 {"x\x59x", "http_xyx_0", true}, 118 {"x\x59x", "http_xyx_0", true},
119 {"x\x5ax", "http_xzx_0", true}, 119 {"x\x5ax", "http_xzx_0", true},
120 {"x\x5bx", "__0", false}, 120 {"x\x5bx", "__0", false},
121 {"x\x5cx", "http_x_0", false}, // "x\x", the \ and following are ignored. 121 {"x\x5cx", "http_x_0", false}, // "x\x", the \ and following are ignored.
122 {"x\x5dx", "__0", false}, 122 {"x\x5dx", "__0", false},
123 {"x\x5ex", "__0", false}, 123 {"x\x5ex", "__0", false},
124 {"x\x5fx", "http_x_x_0", true}, 124 {"x\x5fx", "http_x_x_0", true},
125 {"x\x60x", "http_x%60x_0", false}, 125 {"x\x60x", "__0", false},
126 {"x\x61x", "http_xax_0", true}, 126 {"x\x61x", "http_xax_0", true},
127 {"x\x62x", "http_xbx_0", true}, 127 {"x\x62x", "http_xbx_0", true},
128 {"x\x63x", "http_xcx_0", true}, 128 {"x\x63x", "http_xcx_0", true},
129 {"x\x64x", "http_xdx_0", true}, 129 {"x\x64x", "http_xdx_0", true},
130 {"x\x65x", "http_xex_0", true}, 130 {"x\x65x", "http_xex_0", true},
131 {"x\x66x", "http_xfx_0", true}, 131 {"x\x66x", "http_xfx_0", true},
132 {"x\x67x", "http_xgx_0", true}, 132 {"x\x67x", "http_xgx_0", true},
133 {"x\x68x", "http_xhx_0", true}, 133 {"x\x68x", "http_xhx_0", true},
134 {"x\x69x", "http_xix_0", true}, 134 {"x\x69x", "http_xix_0", true},
135 {"x\x6ax", "http_xjx_0", true}, 135 {"x\x6ax", "http_xjx_0", true},
136 {"x\x6bx", "http_xkx_0", true}, 136 {"x\x6bx", "http_xkx_0", true},
137 {"x\x6cx", "http_xlx_0", true}, 137 {"x\x6cx", "http_xlx_0", true},
138 {"x\x6dx", "http_xmx_0", true}, 138 {"x\x6dx", "http_xmx_0", true},
139 {"x\x6ex", "http_xnx_0", true}, 139 {"x\x6ex", "http_xnx_0", true},
140 {"x\x6fx", "http_xox_0", true}, 140 {"x\x6fx", "http_xox_0", true},
141 {"x\x70x", "http_xpx_0", true}, 141 {"x\x70x", "http_xpx_0", true},
142 {"x\x71x", "http_xqx_0", true}, 142 {"x\x71x", "http_xqx_0", true},
143 {"x\x72x", "http_xrx_0", true}, 143 {"x\x72x", "http_xrx_0", true},
144 {"x\x73x", "http_xsx_0", true}, 144 {"x\x73x", "http_xsx_0", true},
145 {"x\x74x", "http_xtx_0", true}, 145 {"x\x74x", "http_xtx_0", true},
146 {"x\x75x", "http_xux_0", true}, 146 {"x\x75x", "http_xux_0", true},
147 {"x\x76x", "http_xvx_0", true}, 147 {"x\x76x", "http_xvx_0", true},
148 {"x\x77x", "http_xwx_0", true}, 148 {"x\x77x", "http_xwx_0", true},
149 {"x\x78x", "http_xxx_0", true}, 149 {"x\x78x", "http_xxx_0", true},
150 {"x\x79x", "http_xyx_0", true}, 150 {"x\x79x", "http_xyx_0", true},
151 {"x\x7ax", "http_xzx_0", true}, 151 {"x\x7ax", "http_xzx_0", true},
152 {"x\x7bx", "http_x%7bx_0", false}, 152 {"x\x7bx", "__0", false},
153 {"x\x7cx", "http_x%7cx_0", false}, 153 {"x\x7cx", "__0", false},
154 {"x\x7dx", "http_x%7dx_0", false}, 154 {"x\x7dx", "__0", false},
155 {"x\x7ex", "__0", false}, 155 {"x\x7ex", "__0", false},
156 {"x\x7fx", "__0", false}, 156 {"x\x7fx", "__0", false},
157 {"x\x80x", "__0", false}, 157 {"x\x80x", "__0", false},
158 }; 158 };
159 159
160 for (size_t i = 0; i < arraysize(cases); ++i) { 160 for (size_t i = 0; i < arraysize(cases); ++i) {
161 GURL origin("http://" + cases[i].hostname); 161 GURL origin("http://" + cases[i].hostname);
162 DatabaseIdentifier identifier = 162 DatabaseIdentifier identifier =
163 DatabaseIdentifier::CreateFromOrigin(origin); 163 DatabaseIdentifier::CreateFromOrigin(origin);
164 EXPECT_EQ(cases[i].expected, identifier.ToString()) 164 EXPECT_EQ(cases[i].expected, identifier.ToString())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 {"file__0", 197 {"file__0",
198 "", "", 0, GURL("file:///"), true}, 198 "", "", 0, GURL("file:///"), true},
199 {"__0", 199 {"__0",
200 "", "", 0, GURL(), true}, 200 "", "", 0, GURL(), true},
201 {"http_foo_bar_baz.org_0", 201 {"http_foo_bar_baz.org_0",
202 "http", "foo_bar_baz.org", 0, GURL("http://foo_bar_baz.org"), false}, 202 "http", "foo_bar_baz.org", 0, GURL("http://foo_bar_baz.org"), false},
203 {"http_xn--n3h.unicode.com_0", 203 {"http_xn--n3h.unicode.com_0",
204 "http", "xn--n3h.unicode.com", 0, 204 "http", "xn--n3h.unicode.com", 0,
205 GURL("http://xn--n3h.unicode.com"), false}, 205 GURL("http://xn--n3h.unicode.com"), false},
206 {"http_dot.com_0", "http", "dot.com", 0, GURL("http://dot.com"), false}, 206 {"http_dot.com_0", "http", "dot.com", 0, GURL("http://dot.com"), false},
207 {"http_escaped%3Dfun.com_0", "http", "escaped%3dfun.com", 0,
208 GURL("http://escaped%3dfun.com"), false},
209 {"http_[__1]_8080", 207 {"http_[__1]_8080",
210 "http", "[::1]", 8080, GURL("http://[::1]:8080"), false}, 208 "http", "[::1]", 8080, GURL("http://[::1]:8080"), false},
211 {"http_[3ffe_2a00_100_7031__1]_0", 209 {"http_[3ffe_2a00_100_7031__1]_0",
212 "http", "[3ffe:2a00:100:7031::1]", 0, 210 "http", "[3ffe:2a00:100:7031::1]", 0,
213 GURL("http://[3ffe:2a00:100:7031::1]"), false}, 211 GURL("http://[3ffe:2a00:100:7031::1]"), false},
214 {"http_[__ffff_8190_3426]_0", 212 {"http_[__ffff_8190_3426]_0",
215 "http", "[::ffff:8190:3426]", 0, GURL("http://[::ffff:8190:3426]"), false}, 213 "http", "[::ffff:8190:3426]", 0, GURL("http://[::ffff:8190:3426]"), false},
216 }; 214 };
217 215
218 for (size_t i = 0; i < arraysize(valid_cases); ++i) { 216 for (size_t i = 0; i < arraysize(valid_cases); ++i) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 TestValidOriginIdentifier(false, ""); 276 TestValidOriginIdentifier(false, "");
279 TestValidOriginIdentifier(false, "bad..id"); 277 TestValidOriginIdentifier(false, "bad..id");
280 TestValidOriginIdentifier(false, "bad/id"); 278 TestValidOriginIdentifier(false, "bad/id");
281 TestValidOriginIdentifier(false, "bad\\id"); 279 TestValidOriginIdentifier(false, "bad\\id");
282 TestValidOriginIdentifier(false, "http_bad:0_2"); 280 TestValidOriginIdentifier(false, "http_bad:0_2");
283 TestValidOriginIdentifier(false, std::string("bad\0id", 6)); 281 TestValidOriginIdentifier(false, std::string("bad\0id", 6));
284 } 282 }
285 283
286 } // namespace 284 } // namespace
287 } // namespace content 285 } // namespace content
OLDNEW
« no previous file with comments | « components/search_engines/template_url_unittest.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698