| 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 25 matching lines...) Expand all Loading... |
| 36 for (size_t i = 0; i < arraysize(tests); ++i) { | 36 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 37 std::string challenge = "Basic realm=\"Atlantis\""; | 37 std::string challenge = "Basic realm=\"Atlantis\""; |
| 38 scoped_ptr<HttpAuthHandler> basic; | 38 scoped_ptr<HttpAuthHandler> basic; |
| 39 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 39 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
| 40 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); | 40 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); |
| 41 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), | 41 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), |
| 42 base::ASCIIToUTF16(tests[i].password)); | 42 base::ASCIIToUTF16(tests[i].password)); |
| 43 HttpRequestInfo request_info; | 43 HttpRequestInfo request_info; |
| 44 std::string auth_token; | 44 std::string auth_token; |
| 45 TestCompletionCallback callback; | 45 TestCompletionCallback callback; |
| 46 int rv = basic->GenerateAuthToken(&credentials, &request_info, | 46 int rv = basic->GenerateAuthToken(&credentials, request_info, |
| 47 callback.callback(), &auth_token); | 47 callback.callback(), &auth_token); |
| 48 EXPECT_EQ(OK, rv); | 48 EXPECT_EQ(OK, rv); |
| 49 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); | 49 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) { | 53 TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) { |
| 54 static const struct { | 54 static const struct { |
| 55 const char* challenge; | 55 const char* challenge; |
| 56 HttpAuth::AuthorizationResult expected_rv; | 56 HttpAuth::AuthorizationResult expected_rv; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 HttpAuthHandlerBasic::Factory factory; | 89 HttpAuthHandlerBasic::Factory factory; |
| 90 scoped_ptr<HttpAuthHandler> basic; | 90 scoped_ptr<HttpAuthHandler> basic; |
| 91 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( | 91 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
| 92 tests[0].challenge, HttpAuth::AUTH_SERVER, origin, | 92 tests[0].challenge, HttpAuth::AUTH_SERVER, origin, |
| 93 BoundNetLog(), &basic)); | 93 BoundNetLog(), &basic)); |
| 94 | 94 |
| 95 for (size_t i = 0; i < arraysize(tests); ++i) { | 95 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 96 std::string challenge(tests[i].challenge); | 96 std::string challenge(tests[i].challenge); |
| 97 HttpAuthChallengeTokenizer tok(challenge.begin(), | 97 HttpAuthChallengeTokenizer tok(challenge.begin(), |
| 98 challenge.end()); | 98 challenge.end()); |
| 99 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(&tok)); | 99 EXPECT_EQ(tests[i].expected_rv, basic->HandleAnotherChallenge(tok)); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { | 103 TEST(HttpAuthHandlerBasicTest, HandleInitialChallenge) { |
| 104 static const struct { | 104 static const struct { |
| 105 const char* challenge; | 105 const char* challenge; |
| 106 int expected_rv; | 106 int expected_rv; |
| 107 const char* expected_realm; | 107 const char* expected_realm; |
| 108 } tests[] = { | 108 } tests[] = { |
| 109 // No realm (we allow this even though realm is supposed to be required | 109 // No realm (we allow this even though realm is supposed to be required |
| 110 // according to RFC 2617.) | 110 // according to RFC 2617.) |
| 111 { | 111 { |
| 112 "Basic", | 112 "Basic", |
| 113 OK, | 113 OK, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 scoped_ptr<HttpAuthHandler> basic; | 190 scoped_ptr<HttpAuthHandler> basic; |
| 191 int rv = factory.CreateAuthHandlerFromString( | 191 int rv = factory.CreateAuthHandlerFromString( |
| 192 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); | 192 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); |
| 193 EXPECT_EQ(tests[i].expected_rv, rv); | 193 EXPECT_EQ(tests[i].expected_rv, rv); |
| 194 if (rv == OK) | 194 if (rv == OK) |
| 195 EXPECT_EQ(tests[i].expected_realm, basic->realm()); | 195 EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace net | 199 } // namespace net |
| OLD | NEW |