OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 { "foo", "bar", "Basic Zm9vOmJhcg==" }, | 25 { "foo", "bar", "Basic Zm9vOmJhcg==" }, |
26 // Empty username | 26 // Empty username |
27 { "", "foobar", "Basic OmZvb2Jhcg==" }, | 27 { "", "foobar", "Basic OmZvb2Jhcg==" }, |
28 // Empty password | 28 // Empty password |
29 { "anon", "", "Basic YW5vbjo=" }, | 29 { "anon", "", "Basic YW5vbjo=" }, |
30 // Empty username and empty password. | 30 // Empty username and empty password. |
31 { "", "", "Basic Og==" }, | 31 { "", "", "Basic Og==" }, |
32 }; | 32 }; |
33 GURL origin("http://www.example.com"); | 33 GURL origin("http://www.example.com"); |
34 HttpAuthHandlerBasic::Factory factory; | 34 HttpAuthHandlerBasic::Factory factory; |
35 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 35 for (size_t i = 0; i < arraysize(tests); ++i) { |
36 std::string challenge = "Basic realm=\"Atlantis\""; | 36 std::string challenge = "Basic realm=\"Atlantis\""; |
37 scoped_ptr<HttpAuthHandler> basic; | 37 scoped_ptr<HttpAuthHandler> basic; |
38 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 38 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
39 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); | 39 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); |
40 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), | 40 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), |
41 base::ASCIIToUTF16(tests[i].password)); | 41 base::ASCIIToUTF16(tests[i].password)); |
42 HttpRequestInfo request_info; | 42 HttpRequestInfo request_info; |
43 std::string auth_token; | 43 std::string auth_token; |
44 int rv = basic->GenerateAuthToken(&credentials, &request_info, | 44 int rv = basic->GenerateAuthToken(&credentials, &request_info, |
45 CompletionCallback(), &auth_token); | 45 CompletionCallback(), &auth_token); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 }; | 84 }; |
85 | 85 |
86 GURL origin("http://www.example.com"); | 86 GURL origin("http://www.example.com"); |
87 HttpAuthHandlerBasic::Factory factory; | 87 HttpAuthHandlerBasic::Factory factory; |
88 scoped_ptr<HttpAuthHandler> basic; | 88 scoped_ptr<HttpAuthHandler> basic; |
89 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 89 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
90 tests[0].challenge, HttpAuth::AUTH_SERVER, origin, | 90 tests[0].challenge, HttpAuth::AUTH_SERVER, origin, |
91 BoundNetLog(), &basic)); | 91 BoundNetLog(), &basic)); |
92 | 92 |
93 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 93 for (size_t i = 0; i < arraysize(tests); ++i) { |
94 std::string challenge(tests[i].challenge); | 94 std::string challenge(tests[i].challenge); |
95 HttpAuthChallengeTokenizer tok(challenge.begin(), | 95 HttpAuthChallengeTokenizer tok(challenge.begin(), |
96 challenge.end()); | 96 challenge.end()); |
97 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(&tok)); | 97 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(&tok)); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { | 101 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { |
102 static const struct { | 102 static const struct { |
103 const char* challenge; | 103 const char* challenge; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // Handle ISO-8859-1 character as part of the realm. The realm is converted | 176 // Handle ISO-8859-1 character as part of the realm. The realm is converted |
177 // to UTF-8. | 177 // to UTF-8. |
178 { | 178 { |
179 "Basic realm=\"foo-\xE5\"", | 179 "Basic realm=\"foo-\xE5\"", |
180 OK, | 180 OK, |
181 "foo-\xC3\xA5", | 181 "foo-\xC3\xA5", |
182 }, | 182 }, |
183 }; | 183 }; |
184 HttpAuthHandlerBasic::Factory factory; | 184 HttpAuthHandlerBasic::Factory factory; |
185 GURL origin("http://www.example.com"); | 185 GURL origin("http://www.example.com"); |
186 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 186 for (size_t i = 0; i < arraysize(tests); ++i) { |
187 std::string challenge = tests[i].challenge; | 187 std::string challenge = tests[i].challenge; |
188 scoped_ptr<HttpAuthHandler> basic; | 188 scoped_ptr<HttpAuthHandler> basic; |
189 int rv = factory.CreateAuthHandlerFromString( | 189 int rv = factory.CreateAuthHandlerFromString( |
190 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); | 190 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); |
191 EXPECT_EQ(tests[i].expected_rv, rv); | 191 EXPECT_EQ(tests[i].expected_rv, rv); |
192 if (rv == OK) | 192 if (rv == OK) |
193 EXPECT_EQ(tests[i].expected_realm, basic->realm()); | 193 EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 } // namespace net | 197 } // namespace net |
OLD | NEW |