Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Side by Side Diff: net/base/keygen_handler_unittest.cc

Issue 843005: Adds support for the <keygen> element to Windows, matching support present on... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Fixing remaining issues Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/keygen_handler_nss.cc ('k') | net/base/keygen_handler_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 namespace { 15 namespace {
16 16
17 KeygenHandler::Location ValidLocation() {
18 KeygenHandler::Location result;
19 #if defined(OS_WIN)
20 result.container_name = L"Unit tests";
21 result.provider_name = L"Test Provider";
22 #elif defined(OS_MACOSX)
23 result.keychain_path = "/Users/tests/test.chain";
24 #elif defined(USE_NSS)
25 result.slot_name = "Sample slot";
26 #endif
27
28 return result;
29 }
30
17 TEST(KeygenHandlerTest, FLAKY_SmokeTest) { 31 TEST(KeygenHandlerTest, FLAKY_SmokeTest) {
18 KeygenHandler handler(2048, "some challenge"); 32 KeygenHandler handler(2048, "some challenge");
19 handler.set_stores_key(false); // Don't leave the key-pair behind 33 handler.set_stores_key(false); // Don't leave the key-pair behind
20 std::string result = handler.GenKeyAndSignChallenge(); 34 std::string result = handler.GenKeyAndSignChallenge();
21 LOG(INFO) << "KeygenHandler produced: " << result; 35 LOG(INFO) << "KeygenHandler produced: " << result;
22 ASSERT_GT(result.length(), 0U); 36 ASSERT_GT(result.length(), 0U);
23 37
24 // Verify it's valid base64: 38 // Verify it's valid base64:
25 std::string spkac; 39 std::string spkac;
26 ASSERT_TRUE(base::Base64Decode(result, &spkac)); 40 ASSERT_TRUE(base::Base64Decode(result, &spkac));
(...skipping 17 matching lines...) Expand all
44 // Exponent: 65537 (0x10001) 58 // Exponent: 65537 (0x10001)
45 // Challenge String: some challenge 59 // Challenge String: some challenge
46 // Signature Algorithm: md5WithRSAEncryption 60 // Signature Algorithm: md5WithRSAEncryption
47 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: ..... 61 // 92:f3:cc:ff:0b:d3:d0:4a:3a:4c:ba:ff:d6:38:7f:a5:4b:b5: .....
48 // Signature OK 62 // Signature OK
49 // 63 //
50 // The value of |spkac| can be ASN.1-parsed with: 64 // The value of |spkac| can be ASN.1-parsed with:
51 // openssl asn1parse -inform DER 65 // openssl asn1parse -inform DER
52 } 66 }
53 67
68 TEST(KeygenHandlerTest, Cache) {
69 KeygenHandler::Cache* cache = KeygenHandler::Cache::GetInstance();
70 KeygenHandler::Location location1;
71 KeygenHandler::Location location2;
72
73 std::string key1("abcd");
74 cache->Insert(key1, location1);
75
76 // The cache should have stored location1 at key1
77 EXPECT_TRUE(cache->Find(key1, &location2));
78
79 // The cache should have retrieved it into location2, and their equality
80 // should be reflexive
81 EXPECT_TRUE(location1.Equals(location2));
82 EXPECT_TRUE(location2.Equals(location1));
83
84 location2 = ValidLocation();
85 KeygenHandler::KeyCache::KeyLocation location3 = ValidLocation();
86 EXPECT_FALSE(location1.Equals(location2));
87
88 // The cache should miss for an unregistered key
89 std::string key2("def");
90 EXPECT_FALSE(cache->Find(key2, &location2));
91
92 // A cache miss should leave the original location unmolested
93 EXPECT_TRUE(location2.Equals(location3));
94 }
95
54 } // namespace 96 } // namespace
55 97
56 } // namespace net 98 } // namespace net
OLDNEW
« no previous file with comments | « net/base/keygen_handler_nss.cc ('k') | net/base/keygen_handler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698