OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/test/scoped_command_line.h" | 6 #include "base/test/scoped_command_line.h" |
7 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
8 #include "content/public/common/origin_util.h" | 8 #include "content/public/common/origin_util.h" |
| 9 #include "content/public/test/test_utils.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
11 | 12 |
12 using content::IsOriginSecure; | 13 using content::IsOriginSecure; |
13 | 14 |
14 namespace chrome { | 15 namespace chrome { |
15 | 16 |
16 class SecureOriginWhiteListTest : public testing::Test { | 17 class SecureOriginWhiteListTest : public testing::Test { |
17 void TearDown() override { | 18 void TearDown() override { |
18 // Ensure that we reset the whitelisted origins without any flags applied. | 19 // Ensure that we reset the whitelisted origins without any flags applied. |
19 content::ResetSchemesAndOriginsWhitelistForTesting(); | 20 content::ResetSchemesAndOriginsWhitelist(); |
20 }; | 21 }; |
21 }; | 22 }; |
22 | 23 |
23 TEST_F(SecureOriginWhiteListTest, UnsafelyTreatInsecureOriginAsSecure) { | 24 TEST_F(SecureOriginWhiteListTest, UnsafelyTreatInsecureOriginAsSecure) { |
24 EXPECT_FALSE(content::IsOriginSecure(GURL("http://example.com/a.html"))); | 25 EXPECT_FALSE(content::IsOriginSecure(GURL("http://example.com/a.html"))); |
25 EXPECT_FALSE( | 26 EXPECT_FALSE( |
26 content::IsOriginSecure(GURL("http://127.example.com/a.html"))); | 27 content::IsOriginSecure(GURL("http://127.example.com/a.html"))); |
27 // Add http://example.com and http://127.example.com to whitelist by | 28 // Add http://example.com and http://127.example.com to whitelist by |
28 // command-line and see if they are now considered secure origins. | 29 // command-line and see if they are now considered secure origins. |
29 // (The command line is applied via | 30 // (The command line is applied via |
30 // ChromeContentClient::AddSecureSchemesAndOrigins) | 31 // ChromeContentClient::AddSecureSchemesAndOrigins) |
31 base::test::ScopedCommandLine scoped_command_line; | 32 base::test::ScopedCommandLine scoped_command_line; |
32 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); | 33 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
33 command_line->AppendSwitchASCII( | 34 command_line->AppendSwitchASCII( |
34 switches::kUnsafelyTreatInsecureOriginAsSecure, | 35 switches::kUnsafelyTreatInsecureOriginAsSecure, |
35 "http://example.com,http://127.example.com"); | 36 "http://example.com,http://127.example.com"); |
36 command_line->AppendSwitch(switches::kUserDataDir); | 37 command_line->AppendSwitch(switches::kUserDataDir); |
37 content::ResetSchemesAndOriginsWhitelistForTesting(); | 38 content::ResetSchemesAndOriginsWhitelist(); |
38 | 39 |
39 // They should be now white-listed. | 40 // They should be now white-listed. |
40 EXPECT_TRUE(content::IsOriginSecure(GURL("http://example.com/a.html"))); | 41 EXPECT_TRUE(content::IsOriginSecure(GURL("http://example.com/a.html"))); |
41 EXPECT_TRUE(content::IsOriginSecure(GURL("http://127.example.com/a.html"))); | 42 EXPECT_TRUE(content::IsOriginSecure(GURL("http://127.example.com/a.html"))); |
42 | 43 |
43 // Check that similarly named sites are not considered secure. | 44 // Check that similarly named sites are not considered secure. |
44 EXPECT_FALSE(content::IsOriginSecure(GURL("http://128.example.com/a.html"))); | 45 EXPECT_FALSE(content::IsOriginSecure(GURL("http://128.example.com/a.html"))); |
45 EXPECT_FALSE(content::IsOriginSecure( | 46 EXPECT_FALSE(content::IsOriginSecure( |
46 GURL("http://foobar.127.example.com/a.html"))); | 47 GURL("http://foobar.127.example.com/a.html"))); |
47 } | 48 } |
48 | 49 |
49 } // namespace chrome | 50 } // namespace chrome |
OLD | NEW |