OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/internal_auth.h" | 5 #include "chrome/browser/internal_auth.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::map<std::string, std::string> map; | 62 std::map<std::string, std::string> map; |
63 map["key"] = "value"; | 63 map["key"] = "value"; |
64 // Trying huge domain. | 64 // Trying huge domain. |
65 std::string token = InternalAuthGeneration::GeneratePassport( | 65 std::string token = InternalAuthGeneration::GeneratePassport( |
66 long_string_, map); | 66 long_string_, map); |
67 ASSERT_TRUE(token.empty()); | 67 ASSERT_TRUE(token.empty()); |
68 ASSERT_FALSE(InternalAuthVerification::VerifyPassport( | 68 ASSERT_FALSE(InternalAuthVerification::VerifyPassport( |
69 token, long_string_, map)); | 69 token, long_string_, map)); |
70 | 70 |
71 // Trying empty domain. | 71 // Trying empty domain. |
72 token = InternalAuthGeneration::GeneratePassport("", map); | 72 token = InternalAuthGeneration::GeneratePassport(std::string(), map); |
73 ASSERT_TRUE(token.empty()); | 73 ASSERT_TRUE(token.empty()); |
74 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "", map)); | 74 ASSERT_FALSE( |
| 75 InternalAuthVerification::VerifyPassport(token, std::string(), map)); |
75 | 76 |
76 std::string dummy("abcdefghij"); | 77 std::string dummy("abcdefghij"); |
77 for (size_t i = 1000; i--;) { | 78 for (size_t i = 1000; i--;) { |
78 std::string key = dummy; | 79 std::string key = dummy; |
79 std::next_permutation(dummy.begin(), dummy.end()); | 80 std::next_permutation(dummy.begin(), dummy.end()); |
80 std::string value = dummy; | 81 std::string value = dummy; |
81 std::next_permutation(dummy.begin(), dummy.end()); | 82 std::next_permutation(dummy.begin(), dummy.end()); |
82 map[key] = value; | 83 map[key] = value; |
83 } | 84 } |
84 // Trying huge var=value map. | 85 // Trying huge var=value map. |
85 token = InternalAuthGeneration::GeneratePassport("zapata", map); | 86 token = InternalAuthGeneration::GeneratePassport("zapata", map); |
86 ASSERT_TRUE(token.empty()); | 87 ASSERT_TRUE(token.empty()); |
87 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); | 88 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); |
88 | 89 |
89 map.clear(); | 90 map.clear(); |
90 map[""] = "value"; | 91 map[std::string()] = "value"; |
91 // Trying empty key. | 92 // Trying empty key. |
92 token = InternalAuthGeneration::GeneratePassport("zapata", map); | 93 token = InternalAuthGeneration::GeneratePassport("zapata", map); |
93 ASSERT_TRUE(token.empty()); | 94 ASSERT_TRUE(token.empty()); |
94 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); | 95 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); |
95 } | 96 } |
96 | 97 |
97 TEST_F(InternalAuthTest, BasicVerification) { | 98 TEST_F(InternalAuthTest, BasicVerification) { |
98 std::map<std::string, std::string> map; | 99 std::map<std::string, std::string> map; |
99 map["key"] = "value"; | 100 map["key"] = "value"; |
100 std::string token = InternalAuthGeneration::GeneratePassport("zapata", map); | 101 std::string token = InternalAuthGeneration::GeneratePassport("zapata", map); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 179 |
179 token = InternalAuthGeneration::GeneratePassport("zapata", map); | 180 token = InternalAuthGeneration::GeneratePassport("zapata", map); |
180 ASSERT_GT(token.size(), 10u); | 181 ASSERT_GT(token.size(), 10u); |
181 for (int i = 20; i--;) | 182 for (int i = 20; i--;) |
182 InternalAuthGeneration::GenerateNewKey(); | 183 InternalAuthGeneration::GenerateNewKey(); |
183 // Passport should not survive series of key changes. | 184 // Passport should not survive series of key changes. |
184 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); | 185 ASSERT_FALSE(InternalAuthVerification::VerifyPassport(token, "zapata", map)); |
185 } | 186 } |
186 | 187 |
187 } // namespace chrome | 188 } // namespace chrome |
OLD | NEW |