[email protected] | a507b82 | 2014-04-12 05:10:24 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 7 | #include <string> |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 8 | #include <vector> |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 9 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | e4ca79d | 2014-08-22 13:15:10 | [diff] [blame] | 11 | #include "content/browser/appcache/appcache_manifest_parser.h" |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 12 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | a507b82 | 2014-04-12 05:10:24 | [diff] [blame] | 14 | |
| 15 | namespace content { |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 16 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 17 | class AppCacheManifestParserTest : public testing::Test { |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 18 | }; |
| 19 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 20 | TEST(AppCacheManifestParserTest, NoData) { |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 21 | GURL url; |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 22 | AppCacheManifest manifest; |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 23 | EXPECT_FALSE(ParseManifest( |
| 24 | url, "", 0, PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, manifest)); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 25 | EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, // Len is 0. |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 26 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 27 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 30 | TEST(AppCacheManifestParserTest, CheckSignature) { |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 31 | GURL url; |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 32 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 33 | |
| 34 | const std::string kBadSignatures[] = { |
| 35 | "foo", |
| 36 | "CACHE MANIFEST;V2\r", // not followed by whitespace |
| 37 | "CACHE MANIFEST#bad\r", // no whitespace before comment |
| 38 | "cache manifest ", // wrong case |
| 39 | "#CACHE MANIFEST\r", // comment |
| 40 | "xCACHE MANIFEST\n", // bad first char |
| 41 | " CACHE MANIFEST\r", // begins with whitespace |
| 42 | "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value |
| 43 | }; |
| 44 | |
| 45 | for (size_t i = 0; i < arraysize(kBadSignatures); ++i) { |
| 46 | const std::string bad = kBadSignatures[i]; |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 47 | EXPECT_FALSE(ParseManifest(url, bad.c_str(), bad.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 48 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 49 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | const std::string kGoodSignatures[] = { |
| 53 | "CACHE MANIFEST", |
| 54 | "CACHE MANIFEST ", |
| 55 | "CACHE MANIFEST\r", |
| 56 | "CACHE MANIFEST\n", |
| 57 | "CACHE MANIFEST\r\n", |
| 58 | "CACHE MANIFEST\t# ignore me\r", |
| 59 | "CACHE MANIFEST ignore\r\n", |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 60 | "CHROMIUM CACHE MANIFEST\r\n", |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 61 | "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present |
| 62 | }; |
| 63 | |
| 64 | for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { |
| 65 | const std::string good = kGoodSignatures[i]; |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 66 | EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 67 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 68 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 72 | TEST(AppCacheManifestParserTest, NoManifestUrl) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 73 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 74 | const std::string kData("CACHE MANIFEST\r" |
| 75 | "relative/tobase.com\r" |
| 76 | "http://absolute.com/addme.com"); |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 77 | const GURL kUrl; |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 78 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 79 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 80 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 81 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 82 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 83 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 84 | EXPECT_FALSE(manifest.online_whitelist_all); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 87 | TEST(AppCacheManifestParserTest, ExplicitUrls) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 88 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 89 | const GURL kUrl("http://www.foo.com"); |
| 90 | const std::string kData("CACHE MANIFEST\r" |
| 91 | "relative/one\r" |
| 92 | "# some comment\r" |
| 93 | "http://www.foo.com/two#strip\r\n" |
| 94 | "NETWORK:\r" |
| 95 | " \t CACHE:\r" |
| 96 | "HTTP://www.diff.com/three\r" |
| 97 | "FALLBACK:\r" |
| 98 | " \t # another comment with leading whitespace\n" |
| 99 | "IGNORE:\r" |
| 100 | "http://www.foo.com/ignore\r" |
| 101 | "CACHE: \r" |
| 102 | "garbage:#!@\r" |
| 103 | "https://www.foo.com/diffscheme \t \r" |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 104 | " \t relative/four#stripme\n\r" |
| 105 | "*\r"); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 106 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 107 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 108 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 109 | manifest)); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 110 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 111 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 112 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 113 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 114 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 115 | |
| 116 | base::hash_set<std::string> urls = manifest.explicit_urls; |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 117 | const size_t kExpected = 5; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 118 | ASSERT_EQ(kExpected, urls.size()); |
| 119 | EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 120 | EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 121 | EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 122 | EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 123 | |
| 124 | // Wildcard is treated as a relative URL in explicit section. |
| 125 | EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 126 | |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 127 | // We should get the same results with dangerous features disallowed. |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 128 | manifest = AppCacheManifest(); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 129 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 130 | PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 131 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 132 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 133 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 134 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 135 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 136 | |
| 137 | urls = manifest.explicit_urls; |
| 138 | ASSERT_EQ(kExpected, urls.size()); |
| 139 | EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 140 | EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 141 | EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 142 | EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
| 143 | |
| 144 | // Wildcard is treated as a relative URL in explicit section. |
| 145 | EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 148 | TEST(AppCacheManifestParserTest, WhitelistUrls) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 149 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 150 | const GURL kUrl("http://www.bar.com"); |
| 151 | const std::string kData("CACHE MANIFEST\r" |
| 152 | "NETWORK:\r" |
| 153 | "relative/one\r" |
| 154 | "# a comment\r" |
| 155 | "http://www.bar.com/two\r" |
| 156 | "HTTP://www.diff.com/three#strip\n\r" |
| 157 | "FALLBACK:\r" |
| 158 | "garbage\r" |
| 159 | "UNKNOWN:\r" |
| 160 | "http://www.bar.com/ignore\r" |
| 161 | "CACHE:\r" |
| 162 | "NETWORK:\r" |
| 163 | "https://www.wrongscheme.com\n" |
| 164 | "relative/four#stripref \t \r" |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 165 | "http://www.five.com\r\n" |
| 166 | "*foo\r"); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 167 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 168 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 169 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 170 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 171 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 172 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 173 | EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 174 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 175 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 176 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 177 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 178 | const std::vector<AppCacheNamespace>& online = |
| 179 | manifest.online_whitelist_namespaces; |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 180 | const size_t kExpected = 6; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 181 | ASSERT_EQ(kExpected, online.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 182 | EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, online[0].type); |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 183 | EXPECT_FALSE(online[0].is_pattern); |
| 184 | EXPECT_TRUE(online[0].target_url.is_empty()); |
| 185 | EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0].namespace_url); |
| 186 | EXPECT_EQ(GURL("http://www.bar.com/two"), online[1].namespace_url); |
| 187 | EXPECT_EQ(GURL("http://www.diff.com/three"), online[2].namespace_url); |
| 188 | EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3].namespace_url); |
| 189 | EXPECT_EQ(GURL("http://www.five.com"), online[4].namespace_url); |
| 190 | EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 193 | TEST(AppCacheManifestParserTest, FallbackUrls) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 194 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 195 | const GURL kUrl("http://glorp.com"); |
| 196 | const std::string kData("CACHE MANIFEST\r" |
| 197 | "# a comment\r" |
| 198 | "CACHE:\r" |
| 199 | "NETWORK:\r" |
| 200 | "UNKNOWN:\r" |
| 201 | "FALLBACK:\r" |
| 202 | "relative/one \t \t http://glorp.com/onefb \t \r" |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 203 | "*\r" |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 204 | "https://glorp.com/wrong http://glorp.com/wrongfb\r" |
| 205 | "http://glorp.com/two#strip relative/twofb\r" |
| 206 | "HTTP://glorp.com/three relative/threefb#strip\n" |
| 207 | "http://glorp.com/three http://glorp.com/three-dup\r" |
| 208 | "http://glorp.com/solo \t \r\n" |
| 209 | "http://diff.com/ignore http://glorp.com/wronghost\r" |
| 210 | "http://glorp.com/wronghost http://diff.com/ohwell\r" |
| 211 | "relative/badscheme ftp://glorp.com/ignored\r" |
| 212 | "garbage\r\n" |
| 213 | "CACHE:\r" |
| 214 | "# only fallback urls in this test\r" |
| 215 | "FALLBACK:\n" |
| 216 | "relative/four#strip relative/fourfb#strip\r" |
| 217 | "http://www.glorp.com/notsame relative/skipped\r"); |
| 218 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 219 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 220 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 221 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 222 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 223 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 224 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 225 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 226 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 227 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 228 | const std::vector<AppCacheNamespace>& fallbacks = |
| 229 | manifest.fallback_namespaces; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 230 | const size_t kExpected = 5; |
| 231 | ASSERT_EQ(kExpected, fallbacks.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 232 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); |
| 233 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); |
| 234 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type); |
| 235 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[3].type); |
| 236 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[4].type); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 237 | EXPECT_EQ(GURL("http://glorp.com/relative/one"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 238 | fallbacks[0].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 239 | EXPECT_EQ(GURL("http://glorp.com/onefb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 240 | fallbacks[0].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 241 | EXPECT_EQ(GURL("http://glorp.com/two"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 242 | fallbacks[1].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 243 | EXPECT_EQ(GURL("http://glorp.com/relative/twofb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 244 | fallbacks[1].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 245 | EXPECT_EQ(GURL("http://glorp.com/three"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 246 | fallbacks[2].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 247 | EXPECT_EQ(GURL("http://glorp.com/relative/threefb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 248 | fallbacks[2].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 249 | EXPECT_EQ(GURL("http://glorp.com/three"), // duplicates are stored |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 250 | fallbacks[3].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 251 | EXPECT_EQ(GURL("http://glorp.com/three-dup"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 252 | fallbacks[3].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 253 | EXPECT_EQ(GURL("http://glorp.com/relative/four"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 254 | fallbacks[4].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 255 | EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 256 | fallbacks[4].target_url); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 257 | EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 258 | |
| 259 | // Nothing should be ignored since all namespaces are in scope. |
| 260 | manifest = AppCacheManifest(); |
| 261 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 262 | PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 263 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 264 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 267 | TEST(AppCacheManifestParserTest, FallbackUrlsWithPort) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 268 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 269 | const GURL kUrl("http://www.portme.com:1234"); |
| 270 | const std::string kData("CACHE MANIFEST\r" |
| 271 | "FALLBACK:\r" |
| 272 | "http://www.portme.com:1234/one relative/onefb\r" |
| 273 | "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" |
| 274 | "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" |
| 275 | "relative/two relative/twofb\r" |
| 276 | "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" |
| 277 | "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" |
| 278 | "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); |
| 279 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 280 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 281 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 282 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 283 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 284 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 285 | EXPECT_FALSE(manifest.online_whitelist_all); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 286 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 287 | const std::vector<AppCacheNamespace>& fallbacks = |
| 288 | manifest.fallback_namespaces; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 289 | const size_t kExpected = 3; |
| 290 | ASSERT_EQ(kExpected, fallbacks.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 291 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); |
| 292 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); |
| 293 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 294 | EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 295 | fallbacks[0].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 296 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 297 | fallbacks[0].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 298 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 299 | fallbacks[1].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 300 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 301 | fallbacks[1].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 302 | EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 303 | fallbacks[2].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 304 | EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 305 | fallbacks[2].target_url); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 306 | EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 307 | |
| 308 | // Nothing should be ignored since all namespaces are in scope. |
| 309 | manifest = AppCacheManifest(); |
| 310 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 311 | PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 312 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 313 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 314 | } |
| 315 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 316 | TEST(AppCacheManifestParserTest, InterceptUrls) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 317 | AppCacheManifest manifest; |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 318 | const GURL kUrl("http://www.portme.com:1234"); |
| 319 | const std::string kData("CHROMIUM CACHE MANIFEST\r" |
| 320 | "CHROMIUM-INTERCEPT:\r" |
| 321 | "http://www.portme.com:1234/one return relative/int1\r" |
| 322 | "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" |
| 323 | "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" |
| 324 | "relative/two return relative/int2\r" |
| 325 | "relative/three wrong relative/threefb\r" |
| 326 | "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" |
| 327 | "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" |
| 328 | "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" |
| 329 | "relative/wrong/again missing/intercept_type\r"); |
| 330 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 331 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 332 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 333 | manifest)); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 334 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 335 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 336 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 337 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 338 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 339 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 340 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 341 | const std::vector<AppCacheNamespace>& intercepts = |
| 342 | manifest.intercept_namespaces; |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 343 | const size_t kExpected = 3; |
| 344 | ASSERT_EQ(kExpected, intercepts.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 345 | EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[0].type); |
| 346 | EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[1].type); |
| 347 | EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[2].type); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 348 | EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
| 349 | intercepts[0].namespace_url); |
| 350 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"), |
| 351 | intercepts[0].target_url); |
| 352 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
| 353 | intercepts[1].namespace_url); |
| 354 | EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), |
| 355 | intercepts[1].target_url); |
| 356 | EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
| 357 | intercepts[2].namespace_url); |
| 358 | EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), |
| 359 | intercepts[2].target_url); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 360 | |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 361 | // Disallow intercepts this time. |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 362 | manifest = AppCacheManifest(); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 363 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 364 | PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 365 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 366 | EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 367 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 368 | EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 369 | EXPECT_FALSE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 370 | EXPECT_TRUE(manifest.did_ignore_intercept_namespaces); |
| 371 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | TEST(AppCacheManifestParserTest, ComboUrls) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 375 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 376 | const GURL kUrl("http://combo.com:42"); |
| 377 | const std::string kData("CACHE MANIFEST\r" |
| 378 | "relative/explicit-1\r" |
| 379 | "# some comment\r" |
| 380 | "http://combo.com:99/explicit-2#strip\r" |
| 381 | "NETWORK:\r" |
| 382 | "http://combo.com/whitelist-1\r" |
| 383 | "HTTP://www.diff.com/whitelist-2#strip\r" |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 384 | "*\r" |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 385 | "CACHE:\n\r" |
| 386 | "http://www.diff.com/explicit-3\r" |
| 387 | "FALLBACK:\r" |
| 388 | "http://combo.com:42/fallback-1 http://combo.com:42/fallback-1b\r" |
| 389 | "relative/fallback-2 relative/fallback-2b\r" |
| 390 | "UNKNOWN:\r\n" |
| 391 | "http://combo.com/ignoreme\r" |
| 392 | "relative/still-ignored\r" |
| 393 | "NETWORK:\r\n" |
| 394 | "relative/whitelist-3#strip\r" |
| 395 | "http://combo.com:99/whitelist-4\r"); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 396 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 397 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 398 | manifest)); |
[email protected] | b160d6d | 2009-08-10 23:58:18 | [diff] [blame] | 399 | EXPECT_TRUE(manifest.online_whitelist_all); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 400 | |
| 401 | base::hash_set<std::string> urls = manifest.explicit_urls; |
| 402 | size_t expected = 3; |
| 403 | ASSERT_EQ(expected, urls.size()); |
| 404 | EXPECT_TRUE(urls.find("http://combo.com:42/relative/explicit-1") != |
| 405 | urls.end()); |
| 406 | EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end()); |
| 407 | EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); |
| 408 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 409 | const std::vector<AppCacheNamespace>& online = |
| 410 | manifest.online_whitelist_namespaces; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 411 | expected = 4; |
| 412 | ASSERT_EQ(expected, online.size()); |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 413 | EXPECT_EQ(GURL("http://combo.com/whitelist-1"), |
| 414 | online[0].namespace_url); |
| 415 | EXPECT_EQ(GURL("http://www.diff.com/whitelist-2"), |
| 416 | online[1].namespace_url); |
| 417 | EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"), |
| 418 | online[2].namespace_url); |
| 419 | EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"), |
| 420 | online[3].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 421 | |
Victor Costan | 3a41274 | 2018-08-24 21:32:23 | [diff] [blame] | 422 | const std::vector<AppCacheNamespace>& fallbacks = |
| 423 | manifest.fallback_namespaces; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 424 | expected = 2; |
| 425 | ASSERT_EQ(expected, fallbacks.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 426 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); |
| 427 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 428 | EXPECT_EQ(GURL("http://combo.com:42/fallback-1"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 429 | fallbacks[0].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 430 | EXPECT_EQ(GURL("http://combo.com:42/fallback-1b"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 431 | fallbacks[0].target_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 432 | EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 433 | fallbacks[1].namespace_url); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 434 | EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2b"), |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 435 | fallbacks[1].target_url); |
| 436 | |
| 437 | EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 438 | } |
| 439 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 440 | TEST(AppCacheManifestParserTest, UnusualUtf8) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 441 | AppCacheManifest manifest; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 442 | const GURL kUrl("http://bad.com"); |
| 443 | const std::string kData("CACHE MANIFEST\r" |
| 444 | "\xC0" "invalidutf8\r" |
| 445 | "nonbmp" "\xF1\x84\xAB\xBC\r"); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 446 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 447 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 448 | manifest)); |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 449 | base::hash_set<std::string> urls = manifest.explicit_urls; |
Victor Costan | 92940c9 | 2018-09-01 02:39:20 | [diff] [blame] | 450 | EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()) |
| 451 | << "manifest byte stream was passed through, not UTF-8-decoded"; |
[email protected] | 9b26746e | 2009-08-06 21:35:45 | [diff] [blame] | 452 | EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); |
| 453 | } |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 454 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 455 | TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 456 | AppCacheManifest manifest; |
[email protected] | 578d748 | 2009-11-16 20:11:07 | [diff] [blame] | 457 | const GURL kUrl("http://smorg.borg"); |
| 458 | const std::string kData( |
| 459 | "CACHE MANIFEST\r" |
| 460 | "resource.txt this stuff after the white space should be ignored\r"); |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 461 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 462 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 463 | manifest)); |
[email protected] | 578d748 | 2009-11-16 20:11:07 | [diff] [blame] | 464 | |
| 465 | base::hash_set<std::string> urls = manifest.explicit_urls; |
| 466 | EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); |
| 467 | } |
| 468 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 469 | TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 470 | AppCacheManifest manifest; |
[email protected] | a51fb7a | 2010-03-30 23:52:47 | [diff] [blame] | 471 | const GURL kUrl("https://www.foo.com"); |
| 472 | const std::string kData("CACHE MANIFEST\r" |
| 473 | "CACHE: \r" |
| 474 | "relative/secureschemesameorigin\r" |
| 475 | "https://www.foo.com/secureschemesameorigin\r" |
| 476 | "http://www.xyz.com/secureschemedifforigin\r" |
| 477 | "https://www.xyz.com/secureschemedifforigin\r"); |
| 478 | |
[email protected] | b993171f | 2014-05-13 06:11:15 | [diff] [blame] | 479 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 480 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 481 | manifest)); |
[email protected] | a51fb7a | 2010-03-30 23:52:47 | [diff] [blame] | 482 | EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 483 | EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 484 | |
| 485 | base::hash_set<std::string> urls = manifest.explicit_urls; |
[email protected] | eb2ee14 | 2011-02-22 20:03:01 | [diff] [blame] | 486 | const size_t kExpected = 3; |
[email protected] | a51fb7a | 2010-03-30 23:52:47 | [diff] [blame] | 487 | ASSERT_EQ(kExpected, urls.size()); |
| 488 | EXPECT_TRUE(urls.find("https://www.foo.com/relative/secureschemesameorigin") |
| 489 | != urls.end()); |
| 490 | EXPECT_TRUE(urls.find("https://www.foo.com/secureschemesameorigin") != |
| 491 | urls.end()); |
| 492 | EXPECT_FALSE(urls.find("http://www.xyz.com/secureschemedifforigin") != |
| 493 | urls.end()); |
[email protected] | eb2ee14 | 2011-02-22 20:03:01 | [diff] [blame] | 494 | EXPECT_TRUE(urls.find("https://www.xyz.com/secureschemedifforigin") != |
[email protected] | a51fb7a | 2010-03-30 23:52:47 | [diff] [blame] | 495 | urls.end()); |
| 496 | } |
| 497 | |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 498 | TEST(AppCacheManifestParserTest, PatternMatching) { |
| 499 | const GURL kUrl("http://foo.com/manifest"); |
| 500 | const std::string kManifestBody( |
| 501 | "CACHE MANIFEST\r" |
| 502 | "CACHE: \r" |
| 503 | "http://foo.com/page.html\r" |
| 504 | "CHROMIUM-INTERCEPT:\r" |
| 505 | "http://foo.com/intercept_prefix return /prefix\r" |
| 506 | "http://foo.com/intercept_pattern return /pattern isPattern\r" |
| 507 | "http://foo.com/*/intercept_pattern?query return /pattern isPattern\r" |
| 508 | "FALLBACK:\r" |
| 509 | "http://foo.com/fallback_prefix /prefix wrongAnnotation\r" |
| 510 | "http://foo.com/fallback_pattern* /pattern\tisPattern \r" |
| 511 | "NETWORK:\r" |
| 512 | "*\r" |
| 513 | "isPattern\r" // should not be interpretted as a pattern |
| 514 | "http://foo.com/network_pattern* isPattern\r"); |
| 515 | |
| 516 | |
mlamouri | c923031 | 2014-09-09 05:36:43 | [diff] [blame] | 517 | AppCacheManifest manifest; |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 518 | EXPECT_TRUE(ParseManifest(kUrl, kManifestBody.c_str(), kManifestBody.length(), |
| 519 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 520 | manifest)); |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 521 | EXPECT_TRUE(manifest.online_whitelist_all); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 522 | EXPECT_FALSE(manifest.did_ignore_intercept_namespaces); |
| 523 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 524 | EXPECT_EQ(1u, manifest.explicit_urls.size()); |
| 525 | EXPECT_EQ(3u, manifest.intercept_namespaces.size()); |
| 526 | EXPECT_EQ(2u, manifest.fallback_namespaces.size()); |
| 527 | EXPECT_EQ(2u, manifest.online_whitelist_namespaces.size()); |
[email protected] | 10f110fa | 2014-06-15 23:32:46 | [diff] [blame] | 528 | EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, |
| 529 | manifest.intercept_namespaces[0].type); |
| 530 | EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, manifest.fallback_namespaces[0].type); |
| 531 | EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, |
| 532 | manifest.online_whitelist_namespaces[0].type); |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 533 | EXPECT_FALSE(manifest.intercept_namespaces[0].is_pattern); |
| 534 | EXPECT_TRUE(manifest.intercept_namespaces[1].is_pattern); |
| 535 | EXPECT_TRUE(manifest.intercept_namespaces[2].is_pattern); |
| 536 | EXPECT_FALSE(manifest.fallback_namespaces[0].is_pattern); |
| 537 | EXPECT_TRUE(manifest.fallback_namespaces[1].is_pattern); |
| 538 | EXPECT_FALSE(manifest.online_whitelist_namespaces[0].is_pattern); |
| 539 | EXPECT_TRUE(manifest.online_whitelist_namespaces[1].is_pattern); |
| 540 | EXPECT_EQ( |
| 541 | GURL("http://foo.com/*/intercept_pattern?query"), |
| 542 | manifest.intercept_namespaces[2].namespace_url); |
| 543 | EXPECT_EQ( |
| 544 | GURL("http://foo.com/pattern"), |
| 545 | manifest.intercept_namespaces[2].target_url); |
| 546 | EXPECT_EQ( |
| 547 | GURL("http://foo.com/fallback_pattern*"), |
| 548 | manifest.fallback_namespaces[1].namespace_url); |
| 549 | EXPECT_EQ( |
| 550 | GURL("http://foo.com/pattern"), |
| 551 | manifest.fallback_namespaces[1].target_url); |
| 552 | EXPECT_EQ( |
| 553 | GURL("http://foo.com/isPattern"), |
| 554 | manifest.online_whitelist_namespaces[0].namespace_url); |
| 555 | EXPECT_EQ( |
| 556 | GURL(), |
| 557 | manifest.online_whitelist_namespaces[0].target_url); |
| 558 | EXPECT_EQ( |
| 559 | GURL("http://foo.com/network_pattern*"), |
| 560 | manifest.online_whitelist_namespaces[1].namespace_url); |
| 561 | EXPECT_EQ( |
| 562 | GURL(), |
| 563 | manifest.online_whitelist_namespaces[1].target_url); |
| 564 | } |
| 565 | |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 566 | TEST(AppCacheManifestParserTest, IgnoreDangerousFallbacks) { |
| 567 | const GURL kUrl("http://foo.com/scope/manifest?with_query_args"); |
| 568 | const std::string kData( |
| 569 | "CACHE MANIFEST\r" |
| 570 | "FALLBACK:\r" |
| 571 | "http://foo.com/scope/ fallback_url\r" |
| 572 | "http://foo.com/out_of_scope/ fallback_url\r"); |
| 573 | |
| 574 | // Scope matching depends on resolving "." as a relative url. |
Giovanni Ortuño Urquidi | 61b24eda | 2017-08-09 08:13:10 | [diff] [blame] | 575 | EXPECT_EQ(kUrl.GetWithoutFilename().spec(), |
| 576 | std::string("http://foo.com/scope/")); |
michaeln | b4d77cd | 2017-06-08 20:42:52 | [diff] [blame] | 577 | |
| 578 | AppCacheManifest manifest; |
| 579 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 580 | PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, |
| 581 | manifest)); |
| 582 | EXPECT_FALSE(manifest.did_ignore_fallback_namespaces); |
| 583 | EXPECT_EQ(2u, manifest.fallback_namespaces.size()); |
| 584 | |
| 585 | manifest = AppCacheManifest(); |
| 586 | EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 587 | PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 588 | EXPECT_TRUE(manifest.did_ignore_fallback_namespaces); |
| 589 | EXPECT_EQ(1u, manifest.fallback_namespaces.size()); |
| 590 | EXPECT_EQ(GURL("http://foo.com/scope/"), |
| 591 | manifest.fallback_namespaces[0].namespace_url); |
| 592 | } |
| 593 | |
[email protected] | a507b82 | 2014-04-12 05:10:24 | [diff] [blame] | 594 | } // namespace content |