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/string16.h" | 7 #include "base/string16.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 HttpAuth::AUTH_SERVER)); | 99 HttpAuth::AUTH_SERVER)); |
100 cache.Add(origin, realm2_handler->realm(), realm2_handler->auth_scheme(), | 100 cache.Add(origin, realm2_handler->realm(), realm2_handler->auth_scheme(), |
101 "Basic realm=Realm2", | 101 "Basic realm=Realm2", |
102 CreateASCIICredentials("realm2-user", "realm2-password"), | 102 CreateASCIICredentials("realm2-user", "realm2-password"), |
103 "/foo2/index.html"); | 103 "/foo2/index.html"); |
104 | 104 |
105 scoped_ptr<HttpAuthHandler> realm3_basic_handler( | 105 scoped_ptr<HttpAuthHandler> realm3_basic_handler( |
106 new MockAuthHandler(HttpAuth::AUTH_SCHEME_BASIC, | 106 new MockAuthHandler(HttpAuth::AUTH_SCHEME_BASIC, |
107 kRealm3, | 107 kRealm3, |
108 HttpAuth::AUTH_PROXY)); | 108 HttpAuth::AUTH_PROXY)); |
109 cache.Add(origin, realm3_basic_handler->realm(), | 109 cache.Add( |
110 realm3_basic_handler->auth_scheme(), "Basic realm=Realm3", | 110 origin, |
111 CreateASCIICredentials("realm3-basic-user", | 111 realm3_basic_handler->realm(), |
112 "realm3-basic-password"), | 112 realm3_basic_handler->auth_scheme(), |
113 ""); | 113 "Basic realm=Realm3", |
| 114 CreateASCIICredentials("realm3-basic-user", "realm3-basic-password"), |
| 115 std::string()); |
114 | 116 |
115 scoped_ptr<HttpAuthHandler> realm3_digest_handler( | 117 scoped_ptr<HttpAuthHandler> realm3_digest_handler( |
116 new MockAuthHandler(HttpAuth::AUTH_SCHEME_DIGEST, | 118 new MockAuthHandler(HttpAuth::AUTH_SCHEME_DIGEST, |
117 kRealm3, | 119 kRealm3, |
118 HttpAuth::AUTH_PROXY)); | 120 HttpAuth::AUTH_PROXY)); |
119 cache.Add(origin, realm3_digest_handler->realm(), | 121 cache.Add(origin, realm3_digest_handler->realm(), |
120 realm3_digest_handler->auth_scheme(), "Digest realm=Realm3", | 122 realm3_digest_handler->auth_scheme(), "Digest realm=Realm3", |
121 CreateASCIICredentials("realm3-digest-user", | 123 CreateASCIICredentials("realm3-digest-user", |
122 "realm3-digest-password"), | 124 "realm3-digest-password"), |
123 "/baz/index.html"); | 125 "/baz/index.html"); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 entry = cache.LookupByPath(origin, "/foo2/"); | 200 entry = cache.LookupByPath(origin, "/foo2/"); |
199 EXPECT_TRUE(realm2_entry == entry); | 201 EXPECT_TRUE(realm2_entry == entry); |
200 entry = cache.LookupByPath(origin, "/foo2"); | 202 entry = cache.LookupByPath(origin, "/foo2"); |
201 EXPECT_TRUE(realm4_entry == entry); | 203 EXPECT_TRUE(realm4_entry == entry); |
202 entry = cache.LookupByPath(origin, "/"); | 204 entry = cache.LookupByPath(origin, "/"); |
203 EXPECT_TRUE(realm4_entry == entry); | 205 EXPECT_TRUE(realm4_entry == entry); |
204 | 206 |
205 // Negative tests: | 207 // Negative tests: |
206 entry = cache.LookupByPath(origin, "/foo3/index.html"); | 208 entry = cache.LookupByPath(origin, "/foo3/index.html"); |
207 EXPECT_FALSE(realm2_entry == entry); | 209 EXPECT_FALSE(realm2_entry == entry); |
208 entry = cache.LookupByPath(origin, ""); | 210 entry = cache.LookupByPath(origin, std::string()); |
209 EXPECT_FALSE(realm2_entry == entry); | 211 EXPECT_FALSE(realm2_entry == entry); |
210 | 212 |
211 // Confirm we find the same realm, different auth scheme by path lookup | 213 // Confirm we find the same realm, different auth scheme by path lookup |
212 HttpAuthCache::Entry* realm3_digest_entry = | 214 HttpAuthCache::Entry* realm3_digest_entry = |
213 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); | 215 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); |
214 EXPECT_FALSE(NULL == realm3_digest_entry); | 216 EXPECT_FALSE(NULL == realm3_digest_entry); |
215 entry = cache.LookupByPath(origin, "/baz/index.html"); | 217 entry = cache.LookupByPath(origin, "/baz/index.html"); |
216 EXPECT_TRUE(realm3_digest_entry == entry); | 218 EXPECT_TRUE(realm3_digest_entry == entry); |
217 entry = cache.LookupByPath(origin, "/baz/"); | 219 entry = cache.LookupByPath(origin, "/baz/"); |
218 EXPECT_TRUE(realm3_digest_entry == entry); | 220 EXPECT_TRUE(realm3_digest_entry == entry); |
219 entry = cache.LookupByPath(origin, "/baz"); | 221 entry = cache.LookupByPath(origin, "/baz"); |
220 EXPECT_FALSE(realm3_digest_entry == entry); | 222 EXPECT_FALSE(realm3_digest_entry == entry); |
221 | 223 |
222 // Confirm we find the same realm, different auth scheme by path lookup | 224 // Confirm we find the same realm, different auth scheme by path lookup |
223 HttpAuthCache::Entry* realm3DigestEntry = | 225 HttpAuthCache::Entry* realm3DigestEntry = |
224 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); | 226 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); |
225 EXPECT_FALSE(NULL == realm3DigestEntry); | 227 EXPECT_FALSE(NULL == realm3DigestEntry); |
226 entry = cache.LookupByPath(origin, "/baz/index.html"); | 228 entry = cache.LookupByPath(origin, "/baz/index.html"); |
227 EXPECT_TRUE(realm3DigestEntry == entry); | 229 EXPECT_TRUE(realm3DigestEntry == entry); |
228 entry = cache.LookupByPath(origin, "/baz/"); | 230 entry = cache.LookupByPath(origin, "/baz/"); |
229 EXPECT_TRUE(realm3DigestEntry == entry); | 231 EXPECT_TRUE(realm3DigestEntry == entry); |
230 entry = cache.LookupByPath(origin, "/baz"); | 232 entry = cache.LookupByPath(origin, "/baz"); |
231 EXPECT_FALSE(realm3DigestEntry == entry); | 233 EXPECT_FALSE(realm3DigestEntry == entry); |
232 | 234 |
233 // Lookup using empty path (may be used for proxy). | 235 // Lookup using empty path (may be used for proxy). |
234 entry = cache.LookupByPath(origin, ""); | 236 entry = cache.LookupByPath(origin, std::string()); |
235 EXPECT_FALSE(NULL == entry); | 237 EXPECT_FALSE(NULL == entry); |
236 EXPECT_EQ(HttpAuth::AUTH_SCHEME_BASIC, entry->scheme()); | 238 EXPECT_EQ(HttpAuth::AUTH_SCHEME_BASIC, entry->scheme()); |
237 EXPECT_EQ(kRealm3, entry->realm()); | 239 EXPECT_EQ(kRealm3, entry->realm()); |
238 } | 240 } |
239 | 241 |
240 TEST(HttpAuthCacheTest, AddPath) { | 242 TEST(HttpAuthCacheTest, AddPath) { |
241 HttpAuthCache::Entry entry; | 243 HttpAuthCache::Entry entry; |
242 | 244 |
243 // All of these paths have a common root /1/2/2/4/5/ | 245 // All of these paths have a common root /1/2/2/4/5/ |
244 entry.AddPath("/1/2/3/4/5/x.txt"); | 246 entry.AddPath("/1/2/3/4/5/x.txt"); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 535 |
534 std::string GeneratePath(int realm_i, int path_i) { | 536 std::string GeneratePath(int realm_i, int path_i) { |
535 return base::StringPrintf("/%d/%d/x/y", realm_i, path_i); | 537 return base::StringPrintf("/%d/%d/x/y", realm_i, path_i); |
536 } | 538 } |
537 | 539 |
538 void AddRealm(int realm_i) { | 540 void AddRealm(int realm_i) { |
539 AddPathToRealm(realm_i, 0); | 541 AddPathToRealm(realm_i, 0); |
540 } | 542 } |
541 | 543 |
542 void AddPathToRealm(int realm_i, int path_i) { | 544 void AddPathToRealm(int realm_i, int path_i) { |
543 cache_.Add(origin_, GenerateRealm(realm_i), HttpAuth::AUTH_SCHEME_BASIC, "", | 545 cache_.Add(origin_, |
| 546 GenerateRealm(realm_i), |
| 547 HttpAuth::AUTH_SCHEME_BASIC, |
| 548 std::string(), |
544 AuthCredentials(kUsername, kPassword), | 549 AuthCredentials(kUsername, kPassword), |
545 GeneratePath(realm_i, path_i)); | 550 GeneratePath(realm_i, path_i)); |
546 } | 551 } |
547 | 552 |
548 void CheckRealmExistence(int realm_i, bool exists) { | 553 void CheckRealmExistence(int realm_i, bool exists) { |
549 const HttpAuthCache::Entry* entry = | 554 const HttpAuthCache::Entry* entry = |
550 cache_.Lookup( | 555 cache_.Lookup( |
551 origin_, GenerateRealm(realm_i), HttpAuth::AUTH_SCHEME_BASIC); | 556 origin_, GenerateRealm(realm_i), HttpAuth::AUTH_SCHEME_BASIC); |
552 if (exists) { | 557 if (exists) { |
553 EXPECT_FALSE(entry == NULL); | 558 EXPECT_FALSE(entry == NULL); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 CheckPathExistence(0, i, false); | 617 CheckPathExistence(0, i, false); |
613 | 618 |
614 for (int i = 0; i < kMaxPaths; ++i) | 619 for (int i = 0; i < kMaxPaths; ++i) |
615 CheckPathExistence(0, i + 3, true); | 620 CheckPathExistence(0, i + 3, true); |
616 | 621 |
617 for (int i = 0; i < kMaxRealms; ++i) | 622 for (int i = 0; i < kMaxRealms; ++i) |
618 CheckRealmExistence(i, true); | 623 CheckRealmExistence(i, true); |
619 } | 624 } |
620 | 625 |
621 } // namespace net | 626 } // namespace net |
OLD | NEW |