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

Side by Side Diff: Source/platform/weborigin/SecurityOriginTest.cpp

Issue 1180923003: Add window access checks for Suborigins (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 origin->buildRawString(builder); 222 origin->buildRawString(builder);
223 EXPECT_EQ("https://foobar_test.com", builder.toString()); 223 EXPECT_EQ("https://foobar_test.com", builder.toString());
224 224
225 builder.clear(); 225 builder.clear();
226 origin = SecurityOrigin::createFromString("https://test.com"); 226 origin = SecurityOrigin::createFromString("https://test.com");
227 origin->addSuborigin("foobar"); 227 origin->addSuborigin("foobar");
228 origin->buildRawString(builder); 228 origin->buildRawString(builder);
229 EXPECT_EQ("https://foobar_test.com", builder.toString()); 229 EXPECT_EQ("https://foobar_test.com", builder.toString());
230 } 230 }
231 231
232 TEST_F(SecurityOriginTest, SuboriginsIsSameSchemeHostPortAndSuborigin)
233 {
234 blink::RuntimeEnabledFeatures::setSuboriginsEnabled(true);
235 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("https://fo obar_test.com");
236 RefPtr<SecurityOrigin> other1 = SecurityOrigin::createFromString("https://ba zbar_test.com");
237 RefPtr<SecurityOrigin> other2 = SecurityOrigin::createFromString("http://foo bar_test.com");
238 RefPtr<SecurityOrigin> other3 = SecurityOrigin::createFromString("https://fo obar_test.com:1234");
239 RefPtr<SecurityOrigin> other4 = SecurityOrigin::createFromString("https://te st.com");
240
241 EXPECT_TRUE(origin->isSameSchemeHostPortAndSuborigin(origin.get()));
242 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other1.get()));
243 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other2.get()));
244 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other3.get()));
245 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other4.get()));
246 }
247
248 TEST_F(SecurityOriginTest, CanAccess)
249 {
250 struct TestCase {
251 bool canAccess;
252 bool canAccessCheckSuborigins;
253 const char* origin1;
254 const char* origin2;
255 };
256
257 TestCase tests[] = {
258 { true, true, "https://foobar.com", "https://foobar.com" },
259 { false, false, "https://foobar.com", "https://bazbar.com" },
260 { true, false, "https://foobar.com", "https://name_foobar.com" },
261 { true, false, "https://name_foobar.com", "https://foobar.com" },
262 { true, true, "https://name_foobar.com", "https://name_foobar.com" },
263 };
264
265 for (size_t i = 0; i < arraysize(tests); ++i) {
266 RefPtr<SecurityOrigin> origin1 = SecurityOrigin::createFromString(tests[ i].origin1);
267 RefPtr<SecurityOrigin> origin2 = SecurityOrigin::createFromString(tests[ i].origin2);
268 EXPECT_EQ(tests[i].canAccess, origin1->canAccess(origin2.get()));
269 EXPECT_EQ(tests[i].canAccessCheckSuborigins, origin1->canAccessCheckSubo rigins(origin2.get()));
270 }
271 }
272
273 TEST_F(SecurityOriginTest, CanRequests)
274 {
275 struct TestCase {
276 bool canRequest;
277 bool canRequestNoSuborigin;
278 const char* origin;
279 const char* url;
280 };
281
282 TestCase tests[] = {
283 { true, true, "https://foobar.com", "https://foobar.com" },
284 { false, false, "https://foobar.com", "https://bazbar.com" },
285 { true, false, "https://name_foobar.com", "https://foobar.com" },
286 { false, false, "https://name_foobar.com", "https://bazbar.com" },
287 };
288
289 for (size_t i = 0; i < arraysize(tests); ++i) {
290 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(tests[i ].origin);
291 blink::KURL url(blink::ParsedURLString, tests[i].url);
292 EXPECT_EQ(tests[i].canRequest, origin->canRequest(url));
293 EXPECT_EQ(tests[i].canRequestNoSuborigin, origin->canRequestNoSuborigin( url));
294 }
295 }
296
232 } // namespace 297 } // namespace
OLDNEW
« Source/platform/weborigin/SecurityOrigin.h ('K') | « Source/platform/weborigin/SecurityOriginHash.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698