| 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 "base/string_util.h" |
| 7 #include "net/base/mock_host_resolver.h" | 8 #include "net/base/mock_host_resolver.h" |
| 8 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| 10 #include "net/http/http_request_info.h" | 11 #include "net/http/http_request_info.h" |
| 11 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 12 #include "net/http/mock_sspi_library_win.h" | 13 #include "net/http/mock_sspi_library_win.h" |
| 13 #elif defined(OS_POSIX) | 14 #elif defined(OS_POSIX) |
| 14 #include "net/http/mock_gssapi_library_posix.h" | 15 #include "net/http/mock_gssapi_library_posix.h" |
| 15 #include "net/third_party/gssapi/gssapi.h" | 16 #include "net/third_party/gssapi/gssapi.h" |
| 16 #endif | 17 #endif |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { | 219 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { |
| 219 SetupMocks(AuthLibrary()); | 220 SetupMocks(AuthLibrary()); |
| 220 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 221 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 221 EXPECT_EQ(OK, CreateHandler( | 222 EXPECT_EQ(OK, CreateHandler( |
| 222 true, false, true, "http://alias:500", &auth_handler)); | 223 true, false, true, "http://alias:500", &auth_handler)); |
| 223 | 224 |
| 224 ASSERT_TRUE(auth_handler.get() != NULL); | 225 ASSERT_TRUE(auth_handler.get() != NULL); |
| 225 TestCompletionCallback callback; | 226 TestCompletionCallback callback; |
| 226 HttpRequestInfo request_info; | 227 HttpRequestInfo request_info; |
| 227 std::string token; | 228 std::string token; |
| 228 std::wstring username = L"foo"; | 229 string16 username = ASCIIToUTF16("foo"); |
| 229 std::wstring password = L"bar"; | 230 string16 password = ASCIIToUTF16("bar"); |
| 230 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 231 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 231 &request_info, | 232 &request_info, |
| 232 &callback, &token)); | 233 &callback, &token)); |
| 233 #if defined(OS_WIN) | 234 #if defined(OS_WIN) |
| 234 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); | 235 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 235 #elif defined(OS_POSIX) | 236 #elif defined(OS_POSIX) |
| 236 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); | 237 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); |
| 237 #endif | 238 #endif |
| 238 } | 239 } |
| 239 | 240 |
| 240 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { | 241 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { |
| 241 SetupMocks(AuthLibrary()); | 242 SetupMocks(AuthLibrary()); |
| 242 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 243 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 243 EXPECT_EQ(OK, CreateHandler( | 244 EXPECT_EQ(OK, CreateHandler( |
| 244 true, true, true, "http://alias:80", &auth_handler)); | 245 true, true, true, "http://alias:80", &auth_handler)); |
| 245 ASSERT_TRUE(auth_handler.get() != NULL); | 246 ASSERT_TRUE(auth_handler.get() != NULL); |
| 246 TestCompletionCallback callback; | 247 TestCompletionCallback callback; |
| 247 HttpRequestInfo request_info; | 248 HttpRequestInfo request_info; |
| 248 std::string token; | 249 std::string token; |
| 249 std::wstring username = L"foo"; | 250 string16 username = ASCIIToUTF16("foo"); |
| 250 std::wstring password = L"bar"; | 251 string16 password = ASCIIToUTF16("bar"); |
| 251 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 252 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 252 &request_info, | 253 &request_info, |
| 253 &callback, &token)); | 254 &callback, &token)); |
| 254 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
| 255 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); | 256 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); |
| 256 #elif defined(OS_POSIX) | 257 #elif defined(OS_POSIX) |
| 257 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); | 258 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); |
| 258 #endif | 259 #endif |
| 259 } | 260 } |
| 260 | 261 |
| 261 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { | 262 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { |
| 262 SetupMocks(AuthLibrary()); | 263 SetupMocks(AuthLibrary()); |
| 263 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 264 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 264 EXPECT_EQ(OK, CreateHandler( | 265 EXPECT_EQ(OK, CreateHandler( |
| 265 true, true, true, "http://alias:500", &auth_handler)); | 266 true, true, true, "http://alias:500", &auth_handler)); |
| 266 ASSERT_TRUE(auth_handler.get() != NULL); | 267 ASSERT_TRUE(auth_handler.get() != NULL); |
| 267 TestCompletionCallback callback; | 268 TestCompletionCallback callback; |
| 268 HttpRequestInfo request_info; | 269 HttpRequestInfo request_info; |
| 269 std::string token; | 270 std::string token; |
| 270 std::wstring username = L"foo"; | 271 string16 username = ASCIIToUTF16("foo"); |
| 271 std::wstring password = L"bar"; | 272 string16 password = ASCIIToUTF16("bar"); |
| 272 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 273 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 273 &request_info, | 274 &request_info, |
| 274 &callback, &token)); | 275 &callback, &token)); |
| 275 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
| 276 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); | 277 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); |
| 277 #elif defined(OS_POSIX) | 278 #elif defined(OS_POSIX) |
| 278 EXPECT_EQ(L"HTTP@alias:500", auth_handler->spn()); | 279 EXPECT_EQ(L"HTTP@alias:500", auth_handler->spn()); |
| 279 #endif | 280 #endif |
| 280 } | 281 } |
| 281 | 282 |
| 282 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { | 283 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { |
| 283 SetupMocks(AuthLibrary()); | 284 SetupMocks(AuthLibrary()); |
| 284 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 285 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 285 EXPECT_EQ(OK, CreateHandler( | 286 EXPECT_EQ(OK, CreateHandler( |
| 286 false, false, true, "http://alias:500", &auth_handler)); | 287 false, false, true, "http://alias:500", &auth_handler)); |
| 287 ASSERT_TRUE(auth_handler.get() != NULL); | 288 ASSERT_TRUE(auth_handler.get() != NULL); |
| 288 TestCompletionCallback callback; | 289 TestCompletionCallback callback; |
| 289 HttpRequestInfo request_info; | 290 HttpRequestInfo request_info; |
| 290 std::string token; | 291 std::string token; |
| 291 std::wstring username = L"foo"; | 292 string16 username = ASCIIToUTF16("foo"); |
| 292 std::wstring password = L"bar"; | 293 string16 password = ASCIIToUTF16("bar"); |
| 293 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, | 294 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, |
| 294 &request_info, | 295 &request_info, |
| 295 &callback, &token)); | 296 &callback, &token)); |
| 296 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 297 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); | 298 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 298 #elif defined(OS_POSIX) | 299 #elif defined(OS_POSIX) |
| 299 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); | 300 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); |
| 300 #endif | 301 #endif |
| 301 } | 302 } |
| 302 | 303 |
| 303 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { | 304 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { |
| 304 SetupMocks(AuthLibrary()); | 305 SetupMocks(AuthLibrary()); |
| 305 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 306 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
| 306 EXPECT_EQ(OK, CreateHandler( | 307 EXPECT_EQ(OK, CreateHandler( |
| 307 false, false, false, "http://alias:500", &auth_handler)); | 308 false, false, false, "http://alias:500", &auth_handler)); |
| 308 ASSERT_TRUE(auth_handler.get() != NULL); | 309 ASSERT_TRUE(auth_handler.get() != NULL); |
| 309 TestCompletionCallback callback; | 310 TestCompletionCallback callback; |
| 310 HttpRequestInfo request_info; | 311 HttpRequestInfo request_info; |
| 311 std::string token; | 312 std::string token; |
| 312 std::wstring username = L"foo"; | 313 string16 username = ASCIIToUTF16("foo"); |
| 313 std::wstring password = L"bar"; | 314 string16 password = ASCIIToUTF16("bar"); |
| 314 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 315 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
| 315 &username, &password, &request_info, &callback, &token)); | 316 &username, &password, &request_info, &callback, &token)); |
| 316 EXPECT_EQ(OK, callback.WaitForResult()); | 317 EXPECT_EQ(OK, callback.WaitForResult()); |
| 317 #if defined(OS_WIN) | 318 #if defined(OS_WIN) |
| 318 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); | 319 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); |
| 319 #elif defined(OS_POSIX) | 320 #elif defined(OS_POSIX) |
| 320 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); | 321 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); |
| 321 #endif | 322 #endif |
| 322 } | 323 } |
| 323 | 324 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 350 HttpRequestInfo request_info; | 351 HttpRequestInfo request_info; |
| 351 std::string token; | 352 std::string token; |
| 352 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 353 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
| 353 NULL, NULL, &request_info, &callback, &token)); | 354 NULL, NULL, &request_info, &callback, &token)); |
| 354 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 355 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); |
| 355 } | 356 } |
| 356 | 357 |
| 357 #endif // defined(OS_POSIX) | 358 #endif // defined(OS_POSIX) |
| 358 | 359 |
| 359 } // namespace net | 360 } // namespace net |
| OLD | NEW |