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

Side by Side Diff: net/http/url_security_manager_unittest.cc

Issue 1414313002: Allow dynamic updating of authentication policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to cbentzel@'s comments. Created 5 years 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
« no previous file with comments | « net/http/url_security_manager_posix.cc ('k') | net/http/url_security_manager_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/http/url_security_manager.h" 5 #include "net/http/url_security_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "net/http/http_auth_filter.h" 9 #include "net/http/http_auth_filter.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 26 matching lines...) Expand all
37 { "http://baz", true, true }, 37 { "http://baz", true, true },
38 { "http://www.exampl.com", false, false }, 38 { "http://www.exampl.com", false, false },
39 { "http://example.org", false, false }, 39 { "http://example.org", false, false },
40 { "http://foobar.net", false, false }, 40 { "http://foobar.net", false, false },
41 { "http://boo.fubar.com", false, false }, 41 { "http://boo.fubar.com", false, false },
42 }; 42 };
43 43
44 } // namespace 44 } // namespace
45 45
46 TEST(URLSecurityManager, UseDefaultCredentials) { 46 TEST(URLSecurityManager, UseDefaultCredentials) {
47 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist( 47 scoped_ptr<HttpAuthFilter> auth_filter(
48 kTestAuthWhitelist); 48 new HttpAuthFilterWhitelist(kTestAuthWhitelist));
49 ASSERT_TRUE(auth_filter); 49 ASSERT_TRUE(auth_filter);
50 // The URL security manager takes ownership of |auth_filter|. 50 // The URL security manager takes ownership of |auth_filter|.
51 scoped_ptr<URLSecurityManager> url_security_manager( 51 scoped_ptr<URLSecurityManager> url_security_manager(
52 URLSecurityManager::Create(auth_filter, NULL)); 52 URLSecurityManager::Create());
53 url_security_manager->SetDefaultWhitelist(auth_filter.Pass());
53 ASSERT_TRUE(url_security_manager.get()); 54 ASSERT_TRUE(url_security_manager.get());
54 55
55 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 56 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
56 GURL gurl(kTestDataList[i].url); 57 GURL gurl(kTestDataList[i].url);
57 bool can_use_default = 58 bool can_use_default =
58 url_security_manager->CanUseDefaultCredentials(gurl); 59 url_security_manager->CanUseDefaultCredentials(gurl);
59 60
60 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default) 61 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default)
61 << " Run: " << i << " URL: '" << gurl << "'"; 62 << " Run: " << i << " URL: '" << gurl << "'";
62 } 63 }
63 } 64 }
64 65
65 TEST(URLSecurityManager, CanDelegate) { 66 TEST(URLSecurityManager, CanDelegate) {
66 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist( 67 scoped_ptr<HttpAuthFilter> auth_filter(
67 kTestAuthWhitelist); 68 new HttpAuthFilterWhitelist(kTestAuthWhitelist));
68 ASSERT_TRUE(auth_filter); 69 ASSERT_TRUE(auth_filter);
69 // The URL security manager takes ownership of |auth_filter|. 70 // The URL security manager takes ownership of |auth_filter|.
70 scoped_ptr<URLSecurityManager> url_security_manager( 71 scoped_ptr<URLSecurityManager> url_security_manager(
71 URLSecurityManager::Create(NULL, auth_filter)); 72 URLSecurityManager::Create());
73 url_security_manager->SetDelegateWhitelist(auth_filter.Pass());
72 ASSERT_TRUE(url_security_manager.get()); 74 ASSERT_TRUE(url_security_manager.get());
73 75
74 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 76 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
75 GURL gurl(kTestDataList[i].url); 77 GURL gurl(kTestDataList[i].url);
76 bool can_delegate = url_security_manager->CanDelegate(gurl); 78 bool can_delegate = url_security_manager->CanDelegate(gurl);
77 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate) 79 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate)
78 << " Run: " << i << " URL: '" << gurl << "'"; 80 << " Run: " << i << " URL: '" << gurl << "'";
79 } 81 }
80 } 82 }
81 83
82 TEST(URLSecurityManager, CanDelegate_NoWhitelist) { 84 TEST(URLSecurityManager, CanDelegate_NoWhitelist) {
83 // Nothing can delegate in this case. 85 // Nothing can delegate in this case.
84 scoped_ptr<URLSecurityManager> url_security_manager( 86 scoped_ptr<URLSecurityManager> url_security_manager(
85 URLSecurityManager::Create(NULL, NULL)); 87 URLSecurityManager::Create());
86 ASSERT_TRUE(url_security_manager.get()); 88 ASSERT_TRUE(url_security_manager.get());
87 89
88 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 90 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
89 GURL gurl(kTestDataList[i].url); 91 GURL gurl(kTestDataList[i].url);
90 bool can_delegate = url_security_manager->CanDelegate(gurl); 92 bool can_delegate = url_security_manager->CanDelegate(gurl);
91 EXPECT_FALSE(can_delegate); 93 EXPECT_FALSE(can_delegate);
92 } 94 }
93 } 95 }
94 96
95 97
96 } // namespace net 98 } // namespace net
OLDNEW
« no previous file with comments | « net/http/url_security_manager_posix.cc ('k') | net/http/url_security_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698