OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "core/frame/csp/CSPSource.h" | 6 #include "core/frame/csp/CSPSource.h" |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/frame/csp/ContentSecurityPolicy.h" | 9 #include "core/frame/csp/ContentSecurityPolicy.h" |
10 #include "platform/weborigin/KURL.h" | 10 #include "platform/weborigin/KURL.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8000/bar/"))); | 36 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8000/bar/"))); |
37 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/bar/"))); | 37 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/bar/"))); |
38 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/bar/"))); | 38 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/bar/"))); |
39 } | 39 } |
40 | 40 |
41 TEST_F(CSPSourceTest, WildcardMatching) | 41 TEST_F(CSPSourceTest, WildcardMatching) |
42 { | 42 { |
43 KURL base; | 43 KURL base; |
44 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::HasWil
dcard, CSPSource::HasWildcard); | 44 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::HasWil
dcard, CSPSource::HasWildcard); |
45 | 45 |
46 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); | |
47 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"))); | |
48 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:9000/foo/"))); | |
49 EXPECT_TRUE(source.matches(KURL(base, "http://foo.example.com:8000/"))); | 46 EXPECT_TRUE(source.matches(KURL(base, "http://foo.example.com:8000/"))); |
| 47 EXPECT_TRUE(source.matches(KURL(base, "http://foo.example.com:8000/foo"))); |
| 48 EXPECT_TRUE(source.matches(KURL(base, "http://foo.example.com:9000/foo/"))); |
50 EXPECT_TRUE(source.matches(KURL(base, "HTTP://FOO.EXAMPLE.com:8000/foo/BAR")
)); | 49 EXPECT_TRUE(source.matches(KURL(base, "HTTP://FOO.EXAMPLE.com:8000/foo/BAR")
)); |
51 | 50 |
| 51 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8000/"))); |
| 52 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8000/foo"))); |
| 53 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"))); |
52 EXPECT_FALSE(source.matches(KURL(base, "http://example.foo.com:8000/"))); | 54 EXPECT_FALSE(source.matches(KURL(base, "http://example.foo.com:8000/"))); |
53 EXPECT_FALSE(source.matches(KURL(base, "https://example.foo.com:8000/"))); | 55 EXPECT_FALSE(source.matches(KURL(base, "https://example.foo.com:8000/"))); |
54 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/bar/"))); | 56 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/bar/"))); |
55 } | 57 } |
56 | 58 |
57 TEST_F(CSPSourceTest, RedirectMatching) | 59 TEST_F(CSPSourceTest, RedirectMatching) |
58 { | 60 { |
59 KURL base; | 61 KURL base; |
60 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource:
:NoWildcard, CSPSource::NoWildcard); | 62 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource:
:NoWildcard, CSPSource::NoWildcard); |
61 | 63 |
62 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ContentSe
curityPolicy::DidRedirect)); | 64 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ContentSe
curityPolicy::DidRedirect)); |
63 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Conten
tSecurityPolicy::DidRedirect)); | 65 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Conten
tSecurityPolicy::DidRedirect)); |
64 | 66 |
65 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/foo"), Cont
entSecurityPolicy::DidRedirect)); | 67 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8000/foo"), Cont
entSecurityPolicy::DidRedirect)); |
66 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), C
ontentSecurityPolicy::DidRedirect)); | 68 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), C
ontentSecurityPolicy::DidRedirect)); |
67 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Cont
entSecurityPolicy::DidNotRedirect)); | 69 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Cont
entSecurityPolicy::DidNotRedirect)); |
68 } | 70 } |
69 | 71 |
70 } // namespace | 72 } // namespace |
OLD | NEW |