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

Side by Side Diff: net/cert/x509_util_unittest.cc

Issue 2084153003: Remove the test-only X509Certificate constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 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
« no previous file with comments | « net/cert/x509_certificate.cc ('k') | net/ssl/ssl_client_auth_cache_unittest.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/x509_util.h" 5 #include "net/cert/x509_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "crypto/rsa_private_key.h" 12 #include "crypto/rsa_private_key.h"
13 #include "net/cert/x509_certificate.h" 13 #include "net/cert/x509_certificate.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace x509_util { 18 namespace x509_util {
19 19
20 TEST(X509UtilTest, SortClientCertificates) { 20 TEST(X509UtilTest, SortClientCertificates) {
21 CertificateList certs; 21 CertificateList certs;
22 certs.push_back(nullptr);
23
24 std::unique_ptr<crypto::RSAPrivateKey> key(
25 crypto::RSAPrivateKey::Create(1024));
26 ASSERT_TRUE(key);
27
28 scoped_refptr<X509Certificate> cert;
29 std::string der_cert;
30
31 ASSERT_TRUE(CreateSelfSignedCert(key.get(), x509_util::DIGEST_SHA1,
32 "CN=expired", 1, base::Time::UnixEpoch(),
33 base::Time::UnixEpoch(), &der_cert));
34 cert = X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
35 ASSERT_TRUE(cert);
36 certs.push_back(cert);
22 37
23 const base::Time now = base::Time::Now(); 38 const base::Time now = base::Time::Now();
24 const base::TimeDelta five_days = base::TimeDelta::FromDays(5);
25 39
26 certs.push_back(scoped_refptr<X509Certificate>(NULL)); 40 ASSERT_TRUE(CreateSelfSignedCert(
27 certs.push_back(new X509Certificate( 41 key.get(), x509_util::DIGEST_SHA1, "CN=not yet valid", 2,
28 "expired", "expired", 42 now + base::TimeDelta::FromDays(10), now + base::TimeDelta::FromDays(15),
29 base::Time::UnixEpoch(), base::Time::UnixEpoch())); 43 &der_cert));
30 certs.push_back(new X509Certificate( 44 cert = X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
31 "not yet valid", "not yet valid", 45 ASSERT_TRUE(cert);
32 base::Time::Max(), base::Time::Max())); 46 certs.push_back(cert);
33 certs.push_back(new X509Certificate( 47
34 "older cert", "older cert", 48 ASSERT_TRUE(
35 now - five_days, now + five_days)); 49 CreateSelfSignedCert(key.get(), x509_util::DIGEST_SHA1, "CN=older cert",
36 certs.push_back(scoped_refptr<X509Certificate>(NULL)); 50 3, now - base::TimeDelta::FromDays(5),
37 certs.push_back(new X509Certificate( 51 now + base::TimeDelta::FromDays(5), &der_cert));
38 "newer cert", "newer cert", 52 cert = X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
39 now - base::TimeDelta::FromDays(3), now + five_days)); 53 ASSERT_TRUE(cert);
54 certs.push_back(cert);
55
56 certs.push_back(nullptr);
57
58 ASSERT_TRUE(
59 CreateSelfSignedCert(key.get(), x509_util::DIGEST_SHA1, "CN=newer cert",
60 2, now - base::TimeDelta::FromDays(3),
61 now + base::TimeDelta::FromDays(5), &der_cert));
62 cert = X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
63 ASSERT_TRUE(cert);
64 certs.push_back(cert);
40 65
41 std::sort(certs.begin(), certs.end(), ClientCertSorter()); 66 std::sort(certs.begin(), certs.end(), ClientCertSorter());
42 67
68 ASSERT_EQ(6u, certs.size());
43 ASSERT_TRUE(certs[0].get()); 69 ASSERT_TRUE(certs[0].get());
44 EXPECT_EQ("newer cert", certs[0]->subject().common_name); 70 EXPECT_EQ("newer cert", certs[0]->subject().common_name);
45 ASSERT_TRUE(certs[1].get()); 71 ASSERT_TRUE(certs[1].get());
46 EXPECT_EQ("older cert", certs[1]->subject().common_name); 72 EXPECT_EQ("older cert", certs[1]->subject().common_name);
47 ASSERT_TRUE(certs[2].get()); 73 ASSERT_TRUE(certs[2].get());
48 EXPECT_EQ("not yet valid", certs[2]->subject().common_name); 74 EXPECT_EQ("not yet valid", certs[2]->subject().common_name);
49 ASSERT_TRUE(certs[3].get()); 75 ASSERT_TRUE(certs[3].get());
50 EXPECT_EQ("expired", certs[3]->subject().common_name); 76 EXPECT_EQ("expired", certs[3]->subject().common_name);
51 ASSERT_FALSE(certs[4].get()); 77 ASSERT_FALSE(certs[4].get());
52 ASSERT_FALSE(certs[5].get()); 78 ASSERT_FALSE(certs[5].get());
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 720
695 std::string channel_bindings; 721 std::string channel_bindings;
696 ASSERT_FALSE( 722 ASSERT_FALSE(
697 x509_util::GetTLSServerEndPointChannelBinding(*cert, &channel_bindings)); 723 x509_util::GetTLSServerEndPointChannelBinding(*cert, &channel_bindings));
698 EXPECT_TRUE(channel_bindings.empty()); 724 EXPECT_TRUE(channel_bindings.empty());
699 } 725 }
700 726
701 } // namespace x509_util 727 } // namespace x509_util
702 728
703 } // namespace net 729 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/x509_certificate.cc ('k') | net/ssl/ssl_client_auth_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698