OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http/http_auth_handler_negotiate.h" |
| 6 |
| 7 #include "net/base/mock_host_resolver.h" |
| 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" |
| 10 #if defined(OS_WIN) |
| 11 #include "net/http/mock_sspi_library_win.h" |
| 12 #endif |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 // TODO(cbentzel): Remove the OS_WIN condition once Negotiate is supported |
| 18 // on all platforms. |
| 19 #if defined(OS_WIN) |
| 20 namespace { |
| 21 |
| 22 void CreateHandler(bool disable_cname_lookup, bool include_port, |
| 23 const std::string& url_string, |
| 24 SSPILibrary* sspi_library, |
| 25 scoped_refptr<HttpAuthHandlerNegotiate>* handler) { |
| 26 *handler = new HttpAuthHandlerNegotiate(sspi_library, 50, NULL, |
| 27 disable_cname_lookup, |
| 28 include_port); |
| 29 std::string challenge = "Negotiate"; |
| 30 HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 31 GURL gurl(url_string); |
| 32 (*handler)->InitFromChallenge(&props, HttpAuth::AUTH_SERVER, gurl); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 TEST(HttpAuthHandlerNegotiateTest, DisableCname) { |
| 38 MockSSPILibrary mock_library; |
| 39 scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; |
| 40 CreateHandler(true, false, "http://alias:500", &mock_library, &auth_handler); |
| 41 EXPECT_FALSE(auth_handler->NeedsCanonicalName()); |
| 42 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 43 } |
| 44 |
| 45 TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { |
| 46 MockSSPILibrary mock_library; |
| 47 scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; |
| 48 CreateHandler(true, true, "http://alias:80", &mock_library, &auth_handler); |
| 49 EXPECT_FALSE(auth_handler->NeedsCanonicalName()); |
| 50 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 51 } |
| 52 |
| 53 TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { |
| 54 MockSSPILibrary mock_library; |
| 55 scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; |
| 56 CreateHandler(true, true, "http://alias:500", &mock_library, &auth_handler); |
| 57 EXPECT_FALSE(auth_handler->NeedsCanonicalName()); |
| 58 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); |
| 59 } |
| 60 |
| 61 TEST(HttpAuthHandlerNegotiateTest, CnameSync) { |
| 62 MockSSPILibrary mock_library; |
| 63 scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; |
| 64 CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler); |
| 65 EXPECT_TRUE(auth_handler->NeedsCanonicalName()); |
| 66 MockHostResolver* mock_resolver = new MockHostResolver(); |
| 67 scoped_refptr<HostResolver> scoped_resolver(mock_resolver); |
| 68 mock_resolver->set_synchronous_mode(true); |
| 69 mock_resolver->rules()->AddIPv4Rule("alias", "10.0.0.2", |
| 70 "canonical.example.com"); |
| 71 TestCompletionCallback callback; |
| 72 EXPECT_EQ(OK, auth_handler->ResolveCanonicalName(mock_resolver, &callback, |
| 73 NULL)); |
| 74 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 75 } |
| 76 |
| 77 TEST(HttpAuthHandlerNegotiateTest, CnameAsync) { |
| 78 MockSSPILibrary mock_library; |
| 79 scoped_refptr<HttpAuthHandlerNegotiate> auth_handler; |
| 80 CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler); |
| 81 EXPECT_TRUE(auth_handler->NeedsCanonicalName()); |
| 82 MockHostResolver* mock_resolver = new MockHostResolver(); |
| 83 scoped_refptr<HostResolver> scoped_resolver(mock_resolver); |
| 84 mock_resolver->set_synchronous_mode(false); |
| 85 mock_resolver->rules()->AddIPv4Rule("alias", "10.0.0.2", |
| 86 "canonical.example.com"); |
| 87 TestCompletionCallback callback; |
| 88 EXPECT_EQ(ERR_IO_PENDING, auth_handler->ResolveCanonicalName(mock_resolver, |
| 89 &callback, |
| 90 NULL)); |
| 91 EXPECT_EQ(OK, callback.WaitForResult()); |
| 92 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 93 } |
| 94 #endif // defined(OS_WIN) |
| 95 |
| 96 } // namespace net |
OLD | NEW |