diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-28 17:16:34 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-28 17:16:34 +0000 |
commit | e607ee6779f2213b69a3a5d4a5fd1222e4ea58e7 (patch) | |
tree | 658ae78ac264963db0db8bcd553c0bc4f467dc90 /net/http | |
parent | 0825bc6fff157dd1202fe1d4b019ca2db2eacd27 (diff) | |
download | chromium_src-e607ee6779f2213b69a3a5d4a5fd1222e4ea58e7.zip chromium_src-e607ee6779f2213b69a3a5d4a5fd1222e4ea58e7.tar.gz chromium_src-e607ee6779f2213b69a3a5d4a5fd1222e4ea58e7.tar.bz2 |
Adds unit tests for how HttpAuthHandlerNegotiate creates SPNs.
BUG=None
TEST=net_unittests --gtest_filter="*HttpAuthHandlerNegotiate*"
Review URL: http://codereview.chromium.org/1705001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_auth_handler_negotiate.h | 8 | ||||
-rw-r--r-- | net/http/http_auth_handler_negotiate_unittest.cc | 96 |
2 files changed, 102 insertions, 2 deletions
diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h index 7bb9426..77add14 100644 --- a/net/http/http_auth_handler_negotiate.h +++ b/net/http/http_auth_handler_negotiate.h @@ -108,6 +108,12 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { CompletionCallback* callback, const BoundNetLog& net_log); +#if defined(OS_WIN) + // These are public for unit tests + std::wstring CreateSPN(const AddressList& address_list, const GURL& orign); + const std::wstring& spn() const { return spn_; } +#endif // defined(OS_WIN) + protected: virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); @@ -116,8 +122,6 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { #if defined(OS_WIN) void OnResolveCanonicalName(int result); - std::wstring CreateSPN(const AddressList& address_list, const GURL& orign); - HttpAuthSSPI auth_sspi_; AddressList address_list_; scoped_ptr<SingleRequestHostResolver> single_resolve_; diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc new file mode 100644 index 0000000..6ed882f --- /dev/null +++ b/net/http/http_auth_handler_negotiate_unittest.cc @@ -0,0 +1,96 @@ +// 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/http_auth_handler_negotiate.h" + +#include "net/base/mock_host_resolver.h" +#include "net/base/net_errors.h" +#include "net/base/test_completion_callback.h" +#if defined(OS_WIN) +#include "net/http/mock_sspi_library_win.h" +#endif +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +// TODO(cbentzel): Remove the OS_WIN condition once Negotiate is supported +// on all platforms. +#if defined(OS_WIN) +namespace { + +void CreateHandler(bool disable_cname_lookup, bool include_port, + const std::string& url_string, + SSPILibrary* sspi_library, + scoped_refptr<HttpAuthHandlerNegotiate>* handler) { + *handler = new HttpAuthHandlerNegotiate(sspi_library, 50, NULL, + disable_cname_lookup, + include_port); + std::string challenge = "Negotiate"; + HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end()); + GURL gurl(url_string); + (*handler)->InitFromChallenge(&props, HttpAuth::AUTH_SERVER, gurl); +} + +} // namespace + +TEST(HttpAuthHandlerNegotiateTest, DisableCname) { + MockSSPILibrary mock_library; + scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; + CreateHandler(true, false, "http://alias:500", &mock_library, &auth_handler); + EXPECT_FALSE(auth_handler->NeedsCanonicalName()); + EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); +} + +TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { + MockSSPILibrary mock_library; + scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; + CreateHandler(true, true, "http://alias:80", &mock_library, &auth_handler); + EXPECT_FALSE(auth_handler->NeedsCanonicalName()); + EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); +} + +TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { + MockSSPILibrary mock_library; + scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; + CreateHandler(true, true, "http://alias:500", &mock_library, &auth_handler); + EXPECT_FALSE(auth_handler->NeedsCanonicalName()); + EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); +} + +TEST(HttpAuthHandlerNegotiateTest, CnameSync) { + MockSSPILibrary mock_library; + scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; + CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler); + EXPECT_TRUE(auth_handler->NeedsCanonicalName()); + MockHostResolver* mock_resolver = new MockHostResolver(); + scoped_refptr<HostResolver> scoped_resolver(mock_resolver); + mock_resolver->set_synchronous_mode(true); + mock_resolver->rules()->AddIPv4Rule("alias", "10.0.0.2", + "canonical.example.com"); + TestCompletionCallback callback; + EXPECT_EQ(OK, auth_handler->ResolveCanonicalName(mock_resolver, &callback, + NULL)); + EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); +} + +TEST(HttpAuthHandlerNegotiateTest, CnameAsync) { + MockSSPILibrary mock_library; + scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; + CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler); + EXPECT_TRUE(auth_handler->NeedsCanonicalName()); + MockHostResolver* mock_resolver = new MockHostResolver(); + scoped_refptr<HostResolver> scoped_resolver(mock_resolver); + mock_resolver->set_synchronous_mode(false); + mock_resolver->rules()->AddIPv4Rule("alias", "10.0.0.2", + "canonical.example.com"); + TestCompletionCallback callback; + EXPECT_EQ(ERR_IO_PENDING, auth_handler->ResolveCanonicalName(mock_resolver, + &callback, + NULL)); + EXPECT_EQ(OK, callback.WaitForResult()); + EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); +} +#endif // defined(OS_WIN) + +} // namespace net |