OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/tls_client_login_cache.h" |
| 6 |
| 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/auth.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 TEST(TLSClientLoginCacheTest, LookupAddRemove) { |
| 15 TLSClientLoginCache cache; |
| 16 |
| 17 std::string server1("foo1:443"); |
| 18 scoped_refptr<AuthData> auth_data1(new AuthData); |
| 19 auth_data1->username = ASCIIToUTF16("user1"); |
| 20 auth_data1->password = ASCIIToUTF16("secret1"); |
| 21 |
| 22 std::string server2("foo2:443"); |
| 23 scoped_refptr<AuthData> auth_data2(new AuthData); |
| 24 auth_data2->username = ASCIIToUTF16("user2"); |
| 25 auth_data2->password = ASCIIToUTF16("secret2"); |
| 26 |
| 27 std::string server3("foo3:443"); |
| 28 scoped_refptr<AuthData> auth_data3(new AuthData); |
| 29 auth_data3->username = ASCIIToUTF16("user3"); |
| 30 auth_data3->password = ASCIIToUTF16("secret3"); |
| 31 |
| 32 scoped_refptr<AuthData> cached_auth_data; |
| 33 // Lookup non-existent TLS login credentials. |
| 34 cached_auth_data = NULL; |
| 35 EXPECT_FALSE(cache.Lookup(server1, &cached_auth_data)); |
| 36 |
| 37 // Add TLS login credentials for server1. |
| 38 cache.Add(server1, auth_data1); |
| 39 cached_auth_data = NULL; |
| 40 EXPECT_TRUE(cache.Lookup(server1, &cached_auth_data)); |
| 41 EXPECT_EQ(auth_data1, cached_auth_data); |
| 42 |
| 43 // Add TLS login credentials for server2. |
| 44 cache.Add(server2, auth_data2); |
| 45 cached_auth_data = NULL; |
| 46 EXPECT_TRUE(cache.Lookup(server1, &cached_auth_data)); |
| 47 EXPECT_EQ(auth_data1, cached_auth_data.get()); |
| 48 cached_auth_data = NULL; |
| 49 EXPECT_TRUE(cache.Lookup(server2, &cached_auth_data)); |
| 50 EXPECT_EQ(auth_data2, cached_auth_data); |
| 51 |
| 52 // Overwrite the TLS login credentials for server1. |
| 53 cache.Add(server1, auth_data3); |
| 54 cached_auth_data = NULL; |
| 55 EXPECT_TRUE(cache.Lookup(server1, &cached_auth_data)); |
| 56 EXPECT_EQ(auth_data3, cached_auth_data); |
| 57 cached_auth_data = NULL; |
| 58 EXPECT_TRUE(cache.Lookup(server2, &cached_auth_data)); |
| 59 EXPECT_EQ(auth_data2, cached_auth_data); |
| 60 |
| 61 // Remove TLS login credentials of server1. |
| 62 cache.Remove(server1); |
| 63 cached_auth_data = NULL; |
| 64 EXPECT_FALSE(cache.Lookup(server1, &cached_auth_data)); |
| 65 cached_auth_data = NULL; |
| 66 EXPECT_TRUE(cache.Lookup(server2, &cached_auth_data)); |
| 67 EXPECT_EQ(auth_data2, cached_auth_data); |
| 68 |
| 69 // Remove non-existent TLS login credentials. |
| 70 cache.Remove(server1); |
| 71 cached_auth_data = NULL; |
| 72 EXPECT_FALSE(cache.Lookup(server1, &cached_auth_data)); |
| 73 cached_auth_data = NULL; |
| 74 EXPECT_TRUE(cache.Lookup(server2, &cached_auth_data)); |
| 75 EXPECT_EQ(auth_data2, cached_auth_data); |
| 76 } |
| 77 |
| 78 // Check that if the server differs only by port number, it is considered |
| 79 // a separate server. |
| 80 TEST(TLSClientLoginCacheTest, LookupWithPort) { |
| 81 TLSClientLoginCache cache; |
| 82 |
| 83 std::string server1("foo1:443"); |
| 84 scoped_refptr<AuthData> auth_data1(new AuthData); |
| 85 auth_data1->username = ASCIIToUTF16("user1"); |
| 86 auth_data1->password = ASCIIToUTF16("secret1"); |
| 87 |
| 88 std::string server2("foo2:8443"); |
| 89 scoped_refptr<AuthData> auth_data2(new AuthData); |
| 90 auth_data2->username = ASCIIToUTF16("user2"); |
| 91 auth_data2->password = ASCIIToUTF16("secret2"); |
| 92 |
| 93 cache.Add(server1, auth_data1.get()); |
| 94 cache.Add(server2, auth_data2.get()); |
| 95 |
| 96 scoped_refptr<AuthData> cached_auth_data; |
| 97 EXPECT_TRUE(cache.Lookup(server1, &cached_auth_data)); |
| 98 EXPECT_EQ(auth_data1.get(), cached_auth_data); |
| 99 EXPECT_TRUE(cache.Lookup(server2, &cached_auth_data)); |
| 100 EXPECT_EQ(auth_data2.get(), cached_auth_data); |
| 101 } |
| 102 |
| 103 } // namespace net |
OLD | NEW |