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

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: Reply to 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
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 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist(
cbentzel 2015/12/01 20:56:16 Nit: Maybe make |auth_filter| a scoped_ptr?
aberent 2015/12/02 13:30:19 Done.
48 kTestAuthWhitelist); 48 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(
54 scoped_ptr<net::HttpAuthFilter>(auth_filter));
53 ASSERT_TRUE(url_security_manager.get()); 55 ASSERT_TRUE(url_security_manager.get());
54 56
55 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 57 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
56 GURL gurl(kTestDataList[i].url); 58 GURL gurl(kTestDataList[i].url);
57 bool can_use_default = 59 bool can_use_default =
58 url_security_manager->CanUseDefaultCredentials(gurl); 60 url_security_manager->CanUseDefaultCredentials(gurl);
59 61
60 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default) 62 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default)
61 << " Run: " << i << " URL: '" << gurl << "'"; 63 << " Run: " << i << " URL: '" << gurl << "'";
62 } 64 }
63 } 65 }
64 66
65 TEST(URLSecurityManager, CanDelegate) { 67 TEST(URLSecurityManager, CanDelegate) {
66 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist( 68 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist(
67 kTestAuthWhitelist); 69 kTestAuthWhitelist);
68 ASSERT_TRUE(auth_filter); 70 ASSERT_TRUE(auth_filter);
69 // The URL security manager takes ownership of |auth_filter|. 71 // The URL security manager takes ownership of |auth_filter|.
70 scoped_ptr<URLSecurityManager> url_security_manager( 72 scoped_ptr<URLSecurityManager> url_security_manager(
71 URLSecurityManager::Create(NULL, auth_filter)); 73 URLSecurityManager::Create());
74 url_security_manager->SetDelegateWhitelist(
75 scoped_ptr<net::HttpAuthFilter>(auth_filter));
72 ASSERT_TRUE(url_security_manager.get()); 76 ASSERT_TRUE(url_security_manager.get());
73 77
74 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 78 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
75 GURL gurl(kTestDataList[i].url); 79 GURL gurl(kTestDataList[i].url);
76 bool can_delegate = url_security_manager->CanDelegate(gurl); 80 bool can_delegate = url_security_manager->CanDelegate(gurl);
77 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate) 81 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate)
78 << " Run: " << i << " URL: '" << gurl << "'"; 82 << " Run: " << i << " URL: '" << gurl << "'";
79 } 83 }
80 } 84 }
81 85
82 TEST(URLSecurityManager, CanDelegate_NoWhitelist) { 86 TEST(URLSecurityManager, CanDelegate_NoWhitelist) {
83 // Nothing can delegate in this case. 87 // Nothing can delegate in this case.
84 scoped_ptr<URLSecurityManager> url_security_manager( 88 scoped_ptr<URLSecurityManager> url_security_manager(
85 URLSecurityManager::Create(NULL, NULL)); 89 URLSecurityManager::Create());
86 ASSERT_TRUE(url_security_manager.get()); 90 ASSERT_TRUE(url_security_manager.get());
87 91
88 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 92 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
89 GURL gurl(kTestDataList[i].url); 93 GURL gurl(kTestDataList[i].url);
90 bool can_delegate = url_security_manager->CanDelegate(gurl); 94 bool can_delegate = url_security_manager->CanDelegate(gurl);
91 EXPECT_FALSE(can_delegate); 95 EXPECT_FALSE(can_delegate);
92 } 96 }
93 } 97 }
94 98
95 99
96 } // namespace net 100 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698