| 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 "base/nss_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 KeygenHandler::KeyLocation ValidKeyLocation() { | |
| 19 KeygenHandler::KeyLocation result; | |
| 20 #if defined(OS_WIN) | |
| 21 result.container_name = L"Unit tests"; | |
| 22 result.provider_name = L"Test Provider"; | |
| 23 #elif defined(OS_MACOSX) | |
| 24 result.keychain_path = "/Users/tests/test.chain"; | |
| 25 #elif defined(USE_NSS) | |
| 26 result.slot_name = "Sample slot"; | |
| 27 #endif | |
| 28 | |
| 29 return result; | |
| 30 } | |
| 31 | |
| 32 class KeygenHandlerTest : public ::testing::Test { | 18 class KeygenHandlerTest : public ::testing::Test { |
| 33 public: | 19 public: |
| 34 KeygenHandlerTest() {} | 20 KeygenHandlerTest() {} |
| 35 virtual ~KeygenHandlerTest() {} | 21 virtual ~KeygenHandlerTest() {} |
| 36 | 22 |
| 37 virtual void SetUp() { | 23 virtual void SetUp() { |
| 38 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 39 base::OpenPersistentNSSDB(); | 25 base::OpenPersistentNSSDB(); |
| 40 #endif | 26 #endif |
| 41 } | 27 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 71 // Exponent: 65537 (0x10001) | 57 // Exponent: 65537 (0x10001) |
| 72 // Challenge String: some challenge | 58 // Challenge String: some challenge |
| 73 // Signature Algorithm: md5WithRSAEncryption | 59 // Signature Algorithm: md5WithRSAEncryption |
| 74 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: ..... | 60 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: ..... |
| 75 // Signature OK | 61 // Signature OK |
| 76 // | 62 // |
| 77 // The value of |spkac| can be ASN.1-parsed with: | 63 // The value of |spkac| can be ASN.1-parsed with: |
| 78 // openssl asn1parse -inform DER | 64 // openssl asn1parse -inform DER |
| 79 } | 65 } |
| 80 | 66 |
| 81 TEST_F(KeygenHandlerTest, Cache) { | |
| 82 KeygenHandler::Cache* cache = KeygenHandler::Cache::GetInstance(); | |
| 83 KeygenHandler::KeyLocation location1; | |
| 84 KeygenHandler::KeyLocation location2; | |
| 85 | |
| 86 std::string key1("abcd"); | |
| 87 cache->Insert(key1, location1); | |
| 88 | |
| 89 // The cache should have stored location1 at key1. | |
| 90 EXPECT_TRUE(cache->Find(key1, &location2)); | |
| 91 | |
| 92 // The cache should have retrieved it into location2, and their equality | |
| 93 // should be reflexive. | |
| 94 EXPECT_TRUE(location1.Equals(location2)); | |
| 95 EXPECT_TRUE(location2.Equals(location1)); | |
| 96 | |
| 97 location2 = ValidKeyLocation(); | |
| 98 KeygenHandler::KeyLocation location3 = ValidKeyLocation(); | |
| 99 EXPECT_FALSE(location1.Equals(location2)); | |
| 100 | |
| 101 // The cache should miss for an unregistered key. | |
| 102 std::string key2("def"); | |
| 103 EXPECT_FALSE(cache->Find(key2, &location2)); | |
| 104 | |
| 105 // A cache miss should leave the original location unmolested. | |
| 106 EXPECT_TRUE(location2.Equals(location3)); | |
| 107 } | |
| 108 | |
| 109 } // namespace | 67 } // namespace |
| 110 | 68 |
| 111 } // namespace net | 69 } // namespace net |
| OLD | NEW |