OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 string16 password(ASCIIToUTF16(tests[i].password)); | 39 string16 password(ASCIIToUTF16(tests[i].password)); |
40 HttpRequestInfo request_info; | 40 HttpRequestInfo request_info; |
41 std::string auth_token; | 41 std::string auth_token; |
42 int rv = basic->GenerateAuthToken(&username, &password, &request_info, | 42 int rv = basic->GenerateAuthToken(&username, &password, &request_info, |
43 NULL, &auth_token); | 43 NULL, &auth_token); |
44 EXPECT_EQ(OK, rv); | 44 EXPECT_EQ(OK, rv); |
45 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); | 45 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
| 49 TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) { |
| 50 GURL origin("http://www.example.com"); |
| 51 std::string challenge1 = "Basic realm=\"First\""; |
| 52 std::string challenge2 = "Basic realm=\"Second\""; |
| 53 HttpAuthHandlerBasic::Factory factory; |
| 54 scoped_ptr<HttpAuthHandler> basic; |
| 55 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
| 56 challenge1, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); |
| 57 HttpAuth::ChallengeTokenizer tok_first(challenge1.begin(), |
| 58 challenge1.end()); |
| 59 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
| 60 basic->HandleAnotherChallenge(&tok_first)); |
| 61 |
| 62 HttpAuth::ChallengeTokenizer tok_second(challenge2.begin(), |
| 63 challenge2.end()); |
| 64 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM, |
| 65 basic->HandleAnotherChallenge(&tok_second)); |
| 66 } |
| 67 |
49 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { | 68 TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { |
50 static const struct { | 69 static const struct { |
51 const char* challenge; | 70 const char* challenge; |
52 int expected_rv; | 71 int expected_rv; |
53 const char* expected_realm; | 72 const char* expected_realm; |
54 } tests[] = { | 73 } tests[] = { |
55 // No realm (we allow this even though realm is supposed to be required | 74 // No realm (we allow this even though realm is supposed to be required |
56 // according to RFC 2617.) | 75 // according to RFC 2617.) |
57 { | 76 { |
58 "Basic", | 77 "Basic", |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 scoped_ptr<HttpAuthHandler> basic; | 139 scoped_ptr<HttpAuthHandler> basic; |
121 int rv = factory.CreateAuthHandlerFromString( | 140 int rv = factory.CreateAuthHandlerFromString( |
122 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); | 141 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); |
123 EXPECT_EQ(tests[i].expected_rv, rv); | 142 EXPECT_EQ(tests[i].expected_rv, rv); |
124 if (rv == OK) | 143 if (rv == OK) |
125 EXPECT_EQ(tests[i].expected_realm, basic->realm()); | 144 EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
126 } | 145 } |
127 } | 146 } |
128 | 147 |
129 } // namespace net | 148 } // namespace net |
OLD | NEW |