OLD | NEW |
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/cert_issuer_source_static.h" | 5 #include "net/cert/internal/cert_issuer_source_static.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/cert/internal/parsed_certificate.h" | 8 #include "net/cert/internal/parsed_certificate.h" |
9 #include "net/cert/internal/test_helpers.h" | 9 #include "net/cert/internal/test_helpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 scoped_refptr<ParsedCertificate> i2_; | 71 scoped_refptr<ParsedCertificate> i2_; |
72 scoped_refptr<ParsedCertificate> c1_; | 72 scoped_refptr<ParsedCertificate> c1_; |
73 scoped_refptr<ParsedCertificate> c2_; | 73 scoped_refptr<ParsedCertificate> c2_; |
74 scoped_refptr<ParsedCertificate> d_; | 74 scoped_refptr<ParsedCertificate> d_; |
75 }; | 75 }; |
76 | 76 |
77 TEST_F(CertIssuerSourceStaticTest, NoMatch) { | 77 TEST_F(CertIssuerSourceStaticTest, NoMatch) { |
78 CertIssuerSourceStatic source; | 78 CertIssuerSourceStatic source; |
79 source.AddCert(root_); | 79 source.AddCert(root_); |
80 | 80 |
81 std::vector<scoped_refptr<ParsedCertificate>> issuers; | 81 ParsedCertificateList issuers; |
82 source.SyncGetIssuersOf(c1_.get(), &issuers); | 82 source.SyncGetIssuersOf(c1_.get(), &issuers); |
83 ASSERT_EQ(0U, issuers.size()); | 83 ASSERT_EQ(0U, issuers.size()); |
84 } | 84 } |
85 | 85 |
86 TEST_F(CertIssuerSourceStaticTest, OneMatch) { | 86 TEST_F(CertIssuerSourceStaticTest, OneMatch) { |
87 CertIssuerSourceStatic source; | 87 CertIssuerSourceStatic source; |
88 AddAllCerts(&source); | 88 AddAllCerts(&source); |
89 | 89 |
90 std::vector<scoped_refptr<ParsedCertificate>> issuers; | 90 ParsedCertificateList issuers; |
91 source.SyncGetIssuersOf(i1_1_.get(), &issuers); | 91 source.SyncGetIssuersOf(i1_1_.get(), &issuers); |
92 ASSERT_EQ(1U, issuers.size()); | 92 ASSERT_EQ(1U, issuers.size()); |
93 EXPECT_TRUE(issuers[0] == root_); | 93 EXPECT_TRUE(issuers[0] == root_); |
94 | 94 |
95 issuers.clear(); | 95 issuers.clear(); |
96 source.SyncGetIssuersOf(d_.get(), &issuers); | 96 source.SyncGetIssuersOf(d_.get(), &issuers); |
97 ASSERT_EQ(1U, issuers.size()); | 97 ASSERT_EQ(1U, issuers.size()); |
98 EXPECT_TRUE(issuers[0] == i2_); | 98 EXPECT_TRUE(issuers[0] == i2_); |
99 } | 99 } |
100 | 100 |
101 TEST_F(CertIssuerSourceStaticTest, MultipleMatches) { | 101 TEST_F(CertIssuerSourceStaticTest, MultipleMatches) { |
102 CertIssuerSourceStatic source; | 102 CertIssuerSourceStatic source; |
103 AddAllCerts(&source); | 103 AddAllCerts(&source); |
104 | 104 |
105 std::vector<scoped_refptr<ParsedCertificate>> issuers; | 105 ParsedCertificateList issuers; |
106 source.SyncGetIssuersOf(c1_.get(), &issuers); | 106 source.SyncGetIssuersOf(c1_.get(), &issuers); |
107 | 107 |
108 ASSERT_EQ(2U, issuers.size()); | 108 ASSERT_EQ(2U, issuers.size()); |
109 EXPECT_TRUE(std::find(issuers.begin(), issuers.end(), i1_1_) != | 109 EXPECT_TRUE(std::find(issuers.begin(), issuers.end(), i1_1_) != |
110 issuers.end()); | 110 issuers.end()); |
111 EXPECT_TRUE(std::find(issuers.begin(), issuers.end(), i1_2_) != | 111 EXPECT_TRUE(std::find(issuers.begin(), issuers.end(), i1_2_) != |
112 issuers.end()); | 112 issuers.end()); |
113 } | 113 } |
114 | 114 |
115 // Searching for the issuer of a self-issued cert returns the same cert if it | 115 // Searching for the issuer of a self-issued cert returns the same cert if it |
116 // happens to be in the CertIssuerSourceStatic. | 116 // happens to be in the CertIssuerSourceStatic. |
117 // Conceptually this makes sense, though probably not very useful in practice. | 117 // Conceptually this makes sense, though probably not very useful in practice. |
118 // Doesn't hurt anything though. | 118 // Doesn't hurt anything though. |
119 TEST_F(CertIssuerSourceStaticTest, SelfIssued) { | 119 TEST_F(CertIssuerSourceStaticTest, SelfIssued) { |
120 CertIssuerSourceStatic source; | 120 CertIssuerSourceStatic source; |
121 AddAllCerts(&source); | 121 AddAllCerts(&source); |
122 | 122 |
123 std::vector<scoped_refptr<ParsedCertificate>> issuers; | 123 ParsedCertificateList issuers; |
124 source.SyncGetIssuersOf(root_.get(), &issuers); | 124 source.SyncGetIssuersOf(root_.get(), &issuers); |
125 | 125 |
126 ASSERT_EQ(1U, issuers.size()); | 126 ASSERT_EQ(1U, issuers.size()); |
127 EXPECT_TRUE(issuers[0] == root_); | 127 EXPECT_TRUE(issuers[0] == root_); |
128 } | 128 } |
129 | 129 |
130 // CertIssuerSourceStatic never returns results asynchronously. | 130 // CertIssuerSourceStatic never returns results asynchronously. |
131 TEST_F(CertIssuerSourceStaticTest, IsNotAsync) { | 131 TEST_F(CertIssuerSourceStaticTest, IsNotAsync) { |
132 CertIssuerSourceStatic source; | 132 CertIssuerSourceStatic source; |
133 source.AddCert(i1_1_); | 133 source.AddCert(i1_1_); |
134 std::unique_ptr<CertIssuerSource::Request> request; | 134 std::unique_ptr<CertIssuerSource::Request> request; |
135 source.AsyncGetIssuersOf(c1_.get(), base::Bind(&NotCalled), &request); | 135 source.AsyncGetIssuersOf(c1_.get(), base::Bind(&NotCalled), &request); |
136 EXPECT_EQ(nullptr, request); | 136 EXPECT_EQ(nullptr, request); |
137 } | 137 } |
138 | 138 |
139 } // namespace | 139 } // namespace |
140 | 140 |
141 } // namespace net | 141 } // namespace net |
OLD | NEW |