diff options
author | ahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 20:02:30 +0000 |
---|---|---|
committer | ahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 20:02:30 +0000 |
commit | ffdb96f586bb5604ba21bf5931e4c6c2f4ba6c78 (patch) | |
tree | fbe854e3e76a8908183d18611caa4025afde5cd2 /net | |
parent | d40c8492826ae9ac77b12c2cff7fbceb2075a772 (diff) | |
download | chromium_src-ffdb96f586bb5604ba21bf5931e4c6c2f4ba6c78.zip chromium_src-ffdb96f586bb5604ba21bf5931e4c6c2f4ba6c78.tar.gz chromium_src-ffdb96f586bb5604ba21bf5931e4c6c2f4ba6c78.tar.bz2 |
Added unit tests for URLSecurityManager.
BUG=29596
TEST=Pass in --gtest_filter=URLSecurityManager.*
Review URL: http://codereview.chromium.org/1695008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rwxr-xr-x | net/http/url_security_manager_unittest.cc | 88 | ||||
-rw-r--r-- | net/net.gyp | 1 |
2 files changed, 89 insertions, 0 deletions
diff --git a/net/http/url_security_manager_unittest.cc b/net/http/url_security_manager_unittest.cc new file mode 100755 index 0000000..b08a7b2 --- /dev/null +++ b/net/http/url_security_manager_unittest.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/http/url_security_manager.h" + +#include "base/basictypes.h" +#include "googleurl/src/gurl.h" +#include "net/base/net_errors.h" +#include "net/http/http_auth_filter.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +namespace { + +struct TestData { + const char* url; + bool succeds_in_windows_default; + bool succeeds_in_whitelist; +}; + +const char* kTestAuthWhitelist = "*example.com,*foobar.com,baz"; + +// Under Windows the following will be allowed by default: +// localhost +// host names without a period. +// In Posix systems (or on Windows if a whitelist is specified explicitly), +// everything depends on the whitelist. +const TestData kTestDataList[] = { + { "http://localhost", true, false }, + { "http://bat", true, false }, + { "http://www.example.com", false, true }, + { "http://example.com", false, true }, + { "http://foobar.com", false, true }, + { "http://boo.foobar.com", false, true }, + { "http://baz", true, true }, + { "http://www.exampl.com", false, false }, + { "http://example.org", false, false }, + { "http://foobar.net", false, false }, + { "http://boo.fubar.com", false, false }, +}; + +} // namespace + +// For Windows, This relies on the contents of the registry, so in theory it +// might fail. +TEST(URLSecurityManager, FLAKY_CreateNoWhitelist) { + scoped_ptr<URLSecurityManager> url_security_manager( + URLSecurityManager::Create(NULL)); + ASSERT_TRUE(url_security_manager.get()); + + for (size_t i = 0; i < arraysize(kTestDataList); ++i) { + GURL gurl(kTestDataList[i].url); + bool can_use_default = + url_security_manager->CanUseDefaultCredentials(gurl); + +#if defined(OS_WIN) + EXPECT_EQ(kTestDataList[i].succeds_in_windows_default, can_use_default) + << " Run: " << i << " URL: '" << gurl << "'"; +#else + // No whitelist means nothing can use the default. + EXPECT_FALSE(can_use_default) + << " Run: " << i << " URL: '" << gurl << "'"; +#endif // OS_WIN + } +} + +TEST(URLSecurityManager, CreateWhitelist) { + HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist(); + ASSERT_TRUE(auth_filter); + auth_filter->SetWhitelist(kTestAuthWhitelist); + // The URL security manager takes ownership of |auth_filter|. + scoped_ptr<URLSecurityManager> url_security_manager( + URLSecurityManager::Create(auth_filter)); + ASSERT_TRUE(url_security_manager.get()); + + for (size_t i = 0; i < arraysize(kTestDataList); ++i) { + GURL gurl(kTestDataList[i].url); + bool can_use_default = + url_security_manager->CanUseDefaultCredentials(gurl); + + EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default) + << " Run: " << i << " URL: '" << gurl << "'"; + } +} + +} // namespace net diff --git a/net/net.gyp b/net/net.gyp index 76c9f4a..3b95934 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -692,6 +692,7 @@ 'http/http_vary_data_unittest.cc', 'http/mock_sspi_library_win.h', 'http/mock_sspi_library_win.cc', + 'http/url_security_manager_unittest.cc', 'proxy/init_proxy_resolver_unittest.cc', 'proxy/mock_proxy_resolver.h', 'proxy/proxy_bypass_rules_unittest.cc', |