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 password | 19 // Empty password |
20 { L"anon", L"", "Basic YW5vbjo=" }, | 20 { L"anon", L"", "Basic YW5vbjo=" }, |
| 21 // Empty username and empty password. |
| 22 { L"", L"", "Basic Og==" }, |
21 }; | 23 }; |
22 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 24 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
23 std::string challenge = "Basic realm=\"Atlantis\""; | 25 std::string challenge = "Basic realm=\"Atlantis\""; |
24 HttpAuthHandlerBasic basic; | 26 HttpAuthHandlerBasic basic; |
25 basic.InitFromChallenge(challenge.begin(), challenge.end(), | 27 basic.InitFromChallenge(challenge.begin(), challenge.end(), |
26 HttpAuth::AUTH_SERVER); | 28 HttpAuth::AUTH_SERVER); |
27 std::string credentials = basic.GenerateCredentials(tests[i].username, | 29 std::string credentials = basic.GenerateCredentials(tests[i].username, |
28 tests[i].password, | 30 tests[i].password, |
29 NULL, NULL); | 31 NULL, NULL); |
30 EXPECT_STREQ(tests[i].expected_credentials, credentials.c_str()); | 32 EXPECT_STREQ(tests[i].expected_credentials, credentials.c_str()); |
31 } | 33 } |
32 } | 34 } |
33 | 35 |
34 } // namespace net | 36 } // namespace net |
OLD | NEW |