Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo mains, OriginAccessEntry::TreatIPAddressAsIPAddress); | 73 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo mains, OriginAccessEntry::TreatIPAddressAsIPAddress); |
| 74 OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubd omains, OriginAccessEntry::TreatIPAddressAsIPAddress); | 74 OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubd omains, OriginAccessEntry::TreatIPAddressAsIPAddress); |
| 75 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); | 75 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); |
| 76 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); | 76 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); |
| 77 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi n)); | 77 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi n)); |
| 78 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO rigin(*origin)); | 78 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO rigin(*origin)); |
| 79 | 79 |
| 80 blink::Platform::shutdown(); | 80 blink::Platform::shutdown(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST(OriginAccessEntryTest, AllowSubdomainsTest) | |
| 84 { | |
| 85 struct TestCase { | |
| 86 const char* protocol; | |
| 87 const char* host; | |
| 88 const char* origin; | |
| 89 OriginAccessEntry::MatchResult expected; | |
| 90 } inputs[] = { | |
| 91 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin }, | |
| 92 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin }, | |
| 93 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin }, | |
| 94 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix }, | |
| 95 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix }, | |
| 96 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix }, | |
| 97 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin }, | |
| 98 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin }, | |
| 99 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin }, | |
| 100 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin }, | |
| 101 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, | |
| 102 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, | |
| 103 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin }, | |
| 104 }; | |
| 105 | |
| 106 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc). | |
| 107 OriginAccessEntryTestPlatform platform; | |
| 108 blink::Platform::initialize(&platform); | |
| 109 | |
| 110 for (auto test : inputs) { | |
|
Ryan Sleevi
2015/05/13 23:23:34
SCOPED_TRACE(test) ? (assuming Test had a PrintTo,
Ryan Sleevi
2015/05/13 23:23:34
s/auto/const auto&/
| |
| 111 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); | |
| 112 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); | |
| 113 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | |
| 114 | |
| 115 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains, OriginAccessEntry::TreatIPAddressAsDomain); | |
| 116 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); | |
| 117 } | |
| 118 | |
| 119 blink::Platform::shutdown(); | |
| 120 } | |
| 121 | |
| 122 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) | |
| 123 { | |
| 124 struct TestCase { | |
| 125 const char* protocol; | |
| 126 const char* host; | |
| 127 const char* origin; | |
| 128 OriginAccessEntry::MatchResult expected; | |
| 129 } inputs[] = { | |
| 130 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin }, | |
| 131 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::D oesNotMatchOrigin }, | |
| 132 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::DoesNotMatchOrigin }, | |
| 133 { "http", "com", "http://example.com/", OriginAccessEntry::DoesNotMatchO rigin }, | |
| 134 { "http", "com", "http://www.example.com/", OriginAccessEntry::DoesNotMa tchOrigin }, | |
| 135 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::DoesN otMatchOrigin }, | |
| 136 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin }, | |
| 137 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin }, | |
| 138 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin }, | |
| 139 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin }, | |
| 140 { "http", "", "http://example.com/", OriginAccessEntry::DoesNotMatchOrig in }, | |
| 141 { "http", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOrig in }, | |
| 142 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin }, | |
| 143 }; | |
| 144 | |
| 145 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc). | |
| 146 OriginAccessEntryTestPlatform platform; | |
| 147 blink::Platform::initialize(&platform); | |
| 148 | |
| 149 for (auto test : inputs) { | |
|
Ryan Sleevi
2015/05/13 23:23:34
const auto&
| |
| 150 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); | |
| 151 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); | |
| 152 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | |
| 153 | |
| 154 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains, OriginAccessEntry::TreatIPAddressAsDomain); | |
| 155 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); | |
| 156 } | |
| 157 | |
| 158 blink::Platform::shutdown(); | |
| 159 } | |
| 160 | |
| 161 TEST(OriginAccessEntryTest, IPAddressTest) | |
| 162 { | |
| 163 struct TestCase { | |
| 164 const char* protocol; | |
| 165 const char* host; | |
| 166 bool isIPAddress; | |
| 167 } inputs[] = { | |
| 168 { "http", "1.1.1.1", true }, | |
| 169 { "http", "1.1.1.1.1", false }, | |
| 170 { "http", "example.com", false }, | |
| 171 { "http", "hostname.that.ends.with.a.number1", false }, | |
| 172 { "http", "2001:db8::1", false }, | |
| 173 { "http", "[2001:db8::1]", true }, | |
| 174 { "http", "2001:db8::a", false }, | |
| 175 { "http", "[2001:db8::a]", true }, | |
| 176 { "http", "", false }, | |
| 177 }; | |
| 178 | |
| 179 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc). | |
| 180 OriginAccessEntryTestPlatform platform; | |
| 181 blink::Platform::initialize(&platform); | |
| 182 | |
| 183 for (auto test : inputs) { | |
|
Ryan Sleevi
2015/05/13 23:23:34
const auto&
| |
| 184 OriginAccessEntry entry(test.protocol, test.host, OriginAccessEntry::Dis allowSubdomains, OriginAccessEntry::TreatIPAddressAsDomain); | |
| 185 EXPECT_EQ(test.isIPAddress, entry.hostIsIPAddress()) << test.host; | |
| 186 } | |
| 187 | |
| 188 blink::Platform::shutdown(); | |
| 189 } | |
| 190 | |
| 191 TEST(OriginAccessEntryTest, IPAddressAsDomainTest) | |
| 192 { | |
| 193 struct TestCase { | |
| 194 const char* protocol; | |
| 195 const char* host; | |
| 196 const char* origin; | |
| 197 OriginAccessEntry::MatchResult expected; | |
| 198 } inputs[] = { | |
| 199 { "http", "192.0.0.123", "http://192.0.0.123/", OriginAccessEntry::Match esOrigin }, | |
| 200 { "http", "0.0.123", "http://192.0.0.123/", OriginAccessEntry::MatchesOr igin }, | |
| 201 { "http", "0.123", "http://192.0.0.123/", OriginAccessEntry::MatchesOrig in }, | |
| 202 { "http", "1.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc hOrigin }, | |
| 203 }; | |
| 204 | |
| 205 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('. 123', etc). | |
| 206 OriginAccessEntryTestPlatform platform; | |
| 207 blink::Platform::initialize(&platform); | |
| 208 | |
| 209 for (auto test : inputs) { | |
| 210 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); | |
| 211 OriginAccessEntry entry(test.protocol, test.host, OriginAccessEntry::All owSubdomains, OriginAccessEntry::TreatIPAddressAsDomain); | |
| 212 EXPECT_EQ(test.expected, entry.matchesOrigin(*originToTest)); | |
| 213 } | |
| 214 | |
| 215 blink::Platform::shutdown(); | |
| 216 } | |
| 217 | |
| 218 TEST(OriginAccessEntryTest, IPAddressAsIPAddressTest) | |
| 219 { | |
| 220 struct TestCase { | |
| 221 const char* protocol; | |
| 222 const char* host; | |
| 223 const char* origin; | |
| 224 OriginAccessEntry::MatchResult expected; | |
| 225 } inputs[] = { | |
| 226 { "http", "192.0.0.123", "http://192.0.0.123/", OriginAccessEntry::Match esOrigin }, | |
| 227 { "http", "0.0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMa tchOrigin }, | |
| 228 { "http", "0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc hOrigin }, | |
| 229 { "http", "1.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc hOrigin }, | |
| 230 }; | |
| 231 | |
| 232 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('. 123', etc). | |
| 233 OriginAccessEntryTestPlatform platform; | |
| 234 blink::Platform::initialize(&platform); | |
| 235 | |
| 236 for (auto test : inputs) { | |
| 237 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); | |
| 238 OriginAccessEntry entry(test.protocol, test.host, OriginAccessEntry::All owSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); | |
| 239 EXPECT_EQ(test.expected, entry.matchesOrigin(*originToTest)); | |
| 240 } | |
| 241 | |
| 242 blink::Platform::shutdown(); | |
| 243 } | |
| 83 } // namespace | 244 } // namespace |
| 84 | 245 |
| OLD | NEW |