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

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

Issue 299253003: [webcrypto] Only allow crypto.subtle.* to be used from "secure origins". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 TEST(SecurityOriginTest, ValidPortsCreateNonUniqueOrigins) 53 TEST(SecurityOriginTest, ValidPortsCreateNonUniqueOrigins)
54 { 54 {
55 int ports[] = { 0, 80, 443, 5000, MaxAllowedPort }; 55 int ports[] = { 0, 80, 443, 5000, MaxAllowedPort };
56 56
57 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ports); ++i) { 57 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ports); ++i) {
58 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", "example. com", ports[i]); 58 RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", "example. com", ports[i]);
59 EXPECT_FALSE(origin->isUnique()) << "Port " << ports[i] << " should not have generated a unique origin."; 59 EXPECT_FALSE(origin->isUnique()) << "Port " << ports[i] << " should not have generated a unique origin.";
60 } 60 }
61 } 61 }
62 62
63 TEST(SecurityOriginTest, CanAccessFeatureRequringSecureOrigin)
64 {
65 struct TestCase {
66 bool accessGranted;
67 const char* url;
68 };
69
70 TestCase inputs[] = {
71 // Access is granted to webservers running on localhost.
72 { true, "http://localhost" },
73 { true, "http://localhost:100" },
74 { true, "http://127.0.0.1" },
75 { true, "http://[::1]" },
76 { true, "http://[::1]:80" },
77 { true, "http://127.0.0.1:80" },
palmer 2014/05/24 01:44:30 Maybe throw in a few more non-standard ports just
eroman 2014/05/24 02:08:57 Done. Expanded on the tests: * Added ftp://local
78 { true, "ws://127.0.0.1" },
79
80 // Access is granted to all secure transports.
81 { true, "https://foobar.com" },
82 { true, "wss://foobar.com" },
83
84 // Access is denied to insecure transports.
85 { false, "ftp://foobar.com" },
86 { false, "http://foobar.com" },
87 { false, "ws://foobar.com" },
88 { false, "data:text/html;charset=utf-8;base64,PHNjcmlwdD5hbGVydCgnaGkhJy k8L3NjcmlwdD4=" },
89 { false, "javascript:alert('hi')" },
90
91 // Access is granted to local files
92 { true, "file:///home/foobar/index.html" },
93 };
94
95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(inputs); ++i) {
96 SCOPED_TRACE(i);
97 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(inputs[ i].url);
98 EXPECT_EQ(inputs[i].accessGranted, origin->canAccessFeatureRequiringSecu reOrigin());
99 }
100
101 // Unique origins are not considered secure.
102 RefPtr<SecurityOrigin> uniqueOrigin = SecurityOrigin::createUnique();
103 EXPECT_FALSE(uniqueOrigin->canAccessFeatureRequiringSecureOrigin());
104 }
105
63 } // namespace 106 } // namespace
64 107
OLDNEW
« Source/platform/weborigin/SecurityOrigin.cpp ('K') | « Source/platform/weborigin/SecurityOrigin.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698