| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/weborigin/OriginAccessEntry.h" | 32 #include "platform/weborigin/OriginAccessEntry.h" |
| 33 | 33 |
| 34 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
| 35 #include "platform/weborigin/SecurityOrigin.h" | 35 #include "platform/weborigin/SecurityOrigin.h" |
| 36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "public/platform/WebPublicSuffixList.h" | 37 #include "public/platform/WebPublicSuffixList.h" |
| 38 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> |
| 39 | 39 |
| 40 using blink::SecurityOrigin; | 40 namespace blink { |
| 41 using blink::OriginAccessEntry; | |
| 42 | |
| 43 namespace { | |
| 44 | 41 |
| 45 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { | 42 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { |
| 46 public: | 43 public: |
| 47 virtual size_t getPublicSuffixLength(const blink::WebString&) | 44 size_t getPublicSuffixLength(const blink::WebString&) override |
| 48 { | 45 { |
| 49 return m_length; | 46 return m_length; |
| 50 } | 47 } |
| 51 | 48 |
| 52 void setPublicSuffix(const blink::WebString& suffix) | 49 void setPublicSuffix(const blink::WebString& suffix) |
| 53 { | 50 { |
| 54 m_length = suffix.length(); | 51 m_length = suffix.length(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 private: | 54 private: |
| 58 size_t m_length; | 55 size_t m_length; |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 class OriginAccessEntryTestPlatform : public blink::Platform { | 58 class OriginAccessEntryTestPlatform : public blink::Platform { |
| 62 public: | 59 public: |
| 63 virtual blink::WebPublicSuffixList* publicSuffixList() | 60 blink::WebPublicSuffixList* publicSuffixList() override |
| 64 { | 61 { |
| 65 return &m_suffixList; | 62 return &m_suffixList; |
| 66 } | 63 } |
| 67 | 64 |
| 68 // Stub for pure virtual method. | 65 // Stub for pure virtual method. |
| 69 virtual void cryptographicallyRandomValues(unsigned char*, size_t) { ASSERT_
NOT_REACHED(); } | 66 void cryptographicallyRandomValues(unsigned char*, size_t) override { ASSERT
_NOT_REACHED(); } |
| 70 | 67 |
| 71 void setPublicSuffix(const blink::WebString& suffix) | 68 void setPublicSuffix(const blink::WebString& suffix) |
| 72 { | 69 { |
| 73 m_suffixList.setPublicSuffix(suffix); | 70 m_suffixList.setPublicSuffix(suffix); |
| 74 } | 71 } |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 OriginAccessEntryTestSuffixList m_suffixList; | 74 OriginAccessEntryTestSuffixList m_suffixList; |
| 78 }; | 75 }; |
| 79 | 76 |
| 80 TEST(OriginAccessEntryTest, PublicSuffixListTest) | 77 TEST(OriginAccessEntryTest, PublicSuffixListTest) |
| 81 { | 78 { |
| 82 OriginAccessEntryTestPlatform platform; | 79 OriginAccessEntryTestPlatform platform; |
| 83 platform.setPublicSuffix("com"); | 80 platform.setPublicSuffix("com"); |
| 84 blink::Platform::initialize(&platform); | 81 Platform::initialize(&platform); |
| 85 | 82 |
| 86 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www
.google.com"); | 83 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www
.google.com"); |
| 87 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo
mains); | 84 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo
mains); |
| 88 OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubd
omains); | 85 OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubd
omains); |
| 89 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains); | 86 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains); |
| 90 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); | 87 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); |
| 91 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi
n)); | 88 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi
n)); |
| 92 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO
rigin(*origin)); | 89 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO
rigin(*origin)); |
| 93 | 90 |
| 94 blink::Platform::shutdown(); | 91 Platform::shutdown(); |
| 95 } | 92 } |
| 96 | 93 |
| 97 TEST(OriginAccessEntryTest, AllowSubdomainsTest) | 94 TEST(OriginAccessEntryTest, AllowSubdomainsTest) |
| 98 { | 95 { |
| 99 struct TestCase { | 96 struct TestCase { |
| 100 const char* protocol; | 97 const char* protocol; |
| 101 const char* host; | 98 const char* host; |
| 102 const char* origin; | 99 const char* origin; |
| 103 OriginAccessEntry::MatchResult expected; | 100 OriginAccessEntry::MatchResult expected; |
| 104 } inputs[] = { | 101 } inputs[] = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, | 112 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, |
| 116 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, | 113 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, |
| 117 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, | 114 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, |
| 118 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, | 115 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, |
| 119 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, | 116 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, |
| 120 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, | 117 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, |
| 121 }; | 118 }; |
| 122 | 119 |
| 123 OriginAccessEntryTestPlatform platform; | 120 OriginAccessEntryTestPlatform platform; |
| 124 platform.setPublicSuffix("com"); | 121 platform.setPublicSuffix("com"); |
| 125 blink::Platform::initialize(&platform); | 122 Platform::initialize(&platform); |
| 126 | 123 |
| 127 for (const auto& test : inputs) { | 124 for (const auto& test : inputs) { |
| 128 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); | 125 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); |
| 129 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 126 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
| 130 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); | 127 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); |
| 131 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 128 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 132 } | 129 } |
| 133 | 130 |
| 134 blink::Platform::shutdown(); | 131 Platform::shutdown(); |
| 135 } | 132 } |
| 136 | 133 |
| 137 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest) | 134 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest) |
| 138 { | 135 { |
| 139 struct TestCase { | 136 struct TestCase { |
| 140 const char* protocol; | 137 const char* protocol; |
| 141 const char* host; | 138 const char* host; |
| 142 const char* origin; | 139 const char* origin; |
| 143 OriginAccessEntry::MatchResult expected; | 140 OriginAccessEntry::MatchResult expected; |
| 144 } inputs[] = { | 141 } inputs[] = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 155 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, | 152 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, |
| 156 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, | 153 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, |
| 157 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, | 154 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, |
| 158 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, | 155 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, |
| 159 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, | 156 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, |
| 160 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, | 157 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, |
| 161 }; | 158 }; |
| 162 | 159 |
| 163 OriginAccessEntryTestPlatform platform; | 160 OriginAccessEntryTestPlatform platform; |
| 164 platform.setPublicSuffix("com"); | 161 platform.setPublicSuffix("com"); |
| 165 blink::Platform::initialize(&platform); | 162 Platform::initialize(&platform); |
| 166 | 163 |
| 167 for (const auto& test : inputs) { | 164 for (const auto& test : inputs) { |
| 168 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 165 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
| 169 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowRegisterableDomains); | 166 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowRegisterableDomains); |
| 170 | 167 |
| 171 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin << ", Domain: " << entry1.registerable().utf8().data()); | 168 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin << ", Domain: " << entry1.registerable().utf8().data()); |
| 172 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 169 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 173 } | 170 } |
| 174 | 171 |
| 175 blink::Platform::shutdown(); | 172 Platform::shutdown(); |
| 176 } | 173 } |
| 177 | 174 |
| 178 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTestWithDottedSuffix) | 175 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTestWithDottedSuffix) |
| 179 { | 176 { |
| 180 struct TestCase { | 177 struct TestCase { |
| 181 const char* protocol; | 178 const char* protocol; |
| 182 const char* host; | 179 const char* host; |
| 183 const char* origin; | 180 const char* origin; |
| 184 OriginAccessEntry::MatchResult expected; | 181 OriginAccessEntry::MatchResult expected; |
| 185 } inputs[] = { | 182 } inputs[] = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 { "https", "example.appspot.com", "http://www.example.appspot.com/", Ori
ginAccessEntry::DoesNotMatchOrigin }, | 193 { "https", "example.appspot.com", "http://www.example.appspot.com/", Ori
ginAccessEntry::DoesNotMatchOrigin }, |
| 197 { "https", "example.appspot.com", "http://www.www.example.appspot.com/",
OriginAccessEntry::DoesNotMatchOrigin }, | 194 { "https", "example.appspot.com", "http://www.www.example.appspot.com/",
OriginAccessEntry::DoesNotMatchOrigin }, |
| 198 { "http", "example.appspot.com", "http://beispiel.de/", OriginAccessEntr
y::DoesNotMatchOrigin }, | 195 { "http", "example.appspot.com", "http://beispiel.de/", OriginAccessEntr
y::DoesNotMatchOrigin }, |
| 199 { "http", "", "http://example.appspot.com/", OriginAccessEntry::MatchesO
rigin }, | 196 { "http", "", "http://example.appspot.com/", OriginAccessEntry::MatchesO
rigin }, |
| 200 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, | 197 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, |
| 201 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, | 198 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, |
| 202 }; | 199 }; |
| 203 | 200 |
| 204 OriginAccessEntryTestPlatform platform; | 201 OriginAccessEntryTestPlatform platform; |
| 205 platform.setPublicSuffix("appspot.com"); | 202 platform.setPublicSuffix("appspot.com"); |
| 206 blink::Platform::initialize(&platform); | 203 Platform::initialize(&platform); |
| 207 | 204 |
| 208 for (const auto& test : inputs) { | 205 for (const auto& test : inputs) { |
| 209 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 206 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
| 210 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowRegisterableDomains); | 207 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowRegisterableDomains); |
| 211 | 208 |
| 212 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin << ", Domain: " << entry1.registerable().utf8().data()); | 209 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin << ", Domain: " << entry1.registerable().utf8().data()); |
| 213 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 210 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 214 } | 211 } |
| 215 | 212 |
| 216 blink::Platform::shutdown(); | 213 Platform::shutdown(); |
| 217 } | 214 } |
| 218 | 215 |
| 219 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) | 216 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) |
| 220 { | 217 { |
| 221 struct TestCase { | 218 struct TestCase { |
| 222 const char* protocol; | 219 const char* protocol; |
| 223 const char* host; | 220 const char* host; |
| 224 const char* origin; | 221 const char* origin; |
| 225 OriginAccessEntry::MatchResult expected; | 222 OriginAccessEntry::MatchResult expected; |
| 226 } inputs[] = { | 223 } inputs[] = { |
| 227 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match
esOrigin }, | 224 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match
esOrigin }, |
| 228 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::D
oesNotMatchOrigin }, | 225 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::D
oesNotMatchOrigin }, |
| 229 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr
y::DoesNotMatchOrigin }, | 226 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr
y::DoesNotMatchOrigin }, |
| 230 { "http", "com", "http://example.com/", OriginAccessEntry::DoesNotMatchO
rigin }, | 227 { "http", "com", "http://example.com/", OriginAccessEntry::DoesNotMatchO
rigin }, |
| 231 { "http", "com", "http://www.example.com/", OriginAccessEntry::DoesNotMa
tchOrigin }, | 228 { "http", "com", "http://www.example.com/", OriginAccessEntry::DoesNotMa
tchOrigin }, |
| 232 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::DoesN
otMatchOrigin }, | 229 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::DoesN
otMatchOrigin }, |
| 233 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does
NotMatchOrigin }, | 230 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does
NotMatchOrigin }, |
| 234 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, | 231 { "https", "example.com", "http://www.example.com/", OriginAccessEntry::
DoesNotMatchOrigin }, |
| 235 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, | 232 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt
ry::DoesNotMatchOrigin }, |
| 236 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, | 233 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN
otMatchOrigin }, |
| 237 { "http", "", "http://example.com/", OriginAccessEntry::DoesNotMatchOrig
in }, | 234 { "http", "", "http://example.com/", OriginAccessEntry::DoesNotMatchOrig
in }, |
| 238 { "http", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOrig
in }, | 235 { "http", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOrig
in }, |
| 239 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, | 236 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri
gin }, |
| 240 }; | 237 }; |
| 241 | 238 |
| 242 OriginAccessEntryTestPlatform platform; | 239 OriginAccessEntryTestPlatform platform; |
| 243 platform.setPublicSuffix("com"); | 240 platform.setPublicSuffix("com"); |
| 244 blink::Platform::initialize(&platform); | 241 Platform::initialize(&platform); |
| 245 | 242 |
| 246 for (const auto& test : inputs) { | 243 for (const auto& test : inputs) { |
| 247 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); | 244 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); |
| 248 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 245 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
| 249 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); | 246 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); |
| 250 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 247 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 251 } | 248 } |
| 252 | 249 |
| 253 blink::Platform::shutdown(); | 250 Platform::shutdown(); |
| 254 } | 251 } |
| 255 | 252 |
| 256 TEST(OriginAccessEntryTest, IPAddressTest) | 253 TEST(OriginAccessEntryTest, IPAddressTest) |
| 257 { | 254 { |
| 258 struct TestCase { | 255 struct TestCase { |
| 259 const char* protocol; | 256 const char* protocol; |
| 260 const char* host; | 257 const char* host; |
| 261 bool isIPAddress; | 258 bool isIPAddress; |
| 262 } inputs[] = { | 259 } inputs[] = { |
| 263 { "http", "1.1.1.1", true }, | 260 { "http", "1.1.1.1", true }, |
| 264 { "http", "1.1.1.1.1", false }, | 261 { "http", "1.1.1.1.1", false }, |
| 265 { "http", "example.com", false }, | 262 { "http", "example.com", false }, |
| 266 { "http", "hostname.that.ends.with.a.number1", false }, | 263 { "http", "hostname.that.ends.with.a.number1", false }, |
| 267 { "http", "2001:db8::1", false }, | 264 { "http", "2001:db8::1", false }, |
| 268 { "http", "[2001:db8::1]", true }, | 265 { "http", "[2001:db8::1]", true }, |
| 269 { "http", "2001:db8::a", false }, | 266 { "http", "2001:db8::a", false }, |
| 270 { "http", "[2001:db8::a]", true }, | 267 { "http", "[2001:db8::a]", true }, |
| 271 { "http", "", false }, | 268 { "http", "", false }, |
| 272 }; | 269 }; |
| 273 | 270 |
| 274 OriginAccessEntryTestPlatform platform; | 271 OriginAccessEntryTestPlatform platform; |
| 275 platform.setPublicSuffix("com"); | 272 platform.setPublicSuffix("com"); |
| 276 blink::Platform::initialize(&platform); | 273 Platform::initialize(&platform); |
| 277 | 274 |
| 278 for (const auto& test : inputs) { | 275 for (const auto& test : inputs) { |
| 279 SCOPED_TRACE(testing::Message() << "Host: " << test.host); | 276 SCOPED_TRACE(testing::Message() << "Host: " << test.host); |
| 280 OriginAccessEntry entry(test.protocol, test.host, OriginAccessEntry::Dis
allowSubdomains); | 277 OriginAccessEntry entry(test.protocol, test.host, OriginAccessEntry::Dis
allowSubdomains); |
| 281 EXPECT_EQ(test.isIPAddress, entry.hostIsIPAddress()) << test.host; | 278 EXPECT_EQ(test.isIPAddress, entry.hostIsIPAddress()) << test.host; |
| 282 } | 279 } |
| 283 | 280 |
| 284 blink::Platform::shutdown(); | 281 Platform::shutdown(); |
| 285 } | 282 } |
| 286 | 283 |
| 287 TEST(OriginAccessEntryTest, IPAddressMatchingTest) | 284 TEST(OriginAccessEntryTest, IPAddressMatchingTest) |
| 288 { | 285 { |
| 289 struct TestCase { | 286 struct TestCase { |
| 290 const char* protocol; | 287 const char* protocol; |
| 291 const char* host; | 288 const char* host; |
| 292 const char* origin; | 289 const char* origin; |
| 293 OriginAccessEntry::MatchResult expected; | 290 OriginAccessEntry::MatchResult expected; |
| 294 } inputs[] = { | 291 } inputs[] = { |
| 295 { "http", "192.0.0.123", "http://192.0.0.123/", OriginAccessEntry::Match
esOrigin }, | 292 { "http", "192.0.0.123", "http://192.0.0.123/", OriginAccessEntry::Match
esOrigin }, |
| 296 { "http", "0.0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMa
tchOrigin }, | 293 { "http", "0.0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMa
tchOrigin }, |
| 297 { "http", "0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc
hOrigin }, | 294 { "http", "0.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc
hOrigin }, |
| 298 { "http", "1.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc
hOrigin }, | 295 { "http", "1.123", "http://192.0.0.123/", OriginAccessEntry::DoesNotMatc
hOrigin }, |
| 299 }; | 296 }; |
| 300 | 297 |
| 301 OriginAccessEntryTestPlatform platform; | 298 OriginAccessEntryTestPlatform platform; |
| 302 platform.setPublicSuffix("com"); | 299 platform.setPublicSuffix("com"); |
| 303 blink::Platform::initialize(&platform); | 300 Platform::initialize(&platform); |
| 304 | 301 |
| 305 for (const auto& test : inputs) { | 302 for (const auto& test : inputs) { |
| 306 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); | 303 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: "
<< test.origin); |
| 307 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 304 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
| 308 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); | 305 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); |
| 309 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 306 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 310 | 307 |
| 311 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); | 308 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); |
| 312 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); | 309 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); |
| 313 } | 310 } |
| 314 | 311 |
| 315 blink::Platform::shutdown(); | 312 Platform::shutdown(); |
| 316 } | 313 } |
| 317 | 314 |
| 318 } // namespace | 315 } // namespace blink |
| 319 | 316 |
| OLD | NEW |