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

Side by Side Diff: net/cert/internal/trust_store_collection_unittest.cc

Issue 2832703002: Allow the TrustStore interface to return matching intermediates, and identify distrusted certs. (Closed)
Patch Set: mac fix Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/cert/internal/trust_store_collection.h" 5 #include "net/cert/internal/trust_store_collection.h"
6 6
7 #include "net/cert/internal/test_helpers.h" 7 #include "net/cert/internal/test_helpers.h"
8 #include "net/cert/internal/trust_store_in_memory.h" 8 #include "net/cert/internal/trust_store_in_memory.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 scoped_refptr<TrustAnchor> newroot_; 52 scoped_refptr<TrustAnchor> newroot_;
53 scoped_refptr<TrustAnchor> newrootrollover_; 53 scoped_refptr<TrustAnchor> newrootrollover_;
54 54
55 scoped_refptr<ParsedCertificate> target_; 55 scoped_refptr<ParsedCertificate> target_;
56 scoped_refptr<ParsedCertificate> oldintermediate_; 56 scoped_refptr<ParsedCertificate> oldintermediate_;
57 scoped_refptr<ParsedCertificate> newintermediate_; 57 scoped_refptr<ParsedCertificate> newintermediate_;
58 }; 58 };
59 59
60 // Collection contains no stores, should return no results. 60 // Collection contains no stores, should return no results.
61 TEST_F(TrustStoreCollectionTest, NoStores) { 61 TEST_F(TrustStoreCollectionTest, NoStores) {
62 TrustAnchors matches; 62 TrustAnchors anchors;
63 ParsedCertificateList intermediates;
63 64
64 TrustStoreCollection collection; 65 TrustStoreCollection collection;
65 collection.FindTrustAnchorsForCert(target_, &matches); 66 collection.FindIssuers(target_, &anchors, &intermediates);
66 67
67 EXPECT_TRUE(matches.empty()); 68 EXPECT_TRUE(anchors.empty());
69 EXPECT_TRUE(intermediates.empty());
68 } 70 }
69 71
70 // Collection contains only one store. 72 // Collection contains only one store.
71 TEST_F(TrustStoreCollectionTest, OneStore) { 73 TEST_F(TrustStoreCollectionTest, OneStore) {
72 TrustAnchors matches; 74 TrustAnchors anchors;
75 ParsedCertificateList intermediates;
73 76
74 TrustStoreCollection collection; 77 TrustStoreCollection collection;
75 TrustStoreInMemory in_memory; 78 TrustStoreInMemory in_memory;
76 in_memory.AddTrustAnchor(newroot_); 79 in_memory.AddTrustAnchor(newroot_);
77 collection.AddTrustStore(&in_memory); 80 collection.AddTrustStore(&in_memory);
78 collection.FindTrustAnchorsForCert(newintermediate_, &matches); 81 collection.FindIssuers(newintermediate_, &anchors, &intermediates);
mattm 2017/04/20 03:19:07 These tests should all check the returned intermed
79 82
80 ASSERT_EQ(1U, matches.size()); 83 ASSERT_EQ(1U, anchors.size());
81 EXPECT_EQ(newroot_, matches[0]); 84 EXPECT_EQ(newroot_, anchors[0]);
85 }
86
87 // LookupCert() should append to its output parameters rather than assign them.
88 TEST_F(TrustStoreCollectionTest, OutputVectorsAppendedTo) {
89 TrustAnchors anchors;
90 ParsedCertificateList intermediates;
91
92 // Populate the out-parameters with some values.
93 anchors.resize(3);
94 intermediates.resize(5);
95
96 TrustStoreCollection collection;
97 TrustStoreInMemory in_memory;
98 in_memory.AddTrustAnchor(newroot_);
99 collection.AddTrustStore(&in_memory);
100 collection.FindIssuers(newintermediate_, &anchors, &intermediates);
101
102 ASSERT_EQ(4U, anchors.size());
103 EXPECT_EQ(newroot_, anchors[3]);
82 } 104 }
83 105
84 // Collection contains two stores. 106 // Collection contains two stores.
85 TEST_F(TrustStoreCollectionTest, TwoStores) { 107 TEST_F(TrustStoreCollectionTest, TwoStores) {
86 TrustAnchors matches; 108 TrustAnchors anchors;
109 ParsedCertificateList intermediates;
87 110
88 TrustStoreCollection collection; 111 TrustStoreCollection collection;
89 TrustStoreInMemory in_memory1; 112 TrustStoreInMemory in_memory1;
90 TrustStoreInMemory in_memory2; 113 TrustStoreInMemory in_memory2;
91 in_memory1.AddTrustAnchor(newroot_); 114 in_memory1.AddTrustAnchor(newroot_);
92 in_memory2.AddTrustAnchor(oldroot_); 115 in_memory2.AddTrustAnchor(oldroot_);
93 collection.AddTrustStore(&in_memory1); 116 collection.AddTrustStore(&in_memory1);
94 collection.AddTrustStore(&in_memory2); 117 collection.AddTrustStore(&in_memory2);
95 collection.FindTrustAnchorsForCert(newintermediate_, &matches); 118 collection.FindIssuers(newintermediate_, &anchors, &intermediates);
96 119
97 ASSERT_EQ(2U, matches.size()); 120 ASSERT_EQ(2U, anchors.size());
98 EXPECT_EQ(newroot_, matches[0]); 121 EXPECT_EQ(newroot_, anchors[0]);
99 EXPECT_EQ(oldroot_, matches[1]); 122 EXPECT_EQ(oldroot_, anchors[1]);
100 } 123 }
101 124
102 } // namespace 125 } // namespace
103 126
104 } // namespace net 127 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698