| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "net/http/http_auth_handler_basic.h" | 8 #include "net/http/http_auth_handler_basic.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 TEST(HttpAuthHandlerBasicTest, GenerateCredentials) { | 12 TEST(HttpAuthHandlerBasicTest, GenerateCredentials) { |
| 13 static const struct { | 13 static const struct { |
| 14 const wchar_t* username; | 14 const wchar_t* username; |
| 15 const wchar_t* password; | 15 const wchar_t* password; |
| 16 const char* expected_credentials; | 16 const char* expected_credentials; |
| 17 } tests[] = { | 17 } tests[] = { |
| 18 { L"foo", L"bar", "Basic Zm9vOmJhcg==" }, | 18 { L"foo", L"bar", "Basic Zm9vOmJhcg==" }, |
| 19 // Empty username | 19 // Empty username |
| 20 { L"", L"foobar", "Basic OmZvb2Jhcg==" }, | 20 { L"", L"foobar", "Basic OmZvb2Jhcg==" }, |
| 21 // Empty password | 21 // Empty password |
| 22 { L"anon", L"", "Basic YW5vbjo=" }, | 22 { L"anon", L"", "Basic YW5vbjo=" }, |
| 23 // Empty username and empty password. | 23 // Empty username and empty password. |
| 24 { L"", L"", "Basic Og==" }, | 24 { L"", L"", "Basic Og==" }, |
| 25 }; | 25 }; |
| 26 GURL origin("http://www.example.com"); |
| 26 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 27 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 27 std::string challenge = "Basic realm=\"Atlantis\""; | 28 std::string challenge = "Basic realm=\"Atlantis\""; |
| 28 scoped_refptr<HttpAuthHandlerBasic> basic = new HttpAuthHandlerBasic; | 29 scoped_refptr<HttpAuthHandlerBasic> basic = new HttpAuthHandlerBasic; |
| 29 basic->InitFromChallenge(challenge.begin(), challenge.end(), | 30 basic->InitFromChallenge(challenge.begin(), challenge.end(), |
| 30 HttpAuth::AUTH_SERVER); | 31 HttpAuth::AUTH_SERVER, origin); |
| 31 std::string credentials = basic->GenerateCredentials(tests[i].username, | 32 std::string credentials = basic->GenerateCredentials(tests[i].username, |
| 32 tests[i].password, | 33 tests[i].password, |
| 33 NULL, NULL); | 34 NULL, NULL); |
| 34 EXPECT_STREQ(tests[i].expected_credentials, credentials.c_str()); | 35 EXPECT_STREQ(tests[i].expected_credentials, credentials.c_str()); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 } // namespace net | 39 } // namespace net |
| OLD | NEW |