| OLD | NEW |
| 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/http_auth_handler_negotiate.h" | 5 #include "net/http/http_auth_handler_negotiate.h" |
| 6 | 6 |
| 7 #include "net/base/mock_host_resolver.h" | 7 #include "net/base/mock_host_resolver.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/http/http_request_info.h" | 10 #include "net/http/http_request_info.h" |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include "net/http/mock_sspi_library_win.h" | 12 #include "net/http/mock_sspi_library_win.h" |
| 13 #elif defined(OS_POSIX) | 13 #elif defined(OS_POSIX) |
| 14 #include "net/http/mock_gssapi_library_posix.h" | 14 #include "net/http/mock_gssapi_library_posix.h" |
| 15 #endif | 15 #endif |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 19 typedef net::SSPILibrary SecureServicesLibrary; | 19 typedef net::SSPILibrary SecureServicesLibrary; |
| 20 typedef net::MockSSPILibrary MockSecureServicesLibrary; | 20 typedef net::MockSSPILibrary MockSecureServicesLibrary; |
| 21 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
| 22 typedef net::GSSAPILibrary SecureServicesLibrary; | 22 typedef net::GSSAPILibrary SecureServicesLibrary; |
| 23 typedef net::test::MockGSSAPILibrary MockSecureServicesLibrary; | 23 typedef net::test::MockGSSAPILibrary MockSecureServicesLibrary; |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 | 26 |
| 27 namespace net { | 27 namespace net { |
| 28 | 28 |
| 29 // TODO(cbentzel): Remove the OS_WIN condition once Negotiate is supported | |
| 30 // on all platforms. | |
| 31 namespace { | 29 namespace { |
| 32 | 30 |
| 33 void SetupTransactions(MockSecureServicesLibrary* mock_library) { | 31 void SetupTransactions(MockSecureServicesLibrary* mock_library) { |
| 34 #if defined(OS_POSIX) | 32 #if defined(OS_POSIX) |
| 35 // Copied from an actual transaction! | 33 // Copied from an actual transaction! |
| 36 const char kAuthResponse[] = | 34 const char kAuthResponse[] = |
| 37 "\x60\x82\x02\xCA\x06\x09\x2A\x86\x48\x86\xF7\x12\x01\x02\x02\x01" | 35 "\x60\x82\x02\xCA\x06\x09\x2A\x86\x48\x86\xF7\x12\x01\x02\x02\x01" |
| 38 "\x00\x6E\x82\x02\xB9\x30\x82\x02\xB5\xA0\x03\x02\x01\x05\xA1\x03" | 36 "\x00\x6E\x82\x02\xB9\x30\x82\x02\xB5\xA0\x03\x02\x01\x05\xA1\x03" |
| 39 "\x02\x01\x0E\xA2\x07\x03\x05\x00\x00\x00\x00\x00\xA3\x82\x01\xC1" | 37 "\x02\x01\x0E\xA2\x07\x03\x05\x00\x00\x00\x00\x00\xA3\x82\x01\xC1" |
| 40 "\x61\x82\x01\xBD\x30\x82\x01\xB9\xA0\x03\x02\x01\x05\xA1\x16\x1B" | 38 "\x61\x82\x01\xBD\x30\x82\x01\xB9\xA0\x03\x02\x01\x05\xA1\x16\x1B" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 154 } |
| 157 | 155 |
| 158 } // namespace | 156 } // namespace |
| 159 | 157 |
| 160 TEST(HttpAuthHandlerNegotiateTest, DisableCname) { | 158 TEST(HttpAuthHandlerNegotiateTest, DisableCname) { |
| 161 MockSecureServicesLibrary mock_library; | 159 MockSecureServicesLibrary mock_library; |
| 162 SetupTransactions(&mock_library); | 160 SetupTransactions(&mock_library); |
| 163 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 161 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 164 CreateHandler(true, false, true, "http://alias:500", | 162 CreateHandler(true, false, true, "http://alias:500", |
| 165 &mock_library, &auth_handler); | 163 &mock_library, &auth_handler); |
| 164 ASSERT_TRUE(auth_handler.get() != NULL); |
| 166 TestCompletionCallback callback; | 165 TestCompletionCallback callback; |
| 167 HttpRequestInfo request_info; | 166 HttpRequestInfo request_info; |
| 168 std::string token; | 167 std::string token; |
| 169 std::wstring username = L"foo"; | 168 std::wstring username = L"foo"; |
| 170 std::wstring password = L"bar"; | 169 std::wstring password = L"bar"; |
| 171 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 170 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 172 &request_info, | 171 &request_info, |
| 173 &callback, &token)); | 172 &callback, &token)); |
| 174 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); | 173 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 175 } | 174 } |
| 176 | 175 |
| 177 TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { | 176 TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { |
| 178 MockSecureServicesLibrary mock_library; | 177 MockSecureServicesLibrary mock_library; |
| 179 SetupTransactions(&mock_library); | 178 SetupTransactions(&mock_library); |
| 180 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 179 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 181 CreateHandler(true, true, true, | 180 CreateHandler(true, true, true, |
| 182 "http://alias:80", &mock_library, &auth_handler); | 181 "http://alias:80", &mock_library, &auth_handler); |
| 182 ASSERT_TRUE(auth_handler.get() != NULL); |
| 183 TestCompletionCallback callback; | 183 TestCompletionCallback callback; |
| 184 HttpRequestInfo request_info; | 184 HttpRequestInfo request_info; |
| 185 std::string token; | 185 std::string token; |
| 186 std::wstring username = L"foo"; | 186 std::wstring username = L"foo"; |
| 187 std::wstring password = L"bar"; | 187 std::wstring password = L"bar"; |
| 188 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 188 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 189 &request_info, | 189 &request_info, |
| 190 &callback, &token)); | 190 &callback, &token)); |
| 191 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); | 191 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { | 194 TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { |
| 195 MockSecureServicesLibrary mock_library; | 195 MockSecureServicesLibrary mock_library; |
| 196 SetupTransactions(&mock_library); | 196 SetupTransactions(&mock_library); |
| 197 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 197 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 198 CreateHandler(true, true, true, | 198 CreateHandler(true, true, true, |
| 199 "http://alias:500", &mock_library, &auth_handler); | 199 "http://alias:500", &mock_library, &auth_handler); |
| 200 ASSERT_TRUE(auth_handler.get() != NULL); |
| 200 TestCompletionCallback callback; | 201 TestCompletionCallback callback; |
| 201 HttpRequestInfo request_info; | 202 HttpRequestInfo request_info; |
| 202 std::string token; | 203 std::string token; |
| 203 std::wstring username = L"foo"; | 204 std::wstring username = L"foo"; |
| 204 std::wstring password = L"bar"; | 205 std::wstring password = L"bar"; |
| 205 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 206 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 206 &request_info, | 207 &request_info, |
| 207 &callback, &token)); | 208 &callback, &token)); |
| 208 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); | 209 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); |
| 209 } | 210 } |
| 210 | 211 |
| 211 TEST(HttpAuthHandlerNegotiateTest, CnameSync) { | 212 TEST(HttpAuthHandlerNegotiateTest, CnameSync) { |
| 212 MockSecureServicesLibrary mock_library; | 213 MockSecureServicesLibrary mock_library; |
| 213 SetupTransactions(&mock_library); | 214 SetupTransactions(&mock_library); |
| 214 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 215 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 215 CreateHandler(false, false, true, | 216 CreateHandler(false, false, true, |
| 216 "http://alias:500", &mock_library, &auth_handler); | 217 "http://alias:500", &mock_library, &auth_handler); |
| 218 ASSERT_TRUE(auth_handler.get() != NULL); |
| 217 TestCompletionCallback callback; | 219 TestCompletionCallback callback; |
| 218 HttpRequestInfo request_info; | 220 HttpRequestInfo request_info; |
| 219 std::string token; | 221 std::string token; |
| 220 std::wstring username = L"foo"; | 222 std::wstring username = L"foo"; |
| 221 std::wstring password = L"bar"; | 223 std::wstring password = L"bar"; |
| 222 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 224 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 223 &request_info, | 225 &request_info, |
| 224 &callback, &token)); | 226 &callback, &token)); |
| 225 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); | 227 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 226 } | 228 } |
| 227 | 229 |
| 228 TEST(HttpAuthHandlerNegotiateTest, CnameAsync) { | 230 TEST(HttpAuthHandlerNegotiateTest, CnameAsync) { |
| 229 MockSecureServicesLibrary mock_library; | 231 MockSecureServicesLibrary mock_library; |
| 230 SetupTransactions(&mock_library); | 232 SetupTransactions(&mock_library); |
| 231 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 233 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 232 CreateHandler(false, false, false, | 234 CreateHandler(false, false, false, |
| 233 "http://alias:500", &mock_library, &auth_handler); | 235 "http://alias:500", &mock_library, &auth_handler); |
| 236 ASSERT_TRUE(auth_handler.get() != NULL); |
| 234 TestCompletionCallback callback; | 237 TestCompletionCallback callback; |
| 235 HttpRequestInfo request_info; | 238 HttpRequestInfo request_info; |
| 236 std::string token; | 239 std::string token; |
| 237 std::wstring username = L"foo"; | 240 std::wstring username = L"foo"; |
| 238 std::wstring password = L"bar"; | 241 std::wstring password = L"bar"; |
| 239 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 242 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
| 240 &username, &password, &request_info, &callback, &token)); | 243 &username, &password, &request_info, &callback, &token)); |
| 241 EXPECT_EQ(OK, callback.WaitForResult()); | 244 EXPECT_EQ(OK, callback.WaitForResult()); |
| 242 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); | 245 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 243 } | 246 } |
| 244 | 247 |
| 245 } // namespace net | 248 } // namespace net |
| OLD | NEW |