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 "net/base/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/nss_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 KeygenHandler::KeyLocation ValidKeyLocation() { | 18 KeygenHandler::KeyLocation ValidKeyLocation() { |
18 KeygenHandler::KeyLocation result; | 19 KeygenHandler::KeyLocation result; |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 result.container_name = L"Unit tests"; | 21 result.container_name = L"Unit tests"; |
21 result.provider_name = L"Test Provider"; | 22 result.provider_name = L"Test Provider"; |
22 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
23 result.keychain_path = "/Users/tests/test.chain"; | 24 result.keychain_path = "/Users/tests/test.chain"; |
24 #elif defined(USE_NSS) | 25 #elif defined(USE_NSS) |
25 result.slot_name = "Sample slot"; | 26 result.slot_name = "Sample slot"; |
26 #endif | 27 #endif |
27 | 28 |
28 return result; | 29 return result; |
29 } | 30 } |
30 | 31 |
31 TEST(KeygenHandlerTest, FLAKY_SmokeTest) { | 32 class KeygenHandlerTest : public ::testing::Test { |
| 33 public: |
| 34 KeygenHandlerTest() {} |
| 35 virtual ~KeygenHandlerTest() {} |
| 36 |
| 37 virtual void SetUp() { |
| 38 #if defined(OS_CHROMEOS) |
| 39 base::OpenPersistentNSSDB(); |
| 40 #endif |
| 41 } |
| 42 }; |
| 43 |
| 44 TEST_F(KeygenHandlerTest, FLAKY_SmokeTest) { |
32 KeygenHandler handler(2048, "some challenge"); | 45 KeygenHandler handler(2048, "some challenge"); |
33 handler.set_stores_key(false); // Don't leave the key-pair behind | 46 handler.set_stores_key(false); // Don't leave the key-pair behind |
34 std::string result = handler.GenKeyAndSignChallenge(); | 47 std::string result = handler.GenKeyAndSignChallenge(); |
35 LOG(INFO) << "KeygenHandler produced: " << result; | 48 LOG(INFO) << "KeygenHandler produced: " << result; |
36 ASSERT_GT(result.length(), 0U); | 49 ASSERT_GT(result.length(), 0U); |
37 | 50 |
38 // Verify it's valid base64: | 51 // Verify it's valid base64: |
39 std::string spkac; | 52 std::string spkac; |
40 ASSERT_TRUE(base::Base64Decode(result, &spkac)); | 53 ASSERT_TRUE(base::Base64Decode(result, &spkac)); |
41 // In lieu of actually parsing and validating the DER data, | 54 // In lieu of actually parsing and validating the DER data, |
(...skipping 16 matching lines...) Expand all Loading... |
58 // Exponent: 65537 (0x10001) | 71 // Exponent: 65537 (0x10001) |
59 // Challenge String: some challenge | 72 // Challenge String: some challenge |
60 // Signature Algorithm: md5WithRSAEncryption | 73 // Signature Algorithm: md5WithRSAEncryption |
61 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: ..... | 74 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: ..... |
62 // Signature OK | 75 // Signature OK |
63 // | 76 // |
64 // The value of |spkac| can be ASN.1-parsed with: | 77 // The value of |spkac| can be ASN.1-parsed with: |
65 // openssl asn1parse -inform DER | 78 // openssl asn1parse -inform DER |
66 } | 79 } |
67 | 80 |
68 TEST(KeygenHandlerTest, Cache) { | 81 TEST_F(KeygenHandlerTest, Cache) { |
69 KeygenHandler::Cache* cache = KeygenHandler::Cache::GetInstance(); | 82 KeygenHandler::Cache* cache = KeygenHandler::Cache::GetInstance(); |
70 KeygenHandler::KeyLocation location1; | 83 KeygenHandler::KeyLocation location1; |
71 KeygenHandler::KeyLocation location2; | 84 KeygenHandler::KeyLocation location2; |
72 | 85 |
73 std::string key1("abcd"); | 86 std::string key1("abcd"); |
74 cache->Insert(key1, location1); | 87 cache->Insert(key1, location1); |
75 | 88 |
76 // The cache should have stored location1 at key1. | 89 // The cache should have stored location1 at key1. |
77 EXPECT_TRUE(cache->Find(key1, &location2)); | 90 EXPECT_TRUE(cache->Find(key1, &location2)); |
78 | 91 |
(...skipping 10 matching lines...) Expand all Loading... |
89 std::string key2("def"); | 102 std::string key2("def"); |
90 EXPECT_FALSE(cache->Find(key2, &location2)); | 103 EXPECT_FALSE(cache->Find(key2, &location2)); |
91 | 104 |
92 // A cache miss should leave the original location unmolested. | 105 // A cache miss should leave the original location unmolested. |
93 EXPECT_TRUE(location2.Equals(location3)); | 106 EXPECT_TRUE(location2.Equals(location3)); |
94 } | 107 } |
95 | 108 |
96 } // namespace | 109 } // namespace |
97 | 110 |
98 } // namespace net | 111 } // namespace net |
OLD | NEW |