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

Side by Side Diff: extensions/common/url_pattern_unittest.cc

Issue 416263002: Don't allow null bytes in hosts of host permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « extensions/common/url_pattern.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "extensions/common/url_pattern.h" 6 #include "extensions/common/url_pattern.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace { 10 namespace {
(...skipping 27 matching lines...) Expand all
38 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 38 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
39 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH }, 39 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH },
40 }; 40 };
41 41
42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidPatterns); ++i) { 42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidPatterns); ++i) {
43 URLPattern pattern(URLPattern::SCHEME_ALL); 43 URLPattern pattern(URLPattern::SCHEME_ALL);
44 EXPECT_EQ(kInvalidPatterns[i].expected_result, 44 EXPECT_EQ(kInvalidPatterns[i].expected_result,
45 pattern.Parse(kInvalidPatterns[i].pattern)) 45 pattern.Parse(kInvalidPatterns[i].pattern))
46 << kInvalidPatterns[i].pattern; 46 << kInvalidPatterns[i].pattern;
47 } 47 }
48
49 {
50 // Cannot use a C string, because this contains a null byte.
51 std::string null_host("http://\0www/", 12);
52 URLPattern pattern(URLPattern::SCHEME_ALL);
53 EXPECT_EQ(URLPattern::PARSE_ERROR_INVALID_HOST,
54 pattern.Parse(null_host))
55 << null_host;
56 }
48 }; 57 };
49 58
50 TEST(ExtensionURLPatternTest, Ports) { 59 TEST(ExtensionURLPatternTest, Ports) {
51 const struct { 60 const struct {
52 const char* pattern; 61 const char* pattern;
53 URLPattern::ParseResult expected_result; 62 URLPattern::ParseResult expected_result;
54 const char* expected_port; 63 const char* expected_port;
55 } kTestPatterns[] = { 64 } kTestPatterns[] = {
56 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, 65 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" },
57 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, 66 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" },
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 EXPECT_TRUE(StrictlyContains(pattern10, pattern12)); 804 EXPECT_TRUE(StrictlyContains(pattern10, pattern12));
796 EXPECT_TRUE(StrictlyContains(pattern10, pattern13)); 805 EXPECT_TRUE(StrictlyContains(pattern10, pattern13));
797 806
798 // More... 807 // More...
799 EXPECT_TRUE(StrictlyContains(pattern12, pattern11)); 808 EXPECT_TRUE(StrictlyContains(pattern12, pattern11));
800 EXPECT_TRUE(NeitherContains(pattern11, pattern13)); 809 EXPECT_TRUE(NeitherContains(pattern11, pattern13));
801 EXPECT_TRUE(StrictlyContains(pattern12, pattern13)); 810 EXPECT_TRUE(StrictlyContains(pattern12, pattern13));
802 } 811 }
803 812
804 } // namespace 813 } // namespace
OLDNEW
« no previous file with comments | « extensions/common/url_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698