Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: net/http/http_auth_handler_basic_unittest.cc

Issue 3040016: Net: Convert username and password to string16. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_auth_handler_basic.cc ('k') | net/http/http_auth_handler_digest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_util.h"
8 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
9 #include "net/http/http_auth_handler_basic.h" 10 #include "net/http/http_auth_handler_basic.h"
10 #include "net/http/http_request_info.h" 11 #include "net/http/http_request_info.h"
12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace net { 14 namespace net {
13 15
14 TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { 16 TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) {
15 static const struct { 17 static const struct {
16 const wchar_t* username; 18 const char* username;
17 const wchar_t* password; 19 const char* password;
18 const char* expected_credentials; 20 const char* expected_credentials;
19 } tests[] = { 21 } tests[] = {
20 { L"foo", L"bar", "Basic Zm9vOmJhcg==" }, 22 { "foo", "bar", "Basic Zm9vOmJhcg==" },
21 // Empty username 23 // Empty username
22 { L"", L"foobar", "Basic OmZvb2Jhcg==" }, 24 { "", "foobar", "Basic OmZvb2Jhcg==" },
23 // Empty password 25 // Empty password
24 { L"anon", L"", "Basic YW5vbjo=" }, 26 { "anon", "", "Basic YW5vbjo=" },
25 // Empty username and empty password. 27 // Empty username and empty password.
26 { L"", L"", "Basic Og==" }, 28 { "", "", "Basic Og==" },
27 }; 29 };
28 GURL origin("http://www.example.com"); 30 GURL origin("http://www.example.com");
29 HttpAuthHandlerBasic::Factory factory; 31 HttpAuthHandlerBasic::Factory factory;
30 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 32 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
31 std::string challenge = "Basic realm=\"Atlantis\""; 33 std::string challenge = "Basic realm=\"Atlantis\"";
32 scoped_ptr<HttpAuthHandler> basic; 34 scoped_ptr<HttpAuthHandler> basic;
33 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( 35 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString(
34 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); 36 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic));
35 std::wstring username(tests[i].username); 37 string16 username(ASCIIToUTF16(tests[i].username));
36 std::wstring password(tests[i].password); 38 string16 password(ASCIIToUTF16(tests[i].password));
37 HttpRequestInfo request_info; 39 HttpRequestInfo request_info;
38 std::string auth_token; 40 std::string auth_token;
39 int rv = basic->GenerateAuthToken(&username, &password, &request_info, 41 int rv = basic->GenerateAuthToken(&username, &password, &request_info,
40 NULL, &auth_token); 42 NULL, &auth_token);
41 EXPECT_EQ(OK, rv); 43 EXPECT_EQ(OK, rv);
42 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); 44 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str());
43 } 45 }
44 } 46 }
45 47
46 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { 48 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) {
(...skipping 23 matching lines...) Expand all
70 std::string challenge = tests[i].challenge; 72 std::string challenge = tests[i].challenge;
71 scoped_ptr<HttpAuthHandler> basic; 73 scoped_ptr<HttpAuthHandler> basic;
72 int rv = factory.CreateAuthHandlerFromString( 74 int rv = factory.CreateAuthHandlerFromString(
73 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); 75 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic);
74 EXPECT_EQ(tests[i].expected_rv, rv); 76 EXPECT_EQ(tests[i].expected_rv, rv);
75 if (rv == OK) 77 if (rv == OK)
76 EXPECT_EQ(tests[i].expected_realm, basic->realm()); 78 EXPECT_EQ(tests[i].expected_realm, basic->realm());
77 } 79 }
78 } 80 }
79 81
80 } // namespace net 82 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_basic.cc ('k') | net/http/http_auth_handler_digest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698