| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/x509_util.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/time.h" | |
| 10 #include "net/base/x509_certificate.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 namespace x509_util { | |
| 16 | |
| 17 TEST(X509UtilTest, SortClientCertificates) { | |
| 18 CertificateList certs; | |
| 19 | |
| 20 const base::Time now = base::Time::Now(); | |
| 21 const base::TimeDelta five_days = base::TimeDelta::FromDays(5); | |
| 22 | |
| 23 certs.push_back(scoped_refptr<X509Certificate>(NULL)); | |
| 24 certs.push_back(new X509Certificate( | |
| 25 "expired", "expired", | |
| 26 base::Time::UnixEpoch(), base::Time::UnixEpoch())); | |
| 27 certs.push_back(new X509Certificate( | |
| 28 "not yet valid", "not yet valid", | |
| 29 base::Time::Max(), base::Time::Max())); | |
| 30 certs.push_back(new X509Certificate( | |
| 31 "older cert", "older cert", | |
| 32 now - five_days, now + five_days)); | |
| 33 certs.push_back(scoped_refptr<X509Certificate>(NULL)); | |
| 34 certs.push_back(new X509Certificate( | |
| 35 "newer cert", "newer cert", | |
| 36 now - base::TimeDelta::FromDays(3), now + five_days)); | |
| 37 | |
| 38 std::sort(certs.begin(), certs.end(), ClientCertSorter()); | |
| 39 | |
| 40 ASSERT_TRUE(certs[0].get()); | |
| 41 EXPECT_EQ("newer cert", certs[0]->subject().common_name); | |
| 42 ASSERT_TRUE(certs[1].get()); | |
| 43 EXPECT_EQ("older cert", certs[1]->subject().common_name); | |
| 44 ASSERT_TRUE(certs[2].get()); | |
| 45 EXPECT_EQ("not yet valid", certs[2]->subject().common_name); | |
| 46 ASSERT_TRUE(certs[3].get()); | |
| 47 EXPECT_EQ("expired", certs[3]->subject().common_name); | |
| 48 ASSERT_FALSE(certs[4].get()); | |
| 49 ASSERT_FALSE(certs[5].get()); | |
| 50 } | |
| 51 | |
| 52 } // namespace x509_util | |
| 53 | |
| 54 } // namespace net | |
| OLD | NEW |