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 "net/http/http_auth_handler_basic.h" | 5 #include "net/http/http_auth_handler_basic.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 { "", "", "Basic Og==" }, | 37 { "", "", "Basic Og==" }, |
38 }; | 38 }; |
39 GURL origin("http://www.example.com"); | 39 GURL origin("http://www.example.com"); |
40 HttpAuthHandlerBasic::Factory factory; | 40 HttpAuthHandlerBasic::Factory factory; |
41 for (size_t i = 0; i < arraysize(tests); ++i) { | 41 for (size_t i = 0; i < arraysize(tests); ++i) { |
42 std::string challenge = "Basic realm=\"Atlantis\""; | 42 std::string challenge = "Basic realm=\"Atlantis\""; |
43 SSLInfo null_ssl_info; | 43 SSLInfo null_ssl_info; |
44 std::unique_ptr<HttpAuthHandler> basic; | 44 std::unique_ptr<HttpAuthHandler> basic; |
45 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 45 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
46 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, | 46 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, |
47 BoundNetLog(), &basic)); | 47 NetLogWithSource(), &basic)); |
48 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), | 48 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), |
49 base::ASCIIToUTF16(tests[i].password)); | 49 base::ASCIIToUTF16(tests[i].password)); |
50 HttpRequestInfo request_info; | 50 HttpRequestInfo request_info; |
51 std::string auth_token; | 51 std::string auth_token; |
52 TestCompletionCallback callback; | 52 TestCompletionCallback callback; |
53 int rv = basic->GenerateAuthToken(&credentials, &request_info, | 53 int rv = basic->GenerateAuthToken(&credentials, &request_info, |
54 callback.callback(), &auth_token); | 54 callback.callback(), &auth_token); |
55 EXPECT_THAT(rv, IsOk()); | 55 EXPECT_THAT(rv, IsOk()); |
56 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); | 56 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); |
57 } | 57 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM | 91 HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM |
92 } | 92 } |
93 }; | 93 }; |
94 | 94 |
95 GURL origin("http://www.example.com"); | 95 GURL origin("http://www.example.com"); |
96 HttpAuthHandlerBasic::Factory factory; | 96 HttpAuthHandlerBasic::Factory factory; |
97 SSLInfo null_ssl_info; | 97 SSLInfo null_ssl_info; |
98 std::unique_ptr<HttpAuthHandler> basic; | 98 std::unique_ptr<HttpAuthHandler> basic; |
99 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 99 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
100 tests[0].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, | 100 tests[0].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, |
101 origin, BoundNetLog(), &basic)); | 101 origin, NetLogWithSource(), &basic)); |
102 | 102 |
103 for (size_t i = 0; i < arraysize(tests); ++i) { | 103 for (size_t i = 0; i < arraysize(tests); ++i) { |
104 std::string challenge(tests[i].challenge); | 104 std::string challenge(tests[i].challenge); |
105 HttpAuthChallengeTokenizer tok(challenge.begin(), | 105 HttpAuthChallengeTokenizer tok(challenge.begin(), |
106 challenge.end()); | 106 challenge.end()); |
107 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(&tok)); | 107 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(&tok)); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { | 111 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 "foo-\xC3\xA5", | 191 "foo-\xC3\xA5", |
192 }, | 192 }, |
193 }; | 193 }; |
194 HttpAuthHandlerBasic::Factory factory; | 194 HttpAuthHandlerBasic::Factory factory; |
195 GURL origin("http://www.example.com"); | 195 GURL origin("http://www.example.com"); |
196 for (size_t i = 0; i < arraysize(tests); ++i) { | 196 for (size_t i = 0; i < arraysize(tests); ++i) { |
197 std::string challenge = tests[i].challenge; | 197 std::string challenge = tests[i].challenge; |
198 SSLInfo null_ssl_info; | 198 SSLInfo null_ssl_info; |
199 std::unique_ptr<HttpAuthHandler> basic; | 199 std::unique_ptr<HttpAuthHandler> basic; |
200 int rv = factory.CreateAuthHandlerFromString( | 200 int rv = factory.CreateAuthHandlerFromString( |
201 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, BoundNetLog(), | 201 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, |
202 &basic); | 202 NetLogWithSource(), &basic); |
203 EXPECT_EQ(tests[i].expected_rv, rv); | 203 EXPECT_EQ(tests[i].expected_rv, rv); |
204 if (rv == OK) | 204 if (rv == OK) |
205 EXPECT_EQ(tests[i].expected_realm, basic->realm()); | 205 EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 } // namespace net | 209 } // namespace net |
OLD | NEW |